/* ─── Beat transitions ───────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
}

/* ─── Beat 1: Intro story ──────────────────────────────── */
#intro-beat {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 56px);
  padding: 2.5rem clamp(1.5rem, 5vw, 4rem);
  overflow-y: auto;
}

#story-container {
  max-width: 600px;
  width: 100%;
}

/* Story lines — fade + rise in one by one */
.story-line {
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: clamp(0.95rem, 1.45vw, 1.08rem);
  font-weight: 600;
  line-height: 1.8;
  color: rgba(255, 255, 255, 0.88);
  margin-bottom: 0.55em;
  opacity: 0;
  transform: translateY(7px);
  transition: opacity 0.65s ease, transform 0.65s ease;
}
.story-line.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Invisible spacer — whitespace only, no animation, no timing slot */
.story-line--pause {
  min-height: 0.85em;
  margin-bottom: 0;
  pointer-events: none;
  opacity: 1;
  transform: none;
  transition: none;
}

/* Underlined emphasis within story lines */
.story-u {
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
  text-decoration-color: rgba(255, 255, 255, 0.65);
}

/* The beam line — slightly brighter and given more breathing room above */
.story-line--beam {
  color: rgba(255, 255, 255, 0.96);
  font-weight: 700;
}

/* Big drop-cap "3" — opening of a chapter */
.story-dropcap {
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 4.2rem;
  font-weight: 900;
  line-height: 0.82;
  float: left;
  margin-right: 0.07em;
  margin-top: 0.05em;
  color: #7c3aed;
  text-shadow: 0 0 30px rgba(124, 58, 237, 0.35);
}

/* CTA container — always visible, just a centred flex wrapper */
#intro-bottom {
  margin-top: 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

/* Start button animates in at the end of the story sequence */
#startBtn {
  opacity: 0;
  transform: translateY(7px);
  transition: opacity 0.65s ease, transform 0.65s ease;
}
#startBtn.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Skip button — lives at the bottom alongside the start button */
#skipBtn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.75rem;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.04em;
  padding: 8px 18px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, background 0.2s ease, color 0.2s ease;
}

/* Fade in 1.5 s after beat 1 starts */
body[data-beat="1"] #skipBtn {
  opacity: 1;
  pointer-events: auto;
  transition-delay: 1.5s;
}

/* Hide skip once the start button is revealed — they'd be redundant together */
body[data-beat="1"]:has(#startBtn.visible) #skipBtn {
  opacity: 0;
  pointer-events: none;
  transition-delay: 0s;
}

#skipBtn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.85);
}

@media print { #skipBtn { display: none !important; } }

/* Hide diamond on small screens — just show start button */
@media (max-width: 780px) {
  #intro-top, #intro-middle { display: none !important; }
  #intro-bottom { margin: auto; }
}

#startBtn {
  padding: 16px 48px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: 'Nunito', system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.45);
  letter-spacing: 0.04em;
}

#startBtn:hover {
  background: #6d28d9;
  box-shadow: 0 12px 40px rgba(124, 58, 237, 0.55);
  transform: translateY(-2px);
}

#startBtn:active {
  transform: translateY(0);
  background: #5b21b6;
}

/* ─── Beat-state panel visibility ───────────────────────────────────
   body[data-beat] + .has-picked + .worksheet-visible are set by ui.js.
   All panels start invisible (opacity 0, nudged right) and slide into
   place when their beat condition is met — matching the main site's
   smooth act-transition pattern.
──────────────────────────────────────────────────────────────────── */

/* Base: all panels invisible, slide-ready */
.skill-counter,
.hint-card,
.floating-action-buttons {
  opacity: 0;
  transform: translateX(10px);
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

/* Beat 2 — Hint 1 (Plan / skill counter) always slides in */
body[data-beat="2"] .skill-counter {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

/* Beat 2 + at least one skill picked — Generate box slides in */
body[data-beat="2"].has-picked .floating-action-buttons {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  transition-delay: 0.16s;
}

/* Beat 3 + worksheet revealed — Print and Repeat slide in */
body[data-beat="3"].worksheet-visible #hint-4 {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

body[data-beat="3"].worksheet-visible #hint-5 {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  transition-delay: 0.12s;
}

/* ─── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: #051525;  /* dark ocean fallback before Three.js renders */
  color: #222;
  padding-top: 56px;
}

/* ─── Fixed site header ──────────────────────────────────────────── */
#site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid #e0e4f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

#site-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#site-logo {
  height: 32px;
  width: auto;
}

#site-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #7c3aed;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#site-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: #888;
}

@media print {
  #site-header { display: none !important; }
}

/* ─── Controls Panel ────────────────────────────────────────────── */
.controls {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 20px 32px;
}

.controls h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: #7c3aed;
  text-align: center;
}

/* ─── Form sections ─────────────────────────────────────────────── */
.form-section {
  background: #faf6ee;
  border: 1px solid #e2d9c5;
  border-left: 4px solid #7c3aed;
  border-radius: 8px;
  padding: 11px 14px;
  margin-bottom: 10px;
}

.form-section h2 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7c3aed;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

/* ─── Accordion ──────────────────────────────────────────────────── */
.form-section.collapsed > h2 {
  margin-bottom: 0;
}

.form-section.collapsed > :not(h2) {
  display: none;
}

.accordion-chevron {
  margin-left: 5px;
  display: inline-block;
  transition: transform 0.2s ease;
  opacity: 0.55;
  text-transform: none;
  letter-spacing: normal;
  font-size: 1.15em;
  line-height: 1;
  vertical-align: middle;
}

.form-section.collapsed .accordion-chevron {
  transform: rotate(-90deg);
}

.skip-all-btn {
  font-size: 0.7rem;
  padding: 4px 10px;
  background: #e0e0e0;
  color: #555;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  transition: all 0.2s;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.skip-all-btn.active {
  opacity: 1;
  pointer-events: auto;
}

.skip-all-btn:hover {
  background: #d3d3d3;
}


/* ─── Student name ──────────────────────────────────────────────── */
.name-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.name-row label {
  font-weight: 500;
  white-space: nowrap;
}

.name-row input[type="text"] {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.name-row input[type="text"]:focus {
  border-color: #7c3aed;
}

/* ─── Skill rows ─────────────────────────────────────────────────── */
.skill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid #ede4d0;
  gap: 8px;
}

.skill-row:last-child { border-bottom: none; }

.skill-label {
  flex: 1;
  font-size: 0.92rem;
  line-height: 1.3;
}

.multiply-icon {
  display: inline-block;
  transform: rotate(45deg);
}

/* ─── Toggle button groups ───────────────────────────────────────── */
.toggle-group {
  display: flex;
  border: 1px solid #d4c8b0;
  border-radius: 5px;
  flex-shrink: 0;
}

.toggle-group button {
  border: none;
  background: #fdf9f2;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  border-right: 1px solid #d4c8b0;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  line-height: 1.2;
}

.toggle-group button:first-child { border-radius: 4px 0 0 4px; }
.toggle-group button:last-child  { border-right: none; border-radius: 0 4px 4px 0; }

.toggle-group button[data-hint] { position: relative; overflow: visible; }

.toggle-group button[data-hint]::after {
  content: attr(data-hint);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 30, 10, 0.82);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 400;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 20;
}

.toggle-group button[data-hint]:hover::after { opacity: 1; }

.toggle-group button:hover { background: #f3ead8; }

/* State: Mastered */
.toggle-group button.active-mastered {
  background: #d4edda;
  color: #1a5c2a;
  font-weight: 600;
}

/* State: Practicing */
.toggle-group button.active-practicing {
  background: #fff3cd;
  color: #7a5000;
  font-weight: 600;
}

/* State: Not yet */
.toggle-group button.active-notyet {
  background: #f8d7da;
  color: #721c24;
  font-weight: 600;
}

/* State: Skip */
.toggle-group button.active-skip {
  background: #e0e0e0;
  color: #555;
  font-weight: 600;
}

/* ─── In-development section ────────────────────────────────────── */
.form-section--dev {
  border-style: dashed;
  border-color: #ccc;
  background: #fafafa;
}

.dev-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: #7a5000;
  background: #fff3cd;
  border: 1px solid #f0d080;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 6px;
  text-transform: none;
  letter-spacing: 0;
}

.dev-note {
  font-size: 0.78rem;
  color: #888;
  font-style: italic;
  margin-top: 10px;
}

/* ─── Word problem toggle ───────────────────────────────────────── */
.toggle-group button.active-wp-mcas {
  background: #e8f0fb;
  color: #1a3a6b;
  font-weight: 600;
}

.toggle-group button.active-wp-plain {
  background: #e8f8e8;
  color: #1a5c2a;
  font-weight: 600;
}

/* ─── Arithmetic format toggle (purple/gray styling) ────────────── */
#arithmeticFormatToggle button.active-mastered {
  background: #e6d9f5;
  color: #5a3d7a;
  font-weight: 600;
}

#arithmeticFormatToggle button:not(.active-mastered) {
  background: #f5f5f5;
  color: #888;
}

/* ─── Generate button (hidden, using floating version) ────────── */
.generate-btn {
  display: none;
}

.print-btn-wrap {
  display: none !important;
}

/* ─── Worksheet length toggle (hidden, moved to floating buttons) ── */
#worksheetLengthToggle {
  display: none !important;
}

#worksheetLengthToggle.form-section {
  display: none !important;
}

#worksheetLengthToggle.form-section,
#worksheetLengthToggle ~ div.form-section:has(#worksheetLengthToggle) {
  display: none !important;
}

/* ─── Skill Maps title ──────────────────────────────────────────── */
.skill-maps-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 10px;
}

.skill-counter {
  position: fixed;
  left: calc(50% + 400px);
  top: min(190px, 20vh);
  width: 210px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 20px;
  padding: 14px;
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 28px rgba(0, 0, 0, 0.28);
  text-align: left;
}

.skill-counter::after {
  content: '';
  position: absolute;
  right: calc(100% + 2px);
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 11px solid rgba(255, 255, 255, 0.55);
  border-left: none;
}

.skill-counter-hint {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.55;
  font-weight: 400;
  margin-bottom: 10px;
}

.skill-counter-tally {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 10px;
  padding: 8px 10px;
}

.skill-counter-tally #skillSlotsLeft {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

.skill-slots-label {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.4;
  font-weight: 400;
}

.skill-counter.full .skill-counter-tally {
  background: rgba(255, 80, 80, 0.2);
  border-color: rgba(255, 100, 100, 0.35);
}

.skill-counter.full .skill-counter-tally #skillSlotsLeft,
.skill-counter.full .skill-slots-label {
  color: #ffaaaa;
}

/* ─── Floating action buttons ──────────────────────────────────── */
.floating-action-buttons {
  position: fixed;
  left: calc(50% + 400px);
  top: min(420px, calc(100vh - 220px));
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 99;
  margin-top: 0;
  background: rgba(255, 255, 255, 0.10);
  padding: 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 28px rgba(0, 0, 0, 0.28);
}


/* Hint 3 header — instruction + number badge */
.floating-hint-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 10px;
  margin-bottom: 2px;
}

.floating-hint-header p {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.5;
  font-weight: 400;
}

.floating-action-buttons .generate-label {
  font-weight: 700;
  color: #6b4c93;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.floating-action-buttons .generate-label-text {
  display: block;
}

.floating-action-buttons .questions-per-page {
  font-weight: 400;
  font-size: 0.75rem;
  color: #888;
}

.floating-action-buttons-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.floating-action-buttons button {
  padding: 8px 12px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 10px rgba(0,0,0,0.14);
  text-align: center;
  line-height: 1.3;
}

.floating-action-buttons-row button {
  flex: 1;
  min-width: 0;
}

#floatingPrintBtn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  box-shadow: 0 2px 10px rgba(0,0,0,0.14);
}

#floatingPrintBtn:hover:not(:disabled) {
  background: #6d28d9;
}

#floatingPrintBtn:disabled {
  background: #c084fc;
}

.floating-action-buttons button:hover:not(:disabled) {
  background: #6d28d9;
}

.floating-action-buttons button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #6b8fbe;
}

@media print {
  .skill-counter { display: none !important; }
  .floating-action-buttons { display: none !important; }
}

/* ─── Fixed hint cards — liquid glass ───────────────────────────── */
.hint-card {
  position: fixed;
  width: 165px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 20px;
  padding: 14px;
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 6px 28px rgba(0, 0, 0, 0.28);
}

/* Left-side cards: arrow → */
.hint-card::after {
  content: '';
  position: absolute;
  left: calc(100% + 2px);
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 11px solid rgba(255, 255, 255, 0.55);
}

/* Right-side cards: arrow ← */
.hint-card--right::after {
  left: auto;
  right: calc(100% + 2px);
  border-left: none;
  border-right: 11px solid rgba(255, 255, 255, 0.55);
}

/* Individual positions */
#hint-4 {
  left: calc(50% + 400px);
  top: 40%;
}

#hint-5 {
  left: calc(50% + 400px);
  top: calc(40% + 200px);
}

.hint-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.hint-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.95);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hint-number {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  font-weight: 900;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.hint-header-row .hint-number {
  margin-bottom: 0;
}

.hint-card p {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.55;
  font-weight: 400;
}

@media (max-width: 900px) {
  .hint-card { display: none !important; }
}

@media print {
  .hint-card { display: none !important; }
}

/* ─── Skills section title ───────────────────────────────────────── */
.skills-section-title {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fff;
  background: #7c3aed;
  padding: 10px 18px;
  border-radius: 8px;
  margin: 20px 0 12px;
}

/* ─── Helper key ─────────────────────────────────────────────────── */
.helper-key {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 14px;
  line-height: 1.8;
}

.helper-key strong { color: #444; }

.helper-key .key-item {
  display: inline-block;
}

/* ─── Print button ───────────────────────────────────────────────── */
.print-btn-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 16px;
  display: none;
}

.print-btn {
  padding: 9px 22px;
  background: #2c5fa8;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.print-btn:hover { background: #1e4a8a; }

/* ─── Rainbow arch — appears after worksheet reveal ─────────────── */
#gen-rainbow {
  position: fixed;
  inset: 0;
  z-index: 5;           /* above ocean, below worksheet content */
  pointer-events: none;
  opacity: 0;
  /* Radial ellipse centred below-left — narrower width = steeper, more angular arch */
  background: radial-gradient(
    ellipse 155% 260% at 42% 126%,
    transparent                    22%,
    rgba(255,  70,  70, 0.9)       26%,
    rgba(255, 145,  40, 0.9)       30%,
    rgba(255, 225,  45, 0.9)       34%,
    rgba( 45, 195,  75, 0.9)       38%,
    rgba( 45,  95, 255, 0.9)       42%,
    rgba( 95,  25, 195, 0.9)       46%,
    rgba(155,  40, 215, 0.9)       50%,
    transparent                    56%
  );
  /* transition injected by JS */
}

@media print { #gen-rainbow { display: none !important; } }

/* ─── Generation flash overlay ──────────────────────────────────── */
#gen-flash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  /* Radial gradient so the centre burns hottest — reads as a light source */
  background: radial-gradient(ellipse at center, #ffffff 0%, #fffef5 60%, #fff8e7 100%);
  opacity: 0;
  pointer-events: none;
  /* transition injected by JS so timing matches config values */
}

/* ─── Beat 2 — Generate ─────────────────────────────────────────── */
#generate-beat {
  padding-top:    clamp(3rem, 6vh, 5rem);
  padding-bottom: clamp(3rem, 6vh, 5rem);
}

/* ─── Beat 3 — Worksheet output ─────────────────────────────────── */
#worksheet-beat {
  display: none;   /* shown by generateWorksheet() in ui.js */
  padding-top: clamp(3rem, 5vh, 4rem);
  padding-bottom: 40px;
}

/* ─── Worksheet area ─────────────────────────────────────────────── */
#worksheet {
  display: none;
  max-width: var(--config-worksheet-width, 830px);
  margin: 0 auto 40px;
  padding: 32px 40px;
  background: #fff;
  border: 1px solid #ddd;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-family: Georgia, 'Times New Roman', serif;
}

/* ─── Worksheet header ──────────────────────────────────────────── */
.ws-header {
  border-bottom: 2px solid #222;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.ws-name {
  font-size: 1.6rem;
  font-weight: bold;
  letter-spacing: 0.01em;
}

.ws-meta {
  display: flex;
  gap: 24px;
  font-size: 0.95rem;
  align-items: baseline;
}

.ws-meta span { white-space: nowrap; }

.ws-meta .blank-line {
  display: inline-block;
  border-bottom: 1px solid #333;
  width: 120px;
  vertical-align: bottom;
  margin-left: 4px;
}

.ws-subheader {
  font-style: italic;
  font-size: 0.88rem;
  color: #444;
  margin: 10px 0 16px;
  padding: 7px 10px;
  border-left: 3px solid #bbb;
  background: #fafafa;
}

/* ─── Section headers ────────────────────────────────────────────── */
.ws-section-header {
  font-size: 0.95rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 18px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid #aaa;
  color: #333;
}

/* ─── Question blocks ────────────────────────────────────────────── */
.questions-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px 24px;
}

.question-block {
  page-break-inside: avoid;
  break-inside: avoid;
  padding: 8px 0;
}

.question-block.has-visual {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: flex-start;
}

.question-line {
  font-size: 0.97rem;
  line-height: var(--config-line-spacing, 1.5);
  margin-bottom: 6px;
}

.question-number {
  font-weight: bold;
  font-size: 0.95rem;
  color: #222;
  margin-right: 3px;
}

/* Answer area for visual questions */
.answer-area-large {
  border: 1px dashed #bbb;
  border-radius: 4px;
  min-height: 48px;
  margin-top: 8px;
  flex: 1;
}

.visual-wrap {
  flex-shrink: 0;
  transform: translateY(var(--config-y-adjustment, 0px));
}

.visual-bar-empty {
  transform: translateY(calc(var(--config-offset-bar-empty, 0px) + var(--config-y-adjustment, 0px))) scale(var(--config-scale-bar-empty, 1.0));
  transform-origin: top left;
  margin-bottom: calc((1 - var(--config-scale-bar-empty, 1.0)) * calc(var(--config-base-height-bar-empty, 40px) * -1));
}

.visual-bar-filled {
  transform: translateY(calc(var(--config-offset-bar-filled, 0px) + var(--config-y-adjustment, 0px))) scale(var(--config-scale-bar-filled, 1.0));
  transform-origin: top left;
  margin-bottom: calc((1 - var(--config-scale-bar-filled, 1.0)) * calc(var(--config-base-height-bar-filled, 40px) * -1));
}

.visual-line {
  transform: translateY(calc(var(--config-offset-line, 0px) + var(--config-y-adjustment, 0px))) scale(var(--config-scale-line, 1.0));
  transform-origin: top left;
  margin-bottom: calc((1 - var(--config-scale-line, 1.0)) * calc(var(--config-base-height-line, 40px) * -1));
}

.visual-pie {
  transform: translateY(calc(var(--config-offset-pie, 0px) + var(--config-y-adjustment, 0px))) scale(var(--config-scale-pie, 1.0));
  transform-origin: top left;
  margin-bottom: calc((1 - var(--config-scale-pie, 1.0)) * calc(var(--config-base-height-pie, 40px) * -1) + var(--config-extra-margin-pie, 0px));
}

.visual-geo {
  transform: translateY(calc(var(--config-offset-geo, 0px) + var(--config-y-adjustment, 0px))) scale(var(--config-scale-geo, 1.0));
  transform-origin: top left;
  margin-bottom: calc((1 - var(--config-scale-geo, 1.0)) * calc(var(--config-base-height-geo, 120px) * -1) + var(--config-extra-margin-geo, 0px));
}

/* ─── KaTeX inline adjustments ───────────────────────────────────── */
.katex { font-size: 1em !important; }

/* ─── Stacked arithmetic notation ──────────────────────────────────── */
.stacked-arithmetic {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  font-family: monospace;
  font-size: 0.95em;
  margin: 4px 8px;
}
.stacked-arithmetic-stack {
  display: inline-block;
  text-align: right;
  line-height: 1.4;
}
.stacked-arithmetic .line { display: block; }
.stacked-arithmetic .operator { display: inline-block; width: 20px; text-align: center; }
.stacked-arithmetic .divider { border-top: 1px solid #222; display: block; margin-top: 2px; }
.stacked-arithmetic .answer { font-size: 0.9em; color: #666; min-width: 50px; }

/* ─── Page break marker ───────────────────────────────────────────── */
.page-break-marker {
  text-align: center;
  color: #ccc;
  font-size: 0.85rem;
  margin: 20px 0;
  padding: 8px 0;
  border-top: 1px dashed #ddd;
  border-bottom: 1px dashed #ddd;
}

/* ─── Word Problem Decoder — vocab matching exercise ────────────── */
.vocab-match-block {
  grid-column: 1 / -1;
  padding: 3px 0;
}

.vocab-match-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.8rem;
  line-height: 1.1;
}

.vocab-term {
  text-align: right;
  font-weight: 600;
  padding: 0 6px 0 0;
  width: 26%;
  white-space: nowrap;
}

.vocab-dot {
  text-align: center;
  font-size: 1rem;
  padding: 3px 2px;
  width: 10px;
  color: #222;
}

.vocab-gap {
  width: 18%;
}

.vocab-def {
  text-align: left;
  padding: 0 0 0 6px;
  width: 42%;
}

/* ─── Print styles ───────────────────────────────────────────────── */
@media print {
  body { background: #fff; font-size: var(--config-question-font, 11pt); padding-top: 0; }

  #intro-beat { display: none !important; }
  #generate-beat { display: none !important; }
  .controls { display: none !important; }
  .print-btn-wrap { display: none !important; }
  #worksheet-beat { padding-top: 0 !important; padding-bottom: 0 !important; }

  /* Ensure the print-button wrap never bleeds into the printout */
  #printBtnWrap { display: none !important; }
  #gen-flash, #gen-rainbow { display: none !important; }
  .skill-counter, .floating-action-buttons { display: none !important; }

  #worksheet {
    display: block !important;
    max-width: 100%;
    margin: 0;
    padding: 4px 18px 12px;
    border: none;
    box-shadow: none;
  }

  .ws-header { margin-bottom: 6px; }
  .ws-subheader { margin-bottom: 8px; font-size: 0.9rem; }
  .ws-name { font-size: 1.2rem; }
  .ws-section-header { margin-top: 6px; margin-bottom: 4px; }

  .questions-grid {
    grid-template-columns: 1fr;
    gap: 4px 16px;
  }

  .question-block {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 2px;
  }

  .page-divider {
    display: none !important;
  }

  .page-break-marker {
    height: 0;
    overflow: hidden;
    visibility: hidden;
    page-break-after: always;
  }
}

@page {
  margin: var(--config-margin-top, 1cm) var(--config-margin-right, 1.2cm) var(--config-margin-bottom, 1cm) var(--config-margin-left, 1.2cm);
}

/* ══════════════════════════════════════════════════════════════════
   MOBILE  (≤ 768px)
   Desktop layout is entirely untouched — these rules only apply on
   small screens. The main change: the fixed-position sidebar panels
   (skill counter, generate buttons) become inline flex children
   ordered above/below the controls panel.
══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ─── Header ─────────────────────────────────────────────────── */
  /* Hide the subtitle — logo + "LIGHTNING SHEETS" is enough room  */
  #site-title { display: none; }

  /* ─── Beat 1: Story ──────────────────────────────────────────── */
  /* Shrink drop-cap so it doesn't crowd the first line on phones  */
  .story-dropcap { font-size: 3rem; }

  /* ─── Beat 2: Controls — flex column so we can reorder children  */
  #generate-beat {
    display: flex;
    flex-direction: column;
  }

  .controls { order: 0; }

  /* Skill counter: pull out of fixed positioning → top of beat 2  */
  .skill-counter {
    position: static;
    order: -1;                  /* floats above the controls panel */
    width: auto;
    margin: 16px 20px 0;
    transform: translateY(5px); /* fade-up instead of slide-in-from-right */
  }

  /* Body[data-beat] reveal — match translateY so transition works  */
  body[data-beat="2"] .skill-counter {
    transform: translateY(0);
  }

  /* Remove the pointing arrow (meaningless when inline)            */
  .skill-counter::after { display: none; }

  /* Generate buttons: pull out of fixed positioning → below skills */
  .floating-action-buttons {
    position: static;
    order: 1;                   /* sits below the controls panel   */
    width: auto;
    margin: 0 20px 24px;
    transform: translateY(5px);
  }

  body[data-beat="2"].has-picked .floating-action-buttons {
    transform: translateY(0);
  }

  /* ─── Skill rows: stack label above toggle buttons ───────────── */
  /* On phone widths the 4-button toggle won't fit beside the label */
  .skill-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 0;
  }

  /* Larger tap targets                                             */
  .toggle-group button {
    padding: 9px 12px;
    font-size: 0.82rem;
  }

  /* Slightly tighter card padding                                  */
  .form-section { padding: 14px 14px; }

  /* ─── Beat 3: Print button ───────────────────────────────────── */
  /* Hint cards are hidden ≤ 900px — expose the inline print button */
  body[data-beat="3"].worksheet-visible .print-btn-wrap {
    display: block !important;
  }

  /* Reduce side padding so worksheet doesn't squeeze on phones    */
  #worksheet { padding: 20px 16px; }
}

/* ─── Very small phones (≤ 480px) ───────────────────────────────── */
@media (max-width: 480px) {

  /* Story: bump the clamp minimum up for tiny screens             */
  .story-line {
    font-size: clamp(1rem, 4vw, 1.08rem);
    line-height: 1.7;
  }

  .story-dropcap { font-size: 2.6rem; }

  /* Header: tighter side padding                                  */
  #site-header { padding: 0 14px; }

  /* Controls: tighter margins                                     */
  .controls       { padding: 16px 12px 24px; }
  .skill-counter  { margin: 12px 12px 0; }
  .floating-action-buttons { margin: 0 12px 20px; }

  /* Toggle buttons: tighter on very narrow screens               */
  .toggle-group button {
    padding: 9px 8px;
    font-size: 0.78rem;
  }
}


/* ─── Page footer (teaser + feedback) — inside #worksheet-beat ─── */

#ls-page-footer {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 2.5rem 1rem 2rem;
  text-align: center;
}

#ls-coming-soon {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(221, 228, 236, 0.55);
  margin: 0;
}

.ls-feedback-link {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: rgba(230, 235, 240, 0.35);
  text-decoration: none;
  transition: color 0.2s ease;
}

.ls-feedback-link:hover {
  color: rgba(180, 215, 255, 0.80);
}

#ls-page-footer.revealed {
  display: flex;
}

/* ─── Word Problem Decoder — distinct section heading colour ─── */
.form-section:has([data-section="vocab-decoder"]) h2 span {
  color: #3a44cd;
}

@media print {
  #ls-page-footer { display: none !important; }
}
