:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, sans-serif;
  --background: #090909;
  --panel: #121212;
  --field: #0b0b0b;
  --line: #303030;
  --control-line: #6b6b6b;
  --button: #202020;
  --button-hover: #313322;
  --tile: #191919;
  --tile-hover: #303a1b;
  --text: #f9f9f9;
  --muted: #b6b6b6;
  --accent: #abe400;
  --accent-hover: #c4f535;
  --accent-ink: #090909;
  --focus: #d3fa70;
  background: var(--background);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse 70rem 27rem at 47% -9rem, #3c4725, transparent 82%), var(--background);
}
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: .2em; }
h1, h2, p { margin: 0; }
h1 { margin-bottom: 1.15rem; overflow-wrap: anywhere; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.08; letter-spacing: -.035em; }
h2 { font-size: 1.25rem; line-height: 1.25; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.shell { max-width: 76rem; margin-inline: auto; padding: 1.1rem clamp(.8rem, 3vw, 2.5rem) 2rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; min-height: 3.5rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; padding-bottom: .7rem; }
.brand { display: flex; align-items: baseline; flex-wrap: wrap; gap: .4rem .8rem; color: var(--accent); font-weight: 850; font-size: 1.45rem; line-height: 1; letter-spacing: -.035em; }
.brand span { color: var(--muted); font-size: .9rem; font-weight: 550; letter-spacing: normal; }
.panel { padding: clamp(1rem, 2vw, 1.5rem); border: 1px solid var(--line); border-radius: .85rem; background: var(--panel); min-width: 0; }
.panel > h2 { margin-bottom: .85rem; }
.panel > p + p { margin-top: .5rem; }
.login { max-width: 27rem; margin: clamp(1.5rem, 10vh, 6rem) auto 0; }
.login h1 { font-size: clamp(1.75rem, 5vw, 2.4rem); }
.login > a { display: inline-block; margin-top: 1.35rem; }
.login button { width: 100%; }

form { display: grid; gap: .85rem; }
label { display: grid; gap: .4rem; font-size: .925rem; font-weight: 550; min-width: 0; }
button, input, textarea, select, summary { font: inherit; }
button, .button, input, textarea, select { border: 1px solid var(--control-line); border-radius: .5rem; color: var(--text); }
input, textarea, select { min-width: 0; width: 100%; background: var(--field); padding: .6rem .7rem; font-size: 1rem; }
input, select, button, .button { min-height: 2.55rem; }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); }
select {
  appearance: none;
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 1rem center, right .65rem center;
  background-size: .35rem .35rem;
  background-repeat: no-repeat;
}
button, .button { display: inline-flex; align-items: center; justify-content: center; padding: .48rem .7rem; background: var(--button); text-decoration: none; font-weight: 660; font-size: .925rem; cursor: pointer; }
button:not(:disabled):hover, .button:hover { background: var(--button-hover); }
button:disabled { cursor: default; opacity: .48; }
:is(button, input, textarea, select, a, summary):focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:not(:disabled):hover, .button.primary:hover { background: var(--accent-hover); }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.topbar > .actions { justify-content: flex-end; }
.inline { grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .45rem; }
.code-input { font-family: ui-monospace, monospace; text-transform: uppercase; letter-spacing: .11em; }

.session-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: .85rem; margin-bottom: 1.4rem; }
.session-bar > :empty { display: none; }
.session-bar details { align-self: start; border: 1px solid var(--line); border-radius: .65rem; padding: .75rem 1rem; }
.session-bar summary { cursor: pointer; font-weight: 650; }
.session-bar form { margin-top: .85rem; }
.admin-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(17rem, 1fr); align-items: start; gap: .85rem; }
.stack { display: grid; gap: .85rem; min-width: 0; }
.game-heading { margin-bottom: 1rem; }
.game-heading h1 { margin-bottom: .32rem; }
.game-heading p { font-size: 1.1rem; }
#stage, #response { margin-bottom: .85rem; }

.board-scroll { overflow: auto; }
.board-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.board-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .55rem; margin-bottom: .85rem; }
.board { width: 100%; border-spacing: .28rem; }
.board th { width: 25%; min-width: 6rem; padding-right: .4rem; text-align: left; font-weight: 650; overflow-wrap: anywhere; }
.board td { min-width: 3.3rem; padding: 0; }
.cell { display: flex; width: 100%; min-height: 3.15rem; align-items: center; justify-content: center; padding: .45rem; border: 1px solid var(--control-line); border-radius: .45rem; background: var(--tile); color: var(--accent); font-size: clamp(1rem, 2vw, 1.45rem); font-variant-numeric: tabular-nums; font-weight: 760; }
button.cell:not(:disabled):hover { border-color: var(--accent); background: var(--tile-hover); }
.cell.used { color: var(--muted); background: transparent; opacity: .65; }
.cell.current { border-color: var(--accent); background: var(--tile-hover); }
.cell-numbered { flex-direction: column; gap: .15rem; }
.cell-index { color: var(--muted); font-size: .75rem; line-height: 1; }

.question-top, .submission-head, .team-name, .access-row, .score { display: flex; align-items: center; justify-content: space-between; gap: .65rem; }
.question-top { align-items: start; }
.category { color: var(--accent); font-weight: 750; }
.timing { font-size: .9rem; }
.clock { font: 800 clamp(1.6rem, 5vw, 2.75rem)/1 ui-monospace, monospace; font-variant-numeric: tabular-nums; color: var(--accent); }
.question-text { font-size: clamp(1.45rem, 3vw, 2.35rem); margin-block: 1rem .35rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.solution { display: grid; gap: .3rem; margin-top: 1rem; padding: .85rem 1rem; border-left: .2rem solid var(--accent); background: var(--field); white-space: pre-wrap; overflow-wrap: anywhere; }
.solution span { color: var(--muted); font-size: .9rem; }
.solution strong { font-size: 1.15em; }
.question .actions { margin-top: .85rem; }
.value-form { max-width: 17rem; margin-top: 1rem; }
.round-media { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .65rem; margin-top: 1rem; }
.round-media img { display: block; width: 100%; height: auto; max-height: min(45vh, 30rem); object-fit: contain; border-radius: .55rem; background: var(--field); }
.round-media audio { width: 100%; }

.preview-nav { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .85rem; }
.preview-pager { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.preview-pager p { white-space: nowrap; }
#preview-meta { margin: 1.15rem 0 .65rem; }
.preview-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: .85rem; }
.preview-content .answer-text { font-size: clamp(1.05rem, 2vw, 1.35rem); }

.scores, .team-codes { list-style: none; margin: 0; padding: 0; }
.scores li, .team-codes li, .submission { padding: .75rem 0; border-top: 1px solid var(--line); }
.scores li:last-child, .team-codes li:last-child, .submission:last-child { padding-bottom: 0; }
.score { font-weight: 640; overflow-wrap: anywhere; }
.score strong { color: var(--accent); font: 760 1.35rem ui-monospace, monospace; }
.scores .inline { margin-top: .45rem; }
.team-codes, #access .actions { margin-top: .75rem; }
.team-name, .submission-head { flex-wrap: wrap; overflow-wrap: anywhere; }
.team-name .muted, .submission-head .muted { font-size: .9rem; }
.submission-list { max-height: min(52vh, 30rem); overflow-y: auto; overscroll-behavior: contain; }
.submission-list:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.access-row { margin-top: .45rem; flex-wrap: wrap; }
.access-row code { color: var(--accent); font-size: 1rem; font-weight: 660; letter-spacing: .08em; }
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.submission .answer-text { margin-block: .4rem; }
.submission .actions { margin-top: .55rem; }
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button[aria-pressed="true"]:not(:disabled):hover { background: var(--accent-hover); }

.viewer { max-width: 108rem; }
.viewer .game-heading { margin-block: 1.1rem 1.4rem; }
.viewer .board th { font-size: clamp(1.1rem, 2.25vw, 2.5rem); }
.viewer .cell { min-height: clamp(3.2rem, 10vh, 7rem); font-size: clamp(1.3rem, 3.4vw, 3.5rem); }
.viewer .board-wide .cell { font-size: clamp(1.1rem, 2.45vw, 3.1rem); }
.viewer .cell-index { font-size: clamp(.85rem, 1.15vw, 1.25rem); }
.viewer .question-text { font-size: clamp(2rem, 4.7vw, 5rem); margin: clamp(1.3rem, 4vw, 3rem) 0; }
.viewer .round-media img { max-height: min(53vh, 45rem); }
.viewer .clock { font-size: clamp(2.5rem, 7vw, 6rem); }
.viewer .category, .viewer .solution { font-size: clamp(1.1rem, 2.1vw, 2rem); }
.viewer .timing { font-size: clamp(1rem, 1.4vw, 1.4rem); }
.viewer .scores { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .65rem; }
.viewer .scores li { padding: .7rem .85rem; border: 1px solid var(--line); border-radius: .5rem; }
.viewer .score { font-size: clamp(1rem, 1.7vw, 1.65rem); }
.viewer .score strong { font-size: 1.25em; }
:fullscreen .viewer-action { visibility: hidden; }

.notice { position: fixed; z-index: 1; bottom: 1rem; right: 1rem; max-width: min(28rem, calc(100vw - 2rem)); margin: 0; padding: .8rem 1rem; background: var(--accent); color: var(--accent-ink); border-radius: .55rem; font-weight: 650; }
.notice.connection { bottom: auto; top: .7rem; }

@media (max-width: 48rem) {
  .admin-layout, .preview-nav, .preview-content { grid-template-columns: minmax(0, 1fr); }
  .board { border-spacing: .16rem; }
  .board th { min-width: 5.1rem; }
}
