/* Millbrook Horse Trials — public live page.
   Tokens are lifted from broadcast/brand-packs/millbrook.json (v2.0, "The
   Meadow Line"): forest ground, bone ink, flag orange as the single live
   accent, Newsreader for names and Archivo for data. */

:root {
  --forest:        #123A26;
  --forest-dim:    #0C2719;
  --forest-bright: #1B5237;
  --meadow:        #5F9B54;
  --meadow-dim:    #3F6E39;
  --sage:          #AAC59B;
  --bone:          #ECE5D0;
  --bone-dim:      #DAD0B4;
  --flag:          #E1512A;
  --flag-dim:      #B23C1C;
  --surface:       #0E140C;
  --surface-a92:   rgba(14, 20, 12, .92);
  --hairline:      #2A3626;
  --smoke:         #5A6455;

  --display: 'Newsreader', Spectral, 'Iowan Old Style', Georgia, serif;
  --sans: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --radius: 10px;
  --gutter: clamp(16px, 3vw, 28px);
}

* { box-sizing: border-box; }

/* Any rule that sets `display` outranks the UA's `[hidden] { display: none }`,
   so .pip (inline-flex) and .stat-row (grid) rendered while hidden — which put
   a permanent "LIVE" badge on a page that was not live. A badge that lies is
   worse than no badge. This makes the attribute mean what it says. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--forest-dim);
  color: var(--bone);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  /* A single soft horizon glow so the page reads as a field at dawn rather
     than a black app chrome. */
  background:
    radial-gradient(120% 60% at 50% 0%, var(--forest) 0%, var(--forest-dim) 62%) no-repeat;
  background-attachment: fixed;
}

/* ---------------------------------------------------------------- masthead */

.masthead { padding-top: env(safe-area-inset-top); }

.masthead-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px var(--gutter) 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.wordmark { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.wordmark-name {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(24px, 3.4vw, 38px);
  letter-spacing: -.015em;
  line-height: 1;
}

.wordmark-sub {
  font-family: var(--sans);
  font-weight: 600;
  font-size: clamp(10px, 1.2vw, 12px);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--sage);
  white-space: nowrap;
}

.masthead-right { display: flex; align-items: center; gap: 14px; flex: none; }

.pip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .16em;
  padding: 5px 10px;
  border-radius: 4px;
  background: var(--flag);
  color: var(--bone);
}

.pip-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--bone);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pip-dot { animation: none; } }

.viewers {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--sage);
}

.meadow { display: block; width: 100%; height: 26px; }

/* ------------------------------------------------------------------ layout */

.shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 var(--gutter) 40px;
}

.stage { padding-top: 22px; }

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .columns { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ player */

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  /* On a laptop a full-width 16:9 frame is ~730px tall and pushes the rider
     card off screen — the whole point of the page is seeing both at once. Bound
     the WIDTH by the height budget (rather than capping height, which would
     just letterbox inside an over-wide box) so the frame shrinks in proportion
     and stays centred. */
  width: min(100%, calc((100dvh - 320px) * 16 / 9));
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--hairline);
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, .9);
}

.player video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }

.player-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--forest) 0%, var(--forest-dim) 100%);
  text-align: center;
  padding: 24px;
}

.player-overlay[hidden] { display: none; }

.offline-title {
  font-family: var(--display);
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 300;
  letter-spacing: -.01em;
}

.offline-body {
  margin: 10px auto 0;
  max-width: 40ch;
  font-size: 14px;
  line-height: 1.55;
  color: var(--sage);
}

/* ------------------------------------------------------------------- cards */

.card {
  position: relative;
  background: var(--surface-a92);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow: hidden;
}

.card + .card { margin-top: 16px; }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.eyebrow {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--sage);
}

.division {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--smoke);
  text-align: right;
}

/* The phase rail — dawn / full sun / gold hour. Set from JS. */
.card-rail {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--meadow);
  transition: background .4s ease;
}

.rider-name {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(26px, 3.6vw, 40px);
  line-height: 1.05;
  letter-spacing: -.02em;
  margin: 0;
  /* Names swap every few minutes; a hard cut reads as a glitch. */
  transition: opacity .25s ease;
}

.rider-name.swapping { opacity: 0; }

.rider-horse {
  font-family: var(--display);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(15px, 1.8vw, 19px);
  color: var(--sage);
  margin-top: 4px;
  min-height: 1.2em;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0 0;
  background: var(--hairline);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  overflow: hidden;
}

.stat { background: var(--surface); padding: 11px 12px; }

.stat dt {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--smoke);
}

.stat dd {
  margin: 4px 0 0;
  font-size: clamp(20px, 2.6vw, 26px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

.stat dd.status { color: var(--flag); font-size: 20px; }

/* --------------------------------------------------------------- standings */

.board-list { list-style: none; margin: 0; padding: 0; }

.board-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--hairline);
  font-size: 14px;
}

.board-row:first-child { border-top: 0; }

.board-row.is-current {
  /* The rider on screen, found in the standings. */
  background: linear-gradient(90deg, rgba(225, 81, 42, .14), transparent 70%);
  box-shadow: inset 2px 0 0 var(--flag);
  padding-left: 8px;
  margin-left: -8px;
  border-radius: 3px;
}

.board-place {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--sage);
}

.board-who { min-width: 0; }
.board-rider { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.board-horse {
  display: block;
  font-family: var(--display);
  font-style: italic;
  font-size: 12px;
  color: var(--smoke);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.board-score { font-variant-numeric: tabular-nums; font-weight: 600; }
.board-score.status { color: var(--flag); font-size: 12px; letter-spacing: .08em; }

.board-foot {
  margin-top: 12px;
  font-size: 11px;
  color: var(--smoke);
  letter-spacing: .04em;
}

/* -------------------------------------------------------------------- chat */

.col-chat { position: sticky; top: 16px; }

@media (max-width: 900px) { .col-chat { position: static; } }

.chat { display: flex; flex-direction: column; height: min(72vh, 720px); padding-bottom: 14px; }

@media (max-width: 900px) { .chat { height: 62vh; } }

.chat-head { margin-bottom: 10px; }

.conn { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--smoke); }
.conn[data-state="open"]   { color: var(--meadow); }
.conn[data-state="closed"] { color: var(--flag); }

.messages {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 4px; }

.msg {
  padding: 5px 0;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-nick { font-weight: 600; color: var(--sage); margin-right: 6px; }

.msg.announce {
  background: rgba(225, 81, 42, .12);
  border-left: 2px solid var(--flag);
  padding: 7px 10px;
  margin: 6px 0;
  border-radius: 0 4px 4px 0;
}

.msg.announce .msg-nick { color: var(--flag); }

.msg-del {
  float: right;
  border: 0;
  background: none;
  color: var(--smoke);
  cursor: pointer;
  font-size: 11px;
  padding: 0 4px;
}

.msg-del:hover { color: var(--flag); }

.notice {
  font-size: 12px;
  color: var(--flag);
  padding: 6px 0 0;
}

.composer { padding-top: 10px; border-top: 1px solid var(--hairline); margin-top: 8px; }

.nick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--smoke);
}

.nick-row label { letter-spacing: .1em; text-transform: uppercase; font-weight: 600; }

.send-row { display: flex; gap: 8px; }

input {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--bone);
  background: var(--forest-dim);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 9px 11px;
  min-width: 0;
}

input:focus-visible { outline: 2px solid var(--meadow); outline-offset: 1px; }
input::placeholder { color: var(--smoke); }

#nick { flex: 1; padding: 5px 8px; font-size: 12px; }
#text { flex: 1; }

button {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--bone);
  background: var(--flag);
  border: 0;
  border-radius: 6px;
  padding: 9px 16px;
  cursor: pointer;
  flex: none;
}

button:hover { background: var(--flag-dim); }
button:focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
button:disabled { background: var(--hairline); color: var(--smoke); cursor: default; }

/* Touch. Most of this audience is on a phone at the edge of a field.
   - 44px minimum tap target (the composer was 35px).
   - 16px input text: anything smaller makes iOS Safari zoom the whole page on
     focus, which leaves the viewer scrolled sideways with the video off screen
     and no obvious way back. */
@media (max-width: 900px) {
  #text, #send {
    min-height: 44px;
    font-size: 16px;
  }
  #nick {
    min-height: 36px;
    font-size: 16px;
  }
}

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

.footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--smoke);
}
