/* Advent of Kelly: a winter night, in monospace. */
:root {
  --bg: #0b1222;
  --bg-deep: #070c18;
  --panel: #0f1829;
  --panel-2: #152038;
  --ink: #dde4f0;
  --muted: #8592ab;
  --faint: #4b5874;
  --line: #22304d;
  --gold: #f5c451;
  --holly: #6cc17a;
  --berry: #ef6f6c;
  --frost: #a8d8ff;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--mono);
}
a { color: var(--frost); text-decoration: none; }
a:hover { color: #fff; text-shadow: 0 0 6px var(--frost); }
code {
  font: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 0 .3em;
  border-radius: 3px;
}
em { font-style: normal; color: #fff; text-shadow: 0 0 5px var(--gold); }
strong { color: #fff; font-weight: 700; }
.star { color: var(--gold); text-shadow: 0 0 6px color-mix(in srgb, var(--gold) 60%, transparent); }
.star.empty { color: var(--faint); text-shadow: none; }

/* ASCII buttons: [ Run ] */
button {
  font: inherit;
  background: none;
  border: 0;
  padding: 2px 4px;
  color: var(--frost);
  cursor: pointer;
  white-space: nowrap;
}
button::before { content: "["; color: var(--faint); }
button::after { content: "]"; color: var(--faint); }
button:hover:not(:disabled) { color: #fff; text-shadow: 0 0 6px var(--frost); }
button.primary { color: var(--gold); }
button.primary:hover:not(:disabled) { text-shadow: 0 0 6px var(--gold); }
button:disabled { color: var(--faint); cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 1px dashed var(--gold); outline-offset: 2px; }

input[type="text"], input[type="search"] {
  font: inherit;
  background: var(--bg-deep);
  color: #fff;
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 2px;
}

/* ───────────── Calendar ───────────── */
.calendar-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 32px 16px; }
.masthead { text-align: center; margin-bottom: 28px; }
.masthead h1 { margin: 0; font-size: 28px; font-weight: 700; color: var(--holly); text-shadow: 0 0 8px color-mix(in srgb, var(--holly) 50%, transparent); letter-spacing: .04em; }
.masthead .tagline { color: var(--muted); margin: 4px 0 0; }
.masthead .totals { margin-top: 10px; }
.masthead .next { color: var(--muted); margin-top: 2px; font-size: 14px; }
.masthead .preview { color: var(--berry); font-size: 13px; }

.doors {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  width: min(620px, 100%);
}
.door {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  position: relative;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.door .num { font-size: 26px; font-weight: 700; line-height: 1; }
.door .stars { font-size: 15px; letter-spacing: .15em; min-height: 1.4em; }
.door .note { font-size: 11px; color: var(--muted); }
a.door:hover { border-color: var(--gold); box-shadow: 0 0 14px color-mix(in srgb, var(--gold) 30%, transparent); transform: translateY(-2px); text-shadow: none; color: var(--ink); }
.door.locked {
  color: var(--faint);
  background:
    repeating-linear-gradient(45deg, transparent 0 6px, color-mix(in srgb, var(--line) 45%, transparent) 6px 7px),
    var(--bg-deep);
}
.door.soon { color: var(--muted); border-style: dashed; }
.door.today { border-color: var(--gold); }
.door.today::after { content: "today"; position: absolute; top: 4px; right: 6px; font-size: 10px; color: var(--gold); }
.door.done .num { color: var(--gold); text-shadow: 0 0 8px color-mix(in srgb, var(--gold) 50%, transparent); }
.calendar-page footer { margin-top: 28px; color: var(--muted); font-size: 13px; text-align: center; max-width: 620px; }

@media (max-width: 520px) {
  .doors { gap: 6px; }
  .door .num { font-size: 18px; }
  .door .stars { font-size: 11px; }
  .door.today::after { display: none; }
}

/* ───────────── Day view ───────────── */
.day-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-deep);
}
.topbar h1 { margin: 0; font-size: 15px; font-weight: 700; color: var(--holly); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .stars { letter-spacing: .15em; }
.topbar button { font-size: 13px; }

.workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: var(--left, 46%) 7px minmax(0, 1fr);
}
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.divider { background: var(--bg-deep); border: solid var(--line); border-width: 0 1px; cursor: col-resize; touch-action: none; position: relative; }
.divider::after { content: "⋮"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 12px; }
.divider:hover, .divider.dragging { background: var(--panel-2); }
.divider.horizontal { cursor: row-resize; border-width: 1px 0; }
.divider.horizontal::after { content: "⋯"; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--bg-deep); }
.tabs button { color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--gold); }
.tab-panel { flex: 1; min-height: 0; overflow: auto; padding: 18px 22px 40px; }
.tab-panel[hidden] { display: none; }

.prose { max-width: 78ch; }
.prose h2 { font-size: 15px; color: #fff; margin: 0 0 1em; }
.prose h3 { font-size: 15px; color: var(--holly); margin: 1.6em 0 .5em; }
.prose h4 { font-size: 15px; color: var(--frost); margin: 1.2em 0 .4em; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose pre {
  background: var(--bg-deep);
  border: 1px solid var(--line);
  padding: 8px 12px;
  overflow-x: auto;
  margin: 0 0 1em;
  line-height: 1.45;
}
.prose blockquote { border-left: 2px solid var(--line); margin: 0 0 1em; padding-left: 12px; color: var(--muted); }
.puzzle .part-heading { color: #fff; }
.puzzle .answered { color: var(--muted); }
.puzzle .answered code { color: var(--gold); }
.puzzle .all-done { color: var(--holly); }

/* Runnable examples in the lesson. */
.snippet { margin: 0 0 1.2em; }
.snippet pre { margin: 0; }
.snippet .bar { display: flex; gap: 6px; justify-content: flex-end; font-size: 13px; margin-top: 2px; }
.snippet .result { margin-top: 4px; border-style: dashed; color: var(--ink); white-space: pre-wrap; }
.manual-footer { color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 2em; }

/* Stdlib search */
.stdlib-search { position: sticky; top: -18px; background: var(--panel); padding: 0 0 12px; margin-top: -2px; z-index: 1; }
.stdlib-search input { width: 100%; }
.stdlib-search .count { color: var(--muted); font-size: 12px; margin-top: 4px; }
.fn { border-bottom: 1px dashed var(--line); padding: 10px 0; }
.fn .sig { color: var(--muted); overflow-wrap: anywhere; }
.fn .sig .name { color: var(--ndc-function); font-weight: 700; }
.fn .sig .type { color: var(--frost); }
.fn .fn-docs { margin-top: 4px; font-size: 14px; }
.fn .fn-docs p { margin: 0 0 .4em; }
.fn .fn-docs pre { font-size: 13px; padding: 4px 8px; }
.fn.empty-docs .fn-docs { color: var(--faint); }

.right { display: grid; grid-template-rows: minmax(0, 1fr) 7px var(--console, 260px); }
#editor { min-height: 0; background: var(--panel); position: relative; }
#editor .cm-editor { height: 100%; background: var(--panel); color: var(--ink); }
#editor .cm-editor.cm-focused { outline: none; }
#editor .cm-scroller { font: 14px/1.55 var(--mono); }
#editor .cm-gutters { background: var(--panel); color: var(--faint); border-right: 1px solid var(--line); }
#editor .cm-activeLine, #editor .cm-activeLineGutter { background: color-mix(in srgb, var(--ink) 4%, transparent); }
#editor .cm-content { caret-color: var(--ndc-caret); }
#editor .cm-cursor { border-left-color: var(--ndc-caret); }
#editor .cm-selectionBackground, #editor .cm-focused .cm-selectionBackground,
#editor .cm-content ::selection { background: var(--ndc-selection) !important; }
#editor .cm-matchingBracket { background: color-mix(in srgb, var(--gold) 25%, transparent); color: inherit; }
#editor .cm-selectionMatch { background: color-mix(in srgb, var(--gold) 12%, transparent); }
#editor .cm-panels { background: var(--panel); color: var(--muted); border-top: 1px solid var(--line); }
.cm-tooltip { background: var(--panel-2) !important; color: var(--ink); border: 1px solid var(--line) !important; }
.cm-tooltip-autocomplete > ul { font: 13px/1.5 var(--mono) !important; }
.cm-tooltip-autocomplete > ul > li[aria-selected] { background: var(--gold) !important; color: var(--bg-deep) !important; }
.cm-completionDetail { color: inherit; opacity: .7; font-style: normal !important; margin-left: 1em; }
.cm-tooltip.cm-completionInfo { padding: 0; max-width: 480px; }
.cm-tooltip-lint { padding: 4px 8px; font: 13px/1.45 var(--mono); white-space: pre-wrap; }
.ndc-docs { padding: 6px 10px; max-width: 520px; font: 13px/1.45 var(--mono); }
.ndc-docs p { margin: 4px 0; }
.ndc-docs pre, .ndc-docs code { font: 13px/1.45 var(--mono); }
.ndc-docs pre { margin: 4px 0; white-space: pre-wrap; }
.ndc-editor > * { font-family: var(--mono); }

.console { display: flex; flex-direction: column; min-height: 0; background: var(--bg-deep); }
.console .toolbar { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; row-gap: 0; }
.console .toolbar .status { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.console .toolbar kbd { color: var(--faint); font: 12px var(--mono); }
#out { flex: 1; min-height: 0; margin: 0; padding: 10px 14px; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 14px/1.5 var(--mono); }
#out .verdict-ok { color: var(--holly); }
.error-report { white-space: normal; margin-top: 4px; }
.error-report > div { margin: 2px 0; }
.error-lead { color: var(--berry); font-weight: 700; }
.error-message { color: #fff; }
.error-help { color: var(--muted); }
.error-report details { margin-top: 6px; color: var(--faint); }
.error-report summary { cursor: pointer; font-size: 13px; }
.error-report details pre { margin: 4px 0 0; color: var(--muted); white-space: pre; overflow-x: auto; font-size: 13px; }
.snippet .result .error-report details pre { border: 0; padding: 0; background: none; }
.problems { font-size: 13px; margin-left: 6px; }
.problems::before, .problems::after { content: none; }
.problems.ok, .problems.ok:disabled { color: var(--holly); opacity: .75; }
.problems.bad { color: var(--berry); }
.problems.bad:hover { text-decoration: underline; text-shadow: none; color: var(--berry); }

/* Errors written out under their lines in the editor. The padding and font
   match .cm-line, so the ^^^ line up under the code. */
#editor .cm-scroller { container-type: inline-size; }
#editor .cm-lens {
  max-width: calc(100cqw - var(--cm-gutter-width, 48px) - 2px);
  box-sizing: border-box;
  padding: 1px 2px 3px 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  color: var(--berry);
  background: color-mix(in srgb, var(--berry) 7%, transparent);
}
#editor .cm-lens-pad, #editor .cm-lens-caret { white-space: pre; flex: none; tab-size: 4; }
#editor .cm-lens-caret { font-weight: 700; margin-right: 1ch; }
#editor .cm-lens-text { flex: 1 1 30ch; min-width: 30ch; font-size: 13px; line-height: 1.45; white-space: normal; }
#editor .cm-lens-message { color: #ffd9d8; }
#editor .cm-lens-help { display: block; color: var(--muted); }
#editor .cm-lens code, .cm-tooltip-lint code { background: color-mix(in srgb, var(--ink) 8%, transparent); border: 0; padding: 0 .25em; border-radius: 2px; }
#editor .cm-lens-runtime { color: var(--gold); background: color-mix(in srgb, var(--gold) 7%, transparent); }
#editor .cm-lens-runtime .cm-lens-message { color: #fff1cf; }
#editor .cm-gutter-lint { width: 1.1em; }
#editor .cm-gutter-lint .cm-gutterElement { padding: 0 2px; }
.cm-tooltip-lint .cm-lint-help { color: var(--muted); margin-top: 2px; }
#out .verdict-bad { color: var(--berry); }
#out .hint { color: var(--faint); }
.answer-form { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.answer-form label { color: var(--muted); }
.answer-form input { width: 18ch; }
.answer-form .feedback { font-size: 14px; }
.answer-form .feedback.ok { color: var(--holly); }
.answer-form .feedback.bad { color: var(--berry); }

.closed-door { max-width: 60ch; margin: 15vh auto; text-align: center; padding: 0 16px; }
.closed-door .big { font-size: 22px; color: var(--gold); }

@media (max-width: 860px) {
  .day-page { height: auto; overflow: visible; }
  .workspace { grid-template-columns: 1fr; }
  .workspace > .divider { display: none; }
  .tab-panel { max-height: 60vh; }
  .right { grid-template-rows: 60vh 7px 320px; }
}

/* Optional puzzle help: keep the solution hidden until the reader asks. */
.puzzle-hints { margin: 1.5rem 0; }
.puzzle-hints details { margin: .65rem 0; }
.puzzle-hints summary { cursor: pointer; color: var(--link, #99ff99); }
.puzzle-hints details > p, .puzzle-hints details > pre { margin-left: 1rem; }

.completion-confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 1000; }
.completion-confetti i {
  position: absolute; left: var(--x); top: -15px; width: 7px; height: 12px;
  animation: confetti-fall 2s var(--delay) ease-in forwards;
}
@keyframes confetti-fall {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--drift), 105vh) rotate(var(--turn)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .completion-confetti i { animation: none; top: 12px; transform: rotate(var(--turn)); }
}
.previous-draft { margin: 1rem 0; }
.previous-draft summary { cursor: pointer; }
