@font-face {
  font-family: "Zilla Slab";
  src: url("fonts/zilla-slab-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --surface: #f5f5f2;
  --ink: #15171c;
  --muted: #565b66;
  --line: #d9dad6;
  --honey: #f2b01e;
  --honey-ink: #7a4f00;
  --band: #15171c;
  --band-ink: #f6f4ee;
  --ok: #18794a;
  --ok-ink: #ffffff;
  --bad: #b8322a;
  --bad-ink: #ffffff;
  --focus: #1a5fd0;
  --head: "Zilla Slab", "Rockwell", "Roboto Slab", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 6px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131417;
    --surface: #1c1e22;
    --ink: #eeece6;
    --muted: #a7abb3;
    --line: #34373d;
    --honey: #f5b82e;
    --honey-ink: #f5c75e;
    --band: #0b0c0e;
    --band-ink: #f6f4ee;
    --ok: #23935c;
    --bad: #cf4339;
    --focus: #7fb0ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--sans); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
a { color: inherit; text-decoration-color: var(--honey); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--honey); color: #15171c; padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }
kbd { font: 600 0.78em/1 var(--sans); border: 1px solid currentColor; border-radius: 4px; padding: 2px 5px; opacity: 0.75; }

/* header band */
.top { background: var(--band); color: var(--band-ink); padding: 26px 0 22px; border-bottom: 6px solid var(--honey); }
.top h1 { font: 700 clamp(1.9rem, 5vw, 2.8rem)/1.1 var(--head); margin: 0 0 8px; display: flex; align-items: center; gap: 12px; letter-spacing: -0.01em; }
.top .mark { flex: none; }
.lede { margin: 0; max-width: 62ch; color: #d4d2cb; font-size: 1.05rem; }

main { padding-top: 24px; }
h1, h2, h3, .round-chip, .clock, .word, .speller, [class^="scr-"] { font-variant-numeric: lining-nums; }
h2, h3 { font-family: var(--head); font-weight: 700; line-height: 1.2; }

/* forms */
.setup-grid { display: grid; gap: 20px; }
@media (min-width: 820px) { .setup-grid { grid-template-columns: 1fr 1.35fr; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, legend { font-weight: 700; }
.count { font-weight: 500; color: var(--muted); margin-left: 6px; }
textarea, input[type=text], select {
  font: 16px/1.45 var(--sans); color: var(--ink); background: var(--bg); border: 1.5px solid var(--line);
  border-radius: var(--r); padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 180px; }
textarea:focus, input:focus, select:focus { border-color: var(--ink); }
select { min-height: 46px; }
.hint { margin: 0; color: var(--muted); font-size: 0.95rem; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.rules { border: 0; margin: 4px 0 10px; padding: 0; }
.rules legend { margin-bottom: 8px; padding: 0; }
.rule { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-left: 4px solid transparent; cursor: pointer; }
.rule:has(input:checked) { border-left-color: var(--honey); background: var(--surface); }
.rule input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--ink); flex: none; }
.rule b { display: block; }
.more { margin: 6px 0 16px; }
.more summary, .addmore summary, .log-wrap summary { cursor: pointer; font-weight: 700; padding: 8px 0; min-height: 44px; display: flex; align-items: center; gap: 8px; list-style: none; }
.more summary::-webkit-details-marker, .addmore summary::-webkit-details-marker, .log-wrap summary::-webkit-details-marker { display: none; }
.more summary::before, .addmore summary::before, .log-wrap summary::before { content: ""; width: 0; height: 0; border-left: 7px solid var(--honey-ink); border-top: 5px solid transparent; border-bottom: 5px solid transparent; transition: transform 0.15s; }
details[open] > summary::before { transform: rotate(90deg); }
.more-grid { display: grid; gap: 4px 20px; padding-top: 6px; }
@media (min-width: 720px) { .more-grid { grid-template-columns: 1.4fr 1fr 1fr; } }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }
.error { color: var(--bad); font-weight: 600; margin: 0 0 8px; min-height: 1px; }
.error:empty { display: none; }

/* buttons */
.btn {
  font: 600 1rem/1.2 var(--sans); color: var(--ink); background: var(--bg); border: 1.5px solid var(--ink);
  border-radius: var(--r); padding: 11px 16px; min-height: 46px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.small { font-size: 0.95rem; padding: 8px 12px; min-height: 44px; }
.btn.primary { background: var(--honey); border-color: var(--honey); color: #15171c; }
.btn.primary:hover { background: #ffc23d; }
.btn.big { font-size: 1.15rem; padding: 14px 26px; }
.btn.ghost { border-color: transparent; text-decoration: underline; text-decoration-color: var(--honey); text-underline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0 20px; }
.linkbtn { font: inherit; color: inherit; background: none; border: 0; padding: 6px 2px; min-height: 44px; text-decoration: underline; text-decoration-color: var(--honey); text-underline-offset: 3px; cursor: pointer; }
.saved { color: var(--muted); font-size: 0.95rem; margin: 8px 0 30px; }

/* run view */
.statusbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
.round-chip { font: 700 1.35rem/1 var(--head); background: var(--honey); color: #15171c; padding: 8px 12px 6px; border-radius: var(--r); }
.statusbar .spacer { flex: 1; }
.notice { margin: 14px 0 0; padding: 12px 16px; background: var(--surface); border-left: 5px solid var(--honey); font-weight: 600; font-size: 1.05rem; }
.notice.n-champWord, .notice.n-duelFix { border-left-color: var(--ok); }
.notice.n-allMissed, .notice.n-champMissed, .notice.n-bothMissed { border-left-color: var(--focus); }
.run-grid { display: grid; gap: 24px; margin-top: 18px; }
@media (min-width: 900px) { .run-grid { grid-template-columns: minmax(0, 1fr) 300px; } }
.stage { min-width: 0; }
.turn-kind { display: inline-block; margin: 0 0 8px; padding: 4px 10px; background: var(--ok); color: var(--ok-ink); font-weight: 700; border-radius: var(--r); }
.speller { font: 700 clamp(1.5rem, 4vw, 2.1rem)/1.15 var(--head); margin: 0 0 12px; }
.speller .num { color: var(--muted); font-weight: 700; }
.wordbox { border: 2px solid var(--ink); border-radius: var(--r); padding: 18px 20px 14px; margin-bottom: 16px; }
.word { font: 700 clamp(2.4rem, 8vw, 4.6rem)/1.05 var(--head); margin: 0 0 12px; overflow-wrap: anywhere; letter-spacing: 0.01em; }
.word.long { font-size: clamp(1.9rem, 6vw, 3.6rem); }
.word:empty { display: none; }
.own { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.own label { font-weight: 600; }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.info dt { color: var(--muted); font-weight: 600; }
.info dd { margin: 0; }
.info:empty { display: none; }
.wordmeta { color: var(--muted); margin: 10px 0 0; font-size: 0.95rem; }
.wordmeta:empty { display: none; }
.judge { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.judge .btn { min-height: 76px; font-size: 1.35rem; border: 0; }
.btn.ok { background: var(--ok); color: var(--ok-ink); }
.btn.ok:hover { background: #136a40; }
.btn.bad { background: var(--bad); color: var(--bad-ink); }
.btn.bad:hover { background: #9e2a23; }
.btn.hit { animation: hit 0.35s ease-out; }
@keyframes hit { 0% { transform: scale(0.96); } 100% { transform: scale(1); } }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.clock { font: 700 2rem/1 var(--head); min-width: 3ch; padding: 0 6px; font-variant-numeric: lining-nums tabular-nums; }
.clock.low { color: var(--honey-ink); }
.clock.up { color: var(--bad); }

.board h3 { font-size: 1.2rem; margin: 0 0 8px; }
.board-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.b-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); }
.b-num { color: var(--muted); min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.b-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.b-row.now { background: var(--surface); box-shadow: inset 4px 0 0 var(--honey); font-weight: 700; }
.b-row.out .b-name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted); }
.tag { font-size: 0.9rem; color: var(--muted); white-space: nowrap; }
.tag.now { color: var(--ink); }
.tag.ok { color: var(--ok); font-weight: 700; font-size: 1.1rem; }
.tag.bad { color: var(--bad); font-weight: 700; font-size: 1.1rem; }
.tag.wait { color: var(--honey-ink); font-weight: 600; }
.addmore { margin-top: 12px; }
.addmore textarea { min-height: 90px; margin-bottom: 8px; }
.addmore + .addmore { margin-top: 0; }
.addmore input { margin-bottom: 6px; }
.addmore .hint { margin-bottom: 8px; }
.try { margin: 0 0 14px; }
.elsewhere { margin: 28px 0; max-width: 60ch; }
.elsewhere h2 { margin: 0 0 8px; }
.elsewhere p { margin: 0 0 16px; }
.host-note { margin-bottom: 0; }
.endlink { margin: 8px 0 0; }

.log-wrap { margin: 20px 0 8px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { border-bottom: 2px solid var(--ink); font-size: 0.95rem; }
td.empty { color: var(--muted); }
.r-ok { color: var(--ok); font-weight: 700; }
.r-bad { color: var(--bad); font-weight: 700; }

/* results */
.champ-line { font-size: clamp(2rem, 6vw, 3.2rem); margin: 4px 0 18px; padding-bottom: 12px; border-bottom: 6px solid var(--honey); }
.res-grid { display: grid; gap: 24px; }
@media (min-width: 820px) { .res-grid { grid-template-columns: minmax(0, 1.4fr) 1fr; } }
.res-grid h3 { margin: 0 0 8px; }
.places tr.first td { font-weight: 700; }
.res-actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

/* content */
.guide { max-width: 70ch; padding: 10px 0 30px; border-top: 1px solid var(--line); margin-top: 18px; }
.guide h2 { font-size: 1.6rem; margin: 30px 0 10px; }
.guide h3 { font-size: 1.15rem; margin: 22px 0 6px; }
.guide p { margin: 0 0 12px; }
.src { color: var(--muted); font-size: 0.95rem; }
.warn { background: var(--surface); padding: 12px; }

/* footer */
.foot { border-top: 1px solid var(--line); padding: 22px 0 34px; color: var(--muted); font-size: 0.95rem; }
.foot p { margin: 6px 0; }

/* phone */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .top { padding: 18px 0 16px; }
  .lede { font-size: 1rem; }
  .statusbar .btn.small { flex: 1 1 40%; padding: 8px; }
  .statusbar .spacer { display: none; }
  .judge .btn { min-height: 68px; font-size: 1.2rem; }
  .judge kbd, .tools kbd, .statusbar kbd { display: none; }
  .actions .btn { flex: 1 1 100%; }
  .info { grid-template-columns: 1fr; gap: 0; }
  .info dd { margin-bottom: 6px; }
  .wordbox { padding: 14px 14px 12px; }
}

/* ---------- audience screen ---------- */
.screen { --s-bg: #0d0e10; --s-ink: #f6f4ee; --s-muted: #a9adb5; --s-honey: #f5b82e; }
body.scr-light .screen { --s-bg: #ffffff; --s-ink: #15171c; --s-muted: #4d525c; --s-honey: #a36a00; }
body.screen-mode, body.local-screen { overflow: hidden; }
body.screen-mode > *:not(main), body.local-screen > *:not(main),
body.screen-mode main > *:not(#screen), body.local-screen main > *:not(#screen) { display: none !important; }
body.screen-mode main, body.local-screen main { padding: 0; max-width: none; }
.screen { position: fixed; inset: 0; z-index: 20; background: var(--s-bg); color: var(--s-ink); display: grid; grid-template-rows: auto 1fr auto; padding: 3vh 4vw; }
.scr-top { display: flex; justify-content: space-between; gap: 2vw; font: 700 clamp(1rem, 2.6vw, 2.2rem)/1.2 var(--head); color: var(--s-muted); border-bottom: 0.5vh solid var(--s-honey); padding-bottom: 1.5vh; }
.scr-round { color: var(--s-honey); white-space: nowrap; }
.scr-main { align-self: center; text-align: center; min-width: 0; }
.scr-kind { font: 600 clamp(1rem, 3vw, 2.4rem)/1.2 var(--sans); color: var(--s-muted); margin: 0 0 1vh; }
.screen[data-kind="champ"] .scr-kind, .screen[data-status="done"] .scr-kind { color: var(--s-honey); }
.scr-name { font: 700 clamp(2.6rem, 11vw, 10rem)/1.02 var(--head); margin: 0; overflow-wrap: anywhere; }
.scr-clock { font: 700 clamp(2rem, 7vw, 6rem)/1 var(--head); margin: 2vh 0 0; font-variant-numeric: lining-nums tabular-nums; color: var(--s-muted); }
.scr-clock:empty { display: none; }
.scr-clock.low { color: var(--s-honey); }
.scr-clock.up { color: #ff6b5e; }
.scr-msg { font: 600 clamp(1.1rem, 3vw, 2.6rem)/1.3 var(--sans); margin: 3vh auto 0; max-width: 34ch; }
.scr-last { font: 500 clamp(1rem, 2.6vw, 2.2rem)/1.3 var(--sans); color: var(--s-muted); text-align: center; min-height: 1.3em; }
.scr-last b { color: var(--s-ink); font-family: var(--head); letter-spacing: 0.02em; }
.scr-last .r-ok { color: #3ccf7f; }
.scr-last .r-bad { color: #ff6b5e; }
body.scr-light .scr-last .r-ok { color: var(--ok); }
body.scr-light .scr-last .r-bad { color: var(--bad); }
.scr-ctl { position: fixed; right: 12px; bottom: 12px; display: flex; gap: 8px; opacity: 0.25; transition: opacity 0.2s; }
.scr-ctl:hover, .scr-ctl:focus-within { opacity: 1; }
.scr-ctl .btn { background: transparent; color: var(--s-ink); border-color: var(--s-muted); }

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

/* ---------- print ---------- */
.print-area { display: none; }
@page { margin: 14mm 13mm; }
@media print {
  :root { --ink: #000; --muted: #333; --line: #888; }
  body { background: #fff !important; color: #000; font: 10.5pt/1.35 var(--sans); }
  body > *:not(main), main > *:not(.print-area) { display: none !important; }
  main { padding: 0; max-width: none; }
  .print-area { display: block; }
  .p-head { border-bottom: 2.5pt solid #000; margin-bottom: 10pt; padding-bottom: 6pt; }
  .p-head h2 { font: 700 18pt/1.15 var(--head); margin: 0 0 4pt; }
  .p-head p { margin: 0; font-size: 10pt; }
  .print-area h3 { font: 700 13pt/1.2 var(--head); margin: 14pt 0 5pt; break-after: avoid; }
  table { width: 100%; border-collapse: collapse; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  th, td { border: 0.75pt solid #555; padding: 4pt 5pt; text-align: left; vertical-align: top; }
  thead th { background: #eee; border-bottom: 1.5pt solid #000; font-size: 9.5pt; }
  .p-sheet td { height: 9.5mm; vertical-align: middle; }
  .p-sheet td.n { width: 8mm; text-align: center; }
  .p-sheet td.nm { width: 30%; font-size: 11pt; }
  .p-sheet th:nth-child(n+3) { text-align: center; }
  .p-words td.n { width: 7mm; text-align: center; }
  .p-words td.w { font-weight: 700; font-size: 11.5pt; width: 22%; }
  .p-words .lv { display: block; font-weight: 400; font-size: 8.5pt; color: #444; }
  .p-words td.box { width: 12mm; }
  .p-words td { font-size: 9.5pt; }
  .p-words.plain { width: auto; min-width: 60%; }
  .p-words.plain td.w { width: auto; padding-right: 20mm; }
  .p-log td, .p-places td { padding: 2.5pt 5pt; font-size: 9.5pt; }
  .p-log th, .p-places th { padding: 3pt 5pt; }
  .p-champ { font-size: 14pt; margin: 4pt 0 6pt; }
  .p-places td:first-child { width: 22%; }
  .p-note { font-size: 9.5pt; margin-top: 8pt; }
  .p-sheet.roomy td { height: 13mm; }
  .p-sign { display: flex; gap: 8mm; margin-top: 12mm; font-size: 10.5pt; break-inside: avoid; }
  .p-sign span { flex: 1; border-top: 0.75pt solid #000; padding-top: 2pt; }
}
