/* ---------- Palette ---------- */
:root {
  --paper: #FFFDF8;
  --ink: #1B1A22;
  --proton: #FF3131;
  --electron: #0B44A8;
  --frame: #8B5CF6;
  --tap: #F5A524; /* reserved: "you can tap this" and nothing else */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 1.125rem;
}

/* ---------- Frame ---------- */
.frame {
  position: fixed;
  inset: 6px;
  z-index: 30;
  border: 3px solid var(--frame);
  border-radius: 4px;
  pointer-events: none;
}

/* ---------- Cover ---------- */
.cover {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 24px;
  text-align: center;
}
.cover-title {
  font-family: "Fredoka", sans-serif;
  font-weight: 400;
  font-size: clamp(3rem, 10vw, 6rem);
  margin: 0;
}
.cover-sub { margin: 0 0 1.5rem; font-style: italic; }
.open-btn {
  font: 500 1.3rem "Fredoka", sans-serif;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 2.2rem;
  cursor: pointer;
}
.open-btn:hover { background: #33313f; }
.about-link {
  margin-top: 0.5rem;
  background: none;
  border: 0;
  font: italic 0.9rem "Nunito", sans-serif;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Page ---------- */
.page {
  min-height: 100vh;
  padding: 2.5rem 24px 6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  font-family: "Fredoka", sans-serif;
  font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 4rem);
  margin: 0 0 1.2rem;
  text-align: center;
}

/* ---------- Rule with square end-caps ---------- */
.rule {
  width: 100%;
  height: 12px;
  display: flex;
  align-items: center;
}
.rule .line {
  flex: 1;
  height: 3px;
  background: var(--ink);
  transform-origin: center;
}
.rule .cap { width: 12px; height: 12px; background: var(--ink); flex: none; }

/* ---------- Captions (both pages share one grid cell) ---------- */
.captions {
  margin-top: 1.6rem;
  display: grid;
  justify-items: center;
  width: 100%;
}
.caption {
  grid-area: 1 / 1;
  margin: 0;
  max-width: 42ch;
  text-align: center;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
}
.caption[aria-hidden="true"] { pointer-events: none; }
.caption p { margin: 0 0 0.5rem; }
.footnote { font-style: italic; font-size: 0.95em; }

/* ---------- Scene ---------- */
.scene {
  width: min(100%, 900px);
  height: auto;
  max-height: 52vh;
  margin-top: 1rem;
  overflow: hidden;
}

.orbit { fill: none; stroke: var(--ink); stroke-opacity: 0.18; stroke-width: 2; stroke-dasharray: 2 9; stroke-linecap: round; }
.proton { fill: var(--proton); }
.electron { fill: var(--electron); }

/* Tap-gold ring + invisible hit area over the atom */
.tap-ring { fill: none; stroke: var(--tap); stroke-width: 3; pointer-events: none; }
.hit { fill: transparent; cursor: pointer; }
.hit:focus { outline: none; }
.hit:focus-visible { stroke: var(--frame); stroke-width: 3; stroke-dasharray: 8 8; }
.nucleon-label { font: 500 15px "Fredoka", sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.nuc-sym { font: 500 22px "Fredoka", sans-serif; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.atom-name { font: 500 26px "Fredoka", sans-serif; fill: var(--ink); text-anchor: middle; }
.atom-sub { font: italic 400 18px "Nunito", sans-serif; fill: var(--ink); text-anchor: middle; }
.cloud-dot { fill: var(--electron); }
.cloud-blink { fill: var(--electron); }
.cloud-arrow line { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.cloud-arrow polygon { fill: var(--ink); }
.arrow-label { font: 500 22px "Fredoka", sans-serif; fill: var(--ink); }

.pointer-label { font: 500 30px "Fredoka", sans-serif; fill: var(--ink); }
.pointer-line { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.pointer-head { fill: var(--ink); }

/* ---------- Legend (bottom-left, out of the way of the scenes) ---------- */
.legend {
  position: fixed;
  left: 28px;
  bottom: 24px;
  margin: 0;
  font-style: italic;
  font-size: 0.95rem;
  display: flex;
  gap: 1.2rem;
  align-items: center;
}
.dot { display: inline-block; border-radius: 50%; margin-right: 0.4rem; vertical-align: middle; }
.dot-p { width: 14px; height: 14px; background: var(--proton); }
.dot-n { width: 14px; height: 14px; background: #B8BEC6; margin-left: 0.6rem; }
.dot-e { width: 7px; height: 7px; background: var(--electron); margin-left: 0.6rem; }

/* ---------- Buttons ---------- */
.mute, .nav-btn {
  font: 600 0.9rem "Nunito", sans-serif;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
}
.mute { position: fixed; top: 18px; right: 22px; z-index: 40; font-size: 0.85rem; }
.nav { position: fixed; right: 26px; bottom: 20px; z-index: 10; display: flex; gap: 0.6rem; }
.nav-btn { font-size: 1.05rem; padding: 0.5rem 1.3rem; }
.nav-btn:disabled { opacity: 0.4; cursor: default; }

button:focus-visible { outline: 3px solid var(--frame); outline-offset: 3px; }

/* Tap-gold glow: only ever used to say "tap me" */
.nav-btn.attn {
  border-color: var(--tap);
  box-shadow: 0 0 0 4px rgba(245, 165, 36, 0.35);
  animation: glow 1.4s ease-in-out infinite;
}
@keyframes glow {
  50% { box-shadow: 0 0 0 9px rgba(245, 165, 36, 0.12); }
}

/* ---------- Top bar (contents + page counter) ---------- */
.topbar { position: fixed; top: 18px; left: 22px; z-index: 40; display: flex; align-items: center; gap: 0.8rem; }
.topbar .mute { position: static; }
.counter { font: 600 0.85rem "Nunito", sans-serif; }

/* ---------- Contents page ---------- */
.contents { position: fixed; inset: 0; z-index: 35; background: var(--paper); overflow-y: auto; padding: 5rem 24px 3rem; }
.contents-inner { max-width: 640px; margin: 0 auto; }
.contents h2 { font: 400 2.4rem "Fredoka", sans-serif; margin: 0 0 1.5rem; }
.contents h3 { font: 500 1.05rem "Fredoka", sans-serif; margin: 1.6rem 0 0.4rem; color: var(--frame); }
.contents ul { list-style: none; margin: 0; padding: 0; }
.contents li { margin: 0.15rem 0; }
.toc-item { font: 600 1.05rem "Nunito", sans-serif; color: var(--ink); background: none; border: 0; padding: 0.3rem 0; cursor: pointer; text-align: left; }
.toc-item:hover { text-decoration: underline; }
.toc-soon { color: #8a8790; font-size: 1rem; padding: 0.3rem 0; }
.toc-soon span { font-style: italic; font-size: 0.85rem; }
.contents .toc-code { font: 600 0.75rem "Nunito", sans-serif; color: #6b6875; margin-left: 0.6rem; }

/* Pointer into the IB data booklet, under a caption */
.booklet {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.35rem 0.75rem;
  border-left: 3px solid var(--frame);
  border-radius: 4px;
  background: rgba(139, 92, 246, 0.07);
  font-size: 0.82em;
  text-align: left;
}
.booklet span { font: 500 0.95em "Fredoka", sans-serif; margin-right: 0.35rem; }

/* ---------- Sound lab ---------- */
.lab-link {
  position: fixed;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 10;
  background: none;
  border: 0;
  font: italic 0.75rem "Nunito", sans-serif;
  color: #777;
  text-decoration: underline;
  cursor: pointer;
}
.lab {
  position: fixed;
  right: 22px;
  top: 60px;
  bottom: 20px;
  width: min(360px, calc(100vw - 44px));
  z-index: 50;
  overflow-y: auto;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 1rem 1.2rem;
  font-size: 0.9rem;
}
.lab h2 { font: 500 1.4rem "Fredoka", sans-serif; margin: 0 0 0.5rem; }
.lab fieldset { min-width: 0; border: 1px solid #ccc; border-radius: 8px; margin: 0 0 0.8rem; }
.lab legend { font-weight: 600; padding: 0 0.4rem; }
.lab label { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr) 3rem; align-items: center; gap: 0.5rem; margin: 0.2rem 0; }
.lab input[type=range] { width: 100%; min-width: 0; }
.lab-play { font-size: 0.85rem; padding: 0.2rem 0.9rem; margin-bottom: 0.3rem; }
.lab textarea { width: 100%; font: 0.8rem monospace; margin-bottom: 0.6rem; }
.lab-note { margin: 0.3rem 0; font-style: italic; }

/* ---------- Intro starting state (only when JS is running) ---------- */
.js .fade { opacity: 0; }
.js .rule .line { transform: scaleX(0); }
.js .rule .cap { opacity: 0; }

@media (max-width: 600px) {
  .legend { position: static; margin-top: 0.5rem; }
  .page { padding-bottom: 7rem; }
}

/* ---------- Shared bits for pages 5 onward ---------- */
.particle { fill: var(--ion, #4C6E9E); }
:root { --ion: #4C6E9E; --heat: #E05A2B; --product: #2E9E63; --pos-ion: var(--proton); --neg-ion: var(--electron); }
.molecule-label { font: 500 20px "Fredoka", sans-serif; fill: var(--ink); text-anchor: middle; }
.axis-line { stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; fill: none; }
.energy-curve { stroke: var(--ink); stroke-width: 3; fill: none; stroke-linecap: round; }
.energy-fill { fill: var(--heat); opacity: 0.18; }
.spectrum-strip { fill: #14121b; }
.spectrum-line { stroke-width: 5; }
.mass-bar { fill: var(--electron); }
.mass-axis-label, .graph-label { font: 500 15px "Fredoka", sans-serif; fill: var(--ink); text-anchor: middle; }
.wire { stroke: var(--ink); stroke-width: 4; fill: none; stroke-linecap: round; }
.h-plus { fill: #fff; stroke: var(--ink); stroke-width: 2; }
.h-plus-label { font: 700 13px "Fredoka", sans-serif; fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.flow-arrow { fill: var(--tap); }
.ball { fill: #8B8590; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .nav-btn.attn { animation: none; outline: 3px solid var(--tap); outline-offset: 3px; }
}

/* ---------- Study tools: Check yourself, glossary, data booklet, contents search ---------- */
.study-panel { z-index: 36; }
.sp-sub { color: #5d5a66; font-size: 0.95rem; margin: 0.3rem 0 0.8rem; }
.sp-search { width: 100%; box-sizing: border-box; font: 400 1rem "Nunito", sans-serif; padding: 0.55rem 0.9rem; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); color: var(--ink); margin: 0.2rem 0 0.6rem; }
.sp-link { font: 600 0.9rem "Nunito", sans-serif; color: var(--frame); background: none; border: 0; padding: 0.15rem 0; margin-right: 1rem; cursor: pointer; text-decoration: underline; text-align: left; }
.sp-close { margin-top: 2rem; }
.toc-tools { margin: 0 0 1.2rem; }
.toc-buttons { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0.3rem 0; }
.toc-mark { display: inline-block; width: 1.3rem; font-size: 0.8rem; color: var(--frame); }
.toc-mark.right { color: #2E9E63; font-weight: 700; }
.bk-link { font: inherit; color: var(--frame); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.gl-list dt { font: 500 1.1rem "Fredoka", sans-serif; margin-top: 1rem; }
.gl-list dd { margin: 0.15rem 0 0; }
.gl-links { margin-top: 0.2rem; }
.bk-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.bk-chip { font: 600 0.9rem "Nunito", sans-serif; padding: 0.3rem 0.7rem; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); color: var(--ink); cursor: pointer; }
.bk-chip.active { background: var(--ink); color: var(--paper); }
.bk-chip.missing { opacity: 0.45; }
.bk-view h3 { font: 500 1.25rem "Fredoka", sans-serif; margin: 0.5rem 0; color: var(--ink); }
.bk-scroll { overflow-x: auto; }
.bk-table { border-collapse: collapse; font-size: 0.92rem; width: 100%; }
.bk-table th, .bk-table td { padding: 0.25rem 0.6rem; text-align: left; border-bottom: 1px solid rgba(0,0,0,0.12); }
.bk-table th { font: 500 0.85rem "Fredoka", sans-serif; color: var(--frame); }
.bk-list dt { font-weight: 600; margin-top: 0.7rem; }
.bk-list dd { margin: 0.1rem 0 0; }
.quiz-q { font: 500 1.3rem "Fredoka", sans-serif; margin: 0.4rem 0 1rem; }
.quiz-opts { display: grid; gap: 0.6rem; }
.quiz-opt { display: flex; gap: 0.8rem; align-items: flex-start; text-align: left; font: 400 1.05rem "Nunito", sans-serif; padding: 0.7rem 1rem; border: 2px solid var(--ink); border-radius: 16px; background: var(--paper); color: var(--ink); cursor: pointer; }
.quiz-opt:not(:disabled):hover { background: rgba(139, 92, 246, 0.08); }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.right { border-color: #2E9E63; background: rgba(46, 158, 99, 0.14); }
.quiz-opt.wrong { border-color: #FF3131; background: rgba(255, 49, 49, 0.1); }
.quiz-letter { font: 500 1rem "Fredoka", sans-serif; min-width: 1.4rem; }
.quiz-feedback { margin-top: 1rem; }
.quiz-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.8rem; }

/* ---------- Draggable controls on "now you try" steps ---------- */
.sl { cursor: pointer; outline: none; }
.sl-track { stroke: #cfcad6; stroke-width: 8; stroke-linecap: round; }
.sl-fill { stroke: var(--frame); stroke-width: 8; stroke-linecap: round; }
.sl-knob { fill: #fff; stroke: var(--ink); stroke-width: 3; }
.sl:focus-visible .sl-knob { stroke: var(--tap); stroke-width: 5; }
.dragger { cursor: grab; touch-action: none; }
.dragger:active { cursor: grabbing; }
.chip { cursor: pointer; outline: none; }
.chip:focus-visible rect.chip-bg { stroke: var(--tap); stroke-width: 5; }
.tray { outline: none; }
.tray:focus-visible circle { stroke: var(--tap); stroke-width: 5; }
