/* Frostvale: a vintage Christmas card read at night. Deep evergreen paper,
   pine and sage linework, holly-red seals and antique-gold lettering.
   One narrow column: season header (with the snowfall), player card, then
   Challenges / Leaderboard / Teams & classes.
   Built from the palette #474B41 #4D5D45 #667256 #7A231D #B43B2B, deepened so
   the page reads as one dark green family: #4D5D45 and #667256 are the lines,
   #7A231D is the red for buttons and seals, #B43B2B only brightens it on hover.
   gold = accent text, rose = wrong, leaf = correct. */
:root {
  --night: #1e241c;
  --panel: #283224;
  --panel-2: #34402f;
  --line: #4d5d45;
  --sage: #667256;
  --brick: #7a231d;
  --brick-hi: #8f2c24;
  --snow: #eee7d4;
  --frost: #bdc0ac;
  --mist: #959b86;
  --gold: #d8b76c;
  --gold-dim: #8f7a48;
  --rose: #e8a193;
  --leaf: #adc994;
  --font-display: "IM Fell English", Georgia, "Times New Roman", serif;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--snow);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 64px;
}
[hidden] { display: none !important; }
.wrap { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.muted { color: var(--frost); font-size: 14px; margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--snow); outline-offset: 2px; }

/* Header */
header { position: relative; isolation: isolate; display: flex; flex-direction: column; gap: 10px; }
/* The one ambient motion on the page: light snow drifting behind the title. */
header::before {
  content: ""; position: absolute; inset: -28px -16px auto; height: 130px; z-index: -1; pointer-events: none; /* stops above the intro text */
  /* Flat dots, no fades: three layers, two flakes per tile, tile sizes that don't divide each other so no grid shows. */
  background-image:
    radial-gradient(circle at 18% 22%, rgba(238, 231, 212, .85) 0 1.5px, transparent 2.2px),
    radial-gradient(circle at 67% 71%, rgba(238, 231, 212, .7) 0 1.2px, transparent 1.9px),
    radial-gradient(circle at 81% 14%, rgba(238, 231, 212, .55) 0 1px, transparent 1.6px),
    radial-gradient(circle at 29% 63%, rgba(238, 231, 212, .5) 0 .9px, transparent 1.5px),
    radial-gradient(circle at 52% 41%, rgba(216, 183, 108, .4) 0 2px, transparent 2.8px),
    radial-gradient(circle at 9% 88%, rgba(216, 183, 108, .3) 0 1.6px, transparent 2.3px);
  background-size: 157px 157px, 157px 157px, 103px 103px, 103px 103px, 229px 229px, 229px 229px;
  animation: snowfall 40s linear infinite;
}
@keyframes snowfall { to { background-position: 157px 314px, 157px 314px, -103px 206px, -103px 206px, 0 229px, 0 229px; } }
@media (prefers-reduced-motion: reduce) { header::before { animation: none; } }
.topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.season-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.eyebrow { font-family: var(--font-display); font-style: italic; font-size: 20px; line-height: 1.2; color: var(--gold); }
select {
  font: inherit; font-size: 13px; color: var(--snow); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; max-width: 100%;
}
.lang-switch, .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; flex: none; }
.lang-switch button, .seg button { font-family: var(--font-code); font-size: 12px; font-weight: 600; letter-spacing: .06em; border: 0; border-radius: 999px; padding: 5px 11px; background: transparent; color: var(--frost); }
.lang-switch button:hover, .seg button:hover { color: var(--snow); }
.lang-switch button[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--line); color: var(--snow); }
.stack { display: flex; flex-direction: column; gap: 10px; }
h1 {
  font-family: var(--font-display); font-weight: 400; font-size: clamp(56px, 13vw, 96px); line-height: .9; margin: 0; letter-spacing: -.015em;
  color: var(--snow);
}
.lede { color: var(--frost); margin: 0; max-width: 62ch; }
.season { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; font-family: var(--font-code); font-size: 13px; color: var(--frost); font-variant-numeric: tabular-nums; }
.pill { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor; }
.pill.active { color: var(--leaf); }
.pill.upcoming { color: var(--gold); }
.pill.closed { color: var(--snow); background: var(--brick); border-color: var(--brick-hi); }
#countdown { color: var(--snow); }

/* Player card */
.player, .card { border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.player h2, .card h2 { margin: 0; font-size: 16px; }
.card h3 { margin: 6px 0 0; font-size: 14px; font-family: var(--font-code); text-transform: uppercase; letter-spacing: .08em; color: var(--frost); }
.player p, .card p { margin: 0; color: var(--frost); font-size: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form-row input { flex: 1 1 180px; min-width: 0; }
input[type="text"] {
  font: inherit; font-size: 15px; color: var(--snow); background: var(--night);
  border: 1px solid var(--sage); border-radius: 8px; padding: 9px 12px;
}
input[type="text"]::placeholder { color: var(--mist); }
input[type="text"]:focus { outline: none; border-color: var(--snow); box-shadow: 0 0 0 1px var(--snow); }
.linkish { background: none; border: 0; padding: 0; color: var(--gold); font-weight: 400; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; }
#meView { display: flex; flex-direction: column; gap: 14px; }
.me-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; }
.me-alias { font-family: var(--font-display); font-size: 28px; line-height: 1; }
.me-stats { font-family: var(--font-code); font-size: 13px; color: var(--frost); font-variant-numeric: tabular-nums; }
.me-stats b { color: var(--gold); font-weight: 600; }
.me-levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; }
.lv { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-family: var(--font-code); font-size: 12px; color: var(--frost); font-variant-numeric: tabular-nums; }
.lv-bar { height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; min-width: 40px; }
.lv-bar > i { display: block; height: 100%; background: var(--leaf); }
.me-team { font-size: 14px; }
.me-team b { color: var(--snow); }
.me-actions { display: flex; flex-wrap: wrap; gap: 14px; }
.token-box { display: flex; flex-direction: column; gap: 8px; border-left: 2px solid var(--gold); padding-left: 12px; }
.token-box p { color: var(--snow); }
.token-value { font-family: var(--font-code); font-size: 14px; background: var(--night); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; word-break: break-all; user-select: all; }
.form-msg { font-size: 14px; color: var(--rose); }
.form-msg:empty { display: none; }
.fb-badge { display: inline-block; font-family: var(--font-code); font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--gold); border: 1px solid rgba(234, 217, 168, .55); border-radius: 999px; padding: 1px 7px; white-space: nowrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--frost); padding: 10px 14px; font-size: 15px; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--snow); border-color: transparent; }
.tab[aria-selected="true"] { color: var(--snow); border-bottom-color: var(--brick); border-bottom-width: 3px; }
.panel { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

/* Challenges */
.progress { display: flex; align-items: center; gap: 12px; font-family: var(--font-code); font-size: 13px; color: var(--frost); font-variant-numeric: tabular-nums; }
.bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; max-width: 240px; }
.bar > i { display: block; height: 100%; background: var(--leaf); width: 0; transition: width .4s; }
.levels { display: flex; flex-direction: column; gap: 14px; }
.level { display: flex; flex-direction: column; gap: 8px; }
.level h3 { margin: 0; font-family: var(--font-code); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; color: var(--frost); }
.level h3 span { color: var(--mist); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-code); font-size: 14px; font-variant-numeric: tabular-nums;
  width: 42px; height: 42px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel); color: var(--snow);
  display: grid; place-items: center;
}
.chip:hover { border-color: var(--sage); }
.chip.done { background: transparent; border-color: var(--leaf); color: var(--leaf); }
.chip.active { background: var(--brick); border-color: var(--brick); color: var(--snow); font-weight: 600; }

.case { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.case-head { display: flex; flex-direction: column; gap: 6px; }
.case-meta { font-family: var(--font-code); font-size: 12px; color: var(--gold); letter-spacing: .06em; text-transform: uppercase; }
/* Before the season starts: no statement yet, only the sandbox. */
.case.locked #caseConcepts, .case.locked #caseStats, .case.locked .expect,
.case.locked #submitBtn, .case.locked #hintBtn, .case.locked #hint2Btn, .case.locked #reviewBtn { display: none; }
.case.locked #tryBtn { background: var(--brick); border-color: var(--brick); color: var(--snow); }
.case h3 { font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1.05; margin: 0; text-wrap: balance; }
.concepts { display: flex; flex-wrap: wrap; gap: 6px; }
.concept { font-family: var(--font-code); font-size: 11px; color: var(--leaf); border: 1px solid rgba(210, 232, 185, .45); border-radius: 4px; padding: 1px 6px; }
.case-stats { margin: 0; font-size: 13px; color: var(--frost); }
.prompt { margin: 0; max-width: 65ch; }
.prompt b { color: var(--gold); font-weight: 700; }
code { font-family: var(--font-code); font-size: .88em; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; color: var(--snow); }
.expect { font-family: var(--font-code); font-size: 13px; color: var(--frost); }
.expect .v { color: var(--snow); }
.expect .worth { color: var(--gold); }

/* Editor: a transparent textarea over a highlighted layer with identical metrics */
.editor { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); display: flex; flex-direction: column; }
.editor:focus-within { border-color: var(--gold-dim); }
.ce { position: relative; }
.ce-hl, .ce-input {
  margin: 0; border: 0; border-radius: 10px 10px 0 0; padding: 14px 16px;
  font-family: var(--font-code); font-size: 14px; line-height: 1.6; letter-spacing: normal;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; tab-size: 2;
}
.ce-hl { position: absolute; inset: 0; pointer-events: none; overflow: hidden; color: var(--snow); background: transparent; }
.ce-input {
  position: relative; display: block; width: 100%; min-height: 170px; resize: none; overflow: hidden;
  background: transparent; color: transparent; caret-color: var(--snow); outline: none;
}
.ce-input::placeholder { color: var(--mist); }
.ce-input::selection { background: rgba(143, 44, 36, .6); color: transparent; }
.t-kw { color: var(--rose); }
.t-fn { color: var(--gold); }
.t-tb { color: var(--leaf); }
.t-col { color: var(--frost); }
.t-str { color: var(--gold); font-style: italic; }
.t-num { color: var(--gold); }
.t-com { color: var(--mist); font-style: italic; }
.t-op, .t-ws, .t-id, .t-qid { color: var(--snow); }
.ce-caret { display: inline-block; width: 0; }
.ce-pop {
  position: absolute; z-index: 5; margin: 0; padding: 4px; list-style: none; min-width: 200px; max-width: calc(100% - 16px);
  background: var(--night); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 24px rgba(0, 0, 0, .45);
  font-family: var(--font-code); font-size: 13px; overflow-y: auto;
}
.ce-pop li { display: flex; justify-content: space-between; gap: 16px; padding: 5px 8px; border-radius: 5px; cursor: pointer; }
.ce-pop li small { color: var(--mist); font-size: 11px; }
.ce-pop li.on { background: var(--panel-2); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: center; }
.toolbar .kbd { margin-left: auto; font-family: var(--font-code); font-size: 12px; color: var(--frost); }
.try-note { margin: -8px 0 0; font-size: 13px; color: var(--frost); }
.try-note:empty { display: none; }
button {
  font-family: var(--font-body); font-size: 14px; font-weight: 700;
  border-radius: 8px; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--snow);
}
button:hover { border-color: var(--sage); }
button.primary { background: var(--brick); border-color: var(--brick); color: var(--snow); }
button.primary:hover { background: var(--brick-hi); border-color: var(--brick-hi); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }

.verdict { border-radius: 10px; padding: 12px 14px; font-size: 15px; border: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.verdict .mark { font-family: var(--font-code); font-weight: 600; flex: none; }
.verdict > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.verdict.ok { border-color: var(--leaf); color: var(--leaf); background: rgba(210, 232, 185, .08); }
.verdict.bad { border-color: var(--brick-hi); color: var(--rose); background: rgba(122, 35, 29, .35); }
.verdict.info { color: var(--frost); }
.verdict p { margin: 0; color: var(--snow); }
.verdict strong { color: inherit; }

.reveal { border-left: 2px solid var(--gold-dim); padding: 4px 0 4px 14px; display: flex; flex-direction: column; gap: 8px; }
.reveal .label { font-family: var(--font-code); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); }
.reveal p { margin: 0; }
.reveal .note { color: var(--gold); font-size: 14px; }
.reveal .note:empty { display: none; }
.reveal.confirm { border-left-color: var(--gold); }
.reveal.review { border-left-color: var(--leaf); }
.reveal.review .label { color: var(--leaf); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
pre { margin: 0; font-family: var(--font-code); font-size: 13px; line-height: 1.6; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; color: var(--snow); }

.results { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.results-head { font-family: var(--font-code); font-size: 12px; color: var(--frost); text-transform: uppercase; letter-spacing: .08em; }
/* position: relative keeps absolutely positioned children (screen-reader labels) inside the scroll box */
.table-scroll { position: relative; overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 360px; }
table { border-collapse: collapse; width: 100%; font-family: var(--font-code); font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-2); color: var(--snow); font-weight: 600; }
td.null { color: var(--mist); font-style: italic; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }

/* Schema diagram */
details.schema { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-width: 0; }
details.schema summary { cursor: pointer; padding: 12px 16px; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.schema summary::-webkit-details-marker { display: none; }
details.schema summary::after { content: "+"; font-family: var(--font-code); color: var(--gold); font-size: 18px; }
details.schema[open] summary::after { content: "–"; }
.schema-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.diagram-scroll { position: relative; overflow-x: auto; padding-bottom: 4px; }
.dg { display: block; font-family: var(--font-code); }
.dg-box { fill: var(--night); stroke: var(--line); }
.dg-head { fill: var(--panel-2); }
.dg-name { fill: var(--leaf); font-size: 13px; font-weight: 600; }
.dg-count { fill: var(--mist); font-size: 11px; }
.dg-col { fill: var(--snow); font-size: 12px; }
.dg-col.pk { fill: var(--gold); }
.dg-col.fk { fill: var(--gold); }
.dg-type { fill: var(--mist); font-size: 10.5px; }
.dg-edge { fill: none; stroke: var(--gold-dim); stroke-width: 1.5; }
.dg-arrowhead { fill: var(--gold-dim); }
.dg-dot { fill: var(--gold); }
.schema-note { font-size: 14px; color: var(--frost); margin: 0; }

/* Leaderboard */
.board-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.board-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1; }
.board-updated { margin: -12px 0 0; font-family: var(--font-code); font-size: 12px; color: var(--frost); }
.board-updated:empty { display: none; }
.board { max-height: none; }
td.pos { color: var(--frost); width: 1%; }
tr.podium-1 td.pos { color: var(--gold); font-weight: 600; }
tr.podium-2 td.pos, tr.podium-3 td.pos { color: var(--snow); font-weight: 600; }
tr.mine td { background: rgba(122, 35, 29, .3); }
td.alias { color: var(--snow); font-family: var(--font-body); font-weight: 700; font-size: 14px; }
td.alias .fb-badge { margin-left: 6px; }
.team-tag { margin-left: 6px; font-family: var(--font-code); font-size: 11px; font-weight: 400; color: var(--leaf); }
td.uni { color: var(--frost); font-family: var(--font-body); font-size: 14px; }
td.pts { color: var(--gold); font-weight: 600; text-align: right; }
.empty { color: var(--frost); padding: 24px 16px; text-align: center; font-size: 15px; white-space: normal; }
.summary { display: flex; flex-direction: column; gap: 12px; }
.podium { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.podium li { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: baseline; }
.podium .place { grid-row: span 2; font-family: var(--font-display); font-size: 34px; line-height: 1; color: var(--frost); }
.podium .podium-1 { border-color: var(--gold); }
.podium .podium-1 .place { color: var(--gold); }
.podium .who { font-weight: 700; overflow-wrap: anywhere; }
.podium .pts { font-family: var(--font-code); font-size: 13px; color: var(--gold); }
.facts { margin: 0; padding-left: 18px; color: var(--frost); font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.facts b { color: var(--snow); }
.rules { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--frost); margin: 0; padding-left: 18px; }
.rules b { color: var(--snow); }

/* Teams and classes */
.team-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.team-name { font-family: var(--font-display); font-size: 26px; line-height: 1.1; }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.members li { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 14px; }
.members li.open { border-style: dashed; color: var(--mist); }
.code-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; color: var(--frost); }
.code { font-family: var(--font-code); font-size: 16px; letter-spacing: .14em; color: var(--gold); user-select: all; }
.code-line button { padding: 4px 10px; font-size: 13px; }
#teamForms, .class-forms { display: flex; flex-direction: column; gap: 10px; }
.class-list { display: flex; flex-wrap: wrap; gap: 8px; }
.class-pill { display: inline-flex; align-items: baseline; gap: 8px; font-weight: 700; }
.class-pill small { font-family: var(--font-code); font-weight: 400; font-size: 11px; color: var(--frost); }
.class-pill.on { border-color: var(--gold); }
.class-view { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.progress-scroll { max-height: 420px; }
.progress-grid th, .progress-grid td { padding: 6px 8px; }
.progress-grid tbody th { position: sticky; left: 0; background: var(--panel-2); color: var(--snow); font-family: var(--font-body); font-weight: 700; z-index: 1; }
.progress-grid thead th:first-child { left: 0; z-index: 2; }
.progress-grid td { text-align: center; min-width: 30px; }
.progress-grid .stuck-row th, .progress-grid .stuck-row td { color: var(--frost); font-size: 12px; }
.progress-grid .stuck-row td.hot { color: var(--rose); font-weight: 600; }
.cell.solved { background: rgba(210, 232, 185, .16); color: var(--leaf); }
.cell.stuck { background: rgba(122, 35, 29, .7); color: var(--snow); font-weight: 600; }
.cell.none { color: var(--mist); }
.cell.hinted { box-shadow: inset 0 -3px 0 var(--gold); }
.legend .key { display: inline-block; min-width: 18px; padding: 0 4px; border-radius: 3px; text-align: center; font-family: var(--font-code); font-size: 12px; }
.legend .key.solved { background: rgba(210, 232, 185, .16); color: var(--leaf); }
.legend .key.stuck { background: rgba(122, 35, 29, .7); color: var(--snow); }
.legend .key.hinted { height: 12px; box-shadow: inset 0 -3px 0 var(--gold); background: var(--panel-2); vertical-align: middle; }

.fatal { border: 1px solid var(--brick-hi); background: rgba(122, 35, 29, .35); color: var(--snow); border-radius: 10px; padding: 14px 16px; }
footer { color: var(--frost); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
footer a { color: var(--gold); }

@media (max-width: 480px) {
  .tab { padding: 10px 9px; font-size: 14px; }
  .case h3, .board-head h2 { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { .bar > i { transition: none; } }
