.tutorial-body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.tutorial-shell {
  width: min(1180px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tutorial-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 15px 18px;
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  background: rgba(10, 23, 32, 0.88);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.26);
}

.tutorial-brand {
  text-decoration: none;
}

.tutorial-brand .brand-letter {
  width: 32px;
}

.tutorial-brand .brand-letter > span {
  font-size: 2.45rem;
}

.tutorial-brand .brand-letter > small {
  font-size: 0.62rem;
}

.tutorial-heading h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.55rem, 4vw, 2.45rem);
}

.tutorial-heading > p:last-child {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.tutorial-progress {
  width: min(900px, 100%);
  margin: 0 auto;
}

.tutorial-progress__track {
  height: 7px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
}

.tutorial-progress__track span {
  display: block;
  width: 12.5%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), #fff0a5);
  transition: width 260ms ease;
}

.tutorial-progress p {
  margin: 7px 0 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.tutorial-progress strong {
  color: var(--gold);
}

.tutorial-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

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

.lesson-nav button {
  min-height: 52px;
  padding: 8px 11px;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 9px;
  background: rgba(10, 23, 32, 0.86);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.lesson-nav button span {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold);
  font-weight: 900;
}

.lesson-nav button small {
  color: #b8cbd7;
  font-size: 0.72rem;
  line-height: 1.25;
}

.lesson-nav button.is-current {
  border-color: rgba(241, 197, 90, 0.8);
  background: linear-gradient(145deg, rgba(83, 69, 28, 0.76), rgba(12, 29, 39, 0.95));
  box-shadow: 0 0 0 2px rgba(241, 197, 90, 0.1);
}

.lesson-card {
  min-height: 560px;
  padding: clamp(18px, 3vw, 32px);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(320px, 1.1fr);
  gap: clamp(20px, 4vw, 48px);
  align-items: center;
  background:
    radial-gradient(circle at 86% 18%, rgba(61, 126, 232, 0.13), transparent 32%),
    linear-gradient(145deg, rgba(20, 39, 52, 0.98), rgba(6, 15, 22, 0.98));
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.32);
}

.lesson-copy h2 {
  margin: 0 0 13px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 4vw, 2.8rem);
}

.lesson-text {
  color: #cedde6;
  line-height: 1.58;
}

.lesson-text p {
  margin: 0 0 13px;
}

.lesson-text strong {
  color: #fff2b4;
}

.lesson-callout {
  margin-top: 18px;
  padding: 13px 15px;
  border-left: 4px solid var(--gold);
  border-radius: 5px 10px 10px 5px;
  background: rgba(241, 197, 90, 0.08);
  color: #f3e8b9;
  line-height: 1.42;
}

.lesson-visual-wrap {
  min-width: 0;
}

.lesson-visual {
  min-height: 390px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px),
    rgba(2, 9, 14, 0.56);
  background-size: 24px 24px;
}

.visual-caption {
  min-height: 2.8em;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  line-height: 1.4;
}

.tutorial-controls {
  display: flex;
  justify-content: center;
  gap: 9px;
}

.demo-board {
  --demo-size: 5;
  width: min(100%, 390px);
  aspect-ratio: 1;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(var(--demo-size), 1fr);
  gap: 4px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 12px;
  background: rgba(1, 7, 11, 0.82);
  box-shadow: 0 18px 35px rgba(0,0,0,0.35);
}

.demo-tile {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 6px;
  display: grid;
  place-items: center;
  overflow: visible;
  color: white;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 4.5vw, 2rem);
  font-weight: 900;
  text-shadow: 0 2px 4px rgba(0,0,0,0.42);
  transition: transform 220ms ease, filter 220ms ease, box-shadow 220ms ease, background 220ms ease;
}

.demo-tile.red { background: linear-gradient(145deg, #ea5c67, #8f202b); }
.demo-tile.blue { background: linear-gradient(145deg, #629dff, #2454a4); }
.demo-tile.green { background: linear-gradient(145deg, #75c58a, #2c7040); }
.demo-tile.dark { background: linear-gradient(145deg, #233743, #101b22); }
.demo-tile.dead { background: linear-gradient(145deg, #707980, #30373c); color: #e1e5e8; filter: grayscale(1); }
.demo-tile.worn { box-shadow: inset 0 0 0 3px rgba(255,197,85,.6), inset 0 0 18px rgba(80,42,10,.35); }
.demo-tile.critical { box-shadow: inset 0 0 0 4px rgba(255,90,76,.8), inset 0 0 22px rgba(80,10,10,.5); animation: demoCritical .65s ease-in-out infinite alternate; }
@keyframes demoCritical { from { filter: brightness(.85); } to { filter: brightness(1.15); } }
.demo-tile.blank { color: transparent; }
.demo-tile.selected {
  z-index: 3;
  transform: scale(1.07);
  box-shadow: 0 0 0 3px white, 0 0 20px 6px rgba(255,255,255,0.45);
}
.demo-tile.target {
  z-index: 2;
  animation: tutorialGlow 780ms infinite alternate ease-in-out;
}
.demo-tile.protected::after {
  content: "↩";
  position: absolute;
  top: 2px;
  right: 4px;
  color: #e8f7ff;
  font-family: sans-serif;
  font-size: 0.58em;
}
.demo-tile.sub::before {
  content: attr(data-sub);
  position: absolute;
  left: 4px;
  bottom: 3px;
  min-width: 1.15em;
  min-height: 1.15em;
  padding: 1px;
  border-radius: 3px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.55);
  color: white;
  font-family: Georgia, serif;
  font-size: 0.42em;
}
.demo-tile.lock-top { border-top: 5px solid var(--gold); }
.demo-tile.lock-right { border-right: 5px solid var(--gold); }
.demo-tile.lock-bottom { border-bottom: 5px solid var(--gold); }
.demo-tile.lock-left { border-left: 5px solid var(--gold); }
.demo-tile.blast {
  animation: deltaBlast 760ms ease-out both;
}
.demo-tile.radius {
  box-shadow: inset 0 0 0 3px rgba(255, 224, 112, 0.72);
}

.delta-demo-wrap {
  width: min(100%, 390px);
  display: grid;
  gap: 12px;
  justify-items: center;
}

.delta-cap-badge {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid rgba(241, 197, 90, 0.45);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(28, 25, 12, 0.78);
  color: #f5e8ae;
  font-size: 0.78rem;
  font-weight: 850;
}

.delta-cap-icons {
  color: #fff2a8;
  font-family: Georgia, serif;
  font-size: 1.2rem;
  letter-spacing: 0.22em;
  white-space: nowrap;
}

.lock-cycle-note {
  margin: 7px 0 0;
  color: #bcd0dc;
  font-size: 0.7rem;
  text-align: center;
}

.demo-tile.cycle-focus {
  animation: lockChoicePulse 700ms ease-in-out infinite alternate;
}

@keyframes lockChoicePulse {
  from { filter: brightness(1); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12); }
  to { filter: brightness(1.18); box-shadow: inset 0 0 0 2px rgba(255, 238, 139, 0.75), 0 0 12px rgba(241, 197, 90, 0.35); }
}

.demo-score {
  width: min(100%, 430px);
  display: grid;
  gap: 12px;
}

.demo-score-row {
  padding: 13px 16px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  background: rgba(8, 20, 28, 0.9);
}

.demo-score-row.red { border-left: 6px solid var(--red); }
.demo-score-row.blue { border-left: 6px solid var(--blue); }
.demo-score-row strong { font-size: 1.05rem; }
.demo-score-row span { color: var(--muted); font-size: 0.78rem; }
.demo-score-row b { font-size: 1.3rem; }

.demo-result {
  padding: 22px;
  border: 1px solid rgba(241, 197, 90, 0.5);
  border-radius: 15px;
  text-align: center;
  background: linear-gradient(145deg, rgba(74, 60, 21, 0.82), rgba(8, 22, 30, 0.95));
}

.demo-result small {
  color: var(--gold);
  font-weight: 950;
  letter-spacing: 0.15em;
}

.demo-result h3 {
  margin: 8px 0;
  font-family: Georgia, serif;
  font-size: 2rem;
}

.demo-result p {
  margin: 0;
  color: #c9d9e3;
  line-height: 1.45;
}

@keyframes tutorialGlow {
  from { box-shadow: 0 0 4px 2px rgba(255,235,145,0.52), inset 0 0 5px rgba(255,255,255,0.12); }
  to { box-shadow: 0 0 16px 6px rgba(255,235,145,0.9), inset 0 0 12px rgba(255,255,255,0.28); }
}

@keyframes deltaBlast {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.13); filter: brightness(2); box-shadow: 0 0 25px 10px rgba(255,235,126,0.9); }
  100% { transform: scale(1); filter: brightness(1); }
}

@media (max-width: 850px) {
  .tutorial-header {
    grid-template-columns: 1fr auto;
  }

  .tutorial-brand {
    grid-column: 1 / -1;
    justify-self: center;
  }

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

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

  .lesson-nav button {
    min-height: 44px;
    padding: 6px;
    grid-template-columns: 24px 1fr;
  }

  .lesson-nav button span {
    width: 24px;
    height: 24px;
  }

  .lesson-nav button small {
    font-size: 0.62rem;
  }

  .lesson-card {
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .lesson-visual {
    min-height: 350px;
  }
}

@media (max-width: 560px) {
  .tutorial-shell {
    padding-inline: 7px;
    gap: 9px;
  }

  .tutorial-header {
    padding: 12px;
    grid-template-columns: 1fr;
    text-align: center;
    gap: 10px;
  }

  .tutorial-header > .ui-button {
    width: 100%;
  }

  .tutorial-heading > p:last-child {
    font-size: 0.78rem;
  }

  .tutorial-progress p {
    font-size: 0.68rem;
  }

  .lesson-nav {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 3px;
  }

  .lesson-nav button {
    min-width: 126px;
    scroll-snap-align: start;
  }

  .lesson-card {
    padding: 17px 12px;
    gap: 16px;
  }

  .lesson-copy h2 {
    font-size: 1.7rem;
  }

  .lesson-text {
    font-size: 0.9rem;
  }

  .lesson-visual {
    min-height: 300px;
    padding: 10px;
  }

  .demo-board {
    gap: 3px;
    padding: 4px;
  }

  .locks-demo {
    grid-template-columns: 1fr !important;
    width: min(100%, 330px) !important;
  }

  .tutorial-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .tutorial-controls .ui-button {
    width: 100%;
    padding-inline: 8px;
  }

  #replayLesson {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .demo-tile.target,
  .demo-tile.blast,
  .demo-tile.cycle-focus {
    animation: none;
  }
}

.attrition-demo-wrap { display:grid; gap:14px; justify-items:center; }
.attrition-counter { padding:9px 13px; border:1px solid rgba(241,197,90,.45); border-radius:999px; background:rgba(5,14,20,.88); color:#fff0a5; font-size:.78rem; font-weight:900; letter-spacing:.06em; text-align:center; }
