:root {
  --ink: #2c271d;
  --muted: #6d6049;
  --paper: #fff3cf;
  --paper-strong: #ffe4a6;
  --line: rgba(98, 66, 31, 0.28);
  --shadow: rgba(34, 24, 12, 0.25);
  --triassic: #b7653d;
  --jurassic: #3c8a63;
  --cretaceous: #4576a7;
  --science: #7c5a9d;
  --finale: #c08a2d;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: #14231f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 215, 123, 0.18), transparent 28%),
    radial-gradient(circle at 80% 20%, rgba(75, 142, 126, 0.22), transparent 30%),
    linear-gradient(135deg, #16261f 0%, #273428 48%, #1d221d 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 1260px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 18px 82px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
}

.topbar,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: #fff6d7;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: #f3cf78;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.page-meta {
  min-width: 148px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 244, 207, 0.24);
  border-radius: 8px;
  background: rgba(13, 20, 17, 0.45);
  display: grid;
  gap: 2px;
  text-align: right;
  font-family: Arial, Helvetica, sans-serif;
}

.page-meta span {
  color: #f3cf78;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.page-meta strong {
  font-size: 18px;
}

.chapter-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chapter-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 241, 196, 0.2);
  border-radius: 8px;
  background: rgba(255, 241, 196, 0.1);
  color: #fff5d2;
  padding: 8px 11px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.chapter-chip.active {
  color: #1f2119;
  background: #ffd36c;
  border-color: #ffd36c;
}

.book-frame {
  min-height: 0;
  display: grid;
}

.spread {
  position: relative;
  min-height: clamp(520px, calc(100vh - 214px), 760px);
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid rgba(255, 237, 184, 0.2);
  background:
    linear-gradient(90deg, rgba(74, 47, 22, 0.13), transparent 8%, transparent 46%, rgba(66, 42, 20, 0.16) 50%, transparent 54%, transparent 92%, rgba(74, 47, 22, 0.12)),
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.45), transparent 34%),
    linear-gradient(115deg, #fff2cf 0%, #f6dba1 48%, #ffe7b3 100%);
  box-shadow: 0 24px 80px var(--shadow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 26px;
  padding: clamp(22px, 3.2vw, 38px);
  padding-bottom: clamp(86px, 9vh, 112px);
}

.spread::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(91, 67, 31, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 67, 31, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mix-blend-mode: multiply;
}

.spread::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 24px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(74, 44, 20, 0.18), transparent);
  pointer-events: none;
}

.story-panel,
.visual-panel,
.wide-panel,
.note-ribbon {
  position: relative;
  z-index: 1;
}

.story-panel {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  max-width: 540px;
}

.spread.layout-reverse .story-panel {
  grid-column: 2;
}

.spread.layout-reverse .visual-panel {
  grid-column: 1;
  grid-row: 1;
}

.spread.layout-wide {
  grid-template-columns: 1fr;
}

.spread.layout-wide .story-panel {
  max-width: 100%;
  justify-content: flex-start;
}

.spread.layout-cover {
  grid-template-columns: 0.92fr 1.08fr;
  color: #fff8d8;
  background: #10231d;
}

.spread.layout-cover::before {
  opacity: 0.2;
}

.cover-art {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.52;
  filter: saturate(0.92) contrast(1.04);
}

.cover-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(10, 22, 18, 0.94), rgba(10, 22, 18, 0.48) 54%, rgba(10, 22, 18, 0.85)),
    radial-gradient(circle at 70% 30%, rgba(245, 194, 84, 0.18), transparent 36%);
}

.kicker {
  margin: 0;
  color: var(--accent, #8f522e);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.layout-cover .kicker {
  color: #ffd36c;
}

.story-panel h2 {
  margin: 0;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 0.95;
  letter-spacing: 0;
}

.layout-wide .story-panel h2 {
  font-size: clamp(30px, 3.6vw, 50px);
}

.lead {
  margin: 0;
  max-width: 640px;
  font-size: clamp(18px, 1.9vw, 25px);
  line-height: 1.32;
  color: #3e3526;
}

.layout-cover .lead {
  color: #fff2c8;
}

.fact-list {
  display: grid;
  gap: 9px;
  margin-top: 4px;
}

.fact-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-left: 5px solid var(--accent, #b7653d);
  border-radius: 8px;
  background: rgba(255, 250, 232, 0.62);
  font-size: 16px;
  line-height: 1.35;
}

.layout-cover .fact-item {
  background: rgba(255, 239, 196, 0.14);
  color: #fff7df;
}

.fact-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent, #b7653d);
  color: #fff9e7;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-size: 14px;
}

.compi-note {
  margin-top: auto;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid rgba(75, 105, 58, 0.36);
  background: rgba(236, 255, 218, 0.76);
  color: #2d3e24;
  font-size: 17px;
  line-height: 1.32;
}

.layout-cover .compi-note {
  background: rgba(236, 255, 218, 0.18);
  border-color: rgba(236, 255, 218, 0.34);
  color: #e9ffd6;
}

.compi-note strong {
  display: block;
  margin-bottom: 4px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.visual-panel {
  min-height: 360px;
  align-self: center;
  display: grid;
  place-items: center;
}

.full-bleed-image {
  width: 100%;
  height: min(56vh, 520px);
  object-fit: cover;
  border-radius: 9px;
  box-shadow: 0 16px 42px rgba(72, 45, 18, 0.24);
}

.mini-label {
  font-family: Arial, Helvetica, sans-serif;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.timeline {
  width: min(100%, 560px);
  display: grid;
  gap: 14px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 110px 1fr 74px;
  gap: 12px;
  align-items: center;
}

.timeline-name {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
}

.timeline-track {
  height: 38px;
  border-radius: 8px;
  background: rgba(78, 60, 34, 0.12);
  overflow: hidden;
}

.timeline-bar {
  height: 100%;
  width: var(--w);
  background: linear-gradient(90deg, var(--color), rgba(255, 228, 166, 0.82));
}

.timeline-age {
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 800;
}

.map-card {
  width: min(100%, 560px);
  min-height: 420px;
  position: relative;
  border: 2px solid rgba(103, 73, 38, 0.28);
  border-radius: 10px;
  overflow: hidden;
  background:
    radial-gradient(circle at 42% 45%, #a8c478 0 18%, transparent 19%),
    radial-gradient(circle at 58% 45%, #d39b63 0 16%, transparent 17%),
    radial-gradient(circle at 48% 61%, #90b46a 0 18%, transparent 19%),
    linear-gradient(135deg, #9bc9d0, #e8ce91);
  box-shadow: inset 0 0 0 10px rgba(255, 245, 210, 0.28);
}

.map-card::before {
  content: "";
  position: absolute;
  inset: 34px 52px;
  background: rgba(255, 238, 190, 0.28);
  border: 2px dashed rgba(89, 65, 36, 0.45);
  clip-path: polygon(18% 22%, 38% 9%, 55% 20%, 71% 14%, 86% 36%, 76% 56%, 84% 77%, 61% 84%, 47% 72%, 31% 87%, 16% 70%, 25% 52%, 9% 38%);
}

.map-pin {
  position: absolute;
  width: 150px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 250, 232, 0.9);
  box-shadow: 0 8px 20px rgba(58, 39, 17, 0.16);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 800;
}

.pin-1 { left: 10%; top: 24%; }
.pin-2 { right: 11%; top: 19%; }
.pin-3 { left: 37%; bottom: 15%; }

.species-grid,
.mosaic-grid {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 13px;
}

.species-card,
.mosaic-card {
  min-height: 220px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(90, 65, 36, 0.26);
  background: rgba(255, 250, 232, 0.72);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.dino-silhouette {
  height: 92px;
  position: relative;
  margin: 6px 0 2px;
}

.dino-silhouette::before {
  content: "";
  position: absolute;
  inset: 20px 22px 16px 32px;
  border-radius: 60% 45% 55% 40%;
  background: var(--accent, #6a8f54);
}

.dino-silhouette::after {
  content: "";
  position: absolute;
  width: 58px;
  height: 30px;
  right: 10px;
  top: 18px;
  border-radius: 60% 40% 45% 45%;
  background: var(--accent, #6a8f54);
  box-shadow:
    -118px 21px 0 -10px var(--accent, #6a8f54),
    -44px 54px 0 -10px var(--accent, #6a8f54),
    -8px 55px 0 -11px var(--accent, #6a8f54);
}

.dino-silhouette.long-neck::after {
  width: 88px;
  height: 22px;
  right: -8px;
  top: 8px;
  transform: rotate(-23deg);
  transform-origin: left center;
}

.dino-silhouette.armored::before {
  border-radius: 50% 50% 38% 38%;
}

.dino-silhouette.armored span {
  position: absolute;
  left: 48px;
  top: 12px;
  width: 116px;
  height: 20px;
  background: repeating-linear-gradient(90deg, transparent 0 10px, var(--accent, #6a8f54) 10px 18px);
  clip-path: polygon(0 100%, 7% 20%, 14% 100%, 22% 18%, 31% 100%, 40% 18%, 50% 100%, 60% 18%, 70% 100%, 81% 18%, 92% 100%, 100% 22%, 100% 100%);
}

.species-card h3,
.mosaic-card h3 {
  margin: 0;
  font-size: 22px;
}

.species-card p,
.mosaic-card p {
  margin: 0;
  color: #4b402f;
  font-size: 15px;
  line-height: 1.32;
}

.compare-bars {
  width: min(100%, 590px);
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 76px;
  gap: 12px;
  align-items: center;
}

.bar-name {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
}

.bar-track {
  height: 30px;
  border-radius: 8px;
  background: rgba(85, 62, 34, 0.14);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: var(--w);
  background: linear-gradient(90deg, var(--accent, #4f8d63), #f2c166);
}

.bar-value {
  color: var(--muted);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  font-weight: 800;
}

.layer-diagram {
  width: min(100%, 590px);
  min-height: 430px;
  display: grid;
  align-content: end;
  gap: 0;
  border-radius: 9px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(94, 66, 34, 0.25);
}

.layer {
  min-height: 74px;
  padding: 14px 18px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  color: rgba(41, 31, 21, 0.78);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layer:nth-child(1) { background: #d9bb78; }
.layer:nth-child(2) { background: #b9855b; }
.layer:nth-child(3) { background: #8f694b; color: #fff1cc; }
.layer:nth-child(4) { background: #5e5142; color: #fff1cc; }

.bone {
  width: 126px;
  height: 28px;
  border-radius: 999px;
  background: #f2e3bf;
  position: relative;
  transform: rotate(-10deg);
  box-shadow: inset 0 -4px 0 rgba(114, 83, 47, 0.12);
}

.bone::before,
.bone::after {
  content: "";
  position: absolute;
  top: -13px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #f2e3bf;
}

.bone::before { left: -22px; }
.bone::after { right: -22px; }

.diagram-card {
  width: min(100%, 570px);
  min-height: 430px;
  border-radius: 10px;
  background: rgba(255, 250, 232, 0.68);
  border: 1px solid rgba(90, 65, 36, 0.24);
  padding: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: center;
}

.diagram-node {
  padding: 12px;
  border-left: 5px solid var(--accent, #7c5a9d);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.diagram-node strong {
  display: block;
  margin-bottom: 4px;
  font-family: Arial, Helvetica, sans-serif;
  color: #382e21;
}

.tracks {
  width: min(100%, 570px);
  min-height: 430px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 20% 22%, rgba(255, 255, 255, 0.35), transparent 16%),
    linear-gradient(135deg, #d8ad73, #ba7c4c);
  position: relative;
  overflow: hidden;
}

.track-print {
  position: absolute;
  width: 66px;
  height: 84px;
  border-radius: 55% 55% 60% 60%;
  background: rgba(69, 45, 25, 0.42);
  clip-path: polygon(50% 0, 61% 32%, 94% 17%, 70% 52%, 100% 72%, 61% 69%, 50% 100%, 39% 69%, 0 72%, 30% 52%, 6% 17%, 39% 32%);
  transform: rotate(var(--r));
  left: var(--x);
  top: var(--y);
}

.quiz-panel {
  width: min(100%, 580px);
  display: grid;
  gap: 12px;
}

.quiz-option {
  border: 2px solid rgba(96, 68, 35, 0.24);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(255, 250, 232, 0.7);
}

.quiz-option.good {
  border-color: rgba(61, 138, 99, 0.6);
  background: rgba(224, 250, 218, 0.78);
}

.source-list {
  columns: 2;
  column-gap: 28px;
  padding-left: 18px;
  font-size: 15px;
  line-height: 1.45;
}

.source-list a {
  color: #355f7d;
  text-decoration-thickness: 1px;
}

.controls {
  position: fixed;
  z-index: 10;
  inset: 0;
  pointer-events: none;
}

.nav-button {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: auto;
  border: 1px solid rgba(255, 241, 196, 0.26);
  border-radius: 8px;
  background: rgba(17, 29, 24, 0.86);
  color: #fff6d7;
  padding: 12px 18px;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(12px);
}

.nav-button.primary {
  background: #ffd36c;
  color: #1f2119;
  border-color: #ffd36c;
}

.nav-button:disabled {
  opacity: 0;
  cursor: default;
  pointer-events: none;
}

#prevButton {
  left: 14px;
}

#nextButton {
  right: 14px;
}

.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: rgba(255, 241, 196, 0.14);
  overflow: hidden;
  pointer-events: none;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd36c, #75c49c);
  transition: width 220ms ease;
}

.turning {
  animation: pageTurn 260ms ease;
}

@keyframes pageTurn {
  from {
    transform: translateY(8px) scale(0.992);
    opacity: 0.84;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .page-meta {
    min-width: 112px;
  }

  .spread,
  .spread.layout-cover {
    min-height: auto;
    grid-template-columns: 1fr;
    padding: 24px;
  }

  .spread::after {
    display: none;
  }

  .spread.layout-reverse .story-panel,
  .spread.layout-reverse .visual-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .story-panel {
    max-width: none;
    justify-content: flex-start;
  }

  .visual-panel {
    min-height: 360px;
  }

  .species-grid,
  .mosaic-grid {
    grid-template-columns: 1fr;
  }

  .timeline-row,
  .bar-row {
    grid-template-columns: 1fr;
  }

  .diagram-card {
    grid-template-columns: 1fr;
  }

  .source-list {
    columns: 1;
  }
}
