/* City Quiz — styles. Come Alone family tokens; dark via prefers-color-scheme. */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1d1a22;
  --muted: #625d69;
  --line: rgba(29,26,34,.12);
  --accent: #2fb3a6;
  --accent-ink: #10201e;
  --pink: #ff5c8a;
  --pos: #12806a;
  --neg: #c8324f;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4a00;
  --shadow: 0 10px 30px rgba(29,26,34,.08);
  --radius: 20px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131a;
    --surface: #201d27;
    --surface-2: #2a2633;
    --text: #f3f0f7;
    --muted: #a8a2b1;
    --line: rgba(243,240,247,.12);
    --pos: #4fd1b0;
    --neg: #ff7a93;
    --warn-bg: #3a2f14;
    --warn-ink: #ffd88a;
    --shadow: 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-weight: 500; background: var(--bg); color: var(--text);
  line-height: 1.45; min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 900; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; font-weight: 800; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus, h1:focus { outline: none; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; max-width: 720px; width: 100%; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 900; font-size: 1.15rem; }
.brand-mark { width: 32px; height: 32px; color: var(--accent); }
.lang-wrap select { font-weight: 700; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; }

/* Main */
.app { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { padding: 12px 0 16px; }
.hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); }
.hero p { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.how { list-style: none; margin-top: 14px; display: grid; gap: 8px; counter-reset: how; }
.how li { counter-increment: how; display: flex; gap: 10px; align-items: baseline; font-weight: 700; }
.how li::before { content: counter(how); flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 900; font-size: .85rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-top: 12px; }
.panel h2 { font-size: 1.15rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel h2 small { color: var(--muted); font-weight: 700; font-size: .9rem; }
.panel h1 { font-size: 1.4rem; }
.lead { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.hint.pad { padding: 12px 4px 0; }
.center { text-align: center; }
.err { color: var(--neg); font-weight: 800; margin-top: 10px; }
.err:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 14px; padding: 12px 14px; font-weight: 700; margin-top: 12px; }
.warn a { font-weight: 900; }
.ok-line { margin-top: 10px; font-weight: 800; color: var(--pos); }

.mt { margin-top: 16px; }
.muted { color: var(--muted); }

/* Home: modes */
.modes { display: grid; gap: 10px; margin-top: 8px; }
.mode { display: flex; gap: 14px; align-items: center; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); transition: transform .12s ease; }
.mode:hover { transform: translateY(-1px); }
.mode-ico { flex: 0 0 48px; height: 48px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; font-size: 1.5rem; }
.mode-txt { display: flex; flex-direction: column; min-width: 0; }
.mode-txt strong { font-weight: 900; font-size: 1.15rem; }
.mode-txt span { color: var(--muted); font-size: .95rem; }
.resume { margin-top: 12px; }

/* City picker */
.cities { display: grid; gap: 8px; margin-top: 10px; }
.city { display: grid; grid-template-columns: auto 1fr; gap: 0 12px; align-items: center; background: var(--surface-2); border: 2px solid transparent; border-radius: 16px; padding: 12px 14px; cursor: pointer; }
.city.on { border-color: var(--accent); }
.city input { grid-row: 1 / span 2; width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.city-name { font-weight: 900; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.city-meta { color: var(--muted); font-size: .88rem; }
.badge { font-size: .72rem; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; background: var(--pink); color: #fff; border-radius: 999px; padding: 2px 8px; }

/* Forms */
.field { margin-top: 14px; min-width: 0; }
.field label { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.field select, .add-row input, .copybox {
  width: 100%; font-weight: 700; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); min-width: 0; min-height: 48px;
}
.copybox { position: fixed; left: -9999px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.three { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0 12px; }
.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row input { flex: 1; }
.check { display: flex; gap: 10px; align-items: center; margin-top: 16px; font-weight: 700; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin-top: 10px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 10px 6px; font-weight: 800; cursor: pointer; color: var(--muted); min-height: 44px; }
.seg .on { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 16px;
  padding: 14px 20px; font-weight: 900; font-size: 1.05rem; cursor: pointer; background: var(--surface-2); color: var(--text);
  text-decoration: none; transition: transform .12s ease; min-height: 48px; text-align: center;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; display: flex; }
.btn.big { padding: 16px 22px; font-size: 1.1rem; }
.btn.small { padding: 8px 12px; font-size: .9rem; min-height: 40px; border-radius: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row .btn { flex: 1 1 140px; }
.g-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.g-head .back { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; }
.g-head .back svg { width: 22px; height: 22px; }
.g-head h1 { font-size: 1.4rem; flex: 1; overflow-wrap: anywhere; }

/* Solo play */
.progress { flex: 1; font-weight: 800; color: var(--muted); }
.tnum { font-weight: 900; font-variant-numeric: tabular-nums; min-width: 3.5em; text-align: right; }
.tbar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.tbar i { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: 99px; transition: width .2s linear; }
.tbar.low i { background: var(--neg); }
.qpanel .q { font-size: clamp(1.3rem, 4.6vw, 1.7rem); overflow-wrap: anywhere; }
.opts { display: grid; gap: 10px; margin-top: 16px; }
.opt { display: flex; align-items: center; gap: 12px; text-align: left; border: 2px solid var(--line); background: var(--bg); border-radius: 16px; padding: 12px 14px; font-weight: 800; font-size: 1.05rem; cursor: pointer; min-height: 56px; }
.opt b { flex: 0 0 32px; height: 32px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 900; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; color: inherit; }
.opt.right { border-color: var(--pos); background: color-mix(in srgb, var(--pos) 14%, var(--bg)); }
.opt.right b { background: var(--pos); color: #fff; }
.opt.wrong { border-color: var(--neg); background: color-mix(in srgb, var(--neg) 12%, var(--bg)); }
.opt.wrong b { background: var(--neg); color: #fff; }
.opt.dim { opacity: .55; }
.feedback { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 12px; }
.feedback:empty { display: none; }
.fb-line { font-weight: 900; font-size: 1.1rem; width: 100%; }
.fb-line.ok { color: var(--pos); }
.fb-line.no { color: var(--neg); }
.feedback .hint { margin: 0; flex: 1; font-weight: 700; }
.qpanel + .btn { margin-top: 14px; }

/* Solo result */
.score { font-size: clamp(2.4rem, 10vw, 3.4rem); margin-top: 4px; }
.grid-share { font-family: ui-monospace, monospace; font-size: 1.25rem; line-height: 1.35; background: var(--surface-2); border-radius: 14px; padding: 14px; margin: 14px auto 0; display: inline-block; text-align: left; white-space: pre-wrap; max-width: 100%; }
.review { margin-top: 8px; padding-left: 1.4em; }
.review li { padding: 10px 0; border-top: 1px solid var(--line); }
.review li:first-child { border-top: 0; }
.rq { font-weight: 800; }
.ra { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.src-link { font-weight: 800; font-size: .9rem; color: var(--muted); }
.src { margin-left: auto; }

/* Scoreboard editor */
.board { margin-top: 8px; }
.teams { list-style: none; display: grid; gap: 8px; margin-top: 8px; }
.team { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 14px; padding: 8px 10px; }
.team .place { flex: 0 0 2em; font-weight: 900; color: var(--muted); }
.team .tname { flex: 1; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tscore { min-width: 2.2em; text-align: center; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.pm { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; width: 52px; height: 44px; font-weight: 900; cursor: pointer; font-size: 1rem; }
.pm.plus { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.x { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; color: var(--muted); font-size: 1.3rem; }
.x:hover { background: var(--line); color: var(--text); }

/* Host stage (big screen) */
body.stage .top, body.stage .foot { display: none; }
body.stage .app { max-width: none; padding: 0; display: flex; }
body.stage .screen { flex: 1; display: flex; }
.stage-wrap { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; padding: clamp(12px, 2vw, 28px); gap: 12px; }
.stage-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stage-city { font-weight: 900; color: var(--accent); }
.stage-pos { font-weight: 800; color: var(--muted); flex: 1; }
.stage-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.stage-main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: clamp(16px, 3vh, 36px); width: 100%; max-width: 1400px; margin: 0 auto; position: relative; }
.stage-main.narrow { max-width: 760px; justify-content: flex-start; padding-top: 2vh; }
.stage-q { font-size: clamp(1.8rem, 4.4vw, 4rem); text-align: center; overflow-wrap: anywhere; padding: 0 4vw; }
.stage-title { font-size: clamp(2rem, 5vw, 3.4rem); text-align: center; }
.stage-opts { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 1.6vw, 22px); }
.sopt { display: flex; align-items: center; gap: clamp(10px, 1.4vw, 20px); background: var(--surface); border: 3px solid var(--line); border-radius: clamp(16px, 2vw, 28px); padding: clamp(14px, 2vw, 28px); font-weight: 900; font-size: clamp(1.2rem, 2.6vw, 2.4rem); transition: opacity .3s, transform .3s; overflow-wrap: anywhere; }
.sopt b { flex: 0 0 auto; width: 1.7em; height: 1.7em; border-radius: .4em; background: var(--surface-2); display: grid; place-items: center; }
.sopt.right { border-color: var(--pos); background: color-mix(in srgb, var(--pos) 18%, var(--surface)); transform: scale(1.02); }
.sopt.right b { background: var(--pos); color: #fff; }
.sopt.dim { opacity: .35; }
.stage-src { text-align: center; }
.count { --p: 100; position: absolute; top: 0; right: 0; width: clamp(64px, 8vw, 120px); height: clamp(64px, 8vw, 120px); border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: clamp(1.4rem, 3vw, 2.8rem); font-variant-numeric: tabular-nums; background: radial-gradient(closest-side, var(--bg) 78%, transparent 80% 100%), conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.count.low { background: radial-gradient(closest-side, var(--bg) 78%, transparent 80% 100%), conic-gradient(var(--neg) calc(var(--p) * 1%), var(--surface-2) 0); color: var(--neg); }
.count.up { position: static; width: auto; height: auto; border-radius: 14px; background: var(--neg); color: #fff; padding: 6px 18px; font-size: clamp(1.2rem, 2.4vw, 2rem); justify-self: center; align-self: center; }
.stage-nav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 1400px; width: 100%; margin: 0 auto; }
.stage-nav .btn.big { flex: 1 1 260px; max-width: 520px; margin-left: auto; font-size: clamp(1.1rem, 1.8vw, 1.5rem); }
.keys { text-align: center; color: var(--muted); font-size: .85rem; }
@media (hover: none) { .keys { display: none; } }
@media (max-width: 640px) { .stage-opts { grid-template-columns: 1fr; } .count { position: static; align-self: center; } }
.stage .board .tname { font-size: 1.2rem; }
.winner { text-align: center; font-weight: 900; font-size: clamp(1.4rem, 3.4vw, 2.4rem); color: var(--pink); }
.final { list-style: none; display: grid; gap: 10px; }
.final li { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 18px; font-size: clamp(1.1rem, 2.4vw, 1.8rem); }
.final li.p1 { border: 3px solid var(--accent); font-size: clamp(1.3rem, 3vw, 2.2rem); }
.final .place { font-weight: 900; color: var(--muted); min-width: 2em; }
.final .tname { flex: 1; font-weight: 900; overflow-wrap: anywhere; }

/* Answer sheets / host key (screen preview) */
.sheets { display: grid; gap: 16px; margin-top: 16px; }
.sheet { background: #fff; color: #111; border-radius: 12px; padding: 24px; box-shadow: var(--shadow); font-size: 14px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid #111; padding-bottom: 10px; font-size: 16px; }
.sheet-team { display: flex; gap: 8px; align-items: flex-end; flex: 1 1 260px; font-weight: 800; }
.sheet-team i, .sub i, .sheet-grand i { flex: 1; border-bottom: 1.5px solid #111; min-width: 60px; height: 1.2em; display: inline-block; }
.sheet-hint { color: #555; font-size: 12px; margin-top: 6px; }
.sheet-rounds { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 24px; margin-top: 12px; }
.sheet-round h3 { font-size: 15px; margin-bottom: 4px; }
.sheet-round ol { list-style: none; }
.sheet-round li { display: flex; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px dotted #bbb; }
.qn { width: 2em; font-weight: 800; }
.bub { width: 22px; height: 22px; border: 1.5px solid #111; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; }
.sub, .sheet-grand { display: flex; gap: 8px; align-items: flex-end; margin-top: 6px; font-weight: 800; }
.sub i { max-width: 60px; }
.sheet-grand { margin-top: 16px; font-size: 16px; max-width: 260px; margin-left: auto; }
.sheet-foot { color: #777; font-size: 11px; text-align: right; margin-top: 8px; }
.key .key-round { margin-top: 12px; }
.key ol { padding-left: 1.6em; }
.key li { padding: 3px 0; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 800; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Footer */
.foot { max-width: 720px; width: 100%; margin: 0 auto; padding: 20px 16px 36px; color: var(--muted); font-size: .92rem; text-align: center; border-top: 1px solid var(--line); }
.foot-line + .foot-line { margin-top: 8px; }
.foot-line a { color: var(--text); font-weight: 700; }
.foot-line.small { font-size: .85rem; }

@media (prefers-reduced-motion: reduce) { .screen { animation: none; } .btn, .toast, .mode, .sopt, .tbar i { transition: none; } }

/* Print: A4 answer sheets, one per page */
@page { size: A4; margin: 12mm; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #111; padding: 0; display: block; min-height: 0; }
  .top, .foot, .noprint, .toast, .skip { display: none !important; }
  .app { max-width: none; padding: 0; }
  .screen { animation: none; }
  .sheets { display: block; margin: 0; }
  .sheet { box-shadow: none; border-radius: 0; padding: 0; break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .sheet-rounds { grid-template-columns: repeat(3, 1fr); }
  .sheet-rounds.many { grid-template-columns: repeat(3, 1fr); font-size: 12px; }
  .sheet-round { break-inside: avoid; }
  .key li { break-inside: avoid; }
}
