/* Spark. An engineering pad: green-ruled paper, ink, and a copper trace that powers up as units are completed. */

@font-face { font-family: "Bricolage"; src: url("../vendor/fonts/bricolage-grotesque-latin-wght-normal.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("../vendor/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("../vendor/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("../vendor/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("../vendor/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("../vendor/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --paper: #edf2e1;
  --rule: rgba(64, 120, 84, 0.17);
  --card: #fbfdf6;
  --ink: #17233f;
  --ink-soft: #505c78;
  --line: #c3cfb4;
  --copper: #b65a18;
  --copper-hi: #e58b3a;
  --mark: #ffe066;
  --yes: #1c7458;
  --yes-bg: #d9f0e2;
  --no: #b93226;
  --no-bg: #f9dfd9;
  --display: "Bricolage", "Plex Sans", system-ui, sans-serif;
  --body: "Plex Sans", system-ui, sans-serif;
  --mono: "Plex Mono", ui-monospace, monospace;
  --page: 34rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1b33;
    --rule: rgba(130, 165, 225, 0.09);
    --card: #18274a;
    --ink: #e7edf9;
    --ink-soft: #a3b0cc;
    --line: #2f4270;
    --copper: #e9995a;
    --copper-hi: #ffb877;
    --yes: #5fd0a4;
    --yes-bg: #15382f;
    --no: #ff8f80;
    --no-bg: #44201f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font: 400 1rem/1.5 var(--body);
  background-color: var(--paper);
  background-image: linear-gradient(var(--rule) 1px, transparent 1px), linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 22px 22px;
}
#app { max-width: var(--page); margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
h1, h2 { font-family: var(--display); line-height: 1.12; margin: 0; letter-spacing: -0.015em; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.mono { font-family: var(--mono); }
:focus-visible { outline: 3px solid var(--copper-hi); outline-offset: 3px; }
svg { display: block; }

.eyebrow { font: 500 0.75rem/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--copper); }
.tag { display: inline-block; font: 500 0.6875rem/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; padding: 0.3rem 0.45rem; background: var(--mark); color: #17233f; border-radius: 3px; }
.tag.retry { background: var(--no-bg); color: var(--no); }

/* Buttons: keys you press down */
.btn {
  display: block; width: 100%; padding: 0.9rem 1.1rem; border-radius: 14px; border: 2px solid var(--ink);
  background: var(--card); font: 600 1.0625rem/1.2 var(--display); letter-spacing: 0.005em; text-align: center;
  box-shadow: 0 4px 0 var(--ink); transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); box-shadow: 0 4px 0 var(--copper); border-color: var(--ink); }
.btn.primary:active:not(:disabled) { box-shadow: 0 0 0 var(--copper); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn small { display: block; margin-top: 0.2rem; font: 400 0.75rem/1.2 var(--body); color: var(--ink-soft); }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; border-radius: 12px; flex: none; }
.icon-btn svg, .stat svg, .brand-mark svg, .result-mark svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* Top bar on the path */
.top { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1rem 0.4rem; }
.brand { display: flex; align-items: center; gap: 0.45rem; font: 700 1.3rem/1 var(--display); letter-spacing: -0.02em; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--ink); color: var(--mark); }
.brand-mark svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.stats { display: flex; gap: 0.9rem; }
.stat { display: flex; align-items: center; gap: 0.25rem; font: 500 1rem/1 var(--mono); color: var(--ink-soft); }
.stat.on { color: var(--copper); }
.stat svg { width: 20px; height: 20px; }

.path-page { padding: 0 1rem 3rem; }
.course-head { padding: 1.2rem 0 0.5rem; }
.course-head h1 { font-size: clamp(2rem, 9vw, 2.75rem); font-weight: 750; margin-top: 0.35rem; }
.goal { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; font: 400 0.8125rem/1 var(--mono); color: var(--ink-soft); }
.goal-bar { flex: 1; height: 10px; border-radius: 99px; background: var(--card); border: 1.5px solid var(--ink); overflow: hidden; }
.goal-bar i { display: block; height: 100%; background: var(--copper-hi); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 1.1rem; }
.actions .btn { font-size: 0.9375rem; padding: 0.75rem 0.6rem; }
.actions .btn.wide { grid-column: 1 / -1; font-size: 1.0625rem; }
.btn.primary small { color: inherit; opacity: 0.75; }
.mode { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; margin-top: 0.6rem; font-size: 0.875rem; color: var(--ink-soft); }
.mode .seg { margin-top: 0; }
.mode .seg button { font-size: 0.875rem; color: var(--ink); }

.links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; margin-top: 1rem; }
.link { display: inline-flex; align-items: center; gap: 0.35rem; min-height: 44px; padding: 0; border: 0; background: none; font: 600 0.9375rem/1.2 var(--display); text-decoration: underline; text-decoration-color: var(--copper); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.link svg, .help svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.help svg { display: inline-block; vertical-align: -3px; }

/* The unit path: a circuit trace with a pad per unit */
.path { position: relative; margin-top: 1.5rem; }
.path-wire { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.wire { fill: none; stroke: var(--line); stroke-width: 5; stroke-dasharray: 2 9; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.wire.live { stroke: var(--copper); stroke-dasharray: 14 8; animation: flow 1.1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -22; } }
.node-wrap { position: absolute; transform: translate(-50%, -50%); }
.node {
  position: relative; width: 84px; height: 84px; border-radius: 50%; border: 3px solid var(--ink); background: var(--card);
  box-shadow: 0 6px 0 var(--ink); display: grid; place-items: center; padding: 0; transition: transform 0.06s, box-shadow 0.06s;
}
.node:active { transform: translateY(6px); box-shadow: 0 0 0 var(--ink); }
.node-sym { font: 500 0.9375rem/1 var(--mono); letter-spacing: -0.03em; max-width: 66px; overflow: hidden; white-space: nowrap; }
.node.done { background: var(--copper); border-color: var(--ink); color: #fff8ee; }
.node.next { background: var(--mark); color: #17233f; }
.node.next::after { content: ""; position: absolute; inset: -11px; border-radius: 50%; border: 2px dashed var(--copper); animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pips { position: absolute; bottom: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 4px; }
.pips i { width: 9px; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 22%, transparent); }
.pips i.on { background: currentColor; }
.node-label { position: absolute; top: 50%; transform: translateY(-50%); width: min(40vw, 11.5rem); font-size: 0.9375rem; line-height: 1.25; }
.node-label b { display: block; font: 600 1rem/1.2 var(--display); }
.node-label .tag { margin-top: 0.35rem; }
.label-right .node-label { left: calc(100% + 16px); }
.label-left .node-label { right: calc(100% + 16px); text-align: right; }

.later { margin-top: 2rem; padding-top: 1.2rem; border-top: 2px dashed var(--line); color: var(--ink-soft); font-size: 0.9375rem; }
.later h2 { font-size: 1.05rem; color: var(--ink); margin-bottom: 0.5rem; }
.later p { margin-top: 0.3rem; }
.later em { white-space: nowrap; font-style: normal; font: 400 0.75rem/1 var(--mono); margin-left: 0.3rem; }

/* Unit sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(15, 25, 50, 0.45); z-index: 10; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, var(--page)); z-index: 11;
  background: var(--card); border: 2px solid var(--ink); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 1.4rem 1.2rem calc(1.4rem + env(safe-area-inset-bottom)); display: grid; gap: 0.75rem; animation: rise 0.2s ease-out;
}
.sheet[hidden], .sheet-back[hidden], .feedback[hidden], .foot[hidden] { display: none; }
.sheet h2 { font-size: 1.6rem; font-weight: 700; }
.exam-note { padding: 0.6rem 0.75rem; background: var(--mark); color: #17233f; border-radius: 8px; font-size: 0.9375rem; }
.sheet-progress { font: 400 0.8125rem/1.3 var(--mono); color: var(--ink-soft); }
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } }

/* Lesson */
.bar { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.75rem; position: sticky; top: 0; z-index: 5; background: var(--paper); }
.bar-title { font: 500 0.8125rem/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); flex: 1; }
.progress { flex: 1; height: 14px; border-radius: 99px; background: var(--card); border: 2px solid var(--ink); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--copper-hi); transition: width 0.35s ease-out; }
.combo { min-width: 2.2rem; text-align: right; font: 500 0.9375rem/1 var(--mono); color: var(--ink-soft); }
.combo.hot { color: var(--copper); }
.lesson { flex: 1; padding: 0.75rem 1rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.lesson > .tag { align-self: flex-start; }
.stem { background: var(--card); border: 2px solid var(--ink); border-radius: 16px; padding: 0.9rem 1rem; display: grid; gap: 0.6rem; }
.prompt { font-size: clamp(1.25rem, 5.2vw, 1.5rem); font-weight: 650; line-height: 1.25; }
.fig { width: 100%; max-width: 21rem; height: auto; margin: 0 auto; color: var(--ink); }
.fig-wire { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fig-box { fill: var(--card); stroke: currentColor; stroke-width: 1.8; }
.fig-dot { fill: currentColor; }
.fig-label { font: italic 500 13px var(--body); fill: currentColor; }
.fig-loop { fill: none; stroke: var(--copper); stroke-width: 1.5; stroke-linecap: round; }

.choices { display: grid; gap: 0.7rem; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice {
  display: flex; align-items: center; gap: 0.75rem; min-height: 58px; padding: 0.7rem 0.9rem; text-align: left; border-radius: 14px;
  border: 2px solid var(--ink); background: var(--card); box-shadow: 0 4px 0 var(--ink); font-weight: 500; transition: transform 0.06s, box-shadow 0.06s;
}
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: none; }
.choice kbd { flex: none; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px; border: 1.5px solid var(--line); font: 500 0.8125rem/1 var(--mono); color: var(--ink-soft); }
.choice.picked { background: var(--mark); color: #17233f; }
.choice.picked kbd { border-color: #17233f; color: #17233f; }
.choice.right { background: var(--yes-bg); border-color: var(--yes); box-shadow: 0 4px 0 var(--yes); color: var(--ink); }
.choice.wrong { background: var(--no-bg); border-color: var(--no); box-shadow: 0 4px 0 var(--no); color: var(--ink); }
.choice:disabled { cursor: default; }

.num { display: flex; align-items: stretch; border: 2px solid var(--ink); border-radius: 14px; background: var(--card); overflow: hidden; box-shadow: 0 4px 0 var(--ink); }
.num:focus-within { outline: 3px solid var(--copper-hi); outline-offset: 3px; }
.num input { flex: 1; min-width: 0; border: 0; background: none; color: inherit; padding: 0.9rem 1rem; font: 500 1.375rem/1.2 var(--mono); outline: none; }
.num input::placeholder { color: var(--ink-soft); opacity: 0.6; font-size: 1rem; }
.num-unit { display: grid; place-items: center; padding: 0 1rem; border-left: 2px solid var(--ink); background: var(--paper); font: 500 1.125rem/1 var(--mono); }
.num-help { font-size: 0.875rem; color: var(--ink-soft); }
.num-help.bad { color: var(--no); font-weight: 500; }
.num.small { box-shadow: none; margin-top: 0.5rem; max-width: 15rem; }
.num.small input { font-size: 1.0625rem; padding: 0.6rem 0.75rem; }
.num.small .num-unit { font-size: 0.9375rem; padding: 0 0.75rem; }

.foot { position: sticky; bottom: 0; padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 30%); }
.feedback { position: sticky; bottom: 0; border-top: 3px solid; animation: up 0.18s ease-out; }
.feedback.good { background: var(--yes-bg); border-color: var(--yes); }
.feedback.bad { background: var(--no-bg); border-color: var(--no); }
.feedback-in { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); display: grid; gap: 0.55rem; max-height: 62dvh; overflow-y: auto; }
.feedback h2 { font-size: 1.35rem; font-weight: 700; }
.feedback.good h2 { color: var(--yes); }
.feedback.bad h2 { color: var(--no); }
.feedback .hint { font-weight: 500; }
.feedback .why { line-height: 1.75; }
.feedback .btn { margin-top: 0.4rem; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.katex { font-size: 1.08em; }

/* Result */
.result { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.8rem; padding: 2rem 1.2rem; text-align: center; }
.result-mark { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; background: var(--mark); color: #17233f; border: 3px solid var(--ink); box-shadow: 0 6px 0 var(--ink); }
.result-mark svg { width: 44px; height: 44px; fill: currentColor; stroke: none; }
.result h1 { font-size: 2.4rem; font-weight: 750; margin-top: 0.6rem; }
.result-sub { color: var(--ink-soft); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; width: 100%; margin: 1rem 0 0.4rem; }
.result-stats div { background: var(--card); border: 2px solid var(--ink); border-radius: 14px; padding: 0.8rem 0.3rem; }
.result-stats dt { font: 400 0.6875rem/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.result-stats dd { margin: 0.35rem 0 0; font: 700 1.6rem/1 var(--display); }
.result-note { color: var(--ink-soft); font-size: 0.9375rem; max-width: 24rem; }
.result .btn { margin-top: 1rem; }

/* Notes */
.notes { padding: 0.5rem 1rem 2rem; display: grid; gap: 1.1rem; }
.notes h1 { font-size: 1.9rem; font-weight: 720; }
.notes-body { background: var(--card); border: 2px solid var(--ink); border-radius: 16px; padding: 1.1rem 1.1rem; display: grid; gap: 0.9rem; }
.notes-body .f { padding: 0.7rem 0.8rem; background: var(--paper); border-left: 4px solid var(--copper); border-radius: 0 8px 8px 0; overflow-x: auto; line-height: 3; }

.lede { color: var(--ink-soft); }
.jump { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.jump button { padding: 0.5rem 0.7rem; min-height: 40px; border: 1.5px solid var(--ink); border-radius: 99px; background: var(--card); font-size: 0.8125rem; font-weight: 500; }
.formula-unit { display: grid; gap: 0.5rem; scroll-margin-top: 4.5rem; }
.formula-unit h2 { font-size: 1.3rem; }
.help .notes-body h2 { font-size: 1.1rem; margin-top: 0.5rem; }
.help .notes-body h2:first-child { margin-top: 0; }
.sheet.tall { max-height: 82dvh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.sheet .notes-body.plain { border: 0; padding: 0; background: none; }

/* Mock exam: laid out like the paper */
.exam { padding: 0.5rem 1rem 2.5rem; display: grid; gap: 1.1rem; }
.exam-head { padding: 1rem 1.1rem; background: var(--card); border: 2px solid var(--ink); border-radius: 16px; display: grid; gap: 0.4rem; }
.exam-head h1 { font-size: 1.7rem; font-weight: 720; }
.exam-head p { font-size: 0.875rem; color: var(--ink-soft); }
.exam-head.pass { background: var(--yes-bg); border-color: var(--yes); }
.exam-head.fail { background: var(--no-bg); border-color: var(--no); }
.exam-head.pass h1, .exam-head.fail h1 { font-size: 2.6rem; }
.ex { background: var(--card); border: 2px solid var(--ink); border-radius: 16px; padding: 1rem 1.1rem; display: grid; gap: 0.75rem; }
.ex h2 { font-size: 1.15rem; display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.ex h2 span { font: 400 0.8125rem/1 var(--mono); color: var(--ink-soft); white-space: nowrap; }
.ex ol { margin: 0; padding-left: 1.3rem; display: grid; gap: 0.9rem; }
.ex li.right::marker { color: var(--yes); }
.ex li.wrong::marker { color: var(--no); }
.ex-sol { margin-top: 0.45rem; padding: 0.5rem 0.65rem; border-radius: 8px; font-size: 0.9375rem; line-height: 1.7; background: var(--paper); }
li.right > .ex-sol { background: var(--yes-bg); }
li.wrong > .ex-sol { background: var(--no-bg); }
.seg { display: inline-flex; margin-top: 0.45rem; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; }
.ex-tf li > span:first-child { display: block; }
.seg button { border: 0; background: var(--card); padding: 0.45rem 0.9rem; font-weight: 500; min-height: 40px; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button.picked { background: var(--mark); color: #17233f; }
.clock { font-size: 0.9375rem; color: var(--ink-soft); padding-right: 0.4rem; }

@media (min-width: 40rem) {
  .node-label { width: 12.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
