/* ==========================================================================
   VimWorm — css/screens.css
   Screen composition + the game stage: title screen, garden map, terminal,
   buffer/worm renderer surface, statusline, free roam, cheat sheet, overlays,
   toasts and the responsive contract. Loaded after css/base.css.

   CONTENTS
   01  Landing / title screen (hero, logo, mascot, how-to card, footer)
   02  Garden map (progress, chapters, level cards, rating stars)
   03  Game screen shell + lesson rail
   04  HUD + stage caption
   05  Terminal (chrome, body, scanlines)
   06  Buffer renderer surface (lines, chars, layers, worm, fruit, caret)
   07  Statusline (mode / pending / message / recent keys)
   08  Free roam
   09  Cheat sheet (hero, tabs, panels, groups, rows)
   10  Overlays: complete / help / confirm + rating stars
   11  Toast layer
   12  FX layer
   13  Keyframes owned by screens
   14  Responsive: ≤1100px · ≤900px · ≤620px
   ========================================================================== */

/* ==========================================================================
   01 · LANDING / TITLE SCREEN
   Two-column title layout: hero lockup on the left, "how to wiggle" card on
   the right. Footer pinned to the bottom of the viewport.
   ========================================================================== */

/* Per-screen modifiers: each inner panel owns its scroll area, so screens only
   clip stray horizontal fx. `clip` (not `hidden`) keeps the sticky topbar sticky. */
.screen--landing,
.screen--map,
.screen--game,
.screen--freeplay,
.screen--cheatsheet {
  overflow-x: clip;
  isolation: isolate;
}

.screen--landing {
  padding-bottom: 0;
}

.screen--landing > .landing {
  flex: 1 0 auto;
}

.landing {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(320px, 0.88fr);
  gap: clamp(2rem, 4vw, 4rem);
  align-items: center;
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  padding: clamp(1.2rem, 3vh, 2.4rem) var(--gutter) clamp(1.6rem, 4vh, 3rem);
}

/* ---- hero lockup -------------------------------------------------------- */

.hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
  padding-block: clamp(0.25rem, 1.5vh, 1.25rem);
}

.hero > * {
  animation: hero-rise 0.7s var(--ease-out) both;
}

.hero > :nth-child(1) {
  animation-delay: 40ms;
}

.hero > :nth-child(2) {
  animation-delay: 100ms;
}

.hero > :nth-child(3) {
  animation-delay: 180ms;
}

.hero > :nth-child(4) {
  animation-delay: 260ms;
}

.hero > :nth-child(5) {
  animation-delay: 340ms;
}

.hero > .eyebrow {
  margin-bottom: var(--sp-2);
}

.logo {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  margin: 0.4rem 0 0.15rem;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 9.5vw, 6.6rem);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.055em;
}

.logo__vim {
  color: var(--ink);
  text-shadow: 0 0 44px rgba(245, 241, 223, 0.12);
}

.logo__worm {
  background: linear-gradient(100deg, var(--lime) 0%, #dcffa0 32%, var(--mint) 68%, #9ff5ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(184, 255, 92, 0.32));
}

.logo__squiggle {
  position: absolute;
  left: 0.04em;
  bottom: -0.1em;
  width: 100%;
  height: 0.18em;
  overflow: visible;
  pointer-events: none;
}

.logo__squiggle path {
  fill: none;
  stroke: var(--lime);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 900;
  stroke-dashoffset: 900;
  filter: drop-shadow(0 0 7px rgba(184, 255, 92, 0.55));
  animation: logo-draw 1.5s var(--ease-out) 0.45s forwards;
}

.hero .tagline {
  /* clears the hand-drawn squiggle that hangs under the logo */
  margin-top: calc(var(--sp-3) + 0.5em);
}

/* ---- hero actions ------------------------------------------------------- */

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: var(--sp-6);
}

.hero__actions .btn--primary {
  box-shadow:
    0 14px 34px -12px rgba(184, 255, 92, 0.72),
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 0 0 1px rgba(7, 17, 15, 0.18) inset;
}

.hero__actions .btn--link {
  margin-left: 0.15rem;
}

/* ---- hero stats --------------------------------------------------------- */

.hero__stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(0.9rem, 3vw, 1.9rem);
  width: min(100%, 34rem);
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px dashed var(--line-soft);
}

.hero__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

.hero__stat-value {
  color: var(--lime);
  font-family: var(--font-mono);
  font-size: clamp(1.15rem, 2vw, 1.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  text-shadow: 0 0 18px rgba(184, 255, 92, 0.35);
}

.hero__stat-label {
  color: var(--ink-mute);
  font-size: 0.64rem;
  line-height: 1.3;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---- how-to card -------------------------------------------------------- */

.howto {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: clamp(1.35rem, 2.6vw, 2rem);
  margin-top: clamp(0.25rem, 2vh, 1.5rem);
  animation: hero-rise 0.7s 0.25s var(--ease-out) both;
}

.howto__title {
  margin-top: -0.1rem;
  font-size: clamp(1.2rem, 1.8vw, 1.45rem);
  letter-spacing: -0.025em;
}

.howto__steps {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.howto__steps li {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}

.howto__steps li > div {
  min-width: 0;
}

.howto__steps strong {
  color: var(--ink);
  font-weight: 600;
}

.howto__steps em {
  color: var(--lime);
  font-style: normal;
}

.howto__num {
  display: grid;
  flex: none;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  margin-top: 0.08rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--lime-soft);
  box-shadow: inset 0 0 12px rgba(184, 255, 92, 0.12);
  color: var(--lime);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.howto .keycaps {
  margin-top: 0.15rem;
}

.howto__foot {
  margin-top: 0.1rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--line);
  color: var(--ink-mute);
  font-size: 0.74rem;
  line-height: 1.5;
}

/* ---- mascot: a five-segment glow-worm, built from divs ------------------ */

.mascot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 96px;
  margin: 0 auto var(--sp-1);
  padding-right: 10px;
  background: radial-gradient(ellipse 210px 26px at 50% 88%, rgba(184, 255, 92, 0.18), transparent 72%);
}

.mascot__seg {
  position: relative;
  width: calc(31px - var(--i, 1) * 2px);
  height: calc(31px - var(--i, 1) * 2px);
  margin-left: -12px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #ecffb8 0%, var(--lime) 48%, #5aa82f 100%);
  box-shadow:
    inset -3px -4px 6px rgba(23, 60, 14, 0.45),
    inset 2px 2px 5px rgba(255, 255, 255, 0.4),
    0 0 16px rgba(184, 255, 92, 0.35);
  z-index: calc(10 - var(--i, 1));
  animation: mascot-wiggle 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i, 1) * -0.18s);
}

.mascot__seg:first-child {
  margin-left: 0;
}

.mascot__head {
  position: relative;
  z-index: 20;
  width: 62px;
  height: 56px;
  margin-left: -10px;
  border-radius: 52% 52% 46% 46%;
  background: radial-gradient(circle at 32% 24%, #f4ffc9 0%, #c9ff7c 38%, var(--lime) 62%, #68bd36 100%);
  box-shadow:
    inset -4px -6px 9px rgba(23, 60, 14, 0.4),
    inset 3px 3px 7px rgba(255, 255, 255, 0.5),
    0 0 24px rgba(184, 255, 92, 0.45);
  animation: mascot-bob 2.6s ease-in-out infinite;
}

.mascot__eye {
  position: absolute;
  top: 35%;
  width: 10px;
  height: 11px;
  border-radius: 50%;
  background: #0a1a10;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.18);
  animation: mascot-blink 5.4s ease-in-out infinite;
}

.mascot__eye::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}

.mascot__eye--l {
  left: 15px;
}

.mascot__eye--r {
  right: 15px;
  animation-delay: 0.1s;
}

.mascot__smile {
  position: absolute;
  bottom: 13px;
  left: 50%;
  width: 17px;
  height: 9px;
  border: 2.5px solid #0a1a10;
  border-top: 0;
  border-radius: 0 0 14px 14px;
  transform: translateX(-50%);
}

/* ---- landing footer ----------------------------------------------------- */

.landing__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-5);
  width: 100%;
  max-width: 1180px;
  margin: auto auto 0;
  padding: var(--sp-4) var(--gutter) var(--sp-6);
  border-top: 1px solid var(--line-soft);
}

.landing__note {
  color: var(--ink-mute);
  font-size: 0.76rem;
  line-height: 1.5;
}

.landing__note > span {
  margin-right: 0.35rem;
  color: var(--gold);
}

.landing__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* ==========================================================================
   02 · GARDEN MAP
   ========================================================================== */

.map {
  display: flex;
  flex-direction: column;
  gap: clamp(1.1rem, 2.5vh, 1.75rem);
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding: clamp(1rem, 2.5vh, 1.75rem) var(--gutter) var(--sp-10);
}

.map__progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(0.9rem, 2.2vw, 1.75rem);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-lg);
}

.map__progress-copy {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 10.5rem;
}

.map__progress-copy strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.map__progress .progress {
  flex: 1 1 10rem;
  min-width: 8rem;
}

.map__chapters {
  display: flex;
  flex-direction: column;
  gap: clamp(1.6rem, 3vw, 2.5rem);
}

/* ---- chapter headers ---------------------------------------------------- */

.chapter {
  display: flex;
  flex-direction: column;
}

.chapter__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding-bottom: 0.8rem;
  margin-bottom: 1rem;
  border-bottom: 1px dashed var(--line);
}

/* graceful fallback: if a chapter head ends up empty, don't leave a stray rule */
.chapter__head:empty {
  display: none;
}

.chapter__identity {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.chapter__numeral {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(184, 255, 92, 0.22), rgba(184, 255, 92, 0.04));
  box-shadow: inset 0 0 16px rgba(184, 255, 92, 0.1);
  color: var(--lime);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}

.chapter__heading {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.chapter__title {
  font-size: clamp(1.05rem, 1.4vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.chapter__blurb {
  color: var(--ink-mute);
  font-size: 0.82rem;
  line-height: 1.45;
}

/* ---- level grid + cards -------------------------------------------------- */

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 0.9rem;
}

.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.42rem;
  min-height: 156px;
  padding: 1rem 1.05rem 1.05rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    radial-gradient(120% 100% at 8% 0%, rgba(99, 242, 195, 0.06), transparent 62%),
    linear-gradient(162deg, rgba(20, 48, 40, 0.78), rgba(8, 22, 18, 0.9));
  color: var(--ink);
  font: inherit;
  text-align: left;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  translate: 0 0;
  scale: 1;
  transition:
    translate var(--dur-2) var(--ease),
    scale var(--dur-1) var(--ease),
    border-color var(--dur-2) var(--ease),
    box-shadow var(--dur-2) var(--ease);
}

.level-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 80% at 50% 118%, rgba(184, 255, 92, 0.09), transparent 62%);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease);
}

.level-card:hover {
  translate: 0 -3px;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md), 0 0 30px -14px var(--glow-lime);
}

.level-card:hover::before {
  opacity: 1;
}

.level-card:active {
  translate: 0 -1px;
  scale: 0.995;
}

.level-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.level-card__num {
  color: var(--mint);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.14em;
  opacity: 0.9;
}

.level-card__top .badge {
  padding: 0.12em 0.42em;
  border-color: rgba(255, 214, 107, 0.3);
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 0.52rem;
  letter-spacing: 0.08em;
}

.level-card__stars {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.1rem;
  font-size: 0.78rem;
}

.level-card__title {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.level-card__sub {
  color: var(--ink-mute);
  font-size: 0.8rem;
  line-height: 1.4;
}

.level-card__keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  margin-top: auto;
  padding-top: 0.4rem;
  padding-right: 1.5rem;
}

.level-card__keys kbd {
  padding: 0.12em 0.34em 0.16em;
  border-radius: 4px;
  font-size: 0.66rem;
}

.level-card__lock {
  position: absolute;
  right: 0.85rem;
  bottom: 0.85rem;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
  filter: grayscale(0.35);
}

/* current patch — the one the worm should visit next */
.level-card--current {
  border-color: rgba(184, 255, 92, 0.55);
  background:
    radial-gradient(120% 100% at 8% 0%, rgba(184, 255, 92, 0.12), transparent 60%),
    linear-gradient(162deg, rgba(26, 60, 46, 0.9), rgba(9, 24, 19, 0.94));
  box-shadow:
    0 0 0 1px rgba(184, 255, 92, 0.2),
    0 20px 46px -26px rgba(184, 255, 92, 0.55);
}

.level-card--current .level-card__num {
  color: var(--lime);
}

.level-card--current::before {
  opacity: 1;
}

.level-card--current::after {
  content: "";
  position: absolute;
  left: 0;
  top: 1.05rem;
  bottom: 1.05rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--lime), var(--mint));
  box-shadow: 0 0 12px var(--glow-lime);
}

/* locked patch */
.level-card--locked {
  border-style: dashed;
  background: rgba(10, 26, 21, 0.62);
  box-shadow: none;
  opacity: 0.52;
  filter: saturate(0.65);
  cursor: default;
}

.level-card--locked:hover {
  translate: none;
  border-color: var(--line);
  box-shadow: none;
  filter: saturate(0.65);
}

.level-card--locked:hover::before {
  opacity: 0;
}

/* chapter-closing "boss" patch */
.level-card--boss {
  border-color: rgba(255, 178, 122, 0.32);
}

.level-card--boss .level-card__num {
  color: var(--peach);
}

/* ---- rating stars -------------------------------------------------------- */

.stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  line-height: 1;
}

.star {
  display: inline-block;
  color: rgba(245, 241, 223, 0.16);
  font-size: 1.05rem;
  line-height: 1;
  transition: color var(--dur-2) var(--ease), text-shadow var(--dur-2) var(--ease);
}

.star:empty::before {
  content: "★";
}

.star--filled {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 214, 107, 0.55);
}

.level-card__stars .star {
  font-size: 0.78rem;
}

.stars--lg {
  gap: 0.5rem;
  margin-block: 0.2rem;
}

.stars--lg .star {
  font-size: clamp(1.9rem, 3.4vw, 2.6rem);
}

/* ==========================================================================
   03 · GAME SCREEN SHELL + LESSON RAIL
   ========================================================================== */

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  align-items: start;
  align-content: center;
  flex: 1 1 auto;
  gap: clamp(1rem, 1.8vw, 1.5rem);
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: clamp(0.85rem, 2vh, 1.4rem) var(--gutter) var(--sp-8);
}

.lesson-rail {
  position: sticky;
  top: 5.2rem;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.lesson-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: var(--sp-5);
  border-radius: var(--r-lg);
}

.lesson-card .eyebrow {
  margin-bottom: 0.1rem;
}

.lesson-card__title {
  font-size: clamp(1.25rem, 1.8vw, 1.5rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.lesson-card__brief {
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.5;
}

.lesson-card__label {
  margin-top: 0.55rem;
  color: var(--mint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.lesson-card .keycaps {
  margin-top: 0.1rem;
}

/* ---- garden goal preview ------------------------------------------------ */

.goal-preview {
  margin-top: 0.6rem;
}

.goal-preview .lesson-card__label {
  margin-top: 0;
}

.goal-preview__text {
  max-height: 9.5rem;
  margin-top: 0.4rem;
  padding: 0.7rem 0.8rem;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  background: rgba(4, 12, 9, 0.45);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre;
  tab-size: 1;
  scrollbar-width: thin;
}

.goal-preview__text--small {
  max-height: 7.5rem;
  font-size: 0.72rem;
}

/* ---- hint box ----------------------------------------------------------- */

.hint-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.55rem;
  margin-top: 0.7rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--line);
}

.hint-box__text {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-left: 2px solid var(--gold);
  border-radius: 0 8px 8px 0;
  background: var(--gold-soft);
  color: #ffe9b8;
  font-size: 0.82rem;
  line-height: 1.5;
  animation: hint-in var(--dur-3) var(--ease-out) both;
}

/* ---- stage column ------------------------------------------------------- */

.stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
}

/* ==========================================================================
   04 · HUD + STAGE CAPTION
   ========================================================================== */

.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(19, 45, 37, 0.7), rgba(8, 22, 18, 0.78));
  box-shadow: var(--inset-line);
}

.hud__goal {
  display: flex;
  flex: 1 1 12rem;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.hud__goal-label {
  flex: none;
  color: var(--lime);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.3;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.hud__goal .progress {
  flex: 1 1 auto;
  max-width: 20rem;
}

.hud__stats {
  display: flex;
  flex: none;
  align-items: center;
  gap: clamp(0.8rem, 1.8vw, 1.4rem);
}

.hud__stats .stat {
  align-items: center;
  min-width: 2.4rem;
}

.hud__stats .stat + .stat {
  padding-left: clamp(0.8rem, 1.8vw, 1.4rem);
  border-left: 1px solid var(--line);
}

.hud__stats .stat__value {
  font-size: 1.02rem;
}

.hud__stats .stat__label {
  font-size: 0.56rem;
  letter-spacing: 0.1em;
}

.stage-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.3rem 0.5rem;
  padding: 0 0.25rem;
  color: var(--ink-mute);
  font-size: 0.76rem;
  line-height: 1.5;
  text-align: center;
}

.stage-caption kbd {
  font-size: 0.66rem;
}

.stage-caption__hint {
  color: var(--ink-mute);
  opacity: 0.85;
  white-space: nowrap;
}

/* ==========================================================================
   05 · TERMINAL — soil-dark glass, chrome bar, scanlines
   ========================================================================== */

.terminal {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-color: rgba(178, 255, 206, 0.16);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(11, 30, 24, 0.97), rgba(6, 17, 14, 0.99));
  box-shadow:
    0 30px 80px -34px rgba(0, 0, 0, 0.95),
    0 0 0 1px rgba(0, 0, 0, 0.2),
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
}

.terminal__chrome {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(30, 62, 51, 0.82), rgba(14, 34, 28, 0.82));
}

.terminal__dots {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
}

.terminal__dots i {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--peach);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.35),
    0 0 6px rgba(255, 178, 122, 0.35);
}

.terminal__dots i:nth-child(2) {
  background: var(--gold);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.35),
    0 0 6px rgba(255, 214, 107, 0.3);
}

.terminal__dots i:nth-child(3) {
  background: var(--mint);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.35),
    0 0 6px rgba(99, 242, 195, 0.3);
}

.terminal__file {
  overflow: hidden;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.4;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.terminal__mode {
  flex: none;
  margin-left: auto;
  padding: 0.22em 0.6em;
  border-radius: var(--r-pill);
  background: var(--lime);
  box-shadow: 0 0 14px rgba(184, 255, 92, 0.32);
  color: #081307;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}

/* renderer adds .buffer.is-insert / .buffer.is-visual — chrome echoes the mode */
.terminal:has(.buffer.is-insert) .terminal__mode {
  background: var(--peach);
  box-shadow: 0 0 14px rgba(255, 178, 122, 0.42);
  color: #2a1204;
}

.terminal:has(.buffer.is-visual) .terminal__mode {
  background: var(--lavender);
  box-shadow: 0 0 14px rgba(199, 184, 255, 0.45);
  color: #1a1230;
}

.terminal__body {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(130% 100% at 12% 100%, rgba(99, 242, 195, 0.055), transparent 58%),
    #07130f;
}

/* faint CRT scanlines — only inside the terminal body, never over the chrome */
.terminal__body::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.03) 0 1px,
    transparent 1px 4px
  );
  opacity: 0.55;
  pointer-events: none;
}

/* ==========================================================================
   06 · BUFFER RENDERER SURFACE
   .buffer > .buffer__inner > (.buffer__lines > .bline > ...)
                                + .target-layer + .worm-layer + .caret
   JS positions worm/fruit/caret with --x/--y via transform: translate().
   ========================================================================== */

.buffer {
  position: relative;
  overflow: auto;
  min-height: clamp(14rem, 38vh, 22rem);
  max-height: clamp(20rem, 62vh, 40rem);
  padding: 1.05rem 1rem 0.95rem 0.55rem;
  color: var(--ink);
  font-family: var(--font-mono);
  /* squash the inline-block baseline gap; inner re-declares the real sizes */
  font-size: 0;
  line-height: 0;
  tab-size: 1;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.buffer__inner {
  position: relative;
  display: inline-block;
  width: max-content;
  min-width: 100%;
  padding-right: 0.9rem;
  font-size: var(--buffer-fs);
  line-height: var(--buffer-lh);
  vertical-align: top;
  tab-size: 1;
}

.buffer__lines {
  position: relative;
  z-index: 1;
}

/* ---- lines & the line-number gutter ------------------------------------ */

.bline {
  display: flex;
  align-items: stretch;
  height: var(--buffer-lh);
  line-height: var(--buffer-lh);
}

.bline__num {
  display: flex;
  flex: 0 0 2.1rem;
  align-items: center;
  justify-content: flex-end;
  width: 2.1rem;
  padding-right: 0.9rem;
  color: rgba(245, 241, 223, 0.2);
  font-family: var(--font-mono);
  font-size: 0.9em;
  line-height: var(--buffer-lh);
  text-align: right;
  user-select: none;
  -webkit-user-select: none;
}

.bline__chars {
  flex: 0 0 auto;
  white-space: pre;
  tab-size: 1;
}

/* ---- character cells --------------------------------------------------- */

.bchar {
  display: inline;
  white-space: pre;
}

.bchar.is-space,
.bchar--empty {
  white-space: pre;
}

/* the worm head sits on top, but a soft under-glow makes the cell feel alive */
.bchar.is-cursor {
  border-radius: 2px;
  background: rgba(184, 255, 92, 0.1);
}

/* optional renderer hint (never required): a dotted hint under the cell */
.bchar.is-cursor-hint {
  border-radius: 2px;
  box-shadow: inset 0 -1px 0 rgba(184, 255, 92, 0.45);
}

/* visual mode selection — lavender wash that fills the row nicely */
.bchar.is-selected {
  border-radius: 2px;
  background: rgba(199, 184, 255, 0.22);
  box-shadow:
    0 0.3em 0 rgba(199, 184, 255, 0.22),
    0 -0.3em 0 rgba(199, 184, 255, 0.22);
  color: #ffffff;
}

/* /search matches */
.bchar.is-search-match {
  border-radius: 2px;
  background: rgba(255, 214, 107, 0.18);
  box-shadow:
    0 0.26em 0 rgba(255, 214, 107, 0.18),
    0 -0.26em 0 rgba(255, 214, 107, 0.18),
    inset 0 -2px 0 rgba(255, 214, 107, 0.55);
}

.bchar.is-search-current {
  border-radius: 2px;
  background: var(--gold);
  box-shadow:
    0 0.24em 0 var(--gold),
    0 -0.24em 0 var(--gold),
    0 0 14px rgba(255, 214, 107, 0.5);
  color: #1b1405;
}

/* landable goal / fruit cell */
.bchar.is-target {
  border-radius: 2px;
  color: var(--peach);
  text-shadow: 0 0 10px rgba(255, 178, 122, 0.55);
  box-shadow: inset 0 -2px 0 rgba(255, 178, 122, 0.75);
}

/* already collected / removed cell */
.bchar.is-eaten {
  color: var(--ink-mute);
  opacity: 0.5;
}

/* insert-mode caret hint on the character cell (the caret element draws on top) */
.bchar.is-insert-caret-before {
  box-shadow: inset 2px 0 0 rgba(184, 255, 92, 0.85);
}

/* ---- mode tints around the whole buffer --------------------------------- */

.buffer.is-insert {
  box-shadow:
    inset 0 0 0 1px rgba(255, 178, 122, 0.16),
    inset 0 0 70px rgba(255, 178, 122, 0.05);
}

.buffer.is-visual {
  box-shadow:
    inset 0 0 0 1px rgba(199, 184, 255, 0.2),
    inset 0 0 70px rgba(199, 184, 255, 0.06);
}

/* ---- absolute layers ---------------------------------------------------- */

.target-layer,
.worm-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.target-layer {
  z-index: 2;
}

.worm-layer {
  z-index: 4;
}

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

/* ---- worm: head + eyes + trailing segments ----------------------------- */

.worm__head {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  width: 1.5rem;
  height: 1.4rem;
  margin-top: calc(var(--cell-h, 1.15rem) * 0.5 - 0.7rem);
  margin-left: calc(var(--cell-w, 0.6rem) * 0.5 - 0.75rem);
  border-radius: 54% 46% 44% 56% / 52% 52% 48% 48%;
  background: radial-gradient(circle at 33% 26%, #f4ffd0 0%, #d0ff8a 30%, var(--lime) 58%, #6cc236 100%);
  box-shadow:
    0 0 16px rgba(184, 255, 92, 0.55),
    0 0 34px rgba(184, 255, 92, 0.22),
    inset -3px -4px 7px rgba(26, 64, 18, 0.35),
    inset 2px 2px 5px rgba(255, 255, 255, 0.4);
  transform: translate(var(--x, 0px), var(--y, 0px));
  rotate: calc(var(--worm-dir-y, 0) * 5deg);
  transition:
    transform 90ms cubic-bezier(0.2, 0.9, 0.3, 1),
    rotate 160ms var(--ease),
    box-shadow var(--dur-2) var(--ease);
  animation: worm-idle 3.6s ease-in-out infinite;
  will-change: transform;
}

/* a tiny content smile, drawn under the eyes */
.worm__head::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 17%;
  width: 0.42rem;
  height: 0.24rem;
  border: 2px solid #0c2412;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  opacity: 0.85;
  transform: translateX(-50%);
}

.worm__eye {
  position: absolute;
  top: 30%;
  width: 0.34rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #081810;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
  translate: calc(var(--worm-dir-x, 0) * 1.5px) calc(var(--worm-dir-y, 0) * 1px);
  transition: translate var(--dur-2) var(--ease);
  animation: worm-blink 6.4s var(--ease) infinite;
  animation-delay: 1.2s;
}

.worm__eye::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 2px;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
}

.worm__eye--l {
  left: 22%;
}

.worm__eye--r {
  right: 22%;
  animation-delay: 1.3s;
}

.worm__seg {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 0.68rem;
  height: 0.68rem;
  margin-top: calc(var(--cell-h, 1.15rem) * 0.5 - 0.34rem);
  margin-left: calc(var(--cell-w, 0.6rem) * 0.5 - 0.34rem);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #efffc2 0%, var(--lime) 55%, #6abe35 100%);
  box-shadow:
    0 0 10px rgba(184, 255, 92, 0.4),
    inset -2px -3px 5px rgba(26, 64, 18, 0.4),
    inset 1px 1px 3px rgba(255, 255, 255, 0.4);
  transform: translate(var(--x, 0px), var(--y, 0px));
  transition: transform 170ms cubic-bezier(0.22, 0.9, 0.3, 1);
  /* renderer sets --seg = 0..n-1 on each segment: trailing stagger */
  transition-delay: calc(var(--seg, 0) * 16ms);
  will-change: transform;
}

/* mode-specific worm moods (renderer classes) */
.worm.is-inserting .worm__head {
  box-shadow:
    0 0 18px rgba(255, 178, 122, 0.6),
    0 0 36px rgba(255, 178, 122, 0.24),
    inset -3px -4px 7px rgba(26, 64, 18, 0.35),
    inset 2px 2px 5px rgba(255, 255, 255, 0.4);
}

.worm.is-searching .worm__head {
  box-shadow:
    0 0 18px rgba(199, 184, 255, 0.62),
    0 0 36px rgba(199, 184, 255, 0.26),
    inset -3px -4px 7px rgba(26, 64, 18, 0.35),
    inset 2px 2px 5px rgba(255, 255, 255, 0.4);
}

/* ---- fruit targets ------------------------------------------------------ */

.fruit {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  margin-top: calc(var(--cell-h, 1.15rem) * 0.5 - 1.35rem);
  margin-left: calc(var(--cell-w, 0.6rem) * 0.5 - 0.45rem);
  font-size: 0.9rem;
  line-height: 1;
  transform: translate(var(--x, 0px), var(--y, 0px));
  filter: drop-shadow(0 0 7px rgba(255, 178, 122, 0.7)) drop-shadow(0 0 18px rgba(255, 178, 122, 0.3));
  animation: fruit-bob 2.8s ease-in-out infinite;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.fruit.is-eaten {
  /* opacity fallback: under reduced motion (animations off) the fruit still
     disappears immediately instead of lingering on screen. */
  opacity: 0;
  animation: fruit-eaten 0.46s var(--ease-out) forwards;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
}

/* ---- insert caret ------------------------------------------------------- */

.caret {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--lime);
  box-shadow:
    0 0 8px rgba(184, 255, 92, 0.85),
    0 0 18px rgba(184, 255, 92, 0.35);
  transform: translate(var(--x, 0px), var(--y, 0px));
  transition: transform 80ms linear;
  animation: caret-blink 1.1s steps(1, end) infinite;
  pointer-events: none;
}

/* ==========================================================================
   07 · STATUSLINE
   ========================================================================== */

.statusline {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.35rem;
  padding: 0.3rem 0.7rem;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 52, 42, 0.95), rgba(11, 28, 23, 0.97));
  font-family: var(--font-mono);
  font-size: 0.7rem;
  line-height: 1.2;
}

.statusline__mode {
  flex: none;
  padding: 0.24em 0.6em;
  border-radius: 5px;
  background: var(--lime);
  box-shadow: 0 0 14px rgba(184, 255, 92, 0.32);
  color: #081307;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}

/* render.js sets data-mode on the mode block */
.statusline__mode[data-mode="insert"] {
  background: var(--peach);
  box-shadow: 0 0 14px rgba(255, 178, 122, 0.42);
  color: #2a1204;
}

.statusline__mode[data-mode="visual"],
.statusline__mode[data-mode="visual-line"] {
  background: var(--lavender);
  box-shadow: 0 0 14px rgba(199, 184, 255, 0.45);
  color: #1a1230;
}

.statusline__pending {
  flex: none;
  min-width: 1ch;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.statusline__pending:empty {
  display: none;
}

.statusline__spacer {
  flex: 1 1 auto;
}

.statusline__message {
  overflow: hidden;
  max-width: 44ch;
  color: var(--ink-dim);
  font-size: 0.68rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.statusline__message:empty {
  display: none;
}

.statusline__keys {
  flex: none;
  max-width: 40%;
  overflow: hidden;
  color: var(--ink-mute);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.statusline__keys:empty {
  display: none;
}

/* ==========================================================================
   08 · FREE ROAM
   ========================================================================== */

.freeplay-layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  align-items: start;
  gap: clamp(1rem, 1.8vw, 1.5rem);
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: clamp(0.9rem, 2vh, 1.4rem) var(--gutter) var(--sp-8);
}

.fp-rail {
  position: sticky;
  top: 5.2rem;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.fp-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  padding: var(--sp-5);
  border-radius: var(--r-lg);
}

.fp-card__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.fp-card__list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fp-card__list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  color: var(--ink-dim);
  font-size: 0.84rem;
  line-height: 1.5;
}

.fp-card__list kbd {
  font-size: 0.7rem;
}

.fp-card__label {
  margin-top: 0.2rem;
  color: var(--mint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.fp-card__note {
  padding: 0.55rem 0.7rem;
  border: 1px dashed var(--line-soft);
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.18);
  color: var(--ink-mute);
  font-size: 0.8rem;
  line-height: 1.5;
}

.fp-card--tip {
  background:
    radial-gradient(120% 100% at 90% 0%, rgba(255, 214, 107, 0.08), transparent 60%),
    linear-gradient(165deg, rgba(21, 51, 42, 0.7), rgba(8, 22, 18, 0.9));
}

.fp-card--tip .eyebrow {
  color: var(--gold);
}

.fp-card--tip .eyebrow::before {
  background: linear-gradient(90deg, transparent, var(--gold));
}

.fp-card--tip > p:last-child {
  color: var(--ink-dim);
  font-size: 0.84rem;
  line-height: 1.55;
}

.screen--freeplay .buffer {
  max-height: clamp(20rem, 58vh, 40rem);
}

/* ==========================================================================
   09 · CHEAT SHEET
   ========================================================================== */

.cheatsheet {
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 2vh, 1.4rem);
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding: clamp(0.9rem, 2.2vh, 1.5rem) var(--gutter) var(--sp-10);
}

.cheat-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(1.2rem, 3vw, 2.5rem);
  padding: clamp(1.3rem, 2.5vw, 1.9rem) clamp(1.3rem, 3vw, 2.1rem);
  border-radius: var(--r-lg);
}

.cheat-hero__title {
  margin-top: 0.4rem;
  font-size: clamp(1.3rem, 2.2vw, 1.75rem);
  line-height: 1.18;
}

.cheat-hero__body {
  margin-top: 0.5rem;
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

.cheat-hero__tip {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding-left: clamp(1rem, 2vw, 1.5rem);
  border-left: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}

.cheat-hero__tip em {
  color: var(--gold);
  font-style: normal;
  font-weight: 500;
}

/* ---- tab bar ------------------------------------------------------------ */

.cheat-tabs {
  position: sticky;
  top: 4.2rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: rgba(8, 23, 18, 0.88);
  box-shadow: var(--shadow-sm);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.cheat-tab {
  padding: 0.42rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  color: var(--ink-dim);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition:
    color var(--dur-2) var(--ease),
    background-color var(--dur-2) var(--ease),
    border-color var(--dur-2) var(--ease);
}

.cheat-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}

.cheat-tab.is-active {
  border-color: var(--line-strong);
  background: var(--lime-soft);
  box-shadow: inset 0 0 18px rgba(184, 255, 92, 0.1);
  color: var(--lime);
}

/* ---- panels ------------------------------------------------------------- */

.cheat-sections {
  display: block;
}

.cheat-panel {
  display: none;
  padding: clamp(1.2rem, 2.6vw, 1.8rem);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(165deg, rgba(18, 45, 37, 0.6), rgba(7, 20, 16, 0.82));
}

.cheat-panel.is-active {
  display: block;
  animation: panel-in var(--dur-3) var(--ease-out) both;
}

.cheat-panel__title {
  font-size: clamp(1.15rem, 1.8vw, 1.4rem);
}

.cheat-panel__blurb {
  margin-top: 0.3rem;
  color: var(--ink-mute);
  font-size: 0.85rem;
  line-height: 1.5;
}

.cheat-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1.1rem;
}

.cheat-group {
  padding: 0.95rem 1.1rem;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.02);
}

.cheat-group__title {
  margin-bottom: 0.35rem;
  color: var(--mint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.cheat-row {
  display: grid;
  grid-template-columns: minmax(5.6rem, 8.5rem) minmax(0, 1fr);
  align-items: baseline;
  gap: 0.8rem;
  padding: 0.36rem 0;
  border-bottom: 1px dashed rgba(178, 255, 206, 0.07);
}

.cheat-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.cheat-row__keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.22rem;
  font-size: 0.8rem;
}

.cheat-row__keys kbd {
  padding: 0.12em 0.32em 0.16em;
  border-radius: 4px;
  font-size: 0.68rem;
}

.cheat-row__sep {
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.cheat-row__desc {
  color: var(--ink-dim);
  font-size: 0.84rem;
  line-height: 1.5;
}

/* ==========================================================================
   10 · OVERLAYS · complete / help / confirm
   ========================================================================== */

/* help content is informational, so let it breathe (while staying scrollable) */
.modal--help .modal__content {
  max-height: min(64vh, 34rem);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2.5rem);
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 38%, rgba(7, 17, 15, 0.62), rgba(2, 8, 6, 0.86));
  -webkit-backdrop-filter: blur(9px) saturate(1.05);
  backdrop-filter: blur(9px) saturate(1.05);
}

.overlay.is-open {
  animation: overlay-in var(--dur-3) var(--ease-out) both;
}

.overlay.is-open .modal {
  animation: modal-in 0.42s var(--ease-bounce) both;
}

.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(34rem, 100%);
  max-height: calc(100svh - clamp(2rem, 8vw, 5rem));
  padding: clamp(1.4rem, 3.2vw, 2.3rem);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2xl);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(99, 242, 195, 0.1), transparent 55%),
    linear-gradient(168deg, rgba(24, 57, 47, 0.99), rgba(7, 21, 17, 0.99));
  box-shadow:
    0 48px 120px -32px rgba(0, 0, 0, 0.95),
    0 0 70px -24px rgba(184, 255, 92, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
  text-align: center;
}

.modal--small {
  width: min(26rem, 100%);
}

.modal--help {
  width: min(42rem, 100%);
  text-align: left;
}

.modal__title {
  font-size: clamp(1.5rem, 3vw, 2rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.modal__sub {
  margin-top: 0.4rem;
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.55;
}

.modal__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.modal__content {
  overflow-y: auto;
  max-height: min(56vh, 30rem);
  margin-top: 0.9rem;
  padding-right: 0.6rem;
  text-align: left;
  scrollbar-width: thin;
}

.modal__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: clamp(1.1rem, 2.5vw, 1.6rem);
}

/* ---- completion --------------------------------------------------------- */

.modal--complete .eyebrow {
  color: var(--gold);
}

.modal--complete .eyebrow::before {
  background: linear-gradient(90deg, transparent, var(--gold));
}

.complete-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1.2rem, 4vw, 2.5rem);
  margin-top: 1rem;
  padding: clamp(0.7rem, 2vw, 0.95rem) 1rem;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.22);
}

.complete-stats .stat {
  align-items: center;
}

.complete-stats .stat__value {
  font-size: 1.2rem;
}

.complete-keys {
  margin-top: 1rem;
}

.complete-keys .lesson-card__label {
  margin-top: 0;
  margin-bottom: 0.5rem;
  text-align: center;
}

.complete-keys .keycaps {
  justify-content: center;
}

/* ---- help overlay content ---------------------------------------------- */

.help-section {
  padding-bottom: 0.9rem;
  border-bottom: 1px dashed var(--line);
}

.help-section + .help-section {
  margin-top: 0.85rem;
}

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

.help-section__title {
  margin-bottom: 0.4rem;
  color: var(--mint);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.help-section__body {
  color: var(--ink-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

.help-section .keycaps {
  margin-top: 0.3rem;
}

.help-section .goal-preview__text {
  max-height: 8rem;
  margin-top: 0.55rem;
}

.help-hints {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.3rem;
}

.help-hint {
  position: relative;
  padding: 0.48rem 0.7rem 0.48rem 2.1rem;
  border: 1px solid rgba(255, 214, 107, 0.16);
  border-radius: var(--r-sm);
  background: rgba(255, 214, 107, 0.06);
  color: #f2e6c4;
  font-size: 0.86rem;
  line-height: 1.5;
}

.help-hint::before {
  content: "💡";
  position: absolute;
  left: 0.65rem;
  top: 0.58rem;
  font-size: 0.8rem;
  line-height: 1;
}

.help-keys {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.help-keys li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  color: var(--ink-dim);
  font-size: 0.84rem;
  line-height: 1.5;
}

.help-keys kbd {
  font-size: 0.7rem;
}

.help-keys__desc {
  color: var(--ink-mute);
}

/* star pop when a completion modal opens */
.overlay.is-open .stars--lg .star--filled {
  animation: star-pop 0.5s var(--ease-bounce) both;
}

.overlay.is-open .stars--lg .star--filled:nth-child(2) {
  animation-delay: 0.1s;
}

.overlay.is-open .stars--lg .star--filled:nth-child(3) {
  animation-delay: 0.2s;
}

/* ==========================================================================
   11 · TOAST LAYER
   ========================================================================== */

.toast-layer {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.5rem);
  bottom: clamp(0.75rem, 2vw, 1.5rem);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  width: max-content;
  max-width: min(92vw, 24rem);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.62rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(11, 30, 24, 0.97);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font-size: 0.85rem;
  line-height: 1.45;
  animation: toast-in 0.34s var(--ease-bounce) both;
}

.toast::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sky);
  box-shadow: 0 0 9px var(--sky);
}

.toast--good {
  border-color: rgba(184, 255, 92, 0.4);
}

.toast--good::before {
  background: var(--lime);
  box-shadow: 0 0 10px var(--lime);
}

.toast--error {
  border-color: rgba(255, 111, 111, 0.4);
}

.toast--error::before {
  background: var(--danger);
  box-shadow: 0 0 10px var(--danger);
}

.toast--info {
  border-color: rgba(124, 216, 255, 0.32);
}

/* ==========================================================================
   12 · FX LAYER
   Particles are inline-styled spans from js/fx.js; the layer only needs to
   be a transparent, click-through viewport-sized stage.
   ========================================================================== */

.fx-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-fx);
  overflow: hidden;
  pointer-events: none;
}

.fx-layer > * {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ==========================================================================
   13 · KEYFRAMES OWNED BY SCREENS
   ========================================================================== */

@keyframes hero-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes logo-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes mascot-wiggle {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-4px) rotate(2.5deg);
  }
}

@keyframes mascot-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-1.5deg);
  }
  50% {
    transform: translateY(-3px) rotate(1.5deg);
  }
}

@keyframes mascot-blink {
  0%,
  35%,
  44%,
  100% {
    transform: scaleY(1);
  }
  39%,
  41% {
    transform: scaleY(0.12);
  }
}

@keyframes worm-idle {
  0%,
  100% {
    scale: 1 1;
  }
  50% {
    scale: 1.04 1.04;
  }
}

@keyframes worm-blink {
  0%,
  92%,
  100% {
    scale: 1 1;
  }
  94%,
  96% {
    scale: 1 0.12;
  }
}

@keyframes caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.12;
  }
}

@keyframes fruit-bob {
  0%,
  100% {
    translate: 0 0;
    scale: 1;
  }
  50% {
    translate: 0 -4px;
    scale: 1.08;
  }
}

@keyframes fruit-eaten {
  0% {
    translate: 0 -2px;
    scale: 1.2;
    opacity: 1;
  }
  60% {
    translate: 0 -10px;
    scale: 1.9;
    opacity: 0.9;
  }
  100% {
    translate: 0 -16px;
    scale: 0.1;
    opacity: 0;
  }
}

@keyframes hint-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes star-pop {
  0% {
    scale: 0.4;
    opacity: 0;
  }
  60% {
    scale: 1.18;
    opacity: 1;
  }
  100% {
    scale: 1;
    opacity: 1;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ==========================================================================
   14 · RESPONSIVE
   ========================================================================== */

/* ---- tablets / small laptops ------------------------------------------- */

@media (max-width: 1100px) {
  .landing {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.9fr);
    gap: clamp(1.6rem, 3vw, 2.5rem);
  }

  .game-layout {
    grid-template-columns: minmax(215px, 245px) minmax(0, 1fr);
    gap: 1rem;
  }

  .freeplay-layout {
    grid-template-columns: minmax(230px, 270px) minmax(0, 1fr);
    gap: 1rem;
  }

  .lesson-rail,
  .fp-rail {
    position: static;
  }

  .hud__goal .progress {
    max-width: none;
  }

  .cheat-hero {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  }

  .cheat-groups {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

/* ---- stacked layout: rail below the stage ------------------------------- */

@media (max-width: 900px) {
  .landing {
    grid-template-columns: minmax(0, 1fr);
    max-width: 680px;
    gap: 2rem;
  }

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

  .hero__stats {
    width: 100%;
  }

  .howto {
    width: 100%;
  }

  .game-layout,
  .freeplay-layout {
    grid-template-columns: minmax(0, 1fr);
    max-width: 860px;
  }

  /* the playable stage comes first; the lesson notes settle underneath it */
  .stage-wrap {
    order: 1;
  }

  .lesson-rail {
    order: 2;
  }

  .fp-rail {
    order: 2;
  }

  .cheat-hero {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }

  .cheat-hero__tip {
    padding-top: 1rem;
    padding-left: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .cheat-tabs {
    position: static;
  }

  .map__progress {
    padding: 0.85rem 1rem;
  }

  .level-grid {
    grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  }
}

/* ---- phones ------------------------------------------------------------- */

@media (max-width: 620px) {
  .hero__actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: stretch;
  }

  .hero__actions .btn--xl {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .hero__actions .btn--link {
    grid-column: 1 / -1;
    justify-self: start;
  }

  /* landing: centered lockup, full-width CTAs */
  .landing {
    max-width: 100%;
    padding-top: 0.9rem;
    padding-bottom: 1.4rem;
  }

  .hero {
    align-items: center;
    text-align: center;
  }

  .hero .tagline {
    margin-inline: auto;
  }

  .logo {
    justify-content: center;
    font-size: clamp(2.9rem, 15.5vw, 4.4rem);
  }

  .tagline {
    max-width: 100%;
    font-size: 0.98rem;
  }

  .hero__actions {
    justify-content: center;
    width: 100%;
    margin-top: 1.3rem;
  }

  .hero__actions > .btn:not(.btn--link) {
    flex: 1 1 auto;
  }

  .hero__actions .btn--link {
    align-self: center;
    margin-left: 0;
  }

  .hero__stats {
    justify-content: center;
    gap: 0.8rem 1.2rem;
    padding-top: 0.9rem;
  }

  .hero__stat-value {
    font-size: 1.1rem;
  }

  .hero__stat-label {
    font-size: 0.56rem;
  }

  .howto {
    padding: 1.2rem;
  }

  .landing__footer {
    justify-content: center;
    padding-bottom: 1.6rem;
    text-align: center;
  }

  .landing__controls {
    justify-content: center;
  }

  /* map */
  .map,
  .game-layout,
  .freeplay-layout,
  .cheatsheet {
    padding-inline: 0.8rem;
  }

  .map__progress {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .map__progress-copy {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    min-width: 0;
  }

  .map__progress .progress {
    min-width: 0;
  }

  .map__progress .btn--primary {
    align-self: stretch;
  }

  .level-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.65rem;
  }

  .level-card {
    min-height: 138px;
    padding: 0.8rem 0.8rem 0.85rem;
    border-radius: var(--r-md);
  }

  .level-card__title {
    font-size: 0.92rem;
  }

  .level-card__sub {
    font-size: 0.74rem;
  }

  .level-card__keys {
    padding-right: 1.2rem;
  }

  .level-card__lock {
    right: 0.7rem;
    bottom: 0.7rem;
    font-size: 0.8rem;
  }

  .chapter__identity {
    gap: 0.7rem;
  }

  .chapter__numeral {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.8rem;
  }

  .chapter__blurb {
    font-size: 0.76rem;
  }

  /* game stage */
  .game-layout {
    gap: 0.8rem;
    padding-top: 0.7rem;
  }

  .hud {
    gap: 0.45rem 0.7rem;
    padding: 0.5rem 0.65rem;
  }

  .hud__goal {
    flex-basis: 100%;
  }

  .hud__stats {
    justify-content: space-between;
    width: 100%;
    gap: 0.5rem;
  }

  .hud__stats .stat {
    align-items: flex-start;
    min-width: 0;
  }

  .hud__stats .stat + .stat {
    padding-left: 0.8rem;
  }

  .terminal__chrome {
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
  }

  .terminal__dots i {
    width: 8px;
    height: 8px;
  }

  .terminal__file {
    font-size: 0.64rem;
  }

  .terminal__mode {
    font-size: 0.55rem;
  }

  .buffer {
    min-height: 12rem;
    max-height: 52vh;
    padding: 0.7rem 0.7rem 0.8rem 0.3rem;
  }

  .buffer__inner {
    padding-right: 0.6rem;
  }

  .bline__num {
    flex-basis: 1.7rem;
    width: 1.7rem;
    padding-right: 0.55rem;
  }

  .statusline {
    gap: 0.35rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.64rem;
  }

  .statusline__mode {
    font-size: 0.58rem;
  }

  .statusline__message {
    max-width: 20ch;
    font-size: 0.62rem;
  }

  .statusline__keys {
    display: none;
  }

  .stage-caption {
    font-size: 0.7rem;
  }

  .stage-caption__hint {
    display: none;
  }

  .lesson-card {
    padding: 1rem;
  }

  .lesson-card__brief {
    font-size: 0.85rem;
  }

  .goal-preview__text {
    max-height: 7rem;
    font-size: 0.7rem;
  }

  /* free roam */
  .fp-card {
    padding: 1rem;
  }

  .fp-rail {
    gap: 0.8rem;
  }

  /* cheat sheet */
  .cheat-hero {
    padding: 1rem;
  }

  .cheat-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0.35rem;
    border-radius: var(--r-md);
    scrollbar-width: none;
  }

  .cheat-tabs::-webkit-scrollbar {
    display: none;
  }

  .cheat-tab {
    flex: 0 0 auto;
    padding: 0.36rem 0.7rem;
    font-size: 0.76rem;
  }

  .cheat-panel {
    padding: 1rem;
  }

  .cheat-groups {
    grid-template-columns: minmax(0, 1fr);
  }

  .cheat-group {
    padding: 0.8rem 0.85rem;
  }

  .cheat-row {
    grid-template-columns: minmax(4.6rem, 6.4rem) minmax(0, 1fr);
    gap: 0.6rem;
  }

  .cheat-row__desc {
    font-size: 0.8rem;
  }

  /* overlays */
  .overlay {
    padding: 0.75rem;
  }

  .modal {
    padding: 1.15rem 1rem 1.2rem;
    border-radius: var(--r-xl);
    max-height: calc(100svh - 1.5rem);
  }

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

  .modal__actions .btn {
    width: 100%;
  }

  .modal__content {
    max-height: 48vh;
  }

  .modal--help .modal__content {
    max-height: 56vh;
  }

  .complete-stats {
    gap: 0.8rem;
    padding: 0.6rem 0.5rem;
  }

  .complete-stats .stat__value {
    font-size: 1rem;
  }

  .stars--lg .star {
    font-size: 2rem;
  }

  /* toasts */
  .toast-layer {
    right: 0.6rem;
    bottom: 0.6rem;
    left: 0.6rem;
    align-items: stretch;
    max-width: none;
  }

  .toast {
    font-size: 0.8rem;
  }
}
