/* MARIFA · design tokens. Diagrams sit on a dark "circuit board" in both
   themes, so light and glow read as electricity. */
:root {
  --bg: #f4f1ea;
  --bg-2: #ece7dc;
  --surface: #ffffff;
  --text: #17191e;
  --text-dim: #5c6069;
  --line: #e2dccf;
  --accent: #f0a91b;
  --accent-ink: #9a6400;
  --accent-soft: rgba(240, 169, 27, 0.14);
  --explore: #1b8a7a;
  --explore-soft: rgba(27, 138, 122, 0.1);
  --good: #1f7a5c;
  --good-soft: rgba(31, 122, 92, 0.1);
  --bad: #b23a3a;
  --bad-soft: rgba(178, 58, 58, 0.09);
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 8px 24px -12px rgba(20, 20, 30, 0.18);

  --board: #0e1726;
  --board-edge: #1d2a3f;
  --grid-dot: rgba(255, 255, 255, 0.07);
  --wire: #aebccf;
  --board-label: #8fa1b8;
  --amber: #ffb627;
  --copper: #c9a36b;

  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --bg-2: #12151b;
    --surface: #161a21;
    --text: #eeeae2;
    --text-dim: #a2a7b0;
    --line: #262c36;
    --accent: #ffb627;
    --accent-ink: #ffc85a;
    --accent-soft: rgba(255, 182, 39, 0.13);
    --explore: #3cc1ad;
    --explore-soft: rgba(60, 193, 173, 0.1);
    --good: #46b38f;
    --good-soft: rgba(70, 179, 143, 0.12);
    --bad: #e07070;
    --bad-soft: rgba(224, 112, 112, 0.11);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px -14px rgba(0, 0, 0, 0.7);
    --board: #0a111d;
    --board-edge: #1a2639;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

body {
  margin: 0;
  background: radial-gradient(1200px 500px at 50% -200px, var(--bg-2), var(--bg));
  background-color: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---- header ------------------------------------------------------------ */
.top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; letter-spacing: 0.14em; font-size: 0.85rem; }
.logo { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.logo circle { fill: var(--accent-soft); }

.dots { display: flex; gap: 5px; margin: 0 auto; }
.dot {
  width: 28px; height: 28px; border-radius: 50%; padding: 0;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text-dim);
  font: 700 0.72rem var(--font); cursor: pointer; transition: transform 0.15s, background 0.2s;
}
.dot:not(:disabled):hover { transform: translateY(-1px); }
.dot:disabled { opacity: 0.35; cursor: default; }
.dot.done { border-color: var(--good); color: var(--good); }
.dot.current { border-color: var(--accent); background: var(--accent); color: #17191e; box-shadow: 0 0 0 4px var(--accent-soft); }

.score {
  position: relative; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-weight: 700; font-size: 0.85rem; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.score-star { color: var(--accent); }
.score-unit { color: var(--text-dim); font-weight: 600; }
.score.bump { animation: bump 0.5s ease; }
@keyframes bump { 50% { transform: scale(1.15); border-color: var(--accent); } }
.float-points {
  position: absolute; right: 6px; top: -2px; pointer-events: none;
  color: var(--accent-ink); font-weight: 800; font-size: 0.9rem;
  animation: float-up 0.9s ease-out forwards;
}
@keyframes float-up { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-26px); } }

.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ffd36b); transition: width 0.4s ease; }

/* ---- page ------------------------------------------------------------ */
main { max-width: 600px; margin: 0 auto; padding: 18px 16px 48px; }
.step:not([hidden]) { animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.kicker { margin: 6px 0 0; color: var(--text-dim); font-size: 0.85rem; display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 0.75rem;
  letter-spacing: 0.03em; text-transform: uppercase;
}
h1 { margin: 8px 0 10px; font-size: 2.1rem; line-height: 1.1; letter-spacing: -0.02em; font-weight: 800; }
strong { font-weight: 700; }

/* ---- challenge, explore further, what you found ------------------------- */
.task {
  position: relative; margin: 18px 0; padding: 14px 16px 14px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.task::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.task p { margin: 8px 0 0; font-weight: 600; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--accent); color: #17191e; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.02em;
}
.tag::before { content: "◆"; font-size: 0.6rem; }
.bonus::before { background: var(--explore); }
.bonus .tag { background: var(--explore-soft); color: var(--explore); }
.bonus .tag::before { content: "✦"; }
.task.done::before { background: var(--good); }
.task.done .tag { background: var(--good-soft); color: var(--good); }
.task.done .tag::before { content: "✓"; font-size: 0.75rem; }

.found {
  position: relative; margin: 18px 0; padding: 14px 16px 14px 52px;
  background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 30%, transparent);
  border-radius: var(--radius); animation: rise 0.35s ease both;
}
.found::before {
  content: "💡"; position: absolute; left: 16px; top: 13px; font-size: 1.2rem;
}
.found p { margin: 0; }
.found-title { font-weight: 800; margin-bottom: 4px !important; color: var(--good); }

.status { min-height: 1.6em; font-weight: 600; margin: 10px 0; }
.status:empty { margin: 0; min-height: 0; }
.hint { margin: 6px 0; color: var(--text-dim); font-size: 0.9rem; }
.step-nav { margin-top: 22px; }

button { font: inherit; }
.next {
  display: block; width: 100%; padding: 15px 22px; border-radius: 14px; cursor: pointer;
  border: 0; background: linear-gradient(180deg, #ffc44a, var(--accent)); color: #17191e;
  font-weight: 800; font-size: 1.02rem; box-shadow: 0 8px 20px -10px rgba(240, 169, 27, 0.8);
  transition: transform 0.15s;
}
.next:hover { transform: translateY(-1px); }
.secondary {
  padding: 11px 20px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700;
}
.secondary:hover { border-color: var(--accent); }
@media (min-width: 640px) { .next { display: inline-block; width: auto; } }

/* ---- choices and matching ------------------------------------------------ */
.choices { display: grid; gap: 8px; margin-top: 12px; counter-reset: option; }
.choices button, .pick {
  display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 11px 12px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font-weight: 500;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.choices button::before {
  counter-increment: option; content: counter(option, upper-alpha);
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 800; font-size: 0.8rem; color: var(--text-dim);
}
.choices button:not(:disabled):hover, .pick:not(:disabled):hover { border-color: var(--accent); }
.choices button:active, .pick:active { transform: scale(0.99); }
.choices button:disabled, .pick:disabled { cursor: default; }
.choices button.right, .pick.right { border-color: var(--good); background: var(--good-soft); }
.choices button.right::before { content: "✓"; background: var(--good); color: #fff; border-color: var(--good); }
.choices button.wrong, .pick.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choices button.wrong::before { content: "✕"; background: var(--bad); color: #fff; border-color: var(--bad); }
.choices button:disabled:not(.right):not(.wrong) { opacity: 0.55; }
.pick.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.pick.wrong { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.match { display: grid; grid-template-columns: 1fr 1.7fr; gap: 10px; margin: 12px 0; }
.match-col { display: grid; gap: 8px; align-content: start; }
#s2-words .pick { font-weight: 700; justify-content: center; }

/* ---- sliders and toggles --------------------------------------------------- */
.sliders { display: grid; gap: 14px; margin: 14px 0; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.sliders label { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 0.95rem; color: var(--text-dim); }
.sliders strong { color: var(--text); font-variant-numeric: tabular-nums; }
.sliders input { grid-column: 1 / -1; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.equation {
  font-variant-numeric: tabular-nums; font-size: 1.15rem; font-weight: 700; text-align: center;
  margin: 10px 0; padding: 10px; border-radius: 12px; background: var(--accent-soft);
}

.toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin: 6px 0; box-shadow: var(--shadow); }
.toggle button { border: 0; background: transparent; color: var(--text-dim); padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; }
.toggle button[aria-checked="true"] { background: var(--accent); color: #17191e; }

/* ---- the circuit board ---------------------------------------------------- */
.board {
  margin: 18px 0; padding: 10px; border-radius: 20px;
  background: var(--board); border: 1px solid var(--board-edge);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35), var(--shadow);
}
svg { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.board-grid { fill: url(#board-grid); }
.grid-dot { fill: var(--grid-dot); }

.wire path { fill: none; stroke: var(--wire); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.label { fill: var(--board-label); font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.caption { fill: var(--board-label); font-size: 10.5px; font-style: italic; }
.readout { fill: #ffe08a; font-size: 22px; font-weight: 800; }
.contact { fill: var(--copper); stroke: #0e1726; stroke-width: 1.5; }

/* battery cell */
.cell-body { fill: url(#cell-body); stroke: #5b6f8c; stroke-width: 1; }
.cell-cap { fill: var(--amber); }
.cell-nub { fill: #c3cfdd; }
.cell-sign { fill: #17191e; font-size: 12px; font-weight: 900; text-anchor: middle; }
.cell-sign.minus { fill: #d8e1ec; }

/* bulb */
.halo { fill: url(#bulb-glow); opacity: 0; transition: opacity 0.35s; }
.glass { fill: #1b2638; stroke: var(--wire); stroke-width: 2.5; transition: fill 0.35s, stroke 0.35s; }
.filament { fill: none; stroke: #6f8299; stroke-width: 1.8; stroke-linejoin: round; transition: stroke 0.35s; }
.shine { fill: #ffffff; opacity: 0.18; }
.rays line { stroke: var(--amber); stroke-width: 2.5; stroke-linecap: round; opacity: 0; transition: opacity 0.35s; }
.bulb-name { fill: var(--board-label); font-size: 10px; font-weight: 800; opacity: 0; }
.bulb.on .halo { opacity: 1; }
.bulb.on .glass { fill: url(#glass-lit); stroke: #ffd36b; }
.bulb.on .filament { stroke: #fff6d6; }
.bulb.on .shine { opacity: 0.5; }
.bulb.on .rays line { opacity: 0.85; }
.bulb.dim .halo { opacity: 0.35; }
.bulb.dim .glass { fill: #6b5a2c; stroke: #c9a24a; }
.bulb.dim .filament { stroke: #ffd36b; }
.bulb.removed { opacity: 0.22; }
.bulb.removed .bulb-name { opacity: 1; }
.bulb.tappable { cursor: pointer; outline: none; }
.bulb.tappable:focus-visible .glass { stroke: var(--accent); stroke-width: 3.5; }

/* switch */
.lever line { stroke: var(--wire); stroke-width: 5; stroke-linecap: round; }
.pivot { fill: var(--copper); }
.lever { transform-origin: 280px 98px; transition: transform 0.25s cubic-bezier(.3, 1.4, .5, 1); }
.switch.open .lever { transform: rotate(-38deg); }
.switch { cursor: pointer; outline: none; }
.switch:focus-visible .hit, .piece:focus-visible .hit { stroke: var(--amber); stroke-width: 2; }
.hit { fill: transparent; }

/* the gap and the missing wire */
.gap { fill: rgba(255, 182, 39, 0.1); stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 5 4; animation: pulse 1.6s ease-in-out infinite; }
.gap.filled { display: none; }
@keyframes pulse { 50% { fill: rgba(255, 182, 39, 0.24); } }
.piece { cursor: grab; outline: none; }
.piece.dragging { cursor: grabbing; }
.piece-wire { stroke: var(--wire); stroke-width: 5; stroke-linecap: round; }
.piece-end { fill: var(--copper); }
.piece:not(.placed) .piece-wire { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { stroke: #ffd36b; } }
.piece.placed { cursor: default; }
.piece.placed .hit, .piece.placed .piece-label { display: none; }

/* current, shown as glowing dots moving round the loop */
.flow { fill: none; stroke: var(--amber); stroke-width: 6; stroke-dasharray: 0.1 18; stroke-linecap: round; opacity: 0; }
.flow.on { opacity: 1; animation: flow 1.2s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -36.2; } }

/* step 2: the water picture */
.pipe { fill: none; stroke: #2b3b55; stroke-width: 22; stroke-linecap: round; }
.pipe.narrow { stroke-width: 10; }
.water { fill: none; stroke: #67b7ff; stroke-width: 5; stroke-dasharray: 0.1 14; stroke-linecap: round; animation: flow 1s linear infinite; }
.pump circle { fill: #1b2638; stroke: var(--wire); stroke-width: 2.5; }
.pump path { fill: var(--amber); }

/* meters */
.meter-face { fill: #0a0f18; stroke: var(--wire); stroke-width: 2.5; }
.meter-value { fill: #7dffcf; font-size: 12px; font-weight: 800; text-anchor: middle; font-variant-numeric: tabular-nums; }
.meter-unit { fill: var(--board-label); font-size: 7px; font-weight: 700; text-anchor: middle; letter-spacing: 0.05em; }

/* fuse and the shortcut */
.fuse-body { fill: rgba(174, 188, 207, 0.12); stroke: var(--wire); stroke-width: 1.5; }
.fuse-cap { fill: #c3cfdd; }
.fuse-wire { stroke: #ffd36b; stroke-width: 1.5; fill: none; }
.fuse-wire.blown { stroke: var(--bad); stroke-dasharray: 11 8; }
.spark { fill: #ff7a45; opacity: 0; transition: opacity 0.2s; }
.fuse-wire.blown + .spark { opacity: 0.7; }
.shortcut { cursor: pointer; outline: none; }
.hit-line { fill: none; stroke: transparent; stroke-width: 26; }
.short-line { fill: none; stroke: var(--amber); stroke-width: 3; stroke-dasharray: 6 5; stroke-linecap: round; animation: march 0.9s linear infinite; }
@keyframes march { to { stroke-dashoffset: -22; } }
.shortcut-label { fill: var(--amber); font-size: 10px; }
.shortcut.added .short-line { stroke: var(--wire); stroke-width: 5; stroke-dasharray: none; animation: none; }
.shortcut.added .shortcut-label { display: none; }
.shortcut:focus-visible .short-line { stroke-width: 5; }

/* ---- quiz and end -------------------------------------------------------- */
.q { margin: 16px 0; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.q h2 { font-size: 1.02rem; line-height: 1.45; margin: 0; }
.q .why { margin: 12px 0 0; padding-top: 10px; border-top: 1px dashed var(--line); color: var(--text-dim); }

.end-hero { width: 120px; margin: 4px auto 0; }
.end .kicker, .end h1, .end-summary { text-align: center; justify-content: center; }
.end-summary { font-size: 1.1rem; font-weight: 700; }
.badges { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 18px 0; }
.badges li {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  font-weight: 700;
}
.badges li::before {
  content: "★"; display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe08a, var(--accent)); color: #5a3a00; font-size: 1rem;
  box-shadow: 0 4px 12px -4px rgba(240, 169, 27, 0.8);
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 3;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 18px; border-radius: 999px;
  background: #17191e; color: #fff; font-weight: 700; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.3s ease both;
}
.toast::before { content: "★"; color: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.foot { margin-top: 32px; color: var(--text-dim); font-size: 0.78rem; text-align: center; }

/* ---- 3D stages (ADR-0010, art direction D in ADR-0011) ---------------------
   Real objects on engineering drawing paper, with explainer-style labels. */
.stage {
  position: relative; margin: 18px 0; border-radius: 18px; overflow: hidden;
  aspect-ratio: 4 / 3; background: #12365c; border: 1px solid #2a5180;
  box-shadow: var(--shadow);
}
@media (max-width: 520px) { .stage { aspect-ratio: 1 / 1; } }
.scene-canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.scene-labels { position: absolute; inset: 0; pointer-events: none; }
.scene-label { font: 600 15px/1.2 Georgia, "Times New Roman", serif; color: #f1f6ff; white-space: nowrap; text-shadow: 0 1px 2px rgba(5, 20, 40, 0.6); }
.scene-label small { display: block; margin-top: 2px; font: 400 12px/1.3 var(--font); color: #a9c4e4; }
.scene-label.charge { color: #ffb36b; }
.scene-tap {
  padding: 3px 10px; border-radius: 999px; font: 700 11px/1.5 var(--font); letter-spacing: 0.03em;
  color: #12365c; background: #ffb36b; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); transition: opacity 0.3s;
}
.scene-caption {
  margin: -10px 0 14px; font: 600 11px/1.5 Consolas, "Courier New", monospace;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim);
}
@media (max-width: 520px) {
  .scene-label { font-size: 12px; }
  .scene-label small { font-size: 10px; }
}
.stage-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 10px; }
.action {
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 0.88rem;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
}
.action:not(:disabled):hover { border-color: var(--accent); }
.action:disabled { opacity: 0.45; cursor: default; }

@media (max-width: 380px) {
  .brand { display: none; }
  h1 { font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
