
/* Layout concept: radiograph-style light box. Figure on the left, notes panel on the right, tabs across the top. */
:root {
  --bg: #efe9ff;
  --surface: #ffffff;
  --surface-2: #e3d9ff;
  --ink: #1b1237;
  --ink-2: #594d80;
  --line: #b9abe8;
  --edge: #1b1237;
  --bone: #f1ffb8;
  --bone-line: #3a2a8c;
  --hi: #ff3d8b;
  --muscle: #ff6258;
  --muscle-line: #a82a28;
  --accent: #6a3df0;
  --accent-ink: #ffffff;
  --good: #0e9f68;
  --bad: #e03a52;
  --font-display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --font-body: "Outfit", "Segoe UI", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120b2b; --surface: #1d1442; --surface-2: #2a1e5c; --ink: #f6f2ff; --ink-2: #b9aeea;
    --line: #43347f; --edge: #05030f; --bone: #2d2570; --bone-line: #c6ff3d; --hi: #ff3d8b; --muscle: #ff6b6b;
    --muscle-line: #ffb3a8; --accent: #c6ff3d; --accent-ink: #17102f; --good: #3ff0a0; --bad: #ff7090;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #120b2b; --surface: #1d1442; --surface-2: #2a1e5c; --ink: #f6f2ff; --ink-2: #b9aeea;
  --line: #43347f; --edge: #05030f; --bone: #2d2570; --bone-line: #c6ff3d; --hi: #ff3d8b; --muscle: #ff6b6b;
  --muscle-line: #ffb3a8; --accent: #c6ff3d; --accent-ink: #17102f; --good: #3ff0a0; --bad: #ff7090;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-body);
  font-size: 16px; line-height: 1.5; padding-inline: 16px; padding-block: 0 48px;
}
.wrap { max-width: 1040px; margin-inline: auto; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 5vw, 2.5rem); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 1.45rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; }
.mono { font-family: var(--font-mono); }
.eyebrow { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }

header.top { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; padding-block: 28px 18px; }
header.top p { color: var(--ink-2); max-width: 46ch; margin-top: 6px; }
.theme-btn { font: inherit; font-size: 0.85rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }

nav.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); display: flex; gap: 4px; overflow-x: auto; border-bottom: 2px solid var(--line); padding-top: 4px; }
nav.tabs button { font: inherit; font-weight: 600; font-size: 0.95rem; white-space: nowrap; background: none; border: 0; color: var(--ink-2); padding: 10px 14px; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; }
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
button:focus-visible, [tabindex]:focus-visible, .part:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }

section.panel { padding-top: 24px; display: grid; gap: 28px; }
.lede { color: var(--ink-2); max-width: 62ch; }

.explorer { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 24px; align-items: start; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stage svg { display: block; width: 100%; height: auto; max-height: 72vh; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg button { font: inherit; font-size: 0.85rem; font-weight: 600; background: var(--surface); color: var(--ink-2); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.info { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 14px; min-height: 200px; }
.info dl { display: grid; gap: 10px; margin: 0; }
.info dt { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.info dd { margin: 2px 0 0; }
.tag { display: inline-block; font-family: var(--font-mono); font-size: 0.75rem; border: 1px solid var(--line); background: var(--surface-2); border-radius: 4px; padding: 2px 8px; }
.tip { border-left: 4px solid var(--hi); padding: 6px 12px; background: var(--surface-2); border-radius: 0 6px 6px 0; }

.btn { font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* figure parts */
.part { cursor: pointer; }
.bone { fill: var(--bone); stroke: var(--bone-line); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; transition: fill .15s; }
.bone.line { fill: none; stroke-width: 5; }
.part:hover .bone, .part.sel .bone { fill: var(--hi); stroke: var(--hi); }
.part:hover .bone.line, .part.sel .bone.line { fill: none; }
.part.right .bone { fill: var(--good); stroke: var(--good); }
.part.right .bone.line { fill: none; }
.part.wrong .bone { stroke: var(--bad); fill: color-mix(in srgb, var(--bad) 35%, var(--bone)); }
.part.wrong .bone.line { fill: none; }
.part.pair .mus { stroke: var(--hi); stroke-dasharray: 5 3; fill-opacity: .85; }
[hidden] { display: none !important; }
.silhouette { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.mus { fill: var(--muscle); fill-opacity: .55; stroke: var(--muscle-line); stroke-width: 1.8; transition: fill-opacity .15s; }
.part:hover .mus, .part.sel .mus { fill-opacity: .95; stroke: var(--hi); }
.lbl { font-family: var(--font-mono); font-size: 9px; fill: var(--ink-2); pointer-events: none; }

/* game */
.game { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 10px; }
.game .target { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }
.msg { min-height: 1.5em; font-weight: 600; }
.msg.good { color: var(--good); } .msg.bad { color: var(--bad); }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.card h3 { font-size: 1rem; }
.card p { color: var(--ink-2); font-size: 0.93rem; }
button.card { font: inherit; color: inherit; text-align: left; cursor: pointer; }
button.card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.joint-card svg { width: 100%; height: 110px; background: var(--surface-2); border-radius: 6px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 0.93rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }

/* antagonist demo */
.demo { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.demo svg { width: 100%; height: auto; }
.demo input[type="range"] { width: 100%; accent-color: var(--accent); }
.status { display: grid; gap: 8px; }
.pill { display: flex; justify-content: space-between; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--surface-2); }
.pill b { font-family: var(--font-mono); font-size: 0.85rem; }
.pill.on { border-color: var(--muscle); background: color-mix(in srgb, var(--muscle) 18%, var(--surface)); }

/* quiz + flashcards */
.quiz { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 14px; }
.q { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; }
.opts { display: grid; gap: 8px; }
.opt { font: inherit; text-align: left; background: var(--surface-2); color: var(--ink); border: 2px solid transparent; border-radius: 8px; padding: 10px 14px; cursor: pointer; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.good { border-color: var(--good); background: color-mix(in srgb, var(--good) 20%, var(--surface)); }
.opt.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 18%, var(--surface)); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.flash { min-height: 150px; width: 100%; text-align: center; font: inherit; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 24px; cursor: pointer; display: grid; place-items: center; }
.flash .t { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }
.flash .d { font-size: 1.05rem; max-width: 52ch; }
.score { font-family: var(--font-display); font-size: 2.4rem; font-weight: 800; }

@media (max-width: 720px) {
  .explorer, .demo { grid-template-columns: minmax(0, 1fr); }
  .svg-stage { max-width: 340px; margin-inline: auto; width: 100%; }
}
/* 3D viewer */
#tab-skeleton .explorer, #tab-muscles .explorer { grid-template-columns: minmax(0, 440px) minmax(0, 1fr); }
@media (max-width: 720px) { #tab-skeleton .explorer, #tab-muscles .explorer { grid-template-columns: minmax(0, 1fr); } }
.v3d { position: relative; width: 100%; height: min(74vh, 600px); min-height: 400px; border-radius: 10px; overflow: hidden; background: radial-gradient(ellipse at 50% 38%, #2b2358 0%, #120c2e 60%, #07041a 100%); }
.v3d-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.v3d-canvas:active { cursor: grabbing; }
.v3d-ui { position: absolute; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; padding: 8px; }
.v3d-hint { align-self: flex-start; font-family: var(--font-mono); font-size: 0.7rem; color: #cfc8f5; background: rgba(7, 4, 26, 0.6); border-radius: 8px; padding: 4px 8px; max-width: 85%; }
.v3d-btns { pointer-events: auto; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.v3d-btns button { font: inherit; font-size: 0.8rem; font-weight: 700; background: var(--surface); color: var(--ink); border: 2px solid var(--edge); border-radius: 10px; padding: 5px 10px; cursor: pointer; box-shadow: 2px 2px 0 var(--edge); }
.v3d-btns button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
.chip-btn { font: inherit; font-size: 0.78rem; font-weight: 600; background: var(--surface-2); color: var(--ink); border: 2px solid var(--edge); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.chip-btn[aria-pressed="true"] { background: var(--hi); color: #fff; }

/* teen theme: chunky stickers with hard shadows */
h1 { font-size: clamp(1.5rem, 5.4vw, 2.3rem); font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.15rem, 3.6vw, 1.45rem); font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 0.95rem; font-weight: 700; }
.stage, .info, .game, .card, .quiz, .demo, .table-wrap, .flash, .stats {
  border: 2px solid var(--edge); border-radius: 16px; box-shadow: 4px 4px 0 var(--edge);
}
.btn, .theme-btn, .seg, .opt, .pill, .tag { border: 2px solid var(--edge); }
.btn { border-radius: 12px; box-shadow: 3px 3px 0 var(--edge); font-weight: 700; transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--edge); }
.btn.ghost { color: var(--ink); }
.theme-btn { border-radius: 999px; font-weight: 700; }
.seg { border-radius: 12px; flex-wrap: wrap; background: var(--surface); }
.seg button { font-weight: 700; }
.opt { border-radius: 12px; font-weight: 600; }
.opt:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--edge); border-color: var(--edge); }
.pill, .tag { border-radius: 10px; }
.tip { border-left: 6px solid var(--hi); border-radius: 0 12px 12px 0; }
nav.tabs { gap: 6px; padding: 6px 0; border-bottom: 0; }
nav.tabs button { border: 2px solid var(--edge); border-radius: 999px; padding: 8px 16px; margin: 0; background: var(--surface); color: var(--ink); }
nav.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: 3px 3px 0 var(--edge); }
.eyebrow { color: var(--hi); font-weight: 500; }
.score { font-size: 2.2rem; }
.stats { background: var(--surface); padding: 16px; display: grid; gap: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border: 2px solid var(--edge); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.chip { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 500; background: var(--hi); color: #fff; border: 2px solid var(--edge); border-radius: 999px; padding: 5px 12px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.run { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lives { font-size: 1.1rem; letter-spacing: 3px; color: var(--hi); }
.copy-note { font-size: 0.9rem; color: var(--ink-2); }
.copy-note textarea { width: 100%; font: inherit; background: var(--surface-2); color: var(--ink); border: 2px solid var(--edge); border-radius: 10px; padding: 8px; margin-top: 6px; }
/* share dialog */
a.btn { display: inline-block; text-decoration: none; text-align: center; }
.share-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(5, 3, 15, 0.8); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.share-box { position: relative; width: min(100%, 460px); max-height: 100%; overflow-y: auto; background: var(--surface); color: var(--ink); border: 2px solid var(--edge); border-radius: 16px; box-shadow: 4px 4px 0 var(--edge); padding: 18px; display: grid; gap: 12px; }
.share-img { width: 100%; max-width: 340px; height: auto; justify-self: center; border-radius: 12px; border: 2px solid var(--edge); aspect-ratio: 1080 / 1350; background: var(--surface-2); }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-note { font-size: 0.88rem; color: var(--ink-2); }
.share-note textarea { width: 100%; font: inherit; background: var(--surface-2); color: var(--ink); border: 2px solid var(--edge); border-radius: 10px; padding: 8px; margin-top: 6px; }
.share-close { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; font-size: 1.4rem; line-height: 1; background: var(--surface-2); color: var(--ink); border: 2px solid var(--edge); border-radius: 10px; cursor: pointer; }
.share-box h2 { padding-right: 44px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- games ---------- */
.game .opts { display: grid; gap: 8px; }
.combo { position: relative; }
.txt { width: 100%; box-sizing: border-box; font: inherit; font-size: 1rem; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--edge); background: var(--surface); color: var(--ink); }
.txt:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
.txt:disabled { opacity: .7; }
.suggest { list-style: none; margin: 6px 0 0; padding: 4px; position: absolute; left: 0; right: 0; z-index: 6; background: var(--surface); border: 2px solid var(--edge); border-radius: 12px; box-shadow: 4px 4px 0 var(--edge); max-height: 260px; overflow: auto; }
.suggest li { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.suggest li small { font-weight: 400; color: var(--ink-2); margin-left: 6px; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.suggest li[aria-selected="true"] small, .suggest li:hover small { color: inherit; }
.suggest li.none { cursor: default; color: var(--ink-2); font-weight: 400; }
.suggest li.none:hover { background: none; color: var(--ink-2); }
.explorer.playing .info { display: none; }
@media (max-width: 720px) {
  .explorer.playing .v3d { height: min(42vh, 340px); min-height: 250px; }
}
/* celebration effects */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.fx-bit { position: absolute; width: 10px; height: 14px; border-radius: 2px; }
.fx-toast { position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translate(-50%, 140%); opacity: 0; transition: transform .35s cubic-bezier(.3,1.6,.5,1), opacity .2s; background: var(--hi); color: #fff; font-family: var(--font-display); font-weight: 800; padding: 12px 20px; border: 2px solid var(--edge); border-radius: 14px; box-shadow: 4px 4px 0 var(--edge); max-width: calc(100vw - 32px); text-align: center; pointer-events: none; }
.fx-toast.on { transform: translate(-50%, 0); opacity: 1; }
.svg-stage.dancing svg { animation: fx-dance .5s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes fx-dance { from { transform: rotate(-4deg) translateY(0); } to { transform: rotate(4deg) translateY(-8px); } }

.locker { border-top: 2px dashed var(--line); padding-top: 8px; }
.locker summary { cursor: pointer; font-family: var(--font-mono); font-size: 0.8rem; font-weight: 500; color: var(--hi); }
.locker ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 0.9rem; color: var(--ink-2); }
.locker li.on { color: var(--ink); font-weight: 600; }
.locker li small { color: var(--ink-2); font-weight: 400; margin-left: 4px; }

.dance-overlay { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 65; width: min(340px, 92vw); }
.dance-box { background: var(--surface); border: 2px solid var(--edge); border-radius: 16px; box-shadow: 6px 6px 0 var(--edge); padding: 10px; display: grid; gap: 10px; justify-items: center; }
.dance-stage { width: 100%; }
.dance-stage .v3d { height: min(58vh, 440px); min-height: 300px; }
.dance-stage .v3d-ui, .dance-stage .chips { display: none; }

/* phones: let every block shrink to the screen so the page never scrolls sideways */
section.panel { grid-template-columns: minmax(0, 1fr); }
section.panel > *, .explorer > *, .cards > * { min-width: 0; }
.wrap { min-width: 0; }
body { overflow-x: hidden; }
@media (max-width: 480px) {
  body { padding-inline: 10px; }
  header.top { padding-block: 18px 12px; }
  .top-actions { gap: 6px; }
  .theme-btn, .chip { font-size: 0.78rem; padding-inline: 10px; }
  .v3d-btns button { padding: 4px 8px; font-size: 0.75rem; }
  .stage, .info, .game, .quiz, .demo { padding: 10px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) {
  nav.tabs { gap: 4px; overflow-x: visible; flex-wrap: wrap; }
  nav.tabs button { font-size: 0.82rem; padding: 6px 11px; }
}

.back { display: inline-block; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 500; color: var(--ink); text-decoration: none; background: var(--surface); border: 2px solid var(--edge); border-radius: 999px; padding: 3px 12px; margin-bottom: 10px; }
.back:hover { background: var(--surface-2); }

[hidden] { display: none !important; }
.levelbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-block: 0 8px; }
.levelbar .seg { margin-bottom: 0; }
.deep-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.deep { background: var(--surface); border: 2px solid var(--edge); border-radius: 16px; box-shadow: 4px 4px 0 var(--edge); padding: 16px; display: grid; gap: 10px; min-width: 0; }
.deep h3 { margin: 0; }
.deep ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.deep li { color: var(--ink-2); }
@media (min-width: 900px) { .deep-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.perfect-overlay { width: min(460px, 94vw); }
.perfect-title { display: grid; gap: 2px; text-align: center; font-family: var(--font-display, inherit); }
.perfect-title span { font-family: var(--font-mono, monospace); font-size: 0.78rem; color: var(--accent); }
.perfect-svg { width: 100%; height: auto; border-radius: 12px; border: 2px solid var(--edge); background: #bfe6ff; display: block; }
