:root {
  color-scheme: dark;
  --bg: #080b10;
  --panel: rgba(17, 25, 37, 0.9);
  --panel-soft: rgba(255,255,255,0.045);
  --line: rgba(142, 177, 222, 0.24);
  --text: #f4ead7;
  --muted: #aebbd0;
  --gold: #f5c45f;
  --blue: #79b8ff;
  --green: #72df9b;
  --red: #f07171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(121,184,255,0.16), transparent 32rem),
    linear-gradient(235deg, rgba(245,196,95,0.1), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button,
a {
  font: inherit;
}

button,
.game-link {
  min-height: 40px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  padding: 9px 12px;
  background: linear-gradient(180deg, #8f3f2d, #5e281f);
  color: #fff7e6;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}

button.secondary,
.game-link {
  background: linear-gradient(180deg, #34465f, #1e2a3a);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tutorial-shell {
  width: min(1180px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 20px;
}

.tutorial-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 10px 0 18px;
  border-bottom: 1px solid var(--line);
}

.tutorial-header-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0;
}

h1 {
  font-size: 42px;
  line-height: 0.95;
}

h2 {
  font-size: 30px;
  line-height: 1.05;
}

.lesson-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
  padding-top: 18px;
}

.lesson-nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.lesson-tab {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 3px 9px;
  width: 100%;
  text-align: left;
  background: var(--panel-soft);
}

.lesson-tab img {
  grid-row: span 2;
  display: block;
  width: 72px;
  aspect-ratio: 16 / 10;
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 6px;
  object-fit: cover;
  object-position: top center;
  background: #05080d;
}

.lesson-tab.active {
  border-color: rgba(121,184,255,0.58);
  background: rgba(121,184,255,0.13);
}

.lesson-tab span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.lesson-stage,
.board-panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.lesson-stage {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.lesson-copy {
  display: grid;
  gap: 7px;
}

.lesson-copy p:last-child {
  margin: 0;
  max-width: 68rem;
  color: #d8e1ee;
  line-height: 1.5;
}

.gameplay-frame {
  position: relative;
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(121,184,255,0.34);
  border-radius: 8px;
  background: #05080d;
  box-shadow: 0 18px 34px rgba(0,0,0,0.24);
}

.gameplay-frame img {
  display: block;
  width: 100%;
  max-height: 540px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: top center;
  background: #05080d;
}

.gameplay-frame figcaption {
  position: relative;
  z-index: 2;
  padding: 9px 11px;
  border-top: 1px solid rgba(255,255,255,0.09);
  color: #d8e1ee;
  font-size: 12px;
  font-weight: 800;
}

.gameplay-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.gameplay-pin {
  position: absolute;
  left: var(--pin-x);
  top: var(--pin-y);
  display: grid;
  grid-template-columns: 24px minmax(96px, max-content);
  align-items: center;
  gap: 7px;
  max-width: min(260px, 40%);
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff7e6;
  transform: translate(-12px, -12px);
  pointer-events: auto;
  cursor: default;
}

.gameplay-pin b {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.74);
  border-radius: 50%;
  background: rgba(245,196,95,0.95);
  color: #211507;
  font-size: 12px;
  box-shadow: 0 5px 16px rgba(0,0,0,0.4);
}

.gameplay-pin span {
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  background: rgba(5, 8, 13, 0.86);
  color: #fff5dc;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.25;
  box-shadow: 0 8px 20px rgba(0,0,0,0.36);
}

.gameplay-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.gameplay-checkpoint {
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  text-align: left;
}

.gameplay-checkpoint.active {
  border-color: rgba(245,196,95,0.66);
  box-shadow: 0 0 0 2px rgba(245,196,95,0.16);
}

.gameplay-checkpoint img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  object-position: top center;
  background: #05080d;
}

.checkpoint-copy {
  display: grid;
  gap: 4px;
  min-height: 88px;
  padding: 9px;
}

.checkpoint-copy strong {
  font-size: 13px;
}

.checkpoint-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.board-panel {
  padding: 12px;
}

.board-topline {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.board-topline span,
.stat-tile span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.score-pill {
  min-width: 92px;
  padding: 8px 10px;
  border: 1px solid rgba(245,196,95,0.28);
  border-radius: 8px;
  background: rgba(245,196,95,0.1);
  color: #ffe4a2;
  font-weight: 900;
  text-align: center;
}

.card-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  max-width: 100%;
}

.tutorial-card {
  position: relative;
  margin: 0;
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0,0,0,0.24);
}

.tutorial-card-art {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 5 / 7;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(121,184,255,0.22), transparent 56%),
    linear-gradient(145deg, rgba(255,255,255,0.12), transparent 32%),
    #101827;
}

.tutorial-card-art.monster {
  background:
    radial-gradient(circle at 50% 38%, rgba(240,113,113,0.3), transparent 56%),
    linear-gradient(145deg, rgba(255,255,255,0.1), transparent 32%),
    #17101a;
}

.tutorial-card-art.weapon {
  background:
    radial-gradient(circle at 62% 35%, rgba(121,184,255,0.32), transparent 58%),
    linear-gradient(145deg, rgba(255,255,255,0.13), transparent 32%),
    #0d1a2a;
}

.tutorial-card-art.potion {
  background:
    radial-gradient(circle at 50% 48%, rgba(114,223,155,0.28), transparent 58%),
    linear-gradient(145deg, rgba(255,255,255,0.12), transparent 32%),
    #0d221e;
}

.tutorial-card-art svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: saturate(1.12) contrast(1.04);
}

.tutorial-card-rank {
  position: absolute;
  left: 7px;
  top: 7px;
  display: inline-grid;
  min-width: 28px;
  min-height: 28px;
  place-items: center;
  padding: 3px 5px;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 7px;
  background: rgba(5, 8, 13, 0.76);
  color: #fff7e6;
  font-size: 12px;
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(0,0,0,0.28);
}

.tutorial-card-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #fff7e6;
  font-size: 28px;
  font-weight: 950;
}

.tutorial-card figcaption {
  display: grid;
  gap: 3px;
  min-height: 46px;
  padding: 8px;
  background: rgba(7, 11, 18, 0.88);
}

.tutorial-card strong {
  overflow-wrap: normal;
  font-size: 12px;
}

.tutorial-card span {
  color: var(--muted);
  font-size: 11px;
}

.tutorial-card.chosen {
  border-color: rgba(245,196,95,0.8);
  box-shadow: 0 0 0 2px rgba(245,196,95,0.3);
}

.tutorial-card.chosen::after {
  content: "Picked";
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(245,196,95,0.92);
  color: #211507;
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.tutorial-card.multiplier {
  border-color: rgba(121,184,255,0.66);
}

.turn-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.stat-tile {
  min-width: 0;
  padding: 9px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 8px;
  background: rgba(255,255,255,0.045);
}

.stat-tile strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.lesson-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.turn-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}

.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.24);
}

.turn-dot.active {
  background: var(--gold);
}

.lesson-timeline {
  display: grid;
  gap: 7px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 74px 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
}

.timeline-row img {
  display: block;
  width: 64px;
  aspect-ratio: 16 / 10;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  object-fit: cover;
  object-position: top center;
  background: #05080d;
}

.timeline-row.active {
  border-color: rgba(245,196,95,0.44);
  background: rgba(245,196,95,0.08);
}

.timeline-row b {
  color: #fff2cf;
  white-space: nowrap;
}

.timeline-row span {
  color: var(--muted);
  font-size: 12px;
}

.delta.good {
  color: var(--green);
}

.delta.bad {
  color: var(--red);
}

@media (max-width: 820px) {
  .tutorial-shell {
    padding: 14px;
  }

  .tutorial-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .tutorial-header-links {
    width: 100%;
  }

  .tutorial-header-links .game-link {
    flex: 1 1 132px;
    text-align: center;
  }

  h1 {
    font-size: 34px;
  }

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

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

  .lesson-tab {
    grid-template-columns: 1fr;
    min-height: 78px;
  }

  .lesson-tab img {
    width: 100%;
  }

  .card-board {
    grid-template-columns: repeat(5, minmax(96px, 1fr));
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 4px;
  }

  .turn-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gameplay-frame img {
    max-height: 360px;
    aspect-ratio: 4 / 3;
  }

  .gameplay-strip {
    grid-template-columns: 1fr;
  }

  .gameplay-checkpoint {
    display: grid;
    grid-template-columns: 42% minmax(0, 1fr);
  }

  .gameplay-checkpoint img {
    height: 100%;
    min-height: 128px;
  }

  .gameplay-pin {
    grid-template-columns: 22px;
    max-width: 46px;
  }

  .gameplay-pin b {
    width: 22px;
    height: 22px;
  }

  .gameplay-pin span {
    display: none;
  }

  .timeline-row {
    grid-template-columns: 64px 58px minmax(0, 1fr);
  }

  .timeline-row .delta {
    grid-column: 3;
  }
}
