/* Tally Board — styles. System fonts only, light/dark aware. */
:root {
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-2: #f0ede8;
  --text: #1b1a2e;
  --muted: #5e5b70;
  --border: #e3ded6;
  --accent: #e4572e;
  --accent-ink: #ffffff;
  --danger: #c62a3c;
  --shadow: 0 1px 2px rgba(20, 10, 0, .06), 0 8px 24px rgba(20, 10, 0, .07);
  --radius: 18px;
  --ad-border: #cfc8bc;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c;
    --surface: #1c1b2a;
    --surface-2: #272538;
    --text: #f3f1fa;
    --muted: #aba8c0;
    --border: #353349;
    --accent: #ff7a52;
    --accent-ink: #12111c;
    --danger: #ff6b7d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --ad-border: #44415c;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); line-height: 1.5; color: var(--text); background: var(--bg); min-height: 100vh; }
button, input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
code, kbd { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; }
.skip-link:focus { top: 12px; }

/* Header */
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1200px; margin: 0 auto; padding: 14px 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 800; font-size: 1.2rem; }
.brand__logo { width: 34px; height: 34px; }
.header-actions { display: flex; gap: 6px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid transparent; background: none; cursor: pointer; font-weight: 650; }
.btn:disabled { opacity: .45; cursor: default; }
.btn--ghost { border-color: var(--border); background: var(--surface); }
.btn--soft { background: var(--surface-2); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--big { min-height: 52px; padding: 10px 20px; font-size: 1.05rem; }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn--text { padding: 4px 8px; min-height: 0; color: var(--accent); text-decoration: underline; }
.btn:not(:disabled):hover { filter: brightness(1.05); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: none; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1200px; margin: 0 auto; padding: 0 16px 24px; }
@media (min-width: 980px) { .layout { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel__top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.title-input { flex: 1 1 220px; min-width: 0; font-size: 1.6rem; font-weight: 800; border: 1px solid transparent; border-radius: 12px; background: none; padding: 4px 10px; }
.title-input:hover, .title-input:focus { border-color: var(--border); background: var(--surface-2); }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 14px; }
.kbd-hint { margin: 14px 0 0; }
.field-error { color: var(--danger); font-size: .9rem; margin: 6px 0 0; font-weight: 600; }

/* Step chips */
.steps { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.steps__label { color: var(--muted); font-weight: 650; margin-right: 4px; }
.chip { min-width: 48px; min-height: 44px; padding: 6px 14px; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); font-weight: 750; cursor: pointer; }
.chip[aria-checked="true"], .chip--input.is-on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.chip--input { display: inline-flex; padding: 0 4px; }
.chip--input input { width: 80px; border: 0; background: none; text-align: center; font-weight: 750; }
.chip--input input:focus { outline: none; }
.chip--input:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Team rows */
.teams { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.team {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: 40px 48px minmax(0, 1fr) 48px 40px;
  grid-template-areas: "sw name name name del" "minus minus score plus plus" "err err err err err";
  padding: 10px; border-radius: 16px; background: var(--surface-2);
  border-left: 8px solid var(--c);
}
.team.is-selected { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 60%, transparent); }
.team__swatch { grid-area: sw; width: 36px; height: 36px; border-radius: 50%; overflow: hidden; background: var(--c); cursor: pointer; position: relative; box-shadow: inset 0 0 0 2px rgba(0,0,0,.12); }
.team__swatch:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.team__color { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.team__name { grid-area: name; min-width: 0; font-size: 1.15rem; font-weight: 700; border: 1px solid transparent; border-radius: 10px; background: none; padding: 6px 8px; }
.team__name:hover, .team__name:focus { border-color: var(--border); background: var(--surface); }
.team__del { grid-area: del; }
.score-btn { min-height: 64px; border-radius: 14px; border: 0; font-size: 1.5rem; font-weight: 800; cursor: pointer; touch-action: manipulation; user-select: none; }
.score-btn--minus { grid-area: minus; background: var(--surface); color: var(--text); border: 2px solid var(--border); }
.score-btn--plus { grid-area: plus; background: var(--c); color: var(--on-c); }
.score-btn:active { transform: scale(.96); }
.team__del { justify-self: center; }
@media (max-width: 480px) { .panel { padding: 14px; } }
.team__score { grid-area: score; min-width: 0; min-height: 64px; border: 0; background: none; font-size: 2.6rem; font-weight: 900; font-variant-numeric: tabular-nums; text-align: center; cursor: text; border-radius: 12px; }
.team__score:hover { background: var(--surface); }
.team__score--edit { background: var(--surface); border: 2px solid var(--accent); width: 100%; }
.team__err { grid-area: err; }
@media (min-width: 720px) {
  .team { grid-template-columns: 40px minmax(0, 1fr) 88px 120px 88px 40px; grid-template-areas: "sw name minus score plus del" "err err err err err err"; }
}

.empty { text-align: center; color: var(--muted); padding: 22px; border: 2px dashed var(--border); border-radius: 16px; margin: 0; }
.add-team { display: flex; gap: 8px; margin-top: 12px; }
.add-team input { flex: 1; min-width: 0; min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 2px dashed var(--border); background: none; }
.add-team input:focus { border-style: solid; border-color: var(--accent); outline: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 8px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
#resetBtn { margin-left: auto; }

/* Ads */
.ad-slot { display: flex; align-items: center; justify-content: center; margin: 0 auto; border: 1px dashed var(--ad-border); border-radius: 10px; color: var(--muted); font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; background: var(--surface-2); }
.ad-slot--rect { width: 300px; height: 250px; }
.ad-slot--bottom { width: min(728px, calc(100% - 32px)); height: 90px; margin: 24px auto; }
@media (max-width: 760px) { .ad-slot--bottom { width: 320px; height: 100px; } }

/* Content */
.content { max-width: 1200px; margin: 0 auto; padding: 24px 16px 0; display: grid; gap: 20px; }
@media (min-width: 900px) { .content { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.prose h2 { margin-top: 0; }
.prose li { margin-bottom: 6px; }
.faq details { border-top: 1px solid var(--border); padding: 10px 0; }
.faq summary { cursor: pointer; font-weight: 700; }
.site-footer { text-align: center; color: var(--muted); font-size: .9rem; padding: 0 16px 24px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast .btn--text { color: var(--bg); font-weight: 800; }

/* Embed mode */
.embed-only { display: none; }
.is-embed .chrome { display: none !important; }
.is-embed .embed-only { display: inline-block; margin-top: 12px; color: var(--muted); font-size: .85rem; }
.is-embed .layout { grid-template-columns: 1fr; padding-top: 12px; }

/* ===================== Display view ===================== */
.is-display { background: #0e0d18; color: #fff; overflow: hidden; }
.is-display .chrome, .is-display .toast { display: none !important; }
.display-view { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding: clamp(16px, 3vh, 40px) clamp(16px, 4vw, 64px); }
.disp__title { margin: 0 0 2vh; text-align: center; font-size: clamp(1.8rem, 6vh, 4.5rem); font-weight: 900; letter-spacing: -.01em; }
.disp__list { list-style: none; margin: 0; padding: 0; flex: 1; display: grid; grid-auto-rows: 1fr; gap: 1.4vh; min-height: 0; --rowfs: calc(62vh / var(--n)); }
.disp__list.is-compact { grid-template-columns: 1fr 1fr; column-gap: 3vw; --rowfs: 5.4vh; }
.disp__row { display: grid; grid-template-columns: 1.4em minmax(0, 1fr) auto; grid-template-areas: "place name score" "place bar score"; align-items: center; column-gap: .5em; font-size: clamp(16px, var(--rowfs), 120px); line-height: 1.05; min-height: 0; padding: 0 .4em; border-radius: .25em; background: rgba(255,255,255,.04); }
.disp__row.is-leader { background: color-mix(in srgb, var(--c) 22%, transparent); }
.disp__place { grid-area: place; font-weight: 900; opacity: .7; text-align: center; font-size: .55em; }
.is-leader .disp__place { color: #ffd23f; opacity: 1; font-size: .7em; }
.disp__name { grid-area: name; font-size: .42em; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; align-self: end; }
.disp__bar { grid-area: bar; height: .22em; border-radius: 99px; background: rgba(255,255,255,.1); overflow: hidden; align-self: start; margin-top: .1em; }
.disp__fill { display: block; height: 100%; width: var(--w); background: var(--c); border-radius: inherit; transition: width .45s cubic-bezier(.2,.8,.2,1); }
.disp__score { grid-area: score; font-weight: 900; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--c) 35%, #fff); }
.disp__score.bump { animation: bump .4s ease-out; }
@keyframes bump { 40% { transform: scale(1.18); } }
.disp__empty { text-align: center; font-size: 3vh; opacity: .7; }
.disp__controls { position: fixed; right: 16px; bottom: 16px; opacity: 0; transition: opacity .2s; }
.display-view:hover .disp__controls, .disp__controls:focus-within { opacity: 1; }
.disp__controls .btn--ghost { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); color: #fff; }

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