:root {
  --bg: #F5F5F7; --fg: #0B0B0C; --muted: #6E6E73; --line: #DCDCDE; --surface: #EBEBEE;
  --accent: #002FA7; --ok: #1F7A4D; --bad: #B3261E;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0B0B0C; --fg: #F5F5F7; --muted: #8E8E93; --line: #262626; --surface: #151517; --accent: #3D63D6; --ok: #4CC38A; --bad: #FF7B6E; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 1.0625rem/1.6 var(--sans); }
.wrap { max-width: 44rem; margin: 0 auto; padding: 0 1.25rem; }

/* header and tabs */
.top { padding-top: 1.5rem; }
.brand, .here, .sep { font: 700 1.25rem var(--serif); text-decoration: none; color: var(--fg); }
.sep { color: var(--muted); font-weight: 500; margin: 0 .35rem; }
.here { color: var(--accent); }
nav { display: flex; column-gap: 1.25rem; row-gap: 0; flex-wrap: wrap; margin-top: 1rem; border-bottom: 1px solid var(--line); }
nav button { background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: .5rem 0; font: inherit; font-size: .95rem; color: var(--muted); cursor: pointer; }
nav button:hover { color: var(--fg); }
nav button.on { color: var(--fg); border-bottom-color: var(--accent); }
#view { padding-top: 2.5rem; padding-bottom: 5rem; }

/* type */
h1 { font: 700 2.25rem/1.15 var(--serif); letter-spacing: -.01em; margin: 0 0 .75rem; }
h3 { font: 600 1.25rem/1.3 var(--serif); margin: 2.25rem 0 .5rem; }
h4 { font: 600 1rem var(--sans); margin: 0 0 .25rem; }
p { margin: .5rem 0; max-width: 62ch; }
.lede, .muted { color: var(--muted); }
.big { font: 700 3.5rem/1 var(--serif); margin: 1rem 0 .5rem; font-feature-settings: "lnum", "tnum"; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .skip { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* buttons */
button { font: inherit; cursor: pointer; }
.btn { background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 2px; padding: .6rem 1.1rem; transition: transform .15s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--fg); }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }

/* settings */
.settings { margin: 1.5rem 0; border-top: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .85rem 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.row small { display: block; color: var(--muted); font-size: .9rem; }
.row input[type=number] { width: 6rem; font: inherit; background: transparent; color: var(--fg); border: 0; border-bottom: 1px solid var(--muted); border-radius: 0; text-align: right; padding: .2rem 0; }
.row input[type=checkbox] { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); flex: none; }

/* timer line: the one loud thing */
.timebar { position: fixed; top: 0; left: 0; right: 0; height: 3px; background: var(--line); z-index: 10; }
.timebar[hidden] { display: none; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width .25s linear; }
.timebar.low i { background: var(--bad); }

/* question */
.qhead { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; color: var(--muted); font-size: .95rem; }
.clock { font: 600 1.5rem var(--serif); color: var(--fg); font-feature-settings: "lnum", "tnum"; min-width: 3.5rem; text-align: right; }
.q { font: 600 1.6rem/1.35 var(--serif); max-width: 30em; margin: 1.5rem 0; }
.opts { display: flex; flex-direction: column; border-top: 1px solid var(--line); margin: 1.5rem 0 1rem; }
.opt { display: flex; align-items: center; gap: 1rem; background: none; color: var(--fg); border: 0; border-bottom: 1px solid var(--line); padding: .9rem .25rem; text-align: left; font-size: 1.2rem; font-feature-settings: "lnum", "tnum"; transition: padding .15s ease, background .15s ease; }
.opt kbd { display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border: 1px solid var(--line); border-radius: 2px; font: .85rem var(--sans); color: var(--muted); }
.opt:hover:not(:disabled) { padding-left: .9rem; background: var(--surface); }
.opt:disabled { color: var(--fg); cursor: default; }
.opt:disabled:not(.right):not(.wrong) { opacity: .45; }
.opt.right { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.opt.wrong { background: color-mix(in srgb, var(--bad) 16%, transparent); }
.opt.right kbd { border-color: var(--ok); color: var(--ok); }
.opt.wrong kbd { border-color: var(--bad); color: var(--bad); }
.answer { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin: 1.5rem 0 .5rem; }
#a { font: 600 1.6rem var(--serif); background: transparent; color: var(--fg); border: 0; border-bottom: 2px solid var(--fg); border-radius: 0; padding: .25rem 0; width: 10rem; font-feature-settings: "lnum", "tnum"; }
#a:focus { outline: none; border-bottom-color: var(--accent); }
#fb > p { font: 600 1.25rem/1.4 var(--serif); margin: 1rem 0 .25rem; }

/* explanations */
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: .75rem 0; padding-top: 1rem; border-top: 1px solid var(--line); }
.steps[hidden] { display: none; }
.steps.one { grid-template-columns: 1fr; }
.steps ol { margin: .25rem 0; padding-left: 1.2rem; }
.steps li { margin: .4rem 0; max-width: 60ch; }

/* lists and tables */
.review { list-style: none; margin: 1rem 0 1.5rem; padding: 0; border-top: 1px solid var(--line); }
.review li { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.review p { margin: 0 0 .35rem; }
.meta { display: flex; gap: 1.25rem; flex-wrap: wrap; color: var(--muted); font-size: .95rem; margin-bottom: .35rem; }
table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
th, td { text-align: left; padding: .65rem .5rem .65rem 0; border-bottom: 1px solid var(--line); font-feature-settings: "lnum", "tnum"; }
th { color: var(--muted); font-weight: 500; font-size: .9rem; }
details { border-bottom: 1px solid var(--line); padding: .6rem 0; }
summary { cursor: pointer; font-weight: 600; }
details > ol { margin: .5rem 0 0; padding-left: 1.2rem; }

/* drill */
.problem { font: 700 clamp(2.5rem, 9vw, 4.5rem)/1.1 var(--serif); margin: 2rem 0 1rem; font-feature-settings: "lnum", "tnum"; }

@media (max-width: 40rem) {
  .steps { grid-template-columns: 1fr; }
  h1 { font-size: 1.85rem; }
  .q { font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- history and charts ---- */
.trend { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: .25rem; }
.chart { display: block; width: 100%; height: auto; margin: .5rem 0; overflow: visible; }
.hit { cursor: pointer; }
.hit:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; color: var(--muted); font-size: .9rem; margin-top: .5rem; }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.k-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.k-line { width: 16px; height: 2px; background: var(--accent); display: inline-block; }
.tv { margin-top: .25rem; border-bottom: 0; }
.tv summary { font-weight: 400; color: var(--accent); }
.tip { position: fixed; z-index: 20; background: var(--fg); color: var(--bg); padding: .35rem .6rem; border-radius: 2px; font-size: .85rem; pointer-events: none; max-width: 18rem; }
.tip[hidden] { display: none; }
.bars { list-style: none; margin: .75rem 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(7rem, 14rem) 1fr 6.5rem; gap: .75rem; align-items: center; padding: .35rem 0; }
.bl { overflow-wrap: anywhere; }
.bv { color: var(--muted); font-size: .9rem; text-align: right; }
.track { height: 10px; background: var(--surface); border-radius: 0 4px 4px 0; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.field { display: inline-flex; flex-direction: column; gap: .15rem; font-size: .9rem; color: var(--muted); }
.field input, select { font: inherit; font-size: 1.1rem; background: transparent; color: var(--fg); border: 0; border-bottom: 1px solid var(--muted); border-radius: 0; padding: .2rem 0; width: 9rem; }
select { width: auto; max-width: 100%; background: var(--bg); }
h3.tight { margin-top: 0; }

/* ---- question extras ---- */
.q { white-space: pre-line; }
#lo, #hi { font: 600 1.4rem var(--serif); color: var(--fg); font-feature-settings: "lnum", "tnum"; }
.board { width: auto; min-width: 16rem; margin: 1rem 0; font-feature-settings: "lnum", "tnum"; }
.board th, .board td { padding: .45rem 1.25rem .45rem 0; }

/* ---- games ---- */
.tiles { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1rem 0; }
.tile { min-width: 4.5rem; height: 4.5rem; font: 700 1.8rem var(--serif); color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: 2px; transition: border-color .15s ease; }
.tile:hover { border-color: var(--fg); }
.tile.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tiles.ops .tile { height: 3.25rem; min-width: 3.25rem; font-size: 1.4rem; }
.code { font: 600 1.4rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; }
p.code { font-size: 2rem; margin: 1.5rem 0; }
.stage { display: grid; place-items: center; height: 18rem; }
.balloon { background: var(--accent); border-radius: 50%; transition: width .1s ease, height .1s ease; }
.sky { display: grid; grid-template-columns: repeat(6, 3.4rem); gap: .4rem; margin: 1.5rem 0; }
.clue { display: grid; place-items: center; color: var(--muted); font: 600 1.1rem var(--serif); }
.cell { height: 3.4rem; font: 700 1.5rem var(--serif); color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 2px; }
.cell.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
@media (max-width: 40rem) {
  .bars li { grid-template-columns: 1fr 5rem; }
  .bars .track { grid-column: 1 / -1; order: 3; }
  .sky { grid-template-columns: repeat(6, 2.8rem); }
  .cell { height: 2.8rem; }
}
.vsep { width: 1px; background: var(--line); margin: .35rem 0; }
.nbreak { flex-basis: 100%; height: 0; }

.events { white-space: pre-line; font-size: 1.1rem; line-height: 1.75; margin: -.5rem 0 1.25rem; }
.review p { white-space: pre-line; }

/* Static pages (firm pages, guides) and links in the nav */
nav a { padding: .5rem 0; font-size: .95rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
nav a:hover { color: var(--fg); }
a.here { text-decoration: none; }
a.btn { display: inline-block; text-decoration: none; }
h2 { font: 600 1.5rem/1.3 var(--serif); margin: 2.5rem 0 .5rem; }
#view a:not(.btn) { color: var(--accent); text-underline-offset: 3px; }
.foot { padding-bottom: 3rem; color: var(--muted); font-size: .95rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.foot a { color: var(--muted); }
