/* PitWall: quiet design.
   Plain system font, sentence case, soft panels. Colour is used only for the kart
   ratings (fast / OK / slow), and always together with the word.
   Light or dark: follows the device, or the choice made in Setup → This device.
   Layout: one column on a phone, roomier on a tablet, two columns from 900 px.
   Order: tokens, base, header + tabs, call, pit line, our team, teams, sheets, setup, screen sizes. */

:root {
  color-scheme: light dark;
  --bg: #f4f4f1;
  --panel: #ffffff;
  --tint: #ecebe5;
  --rule: #e2e1db;
  --rule-2: #c9c7be;
  --ink: #1c1d1a;
  --ink2: #55584f;
  --ink3: #6e7169;
  --fast: #23854f;  --fast-s: #e2f3e9;  --fast-t: #17603a;  --on-fast: #ffffff;
  --ok: #dfa100;    --ok-s: #fbf1d0;    --ok-t: #6b4a00;    --on-ok: #201600;
  --slow: #c93f34;  --slow-s: #fbe5e2;  --slow-t: #8c241b;  --on-slow: #ffffff;
  --late: #c0362b;
  --btn: #1c1d1a;
  --btn-t: #ffffff;
  --scrim: rgba(20, 20, 18, .45);
  --r: 12px;
}
/* Dark: when the device is in dark mode, unless this device chose Light in Setup … */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101210;
    --panel: #191c19;
    --tint: #222622;
    --rule: #2a2e2a;
    --rule-2: #414640;
    --ink: #ecebe6;
    --ink2: #b0b3ab;
    --ink3: #858980;
    --fast: #3aae70;  --fast-s: #16301f;  --fast-t: #7fd9a6;  --on-fast: #04200f;
    --ok: #e0aa25;    --ok-s: #33290f;    --ok-t: #efc55a;    --on-ok: #201600;
    --slow: #c9483c;  --slow-s: #3a1c19;  --slow-t: #f39a90;  --on-slow: #ffffff;
    --late: #f08a7f;
    --btn: #ecebe6;
    --btn-t: #101210;
    --scrim: rgba(0, 0, 0, .6);
  }
}
/* … or when this device chose Dark in Setup. (Same values as above.) */
:root[data-theme="dark"] {
  --bg: #101210;
  --panel: #191c19;
  --tint: #222622;
  --rule: #2a2e2a;
  --rule-2: #414640;
  --ink: #ecebe6;
  --ink2: #b0b3ab;
  --ink3: #858980;
  --fast: #3aae70;  --fast-s: #16301f;  --fast-t: #7fd9a6;  --on-fast: #04200f;
  --ok: #e0aa25;  --ok-s: #33290f;  --ok-t: #efc55a;  --on-ok: #201600;
  --slow: #c9483c;  --slow-s: #3a1c19;  --slow-t: #f39a90;  --on-slow: #ffffff;
  --late: #f08a7f;
  --btn: #ecebe6;
  --btn-t: #101210;
  --scrim: rgba(0, 0, 0, .6);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink3); }
.small { font-size: 13px; }
h2 { font-size: 13px; font-weight: 600; color: var(--ink2); margin: 22px 0 8px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* header + tabs */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 12px 16px 11px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--rule);
}
.top strong { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.status { display: flex; gap: 8px; align-items: center; flex: none; }
#raceClock { color: var(--ink2); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--slow); }
.dot.on { background: var(--fast); }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--ok-s); color: var(--ok-t); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(2, 1fr);
  background: var(--panel); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; padding: 15px 0 14px; color: var(--ink3); font-weight: 600; font-size: 15px; }
.tabs button.on { color: var(--ink); box-shadow: inset 0 2px 0 var(--ink); }

main { max-width: 720px; margin: 0 auto; padding: 0 16px 24px; }

/* section heads */
.sec { display: flex; align-items: baseline; gap: 8px; margin: 20px 0 8px; font-size: 13px; color: var(--ink3); }
.sec b { font-weight: 600; color: var(--ink2); }
.sec .end { margin-left: auto; }

/* the call */
.action { margin-top: 14px; background: var(--panel); border: 1px solid var(--rule); border-left: 4px solid var(--rule-2); border-radius: var(--r); padding: 14px 16px 13px; }
.action .big { font-size: 30px; line-height: 1.1; font-weight: 650; letter-spacing: -.01em; }
.action p { margin: 6px 0 0; font-size: 15.5px; line-height: 1.4; color: var(--ink2); }
.action .soon { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--rule); font-size: 13.5px; color: var(--ink3); }
.action .soon b { color: var(--ink); font-weight: 600; }
.action .btn.wide { margin-top: 12px; }
.action.PIT_NOW { border-left-color: var(--fast); background: var(--fast-s); border-color: transparent; border-left-color: var(--fast); }
.action.PIT_NOW .big { color: var(--fast-t); }
.action.MUST_PIT { background: var(--slow-s); border-color: transparent; border-left-color: var(--slow); }
.action.MUST_PIT .big { color: var(--slow-t); }
.action.WAIT { border-left-color: var(--ok); }
.action.IN_PIT { border-left-color: var(--ink); }
.action.IN_PIT.go { background: var(--fast-s); border-color: transparent; border-left-color: var(--fast); }
.action.IN_PIT.go .big { color: var(--fast-t); }
.warnline { margin: 10px 0 0; padding: 9px 12px; border-radius: 10px; background: var(--slow-s); color: var(--slow-t); font-weight: 600; font-size: 14px; }

/* a rating as a small label: colour plus the word, never colour alone */
.tagr { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.tagr.fast { background: var(--fast-s); color: var(--fast-t); }
.tagr.ok { background: var(--ok-s); color: var(--ok-t); }
.tagr.slow { background: var(--slow-s); color: var(--slow-t); }
.tagr.unknown { background: var(--tint); color: var(--ink2); }

/* pit line: the NEXT kart is a solid colour, the ones behind it a soft tint */
.linebox { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
.kbox {
  position: relative; min-height: 88px; border: 0; border-radius: var(--r); padding: 20px 6px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.kbox .pos { position: absolute; top: 8px; left: 11px; font-size: 12px; font-weight: 600; }
.kbox .rate { font-size: 22px; font-weight: 650; letter-spacing: -.01em; line-height: 1.15; }
.kbox .src { font-size: 12.5px; }
.kbox.fast { background: var(--fast-s); color: var(--fast-t); }
.kbox.ok { background: var(--ok-s); color: var(--ok-t); }
.kbox.slow { background: var(--slow-s); color: var(--slow-t); }
.kbox.unknown { background: var(--tint); color: var(--ink2); }
.kbox.first .rate { font-size: 24px; }
.kbox.first.fast { background: var(--fast); color: var(--on-fast); }
.kbox.first.ok { background: var(--ok); color: var(--on-ok); }
.kbox.first.slow { background: var(--slow); color: var(--on-slow); }
.kbox.first.unknown { background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink3); }
.dots { position: absolute; top: 11px; right: 10px; display: flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.dots i.fast { background: var(--fast); } .dots i.ok { background: var(--ok); } .dots i.slow { background: var(--slow); }
.kbox.first .dots i { box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .85); }
.lastline { margin: 9px 0 0; font-size: 13px; color: var(--ink3); line-height: 1.7; }
.lastline b { color: var(--ink); font-weight: 600; }

/* buttons */
.btn { border: 1px solid var(--rule); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 10px 14px; font-weight: 600; min-height: 44px; white-space: nowrap; }
.btn.wide { white-space: normal; }
.btn.primary, .btn.in { background: var(--btn); border-color: var(--btn); color: var(--btn-t); }
.btn.danger { color: var(--slow-t); border-color: var(--slow-t); background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; min-height: 32px; border-radius: 8px; }
.btn.big { min-height: 50px; font-size: 16px; border-radius: var(--r); flex: 1; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .4; }

/* our team: actions, then our numbers in one strip */
.ours { display: flex; gap: 8px; margin-top: 12px; }
.btn.joker { flex: 0 0 34%; }
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin-top: 10px; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r); }
.strip .cell { padding: 8px 2px 7px; text-align: center; min-width: 0; border-left: 1px solid var(--rule); }
.strip .cell:first-child { border-left: 0; }
.strip .k { font-size: 12px; color: var(--ink3); white-space: nowrap; }
.strip .v { font-size: 19px; font-weight: 650; line-height: 1.25; margin-top: 2px; white-space: nowrap; }
.strip .v.over { color: var(--late); }
.strip .v .tagr { font-size: 14px; }
.strip .s { font-size: 11.5px; color: var(--ink3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 16px; }

/* teams */
.pad { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.tbtn {
  position: relative; min-width: 0; height: 80px; padding: 8px 0 0; overflow: hidden;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.tbtn:active { background: var(--tint); }
.tbtn .no { font-size: 22px; font-weight: 650; line-height: 1.1; }
.tbtn .st { font-size: 13px; color: var(--ink2); }
.tbtn .st.over { color: var(--late); font-weight: 600; }
.tbtn .st.pitword { color: var(--ink3); font-style: italic; }
/* pit stops made: small dots down the right edge */
.tbtn .cnt { position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 2px; }
.tbtn .cnt i { width: 4px; height: 4px; border-radius: 50%; background: var(--rule-2); }
.tbtn .cnt i.on { background: var(--ink); opacity: 1; }
/* what we know about the kart it drives now */
.tbtn .kr { position: absolute; left: 0; right: 0; bottom: 0; height: 22px; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; white-space: nowrap; background: var(--tint); color: var(--ink3); }
.tbtn.fast .kr { background: var(--fast-s); color: var(--fast-t); }
.tbtn.ok .kr { background: var(--ok-s); color: var(--ok-t); }
.tbtn.slow .kr { background: var(--slow-s); color: var(--slow-t); }
.tbtn.mine { border: 2px solid var(--ink); padding-top: 7px; }
.tbtn.inpit { background: var(--tint); }
.crewbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; }
.crewbar .btn { flex: none; }

/* sheets */
dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--rule); border-radius: 16px; padding: 18px; width: min(460px, calc(100vw - 28px)); }
dialog::backdrop { background: var(--scrim); }
dialog h3 { margin: 0 0 4px; font-size: 20px; font-weight: 650; }
dialog p { margin: 0 0 12px; color: var(--ink2); }
/* the two choices in the team sheet: it came into the pit, or it is still on track */
.blk { margin-top: 14px; padding: 14px 0 0; border-top: 1px solid var(--rule); }
.blk.pit { border: 0; background: var(--tint); border-radius: var(--r); padding: 14px; }
.blk-h { font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 4px; }
.blk.pit .blk-h { font-size: 16px; font-weight: 650; color: var(--ink); }
.blk p { margin: 0 0 10px; font-size: 14px; }
.blk .rate3:last-child, .blk .btn.wide:last-child { margin-bottom: 0; }
.rate3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.rate3.small { grid-template-columns: repeat(4, 1fr); }
.rbtn { border: 0; border-radius: var(--r); min-height: 74px; font-size: 21px; font-weight: 650; touch-action: manipulation; }
.rbtn .pre { display: block; font-size: 12px; font-weight: 600; opacity: .85; line-height: 1.3; }
.rbtn.fast { background: var(--fast); color: var(--on-fast); }
.rbtn.ok { background: var(--ok); color: var(--on-ok); }
.rbtn.slow { background: var(--slow); color: var(--on-slow); }
.rbtn.sel { outline: 3px solid var(--ink); outline-offset: 2px; }
.rate3.small .rbtn { min-height: 44px; font-size: 14px; font-weight: 600; }
.rate3.small .rbtn.fast { background: var(--fast-s); color: var(--fast-t); }
.rate3.small .rbtn.ok { background: var(--ok-s); color: var(--ok-t); }
.rate3.small .rbtn.slow { background: var(--slow-s); color: var(--slow-t); }
.rbtn.unknown { background: var(--tint); color: var(--ink2); }
.sep { height: 1px; background: var(--rule); margin: 16px 0 12px; }
.movebar { display: flex; gap: 8px; flex-wrap: wrap; }
.movebar .btn { flex: 1; }
.sheetbar { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px);
  background: var(--btn); color: var(--btn-t); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 10; white-space: nowrap; max-width: calc(100vw - 24px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* setup */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; }
.row .grow { flex: 1; min-width: 0; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink3); }
input, select { background: var(--panel); border: 1px solid var(--rule-2); border-radius: 10px; padding: 10px 11px; min-width: 0; min-height: 44px; }
.teamrow { display: grid; grid-template-columns: 72px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; }
#setupForm .help { margin: 6px 0 0; }
.demo-note { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding: 12px 14px; background: var(--ok-s); color: var(--ok-t); border-radius: var(--r); }
.demo-note p { margin: 0; flex: 1 1 220px; font-size: 14px; }
.demo-note.race { background: var(--tint); color: var(--ink2); }
.notebar { display: flex; gap: 8px; flex-wrap: wrap; }
.steps { margin: 12px 0 0; padding: 12px 14px; border: 1px solid var(--rule); border-left: 4px solid var(--ink); border-radius: var(--r); background: var(--panel); font-size: 14.5px; }

/* online version: the start screen */
#welcome { width: min(440px, calc(100vw - 28px)); padding: 22px 20px 18px; }
#welcome h3 { font-size: 26px; margin-bottom: 4px; }
.choices { display: grid; gap: 10px; margin: 16px 0 12px; }
.choice { display: block; text-align: left; padding: 16px; border: 1px solid var(--rule-2); border-radius: var(--r); background: var(--panel); color: var(--ink); min-height: 76px; }
.choice:active { background: var(--tint); }
.choice b { display: block; font-size: 18px; font-weight: 650; margin-bottom: 3px; }
.choice span { color: var(--ink2); font-size: 14.5px; line-height: 1.35; }
.choice[data-mode="demo"] { background: var(--btn); border-color: var(--btn); color: var(--btn-t); }
.choice[data-mode="demo"] span { color: inherit; opacity: .8; }
.welcome-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* online version: the guided tour */
.tour { position: fixed; inset: 0; z-index: 50; touch-action: none; }
.tour-hole { position: absolute; border-radius: 14px; box-shadow: 0 0 0 9999px var(--scrim), 0 0 0 2px var(--panel); transition: left .25s, top .25s, width .25s, height .25s; pointer-events: none; }
.tour-card { position: absolute; width: min(360px, calc(100vw - 24px)); background: var(--panel); color: var(--ink); border: 1px solid var(--rule-2); border-radius: 14px; padding: 14px 14px 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.tour-text { margin: 0 0 12px; font-size: 15.5px; line-height: 1.45; }
.tour-bar { display: flex; align-items: center; gap: 8px; }
.tour-count { margin-right: auto; font-size: 13px; color: var(--ink3); }
.tour-bar .btn.sm { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.formbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.prefs { display: flex; flex-direction: column; gap: 10px; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pref > span { font-weight: 600; }
/* one choice out of two or three */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--tint); border-radius: 10px; }
.seg button { border: 0; background: transparent; color: var(--ink2); font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 8px; min-height: 38px; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--rule-2); }
details.rules { margin-top: 8px; }
details.rules summary { cursor: pointer; padding: 6px 0; }

/* ---------- screen sizes ----------
   phone   < 600 px   one column, everything on one screen
   tablet  600–899    one column, larger targets
   wide    ≥ 900 px   two columns: call + pit line + our team | teams; tabs move into the header */

@media (max-width: 599px) {
  main { padding: 0 12px 20px; }
  .action { margin-top: 12px; padding: 12px 14px 11px; }
  .action .big { font-size: 28px; }
  .sec { margin: 14px 0 7px; }
  .kbox { min-height: 80px; }
  .pad { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tbtn { height: 72px; padding-top: 6px; }
  .tbtn.mine { padding-top: 5px; }
  .tbtn .kr { height: 21px; }
  .crewbar { flex-direction: column-reverse; align-items: stretch; }
}

@media (min-width: 600px) {
  body { font-size: 16px; }
  main { max-width: 760px; padding: 0 24px 28px; }
  .top { padding-left: 24px; padding-right: 24px; }
  .action { padding: 18px 20px 16px; }
  .action .big { font-size: 36px; }
  .action p { font-size: 17px; }
  .linebox { gap: 10px; }
  .kbox { min-height: 108px; padding-top: 24px; }
  .kbox .pos { font-size: 13px; top: 10px; left: 13px; }
  .kbox .rate { font-size: 26px; } .kbox.first .rate { font-size: 30px; }
  .kbox .src { font-size: 14px; }
  .btn.big { min-height: 56px; font-size: 17px; }
  .strip .cell { padding: 12px 4px 11px; }
  .strip .k { font-size: 13px; } .strip .v { font-size: 22px; } .strip .s { font-size: 12.5px; }
  .pad { gap: 10px; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .tbtn { height: 92px; padding-top: 10px; }
  .tbtn.mine { padding-top: 9px; }
  .tbtn .no { font-size: 26px; } .tbtn .st { font-size: 14.5px; }
  .tbtn .kr { height: 25px; font-size: 13px; }
  .tbtn .cnt { top: 10px; right: 10px; gap: 3px; }
  .tbtn .cnt i { width: 5px; height: 5px; }
  .rbtn { min-height: 84px; font-size: 23px; }
}

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  main { max-width: 1240px; padding: 0 28px 36px; }
  .top { padding-left: 28px; padding-right: 28px; min-height: 52px; align-items: center; }
  /* tabs sit in the middle of the header */
  .tabs {
    top: 0; bottom: auto; left: 50%; right: auto; transform: translateX(-50%);
    display: flex; gap: 4px; padding: calc(8px + env(safe-area-inset-top)) 0 0; background: transparent; border: 0; z-index: 6;
  }
  .tabs button { padding: 8px 18px; border-radius: 8px; }
  .tabs button.on { background: var(--tint); box-shadow: none; }
  #toast { bottom: 28px; }

  .race { display: grid; grid-template-columns: minmax(380px, 5fr) 6fr; gap: 32px; align-items: start; }
  /* the call stays in view while a long team list scrolls */
  .col-main { position: sticky; top: 66px; }
  .col-teams .sec:first-child { margin-top: 14px; }
  .pad { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .tbtn { height: 96px; }

  /* setup: the form on the left, the list of entries on the right */
  #view[data-tab="setup"] { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; align-items: start; }
}

@media (min-width: 1280px) {
  .race { gap: 44px; }
  .action .big { font-size: 40px; }
  .pad { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
  .tbtn { height: 104px; }
  .tbtn .no { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast, .tour-hole { transition: none; }
}
