:root {
  color-scheme: light;
  --page: #f5f7fb;
  --surface: #ffffff;
  --surface-muted: #eef2f7;
  --ink: #111827;
  --ink-soft: #263244;
  --muted: #4b5565;
  --line: #d8e0ea;
  --line-strong: #b8c4d6;
  --hero: #12233f;
  --hero-2: #193762;
  --primary: #2456d6;
  --primary-dark: #1740a6;
  --teal: #0f766e;
  --gold: #b45309;
  --red: #b42318;
  --green: #137a4b;
  --focus: #ffbf47;
  --shadow-sm: 0 10px 24px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 24px 64px rgba(15, 23, 42, 0.16);
  --radius: 12px;
  --content: min(1760px, calc(100% - clamp(32px, 5vw, 72px)));
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

body::selection {
  background: rgba(36, 86, 214, 0.22);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
.app-shell:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 100;
  transform: translateY(-150%);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  padding: 0.7rem 1rem;
  box-shadow: var(--shadow-md);
}

.skip-link:focus {
  transform: translateY(0);
}

code {
  border-radius: 6px;
  background: #e8eef8;
  color: #0f2f70;
  padding: 0.1rem 0.3rem;
}

.site-header {
  color: #ffffff;
  background:
    linear-gradient(115deg, rgba(18, 35, 63, 0.96), rgba(25, 55, 98, 0.9)),
    var(--adventure-bg-image) center / cover no-repeat,
    var(--hero);
}

body.is-playing .site-header {
  background: transparent;
}

.nav-bar,
.hero,
.app-shell,
.site-footer {
  width: var(--content);
  margin: 0 auto;
}

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 0;
}

body.is-playing .nav-bar {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  padding: 12px max(16px, calc((100vw - 1760px) / 2));
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(18, 35, 63, 0.94);
  backdrop-filter: blur(18px);
}

body.is-playing #libraryButton {
  display: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  font-weight: 850;
  text-decoration: none;
}

.brand-icon {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  background: #ffffff;
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
  font-size: 0.9rem;
  font-weight: 900;
}

.nav-action,
.hero-link,
.primary-button,
.secondary-button,
.choice-button,
.text-button {
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-action,
.hero-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: #ffffff;
  color: var(--hero);
  font-weight: 850;
  padding: 0.72rem 1rem;
  text-decoration: none;
}

.nav-action:hover,
.hero-link:hover {
  background: #eef4ff;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(300px, 0.55fr);
  align-items: center;
  gap: clamp(24px, 5vw, 72px);
  min-height: clamp(300px, 44svh, 520px);
  padding: clamp(22px, 4vw, 56px) 0 clamp(34px, 5vw, 72px);
}

body.is-playing .hero {
  display: none;
}

.hero-copy {
  max-width: 920px;
}

.eyebrow {
  margin: 0 0 12px;
  color: #bde7ff;
  font-size: 0.86rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin-top: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 940px;
  margin-bottom: 16px;
  color: #ffffff;
  font-size: clamp(2.75rem, 6.2vw, 6.3rem);
  font-weight: 900;
  line-height: 0.98;
}

h2 {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: clamp(1.75rem, 3.2vw, 3.35rem);
  font-weight: 850;
  line-height: 1.05;
}

h3 {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: clamp(1.1rem, 1.5vw, 1.35rem);
  font-weight: 800;
  line-height: 1.12;
}

.subtitle {
  max-width: 850px;
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(1.02rem, 1.4vw, 1.24rem);
  line-height: 1.45;
}

.hero-link {
  margin-top: 24px;
}

.hero-stage {
  display: grid;
  min-height: clamp(220px, 30svh, 360px);
  place-items: center;
}

.device-shell {
  width: min(100%, 420px);
  aspect-ratio: 1.22;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-md);
  padding: 12px;
}

.device-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.04), rgba(15, 23, 42, 0.86)),
    url("images/Paleolithic.jpg") center / cover no-repeat,
    #24364f;
  color: #ffffff;
  padding: 22px;
}

.screen-kicker {
  color: #bde7ff;
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.device-screen strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.65rem, 3vw, 2.55rem);
  line-height: 1;
}

.device-screen p {
  max-width: 21rem;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.86);
}

.screen-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.screen-options span {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--hero);
  padding: 0.46rem 0.55rem;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 850;
}

.app-shell {
  padding: clamp(30px, 4vw, 58px) 0 clamp(42px, 6vw, 76px);
  outline: 0;
  scroll-margin-top: 88px;
}

body.is-playing .app-shell {
  padding-top: 96px;
}

.app-shell > section[aria-labelledby="libraryHeading"] > .subtitle {
  max-width: 960px;
  color: var(--muted);
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
  padding: 20px 0 30px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: clamp(16px, 1.5vw, 26px);
  margin-top: 28px;
}

.adventure-card,
.status-panel,
.game-panel,
.error-panel,
.warning-panel,
.classroom-box,
.ending-details,
.path-focus {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.adventure-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 410px;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.adventure-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.adventure-card.failed {
  border-color: #f0b8b2;
  background: #fff1f0;
}

.card-image,
.scene-image,
.scene-side-image {
  display: block;
  width: 100%;
  object-fit: cover;
  background: var(--surface-muted);
}

.card-image {
  aspect-ratio: 16 / 8.5;
  border-radius: 10px;
}

.adventure-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 0 4px 4px;
}

.adventure-card h3 {
  margin-bottom: 0;
}

.scene-image {
  aspect-ratio: 21 / 8;
  max-height: 360px;
  border-radius: var(--radius);
}

.scene-side-image {
  width: 100%;
  max-height: 420px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

body.is-playing .scene-image {
  display: block;
}

.card-meta,
.scene-meta {
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game-panel .scene-meta {
  display: none;
}

.card-description {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.topic-question {
  display: none;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-list span {
  border: 1px solid #cdd7e5;
  border-radius: 999px;
  background: #f3f7fb;
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 800;
  padding: 0.24rem 0.58rem;
}

.card-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-top: auto;
}

.primary-button,
.secondary-button,
.text-button,
.choice-button {
  border: 1px solid transparent;
  font-weight: 800;
  padding: 0.78rem 1rem;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.secondary-button,
.text-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.secondary-button:hover,
.text-button:hover {
  border-color: var(--line-strong);
  background: #f7faff;
  box-shadow: var(--shadow-sm);
}

.choice-button {
  width: 100%;
  min-height: 58px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: clamp(1rem, 1.1vw, 1.12rem);
  line-height: 1.45;
  text-align: left;
}

.choice-button:hover,
.choice-button:focus-visible {
  border-color: var(--primary);
  background: #eef4ff;
  color: var(--primary-dark);
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled,
.choice-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.hidden {
  display: none;
}

.status-panel,
.error-panel,
.game-panel,
.warning-panel {
  border-radius: var(--radius);
  padding: clamp(22px, 4vw, 42px);
}

.status-panel {
  min-height: 260px;
  display: grid;
  place-items: center;
  text-align: center;
}

.loader {
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  border: 4px solid rgba(36, 86, 214, 0.18);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.error-panel {
  border-color: #f0b8b2;
  background: #fff1f0;
}

.warning-panel {
  border-color: #f2cf91;
  background: #fff8e8;
  margin-top: 18px;
}

.error-list {
  margin: 14px 0 0;
  padding-left: 1.2rem;
}

body.is-playing {
  background:
    linear-gradient(180deg, rgba(245, 247, 251, 0.86), var(--page) 34rem),
    var(--adventure-bg-image) center top / cover fixed no-repeat,
    var(--page);
}

.game-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.34fr);
  gap: 28px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.game-layout,
.scene-main,
.scene-content {
  display: grid;
  min-width: 0;
}

.game-layout {
  display: contents;
}

.scene-main {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.36fr);
  gap: clamp(22px, 3vw, 42px);
  align-items: start;
}

.scene-content {
  grid-column: 1;
  grid-row: 1;
  gap: 22px;
}

.game-panel > .scene-image {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  aspect-ratio: 4 / 3;
  max-height: 420px;
}

.decision-panel {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  gap: 16px;
  min-width: 0;
  border-radius: var(--radius);
  background: #f8fafc;
  padding: clamp(18px, 2vw, 26px);
}

.scene-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.scene-text {
  max-width: 96ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: clamp(1.02rem, 1.18vw, 1.16rem);
  line-height: 1.75;
  white-space: pre-line;
}

.path-focus,
.classroom-box,
.ending-details {
  border-radius: var(--radius);
  padding: 16px 18px;
}

.path-focus {
  border-color: #b8d8d3;
  background: #e9f8f6;
  color: #0d514c;
  font-weight: 760;
}

.choice-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.classroom-box,
.ending-details {
  border-color: #f2cf91;
  background: #fff8e8;
}

.ending-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 900;
  min-height: 30px;
  padding: 0.24rem 0.68rem;
  white-space: nowrap;
}

.ending-good {
  background: var(--green);
}

.ending-bad {
  background: var(--red);
}

.ending-neutral {
  background: var(--gold);
}

.game-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-panel .game-actions {
  display: none;
}

.vocab-term {
  position: relative;
  display: inline;
  border-bottom: 2px solid rgba(36, 86, 214, 0.42);
  color: var(--primary-dark);
  cursor: help;
  font-weight: 820;
  text-decoration: none;
}

.vocab-popover {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  z-index: 20;
  width: min(320px, 82vw);
  padding: 12px 14px;
  border: 1px solid #1f2937;
  border-radius: 10px;
  background: #111827;
  box-shadow: var(--shadow-md);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 560;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.vocab-term:hover .vocab-popover,
.vocab-term:focus .vocab-popover,
.vocab-term:focus-within .vocab-popover {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (min-width: 1280px) {
  .library-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .hero-stage {
    display: none;
  }

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

  .game-layout {
    display: contents;
  }

  .scene-content {
    grid-column: 1;
    grid-row: 1;
  }

  .game-panel > .scene-image {
    grid-column: 1;
    grid-row: 2;
    max-height: 320px;
    aspect-ratio: 16 / 9;
  }

  .decision-panel {
    grid-column: 1;
    grid-row: 3;
  }

  .scene-main {
    grid-template-columns: 1fr;
  }

  .scene-side-image {
    max-height: 320px;
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 720px) {
  :root {
    --content: min(100% - 28px, 1760px);
  }

  body {
    font-size: 16px;
  }

  .brand-mark span:last-child {
    display: none;
  }

  .nav-bar {
    min-height: 62px;
  }

  .hero {
    padding: 24px 0 34px;
  }

  h1 {
    font-size: clamp(2.45rem, 14vw, 4.2rem);
  }

  .subtitle {
    font-size: 1rem;
  }

  .card-actions,
  .scene-title-row {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .text-button,
  .nav-action,
  .hero-link {
    width: 100%;
  }

  .card-image {
    aspect-ratio: 16 / 9;
  }

  .adventure-card {
    min-height: auto;
  }
}
