/* ===========================================================================
   University of Chichester — Bus Timetable

   Palette:
     --navy     #1D2160  UoC primary navy (used for header, accents)
     --gold     #C9A436  UoC warm gold (highlights, line badges)
     --page-bg  #F2F4F8  off-white page background
     --card-bg  #FFFFFF  board card
     --text     #1A1A2E  near-black body copy
     --muted    #6B7280  secondary / label text
     --border   #DDE3EC  light rule
     --live     #1A7C3E  on-time green
     --row-alt  #F8FAFC  alternating row tint

   Type: "Source Sans 3" for a clean, readable academic feel;
   "JetBrains Mono" for times and line numbers.

   Responsive: fluid layout with clamp(); body[data-tv] for kiosk / wall display.
   =========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600;700&family=JetBrains+Mono:wght@500;600;700&display=swap');

:root {
  --navy:    #1D2160;
  --navy-dk: #141749;
  --gold:    #C9A436;
  --gold-lt: #F5E9C4;
  --page-bg: #F2F4F8;
  --card-bg: #FFFFFF;
  --text:    #1A1A2E;
  --muted:   #6B7280;
  --border:  #DDE3EC;
  --live:    #1A7C3E;
  --row-alt: #F8FAFC;

  --display: 'Source Sans 3', system-ui, sans-serif;
  --mono:    'JetBrains Mono', ui-monospace, monospace;

  --maxw: 1000px;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--display);
  min-height: 100vh;
  line-height: 1.4;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Site header ----------------------------------------------------------- */

.topbar {
  background: var(--card-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.6rem clamp(1rem, 3vw, 2rem);
  border-bottom: 3px solid var(--gold);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.brand-logo {
  height: clamp(1.9rem, 4vw, 2.5rem);
  width: auto;
  display: block;
  flex-shrink: 0;
}
.brand-text {
  font-size: clamp(0.95rem, 1.1vw + 0.7rem, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--navy);
  padding-left: 0.65rem;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

.stop-nav { display: flex; gap: 0.4rem; flex-wrap: wrap; padding: 0.35rem 0; }
.stop-nav a {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(0.8rem, 0.9vw + 0.6rem, 0.95rem);
  text-decoration: none;
  color: var(--navy);
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.stop-nav a:hover {
  border-color: var(--navy);
  background: var(--gold-lt);
}
.stop-nav a[aria-current='page'] {
  color: var(--navy);
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 700;
}
.stop-nav a:focus-visible { outline: 2px solid var(--navy); outline-offset: 3px; }

@media (max-width: 480px) {
  .topbar { padding: 0.5rem 1rem; gap: 0.4rem 0.75rem; }
  .brand-logo { height: 1.6rem; }
  .brand-text { display: none; }
  .stop-nav { padding: 0.15rem 0 0.35rem; }
  .stop-nav a { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
}

/* --- Board ----------------------------------------------------------------- */

main.board {
  flex: 1;
  padding: clamp(1rem, 3vw, 2rem);
}

.board-inner {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(29, 33, 96, 0.08), 0 1px 3px rgba(0,0,0,0.06);
}

.board-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1rem, 2.5vw, 1.5rem) clamp(1rem, 2.5vw, 1.75rem);
  border-bottom: 1px solid var(--border);
  background: var(--card-bg);
}

.eyebrow {
  font-size: clamp(0.68rem, 0.75vw + 0.5rem, 0.8rem);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 0.3rem;
}
.title {
  font-size: clamp(1.5rem, 2.5vw + 0.9rem, 2.4rem);
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}
.subtitle {
  color: var(--muted);
  font-size: clamp(0.875rem, 1vw + 0.65rem, 1.05rem);
  margin-top: 0.2rem;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: clamp(0.72rem, 0.75vw + 0.52rem, 0.85rem);
  white-space: nowrap;
  background: var(--row-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  align-self: flex-start;
  margin-top: 0.2rem;
}
.dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.status.is-live .dot { background: var(--live); animation: pulse 2s infinite; }
.status.is-live { color: var(--live); border-color: rgba(26,124,62,0.25); background: rgba(26,124,62,0.06); }
.status.is-stale .dot { background: var(--gold); }
.status.is-stale { color: #8a6700; border-color: rgba(201,164,54,0.3); background: var(--gold-lt); }
.status.is-error .dot { background: #dc2626; }
.status.is-error { color: #dc2626; border-color: rgba(220,38,38,0.2); background: rgba(220,38,38,0.05); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(26, 124, 62, 0.45); }
  50%       { box-shadow: 0 0 0 0.35rem rgba(26, 124, 62, 0); }
}

/* --- Column headers -------------------------------------------------------- */

.dep-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  padding: 0.45rem clamp(1rem, 2.5vw, 1.75rem);
  background: var(--navy);
  color: rgba(255,255,255,0.65);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* --- Departure rows -------------------------------------------------------- */

.departures { list-style: none; }

.dep {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  padding: clamp(0.65rem, 1.5vw, 1rem) clamp(1rem, 2.5vw, 1.75rem);
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.dep:nth-child(even) { background: var(--row-alt); }
.dep:last-child { border-bottom: 0; }
.dep:hover { background: rgba(29,33,96,0.04); }

.line {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(0.9rem, 1.3vw + 0.6rem, 1.25rem);
  line-height: 1;
  color: var(--navy);
  background: var(--gold-lt);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 0.3em 0.55em;
  min-width: 2.8em;
  text-align: center;
}

.dest {
  min-width: 0;
  font-size: clamp(1rem, 1.3vw + 0.7rem, 1.3rem);
  font-weight: 600;
  color: var(--text);
}
.dest .operator {
  display: block;
  font-size: 0.7em;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: 0.1rem;
}

.when {
  text-align: right;
  white-space: nowrap;
}
.eta {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.3rem, 2vw + 0.75rem, 2.1rem);
  line-height: 1;
  color: var(--navy);
}
.eta .unit {
  font-size: 0.45em;
  color: var(--muted);
  margin-left: 0.1em;
}
.clock {
  display: block;
  font-family: var(--mono);
  font-size: clamp(0.75rem, 0.8vw + 0.55rem, 0.9rem);
  color: var(--muted);
  margin-top: 0.2rem;
}
.dep.is-live .eta { color: var(--live); }
.dep.is-due .eta  { color: #b45309; }
.dep.is-due .line { background: #FEF3C7; border-color: #D97706; color: #92400E; }

/* Empty / placeholder row */
.empty {
  padding: clamp(2rem, 5vw, 3.5rem);
  text-align: center;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.2vw + 0.7rem, 1.2rem);
}

/* --- Footer ---------------------------------------------------------------- */

.board-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: clamp(0.75rem, 1.5vw, 1.1rem) clamp(1rem, 2.5vw, 1.75rem);
  border-top: 1px solid var(--border);
  background: var(--row-alt);
}
.updated {
  font-family: var(--mono);
  color: var(--muted);
  font-size: clamp(0.7rem, 0.75vw + 0.52rem, 0.85rem);
}
.links { display: flex; gap: 1rem; flex-wrap: wrap; }
.links a {
  color: var(--muted);
  text-decoration: none;
  font-size: clamp(0.75rem, 0.8vw + 0.55rem, 0.9rem);
  border-bottom: 1px solid transparent;
  transition: color 0.12s, border-color 0.12s;
}
.links a:hover { color: var(--navy); border-bottom-color: var(--navy); }
.links a:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

/* --- Page footer ----------------------------------------------------------- */

.site-foot {
  text-align: center;
  padding: 1.25rem clamp(1rem, 3vw, 2rem);
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.site-foot a { color: var(--navy); text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }

/* --- TV / kiosk mode (?tv=1) ----------------------------------------------- */

body[data-tv] {
  /* No width cap — previously 1600px, which left huge empty margins on a
     4K (3840px) screen instead of using the space. */
  --maxw: 100%;
  /* Lock to exactly one screen's height with no scroll — a wall display has
     no way to scroll, so anything taller than the viewport must instead
     shrink to fit rather than run off the bottom. */
  height: 100vh;
  overflow: hidden;
}
body[data-tv] #app { height: 100vh; }
body[data-tv] .stop-nav { display: none; }
/* Extra headroom above the logo — some TVs crop the very top edge of the
   picture (overscan), which otherwise clips the brand row. */
body[data-tv] .topbar { padding-top: clamp(1.5rem, 3vw, 2.5rem); flex-shrink: 0; }
body[data-tv] main.board {
  padding: clamp(1rem, 2vw, 3rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* board-inner and departures become flex columns so the row list is exactly
   as tall as "available space" and no taller — N rows always divide that
   space evenly between them, whatever N and whatever the screen's actual
   height turn out to be. */
body[data-tv] .board-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
body[data-tv] .board-head,
body[data-tv] .dep-header,
body[data-tv] .board-foot {
  flex-shrink: 0;
}
body[data-tv] .departures {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body[data-tv] .dep {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

/* The vw-driven sizes below previously capped out around a 1645px viewport
   (i.e. before even 1080p), so on any real TV — let alone 4K — text just
   stopped growing at an HD-tuned size. Raising the clamp() ceilings lets
   everything keep scaling with the screen instead of plateauing early. */
body[data-tv] .eyebrow  { font-size: clamp(0.8rem, 1.1vw, 1.8rem); }
body[data-tv] .title    { font-size: clamp(2.2rem, 3.5vw, 7rem); }
body[data-tv] .subtitle { font-size: clamp(0.9rem, 1.3vw, 2rem); }
body[data-tv] .status   { font-size: clamp(0.85rem, 1.1vw, 1.8rem); padding: 0.5em 1em; }

body[data-tv] .dep-header {
  font-size: clamp(0.72rem, 1vw, 1.6rem);
  padding: clamp(0.45rem, 1vw, 1.2rem) clamp(1rem, 2.5vw, 1.75rem);
}

/* These size the content of a row, and each row's actual height is capped
   by the flexbox above (available space / number of rows) — so they need
   to track viewport *height*, not width. A wide-but-short screen and a
   narrow-but-tall one can have the same width yet very different row
   budgets; vw has no way to reflect that, vh does. */
body[data-tv] .dest            { font-size: clamp(1.3rem, 3.2vh, 3.4rem); }
body[data-tv] .dest .operator  { font-size: clamp(0.55rem, 1.3vh, 1.3rem); }
body[data-tv] .line            { font-size: clamp(1.4rem, 3.4vh, 3.6rem); }
body[data-tv] .eta             { font-size: clamp(1.8rem, 4.2vh, 4.6rem); }
body[data-tv] .clock           { font-size: clamp(0.65rem, 1.4vh, 1.4rem); }
body[data-tv] .dep {
  padding-top:    clamp(0.4rem, 1.8vh, 1.6rem);
  padding-bottom: clamp(0.4rem, 1.8vh, 1.6rem);
}

body[data-tv] .updated  { font-size: clamp(0.7rem, 0.9vw, 1.6rem); }
body[data-tv] .links a  { font-size: clamp(0.75rem, 0.9vw, 1.6rem); }

/* --- Accessibility --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
