/* Sid Scores — phone-first scorer. System fonts on purpose: instant load on bad pub Wi-Fi. */
:root {
  color-scheme: light dark;
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --surface-2: #ECE9E3;
  --text: #17161A;
  --muted: #5F5C66;
  --line: #D9D5CD;
  --accent: #B45309;
  --on-accent: #FFFFFF;
  --good: #177A43;
  --good-bg: #DDF3E5;
  --bad: #C0262D;
  --bad-bg: #FBE2E2;
  --zero: #8A5A00;
  --zero-bg: #FBEFD3;
  --ex: #6D3FD1;
  --ex-bg: #ECE4FB;
  --focus: #B45309;
  --radius: 14px;
  --dock-h: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111013;
    --surface: #1B1A1F;
    --surface-2: #26242B;
    --text: #F2F0EC;
    --muted: #A5A1AD;
    --line: #34313A;
    --accent: #FFB23F;
    --on-accent: #1A1206;
    --good: #4ADE80;
    --good-bg: #12311F;
    --bad: #FF6B6B;
    --bad-bg: #3B1718;
    --zero: #F2C35B;
    --zero-bg: #3A2E12;
    --ex: #B899FF;
    --ex-bg: #2A2140;
    --focus: #FFB23F;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 12px; scroll-padding-bottom: calc(var(--dock-h) + 24px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent; /* replaced by explicit :active states below */
}
body.dock-tabs { --dock-h: 64px; }
body.dock-q { --dock-h: 132px; }
button, input, select, label, a { touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
h2, h3 { text-wrap: balance; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.pts-pos { color: var(--good); }
.pts-neg { color: var(--bad); }
.pts-zero { color: var(--zero); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline-offset: 0; }

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ic.sm { width: 16px; height: 16px; stroke-width: 2.5; }

/* ---------- inputs & buttons ---------- */
input, select {
  min-height: 44px; min-width: 0;
  padding: 0 12px;
  font-size: 16px; /* ≥16px so iOS doesn't zoom on focus */
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
}
input::placeholder { color: var(--muted); opacity: .8; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select { font-weight: 400; }
.field small { font-weight: 400; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field.inline input { width: 96px; }
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; }
.err { color: var(--bad); font-size: 14px; margin: 0; }
.err:empty { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  font-weight: 600; font-size: 15px; white-space: nowrap;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; border-radius: 14px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  background: transparent; border: 0; border-radius: 10px; color: var(--muted);
  transition: background-color .15s ease, transform .1s ease;
}
.chip {
  min-height: 44px; min-width: 64px; padding: 0 14px;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
  transition: background-color .15s ease, transform .1s ease;
}
.btn:active, .icon-btn:active, .chip:active, .out:active, .qchip:active, .nav-btn:active, .tab:active { transform: scale(.96); }
@media (hover: hover) {
  .btn:not(.primary):not(:disabled):hover, .icon-btn:hover, .chip:hover { background: var(--surface-2); }
  .btn.primary:hover { filter: brightness(1.08); }
  .out:not(.on):hover { border-color: var(--muted); }
}

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 10px;
  max-width: 720px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.logo { width: 26px; height: 26px; color: var(--accent); }
.game-name {
  flex: 1; font-size: 19px; font-weight: 800; letter-spacing: -.01em;
  background: transparent; border-color: transparent; padding: 0 6px;
  text-overflow: ellipsis;
}
.game-name:hover { border-color: var(--line); }
.undo { padding: 0 12px; }
body.starting .undo { visibility: hidden; }

main { max-width: 720px; margin: 0 auto; padding: 4px 16px calc(var(--dock-h) + 32px + env(safe-area-inset-bottom)); }
main:focus { outline: none; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card > p { margin: 0 0 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.actions.three { grid-template-columns: repeat(3, 1fr); }
.actions .btn { padding: 0 8px; }

/* ---------- standings (on score view) ---------- */
.stand { padding: 4px 12px; }
.stand-head {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px;
  background: none; border: 0; padding: 0 4px; text-align: left;
}
.stand-head .label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stand-head .lead { flex: 1; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.stand-head .ic { transition: transform .2s ease; color: var(--muted); }
.stand-head[aria-expanded="true"] .ic { transform: rotate(180deg); }
.summary { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.srow { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; font-size: 15px; }
.srow .sr { font-weight: 800; color: var(--muted); min-width: 16px; font-variant-numeric: tabular-nums; }
.srow .sn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.srow .st { font-weight: 800; font-variant-numeric: tabular-nums; }
.srow.first .sr { color: var(--accent); }
@media (min-width: 600px) { .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- question strip + rules ---------- */
.qchips {
  display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain;
  margin: 0 -16px 10px; padding: 2px 16px 6px; scrollbar-width: none;
}
.qchips::-webkit-scrollbar { display: none; }
.qchip {
  flex: none; min-width: 44px; height: 44px; padding: 0 6px; position: relative;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--muted); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.qchip.done { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -3px 0 var(--good); }
.qchip[aria-current="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); box-shadow: none; }
.qchip.ex::after { content: ""; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--ex); }
.qchip.add { display: grid; place-items: center; }

.rules {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--surface-2);
}
.rules.ex { background: var(--ex-bg); }
.rules-text { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 14px; }
.rule-pill { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rules .note { color: var(--muted); font-style: italic; }
.tag-ex { background: var(--ex); color: var(--surface); font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .05em; align-self: center; }
.expanel { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; padding: 14px; border: 1.5px dashed var(--ex); border-radius: 12px; }
.expanel p { margin: 0; }
.expanel .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.expanel .btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- team rows ---------- */
.teams { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.team {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px;
  padding: 6px 12px 12px; transition: border-color .15s ease;
}
.team.pos { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.team.neg { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.team.zero { border-color: color-mix(in srgb, var(--zero) 55%, var(--line)); }
.thead { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.tname {
  min-width: 0; min-height: 44px; padding: 0; background: none; border: 0; text-align: left;
  font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-decoration: underline dotted var(--muted); text-underline-offset: 4px;
}
.ttotal { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qpts { margin-left: auto; font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.qpts.none { color: var(--muted); font-weight: 500; }
.outs { display: flex; flex-wrap: wrap; gap: 8px; }
.out {
  flex: 1 1 0; min-width: 72px; min-height: 54px; padding: 4px 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--surface-2); color: var(--text);
  border: 1.5px solid var(--line); border-radius: 12px;
  transition: background-color .12s ease, border-color .12s ease, transform .1s ease;
}
.out .ol { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.out small { font-size: 13px; opacity: .8; font-variant-numeric: tabular-nums; }
.out.on.pos { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.out.on.neg { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.out.on.zero { background: var(--zero-bg); border-color: var(--zero); color: var(--zero); }
.out.custom { flex: 0 0 64px; min-width: 64px; }
.out.custom.on { background: var(--ex-bg); border-color: var(--ex); color: var(--ex); }
.add-team { margin-top: 12px; width: 100%; }

/* ---------- bottom dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.dock[hidden] { display: none; }
.qbar { display: flex; align-items: center; gap: 10px; max-width: 720px; margin: 0 auto; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.qbar[hidden] { display: none; }
.nav-btn {
  display: grid; place-items: center; width: 64px; height: 52px; flex: none;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2);
  transition: transform .1s ease;
}
.nav-btn .ic { width: 26px; height: 26px; stroke-width: 2.5; }
.nav-btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.qinfo { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.qinfo .qn { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.qinfo .qm { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.qinfo .qm.all { color: var(--good); font-weight: 700; }
.tabbar { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 720px; margin: 0 auto; }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; background: none; border: 0; color: var(--muted); font-size: 12px; font-weight: 700;
  transition: color .15s ease, transform .1s ease;
}
.tab .ic { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- leaderboard ---------- */
.board { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.brow {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; position: relative; overflow: hidden;
}
.brow .bar { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: .12; }
.brow .rank { font-weight: 800; font-size: 20px; color: var(--muted); position: relative; font-variant-numeric: tabular-nums; }
.brow .bn { font-weight: 700; font-size: 18px; position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .bt { font-weight: 800; font-size: 24px; font-variant-numeric: tabular-nums; position: relative; }
.brow.first .rank { color: var(--accent); }
.adj-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.adj-list li { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px; background: var(--surface-2); border-radius: 10px; font-size: 15px; }
.adj-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adj-list strong { font-variant-numeric: tabular-nums; min-width: 40px; }
.table-wrap { overflow-x: auto; overscroll-behavior-x: contain; margin: 0 -16px; padding: 0 16px; }
table.grid { border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
table.grid td.ex { background: var(--ex-bg); }
table.grid .tot { font-weight: 800; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.history li:last-child { border-bottom: 0; }

/* ---------- setup ---------- */
.team-edit { list-style: none; margin: 0 0 12px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.team-edit li { display: flex; align-items: center; gap: 6px; }
.team-edit .idx { width: 24px; text-align: right; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.team-edit input { flex: 1; }
.rule-edit { display: grid; grid-template-columns: minmax(0, 1fr) 96px 44px; gap: 8px; margin-bottom: 8px; align-items: center; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.presets .chip { font-weight: 600; background: transparent; border-style: dashed; }
.hero h2 { margin: 8px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.hero p { margin: 0 0 16px; }
.start-bar {
  position: sticky; bottom: 0; margin: 0 -16px; padding: 16px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 35%);
}

/* ---------- sheets (native <dialog>) ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0; background: var(--surface);
  overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] { animation: sheet-in .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-in { from { transform: translateY(32px); opacity: 0; } }
.sheet-in { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 20px; }
.sheet-in::before { content: ""; align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin-bottom: 2px; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick .chip { min-width: 0; }
@media (min-width: 720px) { .sheet { margin: auto; border-radius: 22px; } }

.present {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border: 0;
  background: var(--bg); padding: max(4vh, env(safe-area-inset-top)) 6vw 4vh; overscroll-behavior: contain;
}
.present-head { display: flex; align-items: center; gap: 16px; margin-bottom: 3vh; }
.present-head h2 { margin: 0; flex: 1; font-size: clamp(26px, 5vw, 56px); letter-spacing: -.02em; }
.present .brow { padding: 2vh 2vw; }
.present .brow .bn { font-size: clamp(20px, 3.2vw, 42px); }
.present .brow .bt { font-size: clamp(24px, 4.2vw, 56px); }
.present .brow .rank { font-size: clamp(20px, 3vw, 40px); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 12px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); width: max-content;
  padding: 6px 6px 6px 16px; min-height: 48px;
  background: var(--text); color: var(--bg); border-radius: 12px; font-weight: 600;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}
.toast[hidden] { display: none; }
.toast-btn { min-height: 36px; padding: 0 12px; background: none; border: 0; border-radius: 8px; color: #B45309; font-weight: 800; }
@media (prefers-color-scheme: light) { .toast-btn { color: #FFB23F; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
