:root {
  --ink: #14233a;
  --muted: #5d6b80;
  --line: rgba(20, 35, 58, 0.14);
  --paper: #fffdf4;
  --sky: #aee7ff;
  --meadow: #9bd96b;
  --navy: #193f78;
  --blue: #2467e8;
  --red: #e84c50;
  --gold: #f2b83d;
  --green: #31a567;
  --violet: #7c5ce6;
  --shadow: 0 20px 46px rgba(20, 35, 58, 0.16);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--sky) 0%, #e6f9ff 39%, #e9f8cf 39%, var(--meadow) 100%);
  line-height: 1.45;
}

button {
  cursor: pointer;
  font: inherit;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 850;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  color: white;
  background: linear-gradient(135deg, var(--green), var(--violet));
  box-shadow: 0 12px 24px rgba(49, 165, 103, 0.22);
  font-weight: 950;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--navy);
  font-weight: 760;
}

.topnav a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  text-decoration: none;
}

.topnav a:hover {
  text-decoration: underline;
}
.topnav .game-menu { border: 1px solid rgba(15, 46, 53, .16); border-radius: 999px; background: #fffdf7; color: #0f2e35; padding: 8px 12px; font: inherit; font-weight: 800; cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.stage,
.control-panel {
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--shadow);
}

.stage {
  min-width: 0;
  padding: 14px;
}

.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 84px;
  padding: 0 4px 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.mode-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.mode-tags span {
  display: inline-grid;
  min-height: 28px;
  place-items: center;
  padding: 5px 9px;
  border: 1px solid rgba(25, 63, 120, 0.2);
  border-radius: 8px;
  color: var(--navy);
  background: #fffdf4;
  font-size: 0.78rem;
  font-weight: 900;
}

h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  letter-spacing: 0;
}

.meter-bank {
  display: grid;
  grid-template-columns: repeat(3, 88px);
  gap: 8px;
}

.meter-card {
  display: grid;
  min-height: 62px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: right;
}

.meter-card span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meter-card strong {
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  line-height: 1;
}

.narration-rail {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 58px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid rgba(20, 35, 58, 0.18);
  border-radius: 8px;
  background: #fffdf4;
}

.narration-rail span {
  display: inline-grid;
  min-width: 74px;
  min-height: 32px;
  place-items: center;
  padding: 5px 9px;
  border-radius: 8px;
  color: white;
  background: var(--navy);
  font-size: 0.78rem;
  font-weight: 900;
}

.narration-rail p {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 760;
}

.canvas-frame {
  position: relative;
  min-height: 500px;
  overflow: hidden;
  border: 3px solid #243b4f;
  border-radius: 8px;
  background: #c6efff;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 500px;
  background: #c6efff;
}

.curtain {
  position: absolute;
  left: 50%;
  top: 50%;
  display: grid;
  gap: 8px;
  width: min(390px, calc(100% - 40px));
  padding: 18px;
  border: 2px solid rgba(20, 35, 58, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 244, 0.94);
  box-shadow: 0 24px 60px rgba(20, 35, 58, 0.22);
  text-align: center;
  transform: translate(-50%, -50%);
}

.curtain[hidden] {
  display: none;
}

.curtain strong {
  font-size: 1.32rem;
}

.curtain span {
  color: var(--muted);
}

.lane-controls {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
}

.lane-controls button,
.primary-button,
.secondary-button,
.segmented button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 850;
}

.lane-controls button {
  min-height: 44px;
  color: white;
}

.control-panel {
  align-self: start;
  padding: 14px;
}

.panel-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 9px;
}

.segmented button,
.secondary-button {
  color: var(--ink);
  background: var(--paper);
}

.segmented button.active {
  border-color: rgba(25, 63, 120, 0.9);
  color: white;
  background: var(--navy);
}

.mode-card {
  display: grid;
  gap: 4px;
  min-height: 74px;
  padding: 12px;
  border: 1px solid rgba(25, 63, 120, 0.26);
  border-radius: 8px;
  background: #fffdf4;
}

.mode-card strong {
  color: var(--navy);
  font-size: 1.06rem;
}

.mode-card span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.primary-button {
  border-color: #174d30;
  color: white;
  background: linear-gradient(180deg, #35b772, #177543);
  box-shadow: 0 10px 20px rgba(49, 165, 103, 0.22);
}

.full {
  width: 100%;
  margin-bottom: 8px;
}

.primary-button:hover,
.secondary-button:hover,
.segmented button:hover,
.lane-controls button:hover {
  filter: brightness(0.98);
}

.secondary-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.secondary-button:disabled:hover {
  filter: none;
}

.seed-shelf {
  display: flex;
  align-content: flex-start;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 112px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.seed-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  padding: 5px 8px;
  border-radius: 8px;
  color: white;
  font-size: 0.82rem;
  font-weight: 850;
}

.story-book {
  min-height: 178px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.story-book strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 1rem;
}

.story-book p {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.93rem;
}

.story-book p:last-child {
  margin-bottom: 0;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.key-grid span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-weight: 900;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 18px;
  }

  .panel-section {
    border-bottom: 0;
  }
}

.adventure-cards {
  display: grid;
  gap: 8px;
}

.adventure-card {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 10px 12px 10px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  text-align: left;
}

.adventure-card::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 10px;
  bottom: 10px;
  width: 5px;
  border-radius: 4px;
  background: var(--swatch, var(--green));
}

.adventure-card strong {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.2;
}

.adventure-card span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.adventure-card.active {
  border-color: var(--swatch, var(--navy));
  box-shadow: 0 0 0 2px var(--swatch, var(--navy));
}

mark.story-word {
  padding: 1px 5px;
  border-radius: 6px;
  color: white;
  background: var(--w, var(--green));
  font-weight: 900;
}

mark.story-blank {
  padding: 1px 8px;
  border-radius: 6px;
  color: #9d2226;
  background: rgba(232, 76, 80, 0.14);
  font-weight: 900;
}

.storybook-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 35, 58, 0.55);
}

.storybook-overlay[hidden] {
  display: none;
}

.book-card {
  position: relative;
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 26px 28px 22px;
  border: 3px solid #d9b98a;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #fffdf4 0%, #fdf6e2 100%);
  box-shadow: 0 30px 80px rgba(20, 35, 58, 0.4);
}

.book-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1.5px dashed rgba(160, 120, 60, 0.4);
  border-radius: 9px;
  pointer-events: none;
}

#bookSticker {
  float: right;
  width: 96px;
  height: 96px;
  margin: 0 0 8px 12px;
}

.book-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.book-card h2 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  line-height: 1.15;
}

.book-body p {
  margin: 0 0 10px;
  font-size: 1.04rem;
  line-height: 1.55;
}

.book-body .book-ending {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1.5px dashed rgba(160, 120, 60, 0.4);
  font-style: italic;
}

.book-body .book-stats {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.book-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.book-buttons button {
  flex: 1 1 120px;
  min-height: 42px;
  border-radius: 8px;
}

@media print {
  body > * {
    display: none !important;
  }

  body {
    background: white;
  }

  .storybook-overlay,
  .storybook-overlay .book-card {
    position: static;
    display: block !important;
    background: white;
    box-shadow: none;
    max-height: none;
    overflow: visible;
  }

  .storybook-overlay {
    padding: 0;
  }

  .book-buttons {
    display: none !important;
  }

  mark.story-word {
    color: black;
    background: none;
    text-decoration: underline;
    font-weight: 900;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell,
  .topbar {
    width: min(100% - 18px, 1500px);
  }

  .stage,
  .control-panel {
    padding: 10px;
  }

  .score-strip {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 1.45rem;
  }

  .meter-bank {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .narration-rail {
    grid-template-columns: 1fr;
  }

  .narration-rail span {
    width: fit-content;
  }

  .canvas-frame,
  #gameCanvas {
    min-height: 380px;
  }

  .lane-controls {
    display: grid;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }
}
