/* 30-15 IFT. Dark by default — rinks are dim and the phone is at arm's length.
   Palette is the validated one from PLAN.md §10; re-run the contrast checks if
   you change it rather than eyeballing. */

:root {
  --bg: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --series-1: #3987e5;
  --grid: #2c2c2a;
  --baseline: #383835;
  --text: #ffffff;
  --muted: #898781;
  --good: #0ca30c;
  --critical: #d03b3b;
  --run: #0ca30c;
  --rest: #e0a12b;
  --radius: 0.6rem;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ec;
  --series-1: #2a78d6;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --text: #0b0b0b;
  --muted: #6b6a65;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

/* ------------------------------------------------------------------ chrome */

#chrome {
  display: flex; align-items: center; gap: .75rem;
  padding: max(.5rem, env(safe-area-inset-top)) .8rem .5rem;
  border-bottom: 1px solid var(--grid);
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
}
.brand { font-weight: 700; letter-spacing: -.02em; color: var(--text); text-decoration: none; }
#nav { display: flex; gap: .1rem; flex: 1; overflow-x: auto; }
#nav a {
  color: var(--muted); text-decoration: none; font-size: .85rem;
  padding: .45rem .5rem; border-radius: .4rem; white-space: nowrap;
}
#nav a:hover { color: var(--text); background: var(--surface-1); }
.pill {
  margin-left: auto; font-size: .72rem; padding: .3rem .55rem; border-radius: 999px;
  border: 1px solid var(--grid); background: var(--surface-1); color: var(--muted);
}
.pill.ok { color: var(--good); }
.pill.pending { color: var(--rest); border-color: var(--rest); }
.pill.off { color: var(--critical); border-color: var(--critical); }

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

.screen { padding: 1rem .8rem calc(2rem + env(safe-area-inset-bottom)); max-width: 46rem; margin: 0 auto; }
.screen.narrow { max-width: 24rem; }
h1 { font-size: 1.5rem; margin: .2rem 0 .8rem; letter-spacing: -.02em; }
h2 { font-size: .95rem; margin: 0 0 .5rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.big { font-size: 1.15rem; }
.hero { font-size: 3rem; font-weight: 700; margin: 0; letter-spacing: -.03em; }
.hero-single { font-size: 1.6rem; font-weight: 700; }
.unit { font-size: .5em; color: var(--muted); font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.spacer { flex: 1; }
.hidden, [hidden] { display: none !important; }

.card {
  background: var(--surface-1); border: 1px solid var(--grid);
  border-radius: var(--radius); padding: .9rem; margin: .8rem 0;
}
.card.warn { border-color: var(--rest); }
.row { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 6rem; }

/* ------------------------------------------------------------------ controls */

button, .btn {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--baseline); border-radius: var(--radius);
  padding: .7rem .9rem; min-height: 44px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem;
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .4; }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }
button.danger { color: var(--critical); border-color: var(--critical); }
button.danger.ghost { background: none; }
button.big { width: 100%; min-height: 56px; font-size: 1.05rem; margin: .35rem 0; }
button.huge { width: 100%; min-height: 68px; font-size: 1.25rem; font-weight: 700; margin: .5rem 0; }
button.tiny { min-height: 32px; padding: .25rem .5rem; font-size: .78rem; }
.btn.wide { width: 100%; margin: .35rem 0 .2rem; }

.field { display: block; font-size: .8rem; color: var(--muted); margin: .5rem 0; }
.field.check { display: flex; align-items: center; gap: .4rem; }
input, select {
  font: inherit; width: 100%; margin-top: .2rem; padding: .6rem .55rem;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--baseline); border-radius: .4rem;
}
input[type="checkbox"] { width: 22px; height: 22px; margin: 0; }
input[type="range"] { padding: 0; }

.seg { display: flex; gap: 0; margin: .5rem 0; }
.seg button { flex: 1; border-radius: 0; min-height: 48px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.seg button.on { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }

.tag { font-size: .7rem; padding: .1rem .4rem; border-radius: .3rem; border: 1px solid var(--baseline); color: var(--muted); }
.tag.ice { color: var(--series-1); border-color: var(--series-1); }
.tag.run { color: var(--good); border-color: var(--good); }
.badge { display: inline-block; font-size: .8rem; padding: .2rem .45rem; border-radius: .3rem; background: var(--surface-2); }
.badge.good { color: var(--good); } .badge.bad { color: var(--critical); }
.badge.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: .9em; }

ul.check { padding-left: 1.1rem; margin: .3rem 0; }
ul.check li { margin: .3rem 0; font-size: .9rem; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .45rem 0; border-bottom: 1px solid var(--grid); }
ul.plain li:last-child { border-bottom: 0; }

/* ------------------------------------------------------------------ chips */

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .4rem; }
.chip {
  min-height: 64px; flex-direction: column; gap: .1rem; padding: .4rem .3rem;
  line-height: 1.1; font-size: .9rem; text-align: center; overflow: hidden;
}
.chip .jersey { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Wrap, never truncate. The whole name has to be readable at arm's length —
   an ellipsis turns "Ryan B" and "Ryan G" into the same chip. */
.chip .nm { font-weight: 600; max-width: 100%; overflow-wrap: break-word; }
.chip .stamp { font-size: .68rem; color: var(--rest); min-height: .9em; }
.chip.on { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.chip.on .jersey { color: rgba(255,255,255,.75); }
.chip.player.out { opacity: .42; border-style: dashed; }

/* ------------------------------------------------------------------ run screen */

.screen.run { padding-top: .5rem; }
.hud { display: flex; align-items: flex-start; gap: .8rem; }
.stage-block { display: flex; flex-direction: column; line-height: 1; }
.stage-block .label { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stage-block .stage { font-size: clamp(3.2rem, 17vw, 5rem); font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stage-block .speed { font-size: 1.15rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.phase { margin-left: auto; text-align: right; display: flex; flex-direction: column; line-height: 1; }
.phase-name { font-size: 1.1rem; font-weight: 800; letter-spacing: .08em; }
.phase-remain { font-size: clamp(2.4rem, 13vw, 3.6rem); font-weight: 700; font-variant-numeric: tabular-nums; }
.phase.run .phase-name, .phase.run .phase-remain { color: var(--run); }
.phase.rest .phase-name, .phase.rest .phase-remain { color: var(--rest); }
.phase.paused .phase-name, .phase.paused .phase-remain { color: var(--critical); }

/* Fixed-height slot. Do NOT let this reflow between RUN and WALK: it shifts
   every player chip twice per stage and causes mis-taps. */
.strip-slot {
  margin: .5rem 0 .7rem; padding: .4rem .2rem .1rem;
  background: var(--surface-1); border: 1px solid var(--grid); border-radius: var(--radius);
}
#strip { display: block; width: 100%; height: auto; }
#strip .course { stroke: var(--baseline); stroke-width: 2; }
#strip .mark { stroke: var(--grid); stroke-width: 2; }
#strip .mark.hit { stroke: var(--run); stroke-width: 4; }
#strip .mark.hit-rest { stroke: var(--rest); stroke-width: 4; }
#strip .mark-label { fill: var(--muted); font-size: 12px; font-weight: 700; }
#strip .mark-m { fill: var(--muted); font-size: 9px; }
#strip #band { fill: none; }
#strip #band.run { fill: var(--run); opacity: .3; }
#strip #band.rest { fill: var(--rest); opacity: .28; }
#strip #hair { stroke: none; stroke-width: 3; }
#strip #hair.run { stroke: var(--run); }
#strip #hair.rest { stroke: var(--rest); }
#strip #ghost { stroke: var(--muted); stroke-width: 2; stroke-dasharray: 3 3; }
#strip #ghost.hidden { stroke: none; }
#strip #arrow { font-size: 15px; fill: var(--muted); }
#strip #arrow.run { fill: var(--run); }
#strip #arrow.rest { fill: var(--rest); }
.strip-caption {
  margin: .15rem .2rem 0; font-size: .9rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;  /* never wrap => never reflow */
}

.run-footer {
  display: flex; gap: .4rem; align-items: center; flex-wrap: wrap;
  margin-top: .8rem; padding-top: .7rem; border-top: 1px solid var(--grid);
}
.run-footer #remaining { font-weight: 700; margin-right: auto; font-variant-numeric: tabular-nums; }
.run-footer button { min-height: 48px; }

/* ------------------------------------------------------------------ tables */

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: .4rem .3rem; border-bottom: 1px solid var(--baseline);
}
table.data td { padding: .35rem .3rem; border-bottom: 1px solid var(--grid); }
table.review td { vertical-align: middle; }
table.review input[type="number"] { width: 4.2rem; text-align: center; }
table.review .note-row td { padding-top: 0; border-bottom: 1px solid var(--baseline); }
table.review .note-row input { font-size: .82rem; padding: .35rem .45rem; }

ul.roster { list-style: none; padding: 0; margin: 0; }
ul.roster li {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem 0; border-bottom: 1px solid var(--grid);
}
ul.roster li.archived { opacity: .45; }
ul.roster .jersey { min-width: 2rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
ul.roster .nm { font-weight: 600; }

.chart { width: 100%; height: auto; overflow: visible; }

/* ------------------------------------------------------------------ toast */

#toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 150%); z-index: 20;
  width: min(30rem, calc(100vw - 1.6rem));
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--baseline); border-radius: var(--radius);
  padding: .7rem .8rem; font-size: .9rem; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  transition: transform .18s ease-out; display: flex; align-items: center; gap: .6rem;
}
#toast.show { transform: translate(-50%, 0); }
#toast button { margin-left: auto; min-height: 40px; }
#toast.good { border-color: var(--good); }
#toast.bad { border-color: var(--critical); }
#toast.pending { border-color: var(--rest); }
#toast.undo { border-color: var(--series-1); }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
  button:active, .btn:active { transform: none; }
}
