/* Gradient Descent into Madness — graph-paper lab notebook, marker-pen colours, ink outlines. */
:root {
  --paper: #EEF3F8; --grid: #D5E0EC; --ink: #16213E; --mute: #66738F;
  --sun: #FFE14A; --pink: #FF4F8B; --teal: #19B8A6; --violet: #6B4DF2; --white: #fff;
  --line: 2.5px solid var(--ink);
  --drop: 5px 5px 0 var(--ink);
  --hand: "Caveat Brush", "Comic Sans MS", cursive;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  font: 400 17px/1.5 "Bricolage Grotesque", system-ui, sans-serif;
}
h1, h2, p, ul, pre { margin: 0; }
h1 { font-weight: 800; font-size: clamp(1.9rem, 4vw, 2.9rem); line-height: 1.05; letter-spacing: -0.02em; }
h2 { font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
small { font-size: 0.82em; color: var(--mute); font-weight: 500; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 3px; }
#app { max-width: 1120px; margin: 0 auto; padding: 20px 16px 72px; }

/* ----- Top bar ----- */
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 10px 16px; background: var(--white); border-bottom: var(--line); position: sticky; top: 0; z-index: 5; }
.logo { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; font-weight: 800; font-size: 1.05rem; cursor: pointer; letter-spacing: -0.01em; }
.logo span { display: flex; }
.rank { display: flex; align-items: center; gap: 10px; margin-left: auto; font-weight: 700; font-size: 0.95rem; }
.xp { width: 110px; height: 12px; border: 2px solid var(--ink); border-radius: 99px; background: var(--white); overflow: hidden; }
.xp i { display: block; height: 100%; background: var(--teal); transition: width .4s; }
.top nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn.btn-signin { background: var(--violet); color: var(--white); }
.acct { display: flex; align-items: center; gap: 8px; }
.acct-note { color: var(--mute); font-size: 0.8rem; }
.acct-avatar { display: flex; min-width: 28px; }

/* ----- Buttons ----- */
.btn {
  background: var(--sun); border: var(--line); border-radius: 12px; padding: 9px 16px; font-weight: 700; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink); transition: transform .06s, box-shadow .06s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 3px 3px 0 var(--ink); }
.btn-alt { background: var(--white); }
.btn-small { padding: 5px 11px; font-size: 0.88rem; border-radius: 99px; background: var(--white); box-shadow: 2px 2px 0 var(--ink); }
.btn-big { font-size: 1.15rem; padding: 13px 24px; border-radius: 16px; box-shadow: var(--drop); }
.back { background: none; border: 0; padding: 0; margin-bottom: 10px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; color: var(--mute); }
.back:hover { color: var(--ink); }

.card { background: var(--white); border: var(--line); border-radius: 16px; box-shadow: var(--drop); padding: 20px; }
.crumb { color: var(--mute); font-weight: 600; font-size: 0.95rem; }
.fine { color: var(--mute); font-size: 0.85rem; max-width: 62ch; margin-top: 22px; }

/* ----- Goblin + speech ----- */
.bubble-row { display: flex; align-items: flex-start; gap: 12px; }
.bubble-row > span { flex: none; display: flex; }
.bubble {
  position: relative; background: var(--white); border: var(--line); border-radius: 18px 18px 18px 4px; padding: 10px 14px;
  font-family: var(--hand); font-size: 1.32rem; line-height: 1.22; max-width: 46ch;
}

/* ----- Title ----- */
.title { display: grid; grid-template-columns: 1fr; position: relative; padding-top: 8px; }
.hero-curve { width: 100%; height: auto; grid-area: 1 / 1; opacity: .95; }
.title-copy { grid-area: 1 / 1; align-self: start; justify-self: end; width: min(100%, 640px); padding: clamp(8px, 4vw, 44px) 0 0; position: relative; text-align: left; }
.title h1 { font-size: clamp(3rem, 9.4vw, 7rem); line-height: .88; letter-spacing: -0.045em; text-shadow: 4px 4px 0 var(--sun); }
.lede { font-size: 1.2rem; max-width: 46ch; margin: 22px 0; background: var(--white); border: var(--line); border-radius: 14px; padding: 12px 16px; }
.title-go { display: flex; flex-wrap: wrap; align-items: center; gap: 22px; }
.axis-t { font: 600 17px "Bricolage Grotesque", sans-serif; fill: var(--mute); }
.title .fine { background: color-mix(in srgb, var(--paper) 88%, transparent); border-radius: 8px; padding: 6px 8px; }

/* ----- Map ----- */
.map-sub { color: var(--mute); margin: 6px 0 14px; max-width: 70ch; }
.map-scroll { overflow-x: auto; background: var(--white); border: var(--line); border-radius: 20px; box-shadow: var(--drop); }
.map { display: block; width: 100%; min-width: 980px; height: auto; }
.world-t { font: 800 25px "Bricolage Grotesque", sans-serif; fill: var(--ink); }
.node { cursor: pointer; }
.node circle { fill: var(--white); stroke: var(--ink); stroke-width: 3.5; }
.node.open circle { fill: var(--sun); }
.node.done circle { fill: var(--teal); }
.node.locked circle { stroke-dasharray: 5 5; fill: var(--paper); }
.node.sel circle { stroke-width: 6.5; stroke: var(--violet); }
.node:focus-visible { outline: none; }
.node:focus-visible circle { stroke: var(--violet); stroke-width: 6.5; }
.node-i { font-size: 20px; pointer-events: none; }
.node-s { font: 700 15px "Bricolage Grotesque", sans-serif; fill: var(--ink); paint-order: stroke; stroke: var(--white); stroke-width: 4; }
.detail { margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.detail h2 { font-size: 1.7rem; font-weight: 800; margin: 2px 0; }
.star-line, .big-stars, .cleared { color: var(--ink); letter-spacing: .08em; }
.locked-note { color: var(--mute); font-weight: 600; }

/* ----- Briefing & result ----- */
.brief, .result { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; }
.brief .btn-big, .result-go { justify-self: start; }
.topic { font-size: 1.15rem; font-weight: 600; color: var(--violet); margin-top: -8px; }
.notes { padding-left: 1.2em; display: grid; gap: 8px; max-width: 68ch; }
.formula { font: 600 1.02rem/1.4 "Bricolage Grotesque", sans-serif; background: var(--paper); border: 2px dashed var(--ink); border-radius: 10px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.big-stars { font-size: 3.6rem; line-height: 1; }
.gain { font-weight: 800; font-size: 1.5rem; }
.gain small { font-size: 1rem; }
.unlocks { display: grid; gap: 8px; border-top: 2px dashed var(--ink); padding-top: 14px; }
.unlocks p { display: flex; gap: 12px; align-items: flex-start; }
.letter { flex: none; display: grid; place-items: center; width: 40px; height: 40px; background: var(--sun); border: var(--line); border-radius: 10px; font-weight: 800; font-size: 1.3rem; transform: rotate(-4deg); }
.result-go { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 6px; }

/* ----- Play ----- */
.play-head h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: 14px; }
.play { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(260px, 1fr); gap: 22px; align-items: start; }
.play aside { display: grid; gap: 16px; }
.stage { padding: 16px; display: grid; gap: 12px; }
.stage canvas { width: 100%; height: auto; display: block; border: 2px solid var(--ink); border-radius: 10px; background: var(--white); }
.clicky { cursor: crosshair; }
.goal p { margin-top: 4px; }
details.card summary { font-weight: 700; cursor: pointer; }
details.card .notes { margin: 12px 0; font-size: 0.95rem; }
.side-action { display: grid; gap: 8px; justify-items: start; }
.side-action:empty { display: none; }
.cleared { font-weight: 800; font-size: 1.25rem; }
.readout { font-size: 1.08rem; }
.readout b { font-weight: 800; font-variant-numeric: tabular-nums; }
.readout b.ok { background: var(--teal); color: var(--white); padding: 0 7px; border-radius: 6px; }
.readout span { display: block; color: var(--mute); font-size: 0.88rem; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: end; }
.ctl { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; flex: 1 1 250px; font-weight: 700; }
.ctl output { font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: right; }
.ctl input[type=range] { width: 100%; accent-color: var(--violet); height: 26px; }
.ctl:has(.seg) { flex-basis: 100%; grid-template-columns: 9.5em 1fr; }
.seg { display: flex; min-width: 0; }
.seg-b { flex: 1; min-width: 0; background: var(--white); border: var(--line); border-left-width: 0; padding: 6px 4px; font-weight: 700; cursor: pointer; }
.seg-b:first-child { border-left-width: 2.5px; border-radius: 10px 0 0 10px; }
.seg-b:last-child { border-radius: 0 10px 10px 0; }
.seg-b[aria-pressed=true] { background: var(--violet); color: var(--white); }

/* ----- Rounds (quiz, card levels, boss) ----- */
.round-count { color: var(--mute); font-weight: 600; }
.prompt { font-size: 1.2rem; font-weight: 600; margin: 4px 0 12px; }
.prompt .big-q { font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.opts-wide { grid-template-columns: 1fr; }
.opt { text-align: left; background: var(--white); border: var(--line); border-radius: 12px; padding: 11px 14px; font-weight: 600; cursor: pointer; box-shadow: 3px 3px 0 var(--ink); }
.opt:hover:not(:disabled) { background: var(--sun); }
.opt:disabled { cursor: default; box-shadow: none; opacity: .7; }
.opt.right { background: var(--teal); color: var(--white); opacity: 1; }
.opt.wrong { background: var(--pink); color: var(--white); opacity: 1; }
.why { margin-top: 14px; padding: 12px 14px; background: var(--paper); border-left: 6px solid var(--violet); border-radius: 0 10px 10px 0; }
.why-next { margin-top: 10px; }
.timer { height: 10px; border: 2px solid var(--ink); border-radius: 99px; overflow: hidden; background: var(--white); }
.timer i { display: block; height: 100%; width: 100%; background: var(--pink); }
.bars { display: grid; gap: 6px; margin-top: 10px; font-size: 0.95rem; font-weight: 600; }
.bars div { display: grid; grid-template-columns: 220px 1fr 3.2em; align-items: center; gap: 10px; }
.bars i { height: 18px; border: 2px solid var(--ink); border-radius: 4px; min-width: 6px; }
.crowd { font-size: 2rem; letter-spacing: .12em; }
.split { display: block; font-size: 1.35rem; margin-top: 2px; }
.split em { display: inline-block; width: 2.6em; font: 600 0.95rem "Bricolage Grotesque", sans-serif; color: var(--mute); }
.boss-hud { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; font-size: 1.05rem; }
.hp { height: 16px; border: var(--line); border-radius: 99px; overflow: hidden; background: var(--white); }
.hp i { display: block; height: 100%; background: var(--violet); margin-left: auto; transition: width .3s; }

.kernel-row { display: flex; align-items: center; gap: 14px; }
.kernel { display: grid; grid-template-columns: repeat(3, 46px); gap: 4px; }
.kernel span { display: grid; place-items: center; height: 38px; border: 2px solid var(--ink); border-radius: 6px; font-weight: 800; font-variant-numeric: tabular-nums; background: var(--white); }
.kernel .pos { background: var(--sun); }
.kernel .neg { background: var(--ink); color: var(--white); }
.codex-h { font-size: 1.5rem; font-weight: 800; margin: 30px 0 14px; }

/* ----- Ratings table ----- */
.table-wrap { overflow-x: auto; }
.ratings { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.ratings th, .ratings td { border: 2px solid var(--ink); padding: 8px 6px; text-align: center; }
.ratings th { font-size: 0.82rem; font-weight: 700; background: var(--paper); line-height: 1.15; }
.ratings tr th:first-child { text-align: left; font-size: 0.95rem; }
.ratings td { font-weight: 700; font-size: 1.2rem; }
.ratings .empty { color: var(--mute); background: repeating-linear-gradient(45deg, #fff, #fff 5px, var(--paper) 5px, var(--paper) 10px); }
.ratings .guess { background: var(--sun); padding: 4px; }
.ratings .guess button { width: 100%; min-height: 40px; background: var(--white); border: var(--line); border-radius: 8px; font-weight: 800; font-size: 1.2rem; cursor: pointer; }
.ratings .guess.done small { display: block; font-size: 0.72rem; color: var(--ink); }

/* ----- Codex ----- */
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.entry { padding: 16px; display: grid; gap: 6px; align-content: start; box-shadow: 4px 4px 0 var(--ink); }
.entry p { font-size: 0.95rem; }
.entry.shut { background: var(--paper); border-style: dashed; box-shadow: none; color: var(--mute); }
.entry.shut .letter { background: var(--white); }

/* ----- Certificate ----- */
.cert-tools { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 14px 0 18px; }
.cert-tools input { border: var(--line); border-radius: 12px; padding: 12px 14px; font-weight: 600; min-width: min(100%, 300px); background: var(--white); }
.cert { width: 100%; height: auto; border: var(--line); border-radius: 12px; box-shadow: var(--drop); }

@media (max-width: 860px) {
  .play { grid-template-columns: 1fr; }
  .title-copy { justify-self: start; }
  .hero-curve { opacity: .35; }
  .rank { margin-left: 0; }
  .bars div { grid-template-columns: 1fr 3.2em; }
  .bars div span { grid-column: 1 / -1; }
  .ctl:has(.seg) { grid-template-columns: 1fr; }
  .seg-b { font-size: 0.92rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
