:root {
  --paper: #f5eedc;
  --paper-deep: #ede1c4;
  --paper-shadow: rgba(90, 60, 30, 0.08);
  --ink: #2b241a;
  --ink-soft: #4a3e2c;
  --ink-faded: #7a6b55;
  --accent: #a33b2a;         /* warm red like the gem */
  --accent-deep: #7a2b1f;
  --forest: #4a6b3a;         /* Jeannie's forest green */
  --gold: #c89b3c;           /* the golden orb */
  --lavender: #6b5a8a;       /* dream */
  --highlight: rgba(163, 59, 42, 0.15);
  --panel-bg: #f0e4c8;
  --rule: #cbbb94;
  --serif: 'Sorts Mill Goudy', Georgia, 'Times New Roman', serif;
  --display: 'IM Fell English', 'Sorts Mill Goudy', Georgia, serif;
  --display-sc: 'IM Fell English SC', 'IM Fell English', Georgia, serif;
  --max-w: 38rem;
  --panel-w: 22rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle paper texture overlay */
.paper-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(120, 85, 40, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(140, 100, 50, 0.05) 0%, transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(100, 70, 30, 0.03) 0%, transparent 50%);
  mix-blend-mode: multiply;
}

/* Grainy noise as a pseudo-element */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0.35;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.2  0 0 0 0 0.15  0 0 0 0 0.1  0 0 0 0.15 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 200px 200px;
  mix-blend-mode: multiply;
}

/* Book container */
#book {
  position: relative;
  z-index: 3;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 4rem 2rem 12rem;
}

/* Chapter pages */
.chapter {
  display: none;
  animation: none;
}
.chapter.active {
  display: block;
  animation: pageIn 0.8s ease-out;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chapter-title {
  font-family: var(--display);
  font-style: italic;
  font-size: 2.6rem;
  line-height: 1.15;
  text-align: center;
  margin: 0 0 0.5rem;
  color: var(--ink);
  font-weight: normal;
  letter-spacing: 0.01em;
}

.chapter-number {
  font-family: var(--display-sc);
  font-size: 0.75rem;
  letter-spacing: 0.3em;
  text-align: center;
  color: var(--ink-faded);
  margin: 0 0 2.5rem;
  text-transform: lowercase;
}

.chapter-ornament {
  text-align: center;
  color: var(--ink-faded);
  font-size: 1.4rem;
  margin: 2rem 0 2.5rem;
  letter-spacing: 0.4em;
  opacity: 0.6;
}

/* Prose */
.chapter p {
  margin: 0 0 1.1rem;
  text-indent: 1.5em;
  hyphens: auto;
}
.chapter p.no-indent,
.chapter p:first-of-type {
  text-indent: 0;
}

/* Drop cap on first paragraph of each chapter */
.chapter p.dropcap::first-letter {
  font-family: var(--display);
  font-style: italic;
  font-size: 3.8rem;
  line-height: 0.85;
  float: left;
  margin: 0.35rem 0.4rem 0 0;
  color: var(--accent);
}

/* Dialogue styling */
.chapter p.dialogue {
  text-indent: 0;
  margin-left: 1rem;
}

/* Clickable words */
.vocab {
  border-bottom: 1px dotted var(--accent);
  color: var(--ink);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  padding: 0 2px;
  border-radius: 2px;
}
.vocab:hover, .vocab:focus {
  color: var(--accent-deep);
  background: var(--highlight);
  outline: none;
}
.vocab.active {
  background: var(--highlight);
  color: var(--accent-deep);
}

/* Footnote marker */
.footnote-marker {
  font-size: 0.7em;
  vertical-align: super;
  color: var(--accent);
  cursor: pointer;
  font-weight: bold;
  padding: 0 2px;
}
.footnote-marker:hover { color: var(--accent-deep); }

/* Side panel */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--panel-w);
  max-width: 85vw;
  height: 100vh;
  background: var(--panel-bg);
  border-left: 1px solid var(--rule);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
  box-shadow: -10px 0 40px rgba(70, 50, 20, 0.15);
  display: flex;
  flex-direction: column;
}
.panel.open {
  transform: translateX(0);
}

.panel-close {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  color: var(--ink-faded);
  cursor: pointer;
  font-family: var(--serif);
  padding: 0.2rem 0.5rem;
  transition: color 0.2s;
}
.panel-close:hover { color: var(--ink); }

.panel-content {
  padding: 3.5rem 2rem 2rem;
  overflow-y: auto;
  flex: 1;
}

.panel-entry {
  margin-bottom: 2rem;
  animation: entryIn 0.4s ease-out;
}
@keyframes entryIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-word {
  font-family: var(--display);
  font-size: 1.6rem;
  font-style: italic;
  color: var(--accent);
  margin: 0 0 0.3rem;
}
.panel-pron {
  font-family: var(--serif);
  font-size: 0.85rem;
  color: var(--ink-faded);
  font-style: italic;
  margin: 0 0 0.8rem;
}
.panel-def {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-soft);
}
.panel-def em {
  color: var(--ink);
}

.panel-nested {
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px dashed var(--rule);
}
.panel-nested-trigger {
  display: inline-block;
  font-family: var(--display);
  font-style: italic;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  border-bottom: 1px dotted var(--accent);
  padding: 2px 0;
  transition: color 0.2s;
}
.panel-nested-trigger:hover { color: var(--accent-deep); }

.panel-source {
  margin-top: 1rem;
  font-size: 0.78rem;
  color: var(--ink-faded);
}
.panel-source a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.panel-source a:hover { color: var(--accent-deep); }

/* Navigation */
#chapter-nav {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--paper);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  box-shadow: 0 4px 20px rgba(70, 50, 20, 0.25), 0 0 0 4px var(--paper);
  border: 1px solid var(--rule);
}
.nav-btn {
  background: none;
  border: none;
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--ink);
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
}
.nav-btn:hover:not(:disabled) {
  background: var(--paper);
  color: var(--accent);
}
.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}
.chapter-indicator {
  font-family: var(--display-sc);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  min-width: 8rem;
  text-align: center;
}

/* Game placeholders and containers */
.game-container {
  margin: 3rem -1rem;
  padding: 2rem 1rem;
  background: var(--paper-deep);
  border-radius: 4px;
  border: 1px solid var(--rule);
  box-shadow: inset 0 0 20px rgba(70, 50, 20, 0.06);
  text-align: center;
  position: relative;
}

.game-title {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

.game-instruction {
  font-size: 0.9rem;
  color: var(--ink-faded);
  margin: 0 0 1.5rem;
  font-style: italic;
}

.game-placeholder {
  padding: 3rem 1rem;
  color: var(--ink-faded);
  font-style: italic;
  opacity: 0.7;
}

/* Chapter transition divider */
.chapter-end {
  text-align: center;
  margin: 3rem 0;
  color: var(--ink-faded);
  font-size: 1.2rem;
  letter-spacing: 0.5em;
  opacity: 0.5;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  html, body { font-size: 17px; }
  #book { padding: 2.5rem 1.2rem 8rem; }
  .chapter-title { font-size: 2rem; }
  .chapter p.dropcap::first-letter { font-size: 3rem; }
  .panel { width: 85vw; }
  .panel-content { padding: 3rem 1.5rem 1.5rem; }
  #chapter-nav { padding: 0.4rem 0.8rem; gap: 0.5rem; }
  .chapter-indicator { min-width: 6rem; font-size: 0.65rem; }
}

/* Cover page */
.cover {
  text-align: center;
  padding: 3rem 0;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.cover-title {
  font-family: var(--display);
  font-style: italic;
  font-size: 4rem;
  line-height: 1;
  color: var(--ink);
  margin: 0 0 1rem;
  letter-spacing: 0.01em;
}
.cover-subtitle {
  font-family: var(--display-sc);
  font-size: 0.9rem;
  letter-spacing: 0.4em;
  color: var(--accent);
  margin: 0 0 3rem;
}
.cover-start {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--ink-soft);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0.5rem 1.5rem;
  border-bottom: 1px solid var(--accent);
  transition: color 0.3s, letter-spacing 0.3s;
}
.cover-start:hover {
  color: var(--accent);
  letter-spacing: 0.05em;
}
@media (max-width: 640px) {
  .cover-title { font-size: 2.8rem; }
}

/* Common utility */
.hidden { display: none !important; }
.centered { text-align: center; }

/* ============================================================
   SCRAMBLE GAME
   ============================================================ */
.scramble-game {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0;
}

.scramble-hint {
  font-family: var(--display);
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-faded);
  text-align: center;
  margin: 0 0 1rem;
}

/* The scatter area where loose tiles live */
.scramble-scatter {
  position: relative;
  width: 100%;
  height: 240px;
  margin: 0 auto 1.5rem;
  background:
    radial-gradient(ellipse at center, rgba(195, 160, 105, 0.10) 0%, transparent 70%);
  border-radius: 6px;
  touch-action: none;
}

/* Individual letter tile */
.letter-tile {
  position: absolute;
  width: 46px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 1.7rem;
  font-style: italic;
  color: var(--ink);
  cursor: grab;
  user-select: none;
  border-radius: 4px;
  box-shadow:
    0 2px 0 rgba(80, 55, 25, 0.25),
    0 3px 6px rgba(80, 55, 25, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  transition: box-shadow 0.2s, transform 0.2s;
  z-index: 2;
}
.letter-tile.dragging {
  cursor: grabbing;
  z-index: 100;
  transform: scale(1.1) rotate(0deg) !important;
  box-shadow:
    0 6px 0 rgba(80, 55, 25, 0.25),
    0 10px 20px rgba(80, 55, 25, 0.35);
}
.letter-tile.placed {
  cursor: default;
  box-shadow:
    0 1px 0 rgba(80, 55, 25, 0.15),
    inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  animation: tileSettle 0.4s ease-out;
}
.letter-tile.placed,
.letter-tile.placed.locked {
  /* When placed in a slot, tile is centered via left:50%/top:50% + this translate */
  transform: translate(-50%, -50%) rotate(0deg);
}
.letter-tile.locked {
  cursor: default;
  opacity: 0.92;
}
@keyframes tileSettle {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(1.15); }
  50% { transform: translate(-50%, -50%) rotate(0deg) scale(0.95); }
  100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); }
}

/* Four muted tile colours (applied by modulo) */
.letter-tile.c1 { background: #f3e5cc; }
.letter-tile.c2 { background: #e8cec8; }
.letter-tile.c3 { background: #d9dfc5; }
.letter-tile.c4 { background: #ecd9aa; }

/* The target row at the bottom */
.scramble-slots {
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  margin: 0 auto;
  padding: 0.8rem 0.5rem;
  background: rgba(195, 160, 105, 0.08);
  border-radius: 4px;
  min-height: 72px;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
}
.scramble-slot {
  width: 46px;
  height: 60px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 1.4rem;
  font-style: italic;
  color: var(--ink);
  transition: all 0.3s;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}
/* The slot's underline — a pseudo element so tiles placed inside don't cover it */
.scramble-slot::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 2px;
  height: 2px;
  background: var(--ink-faded);
  transition: background 0.3s;
  z-index: 0;
}
.scramble-slot.space {
  width: 16px;
}
.scramble-slot.space::after {
  display: none;
}
.scramble-slot.dragover::after {
  background: var(--accent);
  height: 3px;
}
.scramble-slot.filled::after {
  background: var(--forest);
}
.scramble-slot.locked::after {
  background: var(--accent);
  height: 3px;
}
.scramble-slot.locked .scramble-slot-text {
  font-family: var(--display);
  font-style: italic;
  color: var(--ink);
  font-size: 1.5rem;
  z-index: 1;
}
.scramble-slot-text {
  position: relative;
  z-index: 1;
}

/* Success reveal */
.scramble-success {
  text-align: center;
  padding: 1rem;
  font-family: var(--display);
  font-style: italic;
  font-size: 2.2rem;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.8s;
  margin-top: 1rem;
}
.scramble-success.visible {
  opacity: 1;
  animation: successPulse 2s ease-out;
}
@keyframes successPulse {
  0% { transform: scale(0.9); letter-spacing: 0; }
  50% { transform: scale(1.05); letter-spacing: 0.05em; }
  100% { transform: scale(1); letter-spacing: 0.02em; }
}

/* ============================================================
   TINDER GAME
   ============================================================ */
.tinder-game {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  user-select: none;
}

.tinder-board-wrap {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  max-width: 560px;
  background: rgba(255, 252, 240, 0.5);
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(80, 55, 25, 0.15);
  overflow: hidden;
  touch-action: none;
  aspect-ratio: 900 / 378;
}
.tinder-board-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

/* The collectible markers are absolutely positioned overlays */
.tinder-item {
  position: absolute;
  width: 8%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  transition: opacity 0.4s, transform 0.5s;
  pointer-events: none;
  /* Item-specific pulse so kids see it's collectable */
  animation: itemPulse 2.5s ease-in-out infinite;
  mix-blend-mode: multiply;
}
@keyframes itemPulse {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 0.65; }
}
.tinder-item.collected {
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.6);
  animation: none;
}

/* Pat on the board */
.tinder-pat {
  position: absolute;
  width: auto;
  height: 33%;
  transform: translate(-50%, -50%);
  transition: top 0.08s ease-out, left 0.08s ease-out;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 3;
}

.tinder-sidebar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  flex-wrap: wrap;
  justify-content: center;
}

.tinder-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem 1rem;
  background: var(--paper);
  border-radius: 6px;
  border: 1px solid var(--rule);
  min-width: 90px;
  transition: transform 0.3s;
}
.tinder-counter.bump {
  animation: counterBump 0.4s ease-out;
}
@keyframes counterBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.tinder-counter-label {
  font-family: var(--display-sc);
  font-size: 0.75rem;
  color: var(--ink-faded);
  letter-spacing: 0.15em;
  margin-bottom: 0.3rem;
}
.tinder-counter-num {
  font-family: var(--display);
  font-style: italic;
  font-size: 2.2rem;
  line-height: 1;
  color: var(--accent);
}
.tinder-counter.done .tinder-counter-num {
  color: var(--forest);
}

.tinder-hint {
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-faded);
  text-align: center;
  line-height: 1.35;
  max-width: 140px;
}

.tinder-complete {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--forest);
  padding: 2rem 1rem;
}

/* Mobile: smaller counters */
@media (max-width: 640px) {
  .tinder-counter {
    padding: 0.5rem 0.9rem;
    min-width: 70px;
  }
  .tinder-counter-num {
    font-size: 1.7rem;
  }
  .tinder-hint {
    font-size: 0.75rem;
  }
}

/* Pixel sprite rendering everywhere */
.tinder-pat, .tinder-item img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ============================================================
   FOREST WALK
   ============================================================ */
.forest-game {
  max-width: 100%;
}
.forest-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-faded);
  flex-wrap: wrap;
}
.forest-mode-btn {
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.forest-mode-btn:hover {
  background: var(--paper-deep);
}
.forest-mode-btn.active {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.forest-board-wrap {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  border-radius: 4px;
  overflow: hidden;
  touch-action: none;
  box-shadow: 0 4px 16px rgba(80, 55, 25, 0.15);
  aspect-ratio: 500 / 362;
}
.forest-board-img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}
.forest-fog {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 1.2s;
}
.forest-pat {
  position: absolute;
  transform: translate(-50%, -50%);
  transition: top 0.2s ease-out, left 0.2s ease-out;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 3;
}
.forest-hint {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-faded);
  font-size: 0.85rem;
  margin: 1rem 0 0;
}
.forest-complete {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--forest);
  font-size: 1.3rem;
  margin-top: 1rem;
  opacity: 0;
  transition: opacity 1s;
}
.forest-complete.visible { opacity: 1; }

/* ============================================================
   MAZE GAME
   ============================================================ */
.maze-game {
  max-width: 100%;
  text-align: center;
}
.maze-status {
  margin-bottom: 0.8rem;
  font-family: var(--display);
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-soft);
  min-height: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.maze-restart {
  background: var(--paper);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.maze-restart:hover {
  background: var(--accent);
  color: var(--paper);
}
.maze-board-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  touch-action: none;
}
.maze-canvas {
  display: block;
  background: transparent;
  border-radius: 4px;
  max-width: 100%;
}
.maze-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-faded);
}
.maze-control-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.maze-control-label {
  font-size: 0.8rem;
}
.maze-ctrl-btn {
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-family: var(--display);
  font-style: italic;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.maze-ctrl-btn:hover {
  background: var(--paper-deep);
}
.maze-ctrl-btn.active {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.maze-hint {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-faded);
  font-size: 0.85rem;
  margin: 1rem 0 0;
}

/* ============================================================
   ACCESSIBILITY & POLISH
   ============================================================ */
/* Focus ring for keyboard nav */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}
.vocab:focus-visible {
  outline-offset: 4px;
}
.nav-btn:focus-visible,
.cover-start:focus-visible,
.forest-mode-btn:focus-visible,
.maze-restart:focus-visible,
.panel-close:focus-visible {
  outline-offset: 2px;
}

/* Screen reader only helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Prefers-reduced-motion: tone down animations */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   MAZE GATING: hide post-maze text until the chef is escaped
   ============================================================ */
.locked-until-maze {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 1.2s ease-out, opacity 1s ease-in;
  pointer-events: none;
}
.locked-until-maze.revealed {
  max-height: 3000px;
  opacity: 1;
  pointer-events: auto;
}

/* Continue button shown after winning the maze */
.continue-wrap {
  text-align: center;
  margin: 2rem 0 1rem;
}
.continue-btn {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.2rem;
  background: var(--paper);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 0.6rem 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.3s;
  letter-spacing: 0.02em;
}
.continue-btn:hover {
  background: var(--accent);
  color: var(--paper);
  letter-spacing: 0.05em;
}

/* Nested vocab trigger when already expanded */
.panel-nested-trigger.disabled {
  opacity: 0.45;
  cursor: default;
  border-bottom: none;
}

/* Tinder post-win gate (same pattern as maze) */
.locked-until-tinder {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 1.2s ease-out, opacity 1s ease-in;
  pointer-events: none;
}
.locked-until-tinder.revealed {
  max-height: 3000px;
  opacity: 1;
  pointer-events: auto;
}
/* When progress is restored on load, snap open without animation */
.locked-until-maze.revealed.instant,
.locked-until-tinder.revealed.instant {
  transition: none;
  max-height: none;
}

/* ============================================================
   FLIGHT SCENE (salesman chapter — parallax interlude)
   ============================================================ */
.flight-scene {
  margin: 2.5rem 0;
  text-align: center;
}
.flight-wrap {
  position: relative;
  display: block;
  margin: 0 auto;
  width: 100%;
  max-width: 34rem;
  aspect-ratio: 16 / 9;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 2px 12px var(--paper-shadow);
  overflow: hidden;
  background: var(--paper-deep);
}
.flight-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}
.flight-pat {
  position: absolute;
  top: 47%;
  left: 50%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  pointer-events: none;
  /* width set by JS */
}
.flight-caption {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-faded);
  font-size: 0.9rem;
  margin: 0.8rem 0 0;
  letter-spacing: 0.12em;
}

/* ============================================================
   CRÊPE CATCHING GAME (chef chapter)
   ============================================================ */
.crepe-game {
  margin: 2rem 0;
  text-align: center;
  font-family: var(--serif);
}
.crepe-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 34rem;
  margin: 0 auto 0.5rem;
  padding: 0 0.3rem;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-soft);
}
.crepe-score-label { color: var(--ink-faded); margin-right: 0.3rem; }
.crepe-score-num   { color: var(--accent); font-weight: normal; font-size: 1.1rem; }
.crepe-score-goal  { color: var(--ink-faded); margin-left: 0.2rem; }
.crepe-lives { display: inline-flex; gap: 4px; align-items: center; }
.crepe-life {
  width: 14px;
  height: 7px;
  background: #e6be7e;
  border: 1px solid var(--ink);
  border-radius: 50%;
  display: inline-block;
  transition: opacity 0.3s, background 0.3s;
}
.crepe-life.used {
  background: var(--paper-deep);
  opacity: 0.3;
}

.crepe-field {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 34rem;
  height: 320px;
  background: linear-gradient(to bottom, #f2e6c8 0%, #e8d8b0 65%, #d9c18a 100%);
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 2px 12px var(--paper-shadow);
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}
.crepe-chef {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 10px;
  background: #f5eedc;
  border: 1px solid var(--ink);
  border-radius: 6px 6px 2px 2px;
  /* A little chef's hat silhouette indicating where pancakes come from */
}
.crepe-chef::after {
  content: '';
  position: absolute;
  top: 8px; left: 3px;
  width: 18px; height: 3px;
  background: var(--ink);
}

.crepe-lane-hints {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}
.crepe-lane-hint {
  position: absolute;
  top: 0; bottom: 60px;
  background: transparent;
  border-left: 1px dashed rgba(122, 107, 85, 0.15);
  transition: background 0.2s;
}
.crepe-lane-hint:first-child { border-left: none; }
.crepe-lane-hint.active {
  background: rgba(200, 155, 60, 0.08);
}
.crepe-lane-hint.incoming {
  background: rgba(163, 59, 42, 0.12);
  transition: background 0.1s;
}

.crepe-stoves {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 36px;
  pointer-events: none;
}
.crepe-stove {
  position: absolute;
  bottom: 0;
  height: 36px;
  background: linear-gradient(to bottom, #8b7d6b 0%, #5a4c3c 100%);
  border-top: 2px solid var(--ink);
  border-right: 1px solid rgba(0,0,0,0.2);
}
.crepe-stove:last-child { border-right: none; }

.crepe-pat {
  position: absolute;
  bottom: 4px;
  left: 0;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 3;
  /* width/height set by JS */
}

.crepe-pancake {
  position: absolute;
  width: 28px;
  height: 14px;
  background-image: url('../assets/pancake.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  z-index: 2;
  pointer-events: none;
  transition: none;
}
.crepe-pancake.caught {
  transform: scale(0.5);
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
}
.crepe-pancake.splatted {
  transform: scaleY(0.35) scaleX(1.5);
  opacity: 0.8;
  transition: transform 0.25s, opacity 0.7s;
  filter: saturate(0.7);
}

.crepe-catch-puff {
  position: absolute;
  width: 16px;
  height: 16px;
  background: radial-gradient(circle, rgba(245,240,220,0.9) 0%, rgba(245,240,220,0) 70%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
  animation: crepe-puff 0.5s ease-out forwards;
}
@keyframes crepe-puff {
  0%   { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2.2) translateY(-10px); opacity: 0; }
}

.crepe-message {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-style: italic;
  font-size: 1.3rem;
  color: var(--accent-deep);
  text-shadow: 0 1px 2px rgba(245, 238, 220, 0.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 5;
  text-align: center;
  width: 80%;
}
.crepe-message:not(:empty) { opacity: 1; }
.crepe-message.persist { color: var(--forest); font-size: 1.4rem; }

.crepe-hint {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-faded);
  font-size: 0.85rem;
  margin: 0.8rem 0 0;
}
.crepe-restart {
  display: inline-block;
  margin: 0.8rem auto 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 1rem;
  background: var(--paper);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 0.4rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s;
}
.crepe-restart:hover {
  background: var(--accent);
  color: var(--paper);
}

/* Chef gating: hide post-win text until enough crêpes are caught */
.locked-until-crepe {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 1.2s ease-out, opacity 1s ease-in;
  pointer-events: none;
}
.locked-until-crepe.revealed {
  max-height: 4000px;
  opacity: 1;
  pointer-events: auto;
}
.locked-until-crepe.revealed.instant {
  transition: none;
  max-height: none;
}
