/* Story campaign chrome: runner bar, chapter card, cutscene, encounter frame, chapter
   complete, and the campaign entry points on the Library / world page / title.
   Tokens only (see style.css and storybook.css); shared pieces are the .sb-* components.
   The diorama and stage styles live in story-stage.css; the voyage hub lives in voyage.css.
   Look: a Saturday-morning cartoon. Title cards over live scene art, sticker buttons, postcards.
   Rules for everything below: nothing important waits on an animation (buttons are visible and
   clickable from the first frame), and html.reduced-motion keeps every beat but drops the motion. */

/* ---------- Shared bits ---------- */

@keyframes story-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes story-rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes story-blink { 50% { opacity: 0; } }
@keyframes story-beg {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045) rotate(-0.6deg); }
}

.story-ico { display: inline-grid; place-items: center; flex: none; }
.story-ico .sb-icon { width: 1.25em; height: 1.25em; vertical-align: 0; }

.story-rule { display: flex; align-items: center; gap: 14px; justify-content: center; color: var(--sb-gold); margin: 6px auto 14px; max-width: 16rem; }
.story-rule::before, .story-rule::after { content: ''; flex: 1; height: 3px; border-radius: 2px; background: currentColor; opacity: 0.6; }
.story-rule span { font-size: 1.5rem; line-height: 1; }

/* "or press Enter": there is no Enter key on a touch screen. */
.story-keyhint { margin: 0; font-size: 0.9rem; color: var(--kh-ink, var(--ink-muted)); }
.story-keyhint kbd {
  display: inline-block;
  padding: 1px 8px 2px;
  border: 2px solid var(--sb-outline);
  border-radius: 8px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 2px 0 var(--sb-outline);
  font: 600 0.85rem/1.4 var(--font-mono);
}
@media (hover: none) { .story-keyhint { display: none; } }

/* The picture behind a title card or cutscene: a sky-to-sea gradient first (the page is complete
   without any script), the live scene fades in over it once the art kit has loaded. */
.card-art, .cut-art {
  --art-top: var(--sb-sky);
  --art-bottom: var(--sb-sea);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: linear-gradient(180deg, var(--art-top) 0%, var(--art-bottom) 100%);
}
.card-art[data-tone="day"], .cut-art[data-tone="day"] { --art-top: var(--sb-sky); --art-bottom: color-mix(in srgb, var(--sb-sea) 80%, var(--sb-deep)); }
.card-art[data-tone="night"], .cut-art[data-tone="night"] { --art-top: color-mix(in srgb, var(--sb-grape) 55%, var(--sb-deep)); --art-bottom: var(--sb-deep); }
.card-art[data-tone="warm"], .cut-art[data-tone="warm"] { --art-top: var(--sb-sand); --art-bottom: color-mix(in srgb, var(--sb-orange) 60%, var(--sb-sea)); }
.card-art[data-tone="sea"], .cut-art[data-tone="sea"] { --art-top: color-mix(in srgb, var(--sb-sea) 70%, var(--sb-sky)); --art-bottom: var(--sb-deep); }
.scene-canvas {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.is-painted > .scene-canvas { opacity: 1; }

/* ---------- Runner bar ----------
   DOM (campaign.js builds it):
     <div class="cmp-bar">
       <a class="cmp-bar-back" href="#"><svg class="sb-icon">back arrow</svg><span class="cmp-bar-back-label">Voyage</span></a>
       <span class="cmp-bar-title">Chapter 3 · At Full Steam</span>
       <div class="cmp-pips" role="list" aria-label="Step 2 of 4">
         <span class="cmp-pip is-passage is-type-line is-done" role="listitem"><svg class="sb-icon">quill</svg></span>
         ...
       </div>
     </div>
   States: .is-done (finished), .is-current (the step in play), neither (still to come).
   Types (is-type-*): lesson, game, line, passage, encounter, cutscene: each has its own sticker colour. */

.cmp { display: block; }
.cmp-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 18px;
}
.cmp-bar-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 18px 0 12px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 3px 0 var(--sb-outline);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.15s var(--ease-spring), box-shadow 0.15s;
}
.cmp-bar-back:hover { transform: translateX(-2px); }
.cmp-bar-back:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--sb-outline); }
.cmp-bar-back:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.cmp-bar-back .sb-icon { width: 1.3em; height: 1.3em; }
.cmp-bar .cmp-bar-title {
  display: block;
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 18px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 3px 0 var(--sb-outline);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmp-bar-step { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.9rem; }
.cmp-bar:has(.cmp-pips) .cmp-bar-step { display: none; }

.cmp-pips { display: flex; align-items: center; gap: 12px; margin: 0 0 0 auto; padding: 0; list-style: none; }

/* A pip is a sticker in its step type's colour: faded while ahead, solid once done. */
.cmp-pip {
  --pip: var(--sb-sun);
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid color-mix(in srgb, var(--sb-outline) 45%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--pip) 28%, var(--sb-chip));
  color: var(--sb-card-muted);
  transition: transform 0.3s var(--ease-spring), background-color 0.3s, color 0.3s;
}
.cmp-pip.is-type-lesson { --pip: var(--sb-kelp); }
.cmp-pip.is-type-game { --pip: var(--sb-pink); }
.cmp-pip.is-type-line, .cmp-pip.is-type-passage { --pip: var(--sb-sun); }
.cmp-pip.is-type-encounter { --pip: var(--sb-orange); border-radius: 11px; }
.cmp-pip.is-type-cutscene { --pip: var(--sb-grape); }
.cmp-pip .sb-icon { width: 18px; height: 18px; vertical-align: 0; }
.cmp-pip .story-ico .sb-icon { width: 18px; height: 18px; }
.cmp-pip + .cmp-pip::before { /* the thread between pips */
  content: '';
  position: absolute;
  top: 50%;
  right: calc(100% + 1px);
  width: 10px;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--sb-outline) 30%, transparent);
}
.cmp-pip.is-done {
  border-color: var(--sb-outline);
  background: var(--pip);
  color: var(--sb-outline);
  box-shadow: 0 2px 0 var(--sb-outline);
}
.cmp-pip.is-done + .cmp-pip::before { background: var(--sb-outline); }
.cmp-pip.is-current {
  border-color: var(--sb-outline);
  background: var(--pip);
  color: var(--sb-outline);
  transform: scale(1.18);
  box-shadow: 0 2px 0 var(--sb-outline), 0 0 0 4px color-mix(in srgb, var(--sb-glow-color) 55%, transparent);
  animation: sb-bob 2.4s ease-in-out infinite;
}
.cmp-pip.is-current + .cmp-pip::before { background: var(--sb-outline); }
.cmp-body { min-height: 60vh; }

@media (max-width: 599px) {
  .cmp-bar-back:has(.cmp-bar-back-label) { padding: 0; width: 44px; }
  .cmp-bar-back-label { display: none; }
  .cmp-bar:has(.cmp-pips) .cmp-bar-title { order: 3; flex-basis: 100%; }
  .cmp-pips { gap: 10px; }
  .cmp-pip { width: 32px; height: 32px; }
}

/* ---------- Plates (the 1870 engravings, shown on postcards) ---------- */

.plate { margin: 0; position: relative; }
.plate-frame { position: relative; aspect-ratio: 2 / 3; overflow: hidden; background: white; }
.plate-frame img, .plate-frame svg { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 24%; }
.plate-caption { padding-top: 6px; font-size: 0.85rem; font-style: italic; color: var(--ink-muted); }

/* ---------- The chapter card: a cartoon title card ----------
   <section class="story-card sb-frame">
     <div class="card-art" data-tone>  scene canvas, .card-head (ribbon, title, book pill), .card-host
     <div class="card-foot">           what's ahead (pips), the giant Begin button, "Track: ... change" */

.story-card {
  position: relative;
  max-width: 62rem;
  margin: 0 auto 6px;
  background: var(--sb-card);
  overflow: hidden;
  overflow: clip;
  animation: story-rise 0.5s var(--ease-out) both;
}
.story-card .card-art {
  display: flex;
  flex-direction: column;
  min-height: clamp(330px, 52vh, 470px);
  border-radius: calc(var(--radius-lg) - 6px) calc(var(--radius-lg) - 6px) 0 0;
  border-bottom: var(--sb-outline-w) solid var(--sb-outline);
}
.card-head {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: min(100%, 36rem);
  padding: 20px 24px 0;
}
.card-ribbon { font-size: 1.1rem; padding: 5px 22px 5px 20px; transform: rotate(-2deg); }
.card-title {
  margin: 6px 0 4px;
  font-size: clamp(2.3rem, 5.6vw, 4.2rem);
  line-height: 1.02;
  text-wrap: balance;
}
.card-narration { /* the story so far: a caption panel under the title, nobody's speech */
  margin: 2px 0 4px;
  max-width: 30rem;
  padding: 8px 14px 9px;
  border: 2px solid var(--sb-outline);
  border-radius: 16px;
  background: var(--sb-chip);
  color: var(--sb-chip-ink);
  box-shadow: 0 3px 0 var(--sb-outline);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  text-wrap: pretty;
}
.card-narration-tag { display: block; color: var(--sb-card-muted); font: 600 0.85rem/1.3 var(--font-display); }
.card-book { margin: 0; font-size: 0.95rem; background: var(--sb-chip); color: var(--sb-chip-ink); box-shadow: 0 2px 0 var(--sb-outline); }

/* The host, speaking. */
.host-says {
  --badge: 76px;
  display: flex;
  align-items: flex-end;
  gap: 22px; /* the bubble's tail and the badge's ring */
}
.host-badge { display: block; flex: none; width: var(--badge); height: var(--badge); margin-bottom: 6px; }
.host-badge .comp-badge { display: block; }
.host-badge .comp-badge.is-speaking { transform: none; }
.host-badge .comp-medal { box-shadow: 0 0 0 3px var(--who), 0 0 0 calc(3px + var(--sb-outline-w)) var(--sb-outline), 0 5px 0 calc(3px + var(--sb-outline-w)) var(--sb-outline); }
.host-bubble {
  position: relative;
  min-width: 0;
  padding: 22px 20px 14px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 26px;
  background: var(--sb-card);
  color: var(--sb-card-ink);
  box-shadow: var(--sb-pop);
}
.host-bubble::before { /* the tail, pointing at the speaker */
  content: '';
  position: absolute;
  left: -12px;
  bottom: 22px;
  width: 20px;
  height: 20px;
  background: var(--sb-card);
  border-left: var(--sb-outline-w) solid var(--sb-outline);
  border-bottom: var(--sb-outline-w) solid var(--sb-outline);
  border-bottom-left-radius: 5px;
  transform: rotate(45deg);
}
.host-name {
  position: absolute;
  top: -16px;
  left: 16px;
  padding: 1px 14px 2px;
  border: 2px solid var(--sb-outline);
  border-radius: 999px;
  background: var(--sb-sea);
  color: var(--sb-outline);
  box-shadow: 0 2px 0 var(--sb-outline);
  font: 600 0.95rem/1.3 var(--font-display);
  white-space: nowrap;
}
.host-says[data-who="ned"] .host-name { background: var(--sb-orange); }
.host-says[data-who="nemo"] .host-name { background: var(--sb-sun); }
.host-text { margin: 0; font-weight: 700; font-size: 1.15rem; line-height: 1.38; text-wrap: pretty; }
.card-host { /* in the flow under the title block, so a long title never hides behind it */
  position: relative;
  z-index: 2;
  align-self: flex-start;
  margin: auto 22px 22px;
  padding-top: 22px;
  max-width: min(calc(100% - 44px), 34rem);
}

/* The foot: what's ahead, then the giant Begin. */
.card-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px 28px;
  padding: 20px 28px 22px;
  background: var(--sb-card);
  color: var(--sb-card-ink);
  --kh-ink: var(--sb-card-muted);
}
.card-ahead { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card-ahead-label { margin: 0; color: var(--sb-card-muted); font: 700 0.95rem/1 var(--font-body); }
.card-pips { display: flex; flex-wrap: wrap; gap: 8px 10px; margin: 0; padding: 0; list-style: none; }
.card-pip { width: 42px; height: 42px; background: var(--pip); border-color: var(--sb-outline); color: var(--sb-outline); box-shadow: 0 2px 0 var(--sb-outline); animation: sb-pop 0.4s var(--ease-spring) both; animation-delay: calc(0.25s + var(--i, 0) * 0.07s); }
.card-pip .story-ico .sb-icon { width: 22px; height: 22px; }
.card-pip::before { display: none; }
.card-role { display: flex; align-items: center; gap: 8px; margin: 4px 0 0; color: var(--sb-card-muted); font-weight: 700; }
.card-role strong { color: var(--sb-card-ink); }
.card-role .story-ico { color: var(--accent); }
.card-foot .story-actions { grid-column: 2; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.story-begin, .story-continue, .story-continue-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
}
.story-begin {
  min-width: 15rem;
  min-height: 70px;
  padding: 10px 52px 14px;
  font-size: 1.9rem;
  animation: story-beg 2.4s ease-in-out 1s infinite;
}
.story-begin .story-ico .sb-icon { width: 1em; height: 1em; fill: currentColor; }
.story-continue-btn, .story-continue { min-height: 60px; padding: 8px 40px 12px; font-size: 1.5rem; }

/* "Track: Learning the keys · change" (the runner adds it under Begin): a small, tidy link. */
.story-card .cmp-track,
.story-card .cmp-track strong { color: var(--sb-card-muted); }
.story-card .cmp-track { margin: 0; font: 600 0.9rem/1.2 var(--font-body); }
.story-card .cmp-track strong { font-weight: 700; color: var(--sb-card-ink); }
.story-card .cmp-track .lesson-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 6px;
  color: var(--accent);
  font: 700 0.9rem var(--font-body);
}

@media (max-width: 719px) {
  .story-card .card-art { min-height: clamp(330px, 52vh, 400px); }
  .card-book { display: none; }
  .card-head { padding: 16px 16px 0; }
  .card-narration { padding: 6px 11px 7px; font-size: 0.9rem; line-height: 1.3; }
  .card-title { font-size: clamp(2.1rem, 10vw, 2.7rem); }
  .card-host { margin: auto 12px 14px; padding-top: 18px; max-width: calc(100% - 24px); }
  .host-says { --badge: 56px; gap: 18px; }
  .host-bubble { padding: 20px 14px 11px; border-radius: 22px; }
  .host-text { font-size: 1.02rem; line-height: 1.32; }
  .card-foot { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 18px; gap: 12px; }
  /* Begin stays on screen whatever the screen's height */
  .card-foot .story-actions {
    grid-column: 1;
    grid-row: auto;
    position: sticky;
    bottom: 0;
    z-index: 3;
    align-items: stretch;
    margin: 0 -16px -18px;
    padding: 22px 16px 14px;
    background: linear-gradient(to top, var(--sb-card) 68%, transparent);
  }
  .card-ahead { align-items: center; }
  .card-pips { justify-content: center; }
  .card-role { justify-content: center; }
  .story-begin { min-width: 0; min-height: 64px; font-size: 1.7rem; animation: none; }
  .story-card .cmp-track { text-align: center; }
}

/* ---------- Cutscene: a storybook page ---------- */

.story-page {
  max-width: 56rem;
  margin: 0 auto 6px;
  background: var(--sb-card);
  overflow: hidden;
  animation: story-rise 0.5s var(--ease-out) both;
}
.story-cutscene { cursor: pointer; }
.story-page .cut-art {
  height: clamp(190px, 32vh, 300px);
  border-radius: calc(var(--radius-lg) - 6px) calc(var(--radius-lg) - 6px) 0 0;
  border-bottom: var(--sb-outline-w) solid var(--sb-outline);
}
.story-page .cut-page.sb-card {
  --kh-ink: var(--sb-card-muted);
  padding: 26px clamp(20px, 5vw, 48px) 26px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
}
.story-cut-title {
  margin: 0 0 0.45em;
  color: var(--sb-card-ink);
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 4vw, 2.7rem);
  line-height: 1.08;
}
.story-cut-lines { min-height: 4em; }
.story-cut-line {
  margin: 0 0 0.7em;
  color: var(--sb-card-ink);
  font-weight: 700;
  font-size: clamp(1.25rem, 2.2vw, 1.6rem);
  line-height: 1.5;
  text-wrap: pretty;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.7s ease, transform 0.7s var(--ease-out);
}
.story-cut-line.is-in { opacity: 1; transform: none; }
.story-page .story-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-top: 18px; }

@media (max-width: 719px) {
  .story-page .cut-art { height: clamp(150px, 24vh, 210px); }
  .story-page .cut-page.sb-card { padding: 20px 18px 18px; }
  .story-page .story-actions { flex-direction: column; align-items: stretch; text-align: center; }
}

/* ---------- Encounter frame (mission card) ----------
   Structure and layout only (sizes, spacing, positions, motion); css/encounters.css loads after this
   file and owns the colours, borders, shadows and type of .story-frame[data-tone]. */

.story-frame {
  --pad: clamp(18px, 5vw, 36px);
  position: relative;
  margin: calc(var(--badge) / 2 + 12px) auto 5vh;
  padding: 0 var(--pad) 28px;
  text-align: center;
  animation: story-rise 0.6s var(--ease-out) both;
}
/* The emblem in a round porthole; with a countdown, a ring runs around it. */
.story-badge { position: relative; z-index: 1; width: var(--badge); height: var(--badge); margin: calc(var(--badge) / -2) auto 14px; }
.story-badge.has-ring { margin-bottom: 28px; }
.story-porthole {
  position: absolute;
  inset: 12px;
  overflow: hidden;
  border-radius: 50%;
}
.story-porthole svg { display: block; width: 100%; height: 100%; padding: 8px; overflow: visible; }
.story-ring { position: absolute; inset: 0; }
.story-ring svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.story-ring circle { fill: none; stroke-width: 6; }
.story-ring-bar { stroke-linecap: round; transition: stroke-dashoffset 0.1s linear; }
.story-count {
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  padding: 2px 14px 3px;
  border-radius: 999px;
  font: 600 0.9rem var(--font-display);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.story-frame-tag { margin: 0 0 10px; }
.story-frame-title { font-size: clamp(2rem, 6vw, 2.9rem); }
.story-frame-lines { max-width: 30rem; margin: 10px auto 0; text-wrap: pretty; }
.story-frame-lines p { margin: 0 0 0.5em; }

.story-rules { display: grid; gap: 10px; max-width: 32rem; margin: 18px auto 0; padding: 0; list-style: none; text-align: left; }
.story-rule-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px 16px 10px 10px;
  font-size: 1.12rem;
  line-height: 1.35;
  text-wrap: pretty;
  animation: story-in 0.5s var(--ease-out) both;
  animation-delay: calc(0.1s + var(--i, 0) * 0.12s);
}
.story-rule-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}
.story-rule-icon .sb-icon { width: 24px; height: 24px; }

/* The crew's line, in a speech bubble. */
.story-bark { display: flex; align-items: flex-start; gap: 20px; max-width: 32rem; margin: 20px auto 0; text-align: left; }
.story-bark-portrait { --badge: 56px; display: block; flex: none; width: var(--badge); height: var(--badge); }
.story-bark-portrait .comp-badge { display: block; }
.story-bark-portrait .comp-medal { box-shadow: 0 0 0 2px var(--who), 0 0 0 calc(2px + var(--sb-outline-w)) var(--sb-outline), 0 4px 0 calc(2px + var(--sb-outline-w)) var(--sb-outline); }
.story-bark-bubble {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 10px 16px 12px;
}
.story-bark-bubble::before { /* the tail, pointing back at the speaker */
  content: '';
  position: absolute;
  top: 16px;
  left: -9px;
  width: 14px;
  height: 14px;
  border-style: solid;
  border-radius: 0 0 0 4px;
  transform: rotate(45deg);
}
.story-bark-who { margin: 0 0 2px; font-family: var(--font-display); font-weight: 600; }
.story-bark-text { margin: 0; font-size: 1.15rem; line-height: 1.4; }

.story-frame .story-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; margin-top: 24px; position: relative; z-index: 1; }
.story-frame .story-keyhint { flex-basis: 100%; }

.em-ring { fill: none; stroke: var(--sb-outline); stroke-width: 2; opacity: 0.35; }
.em-line { fill: none; stroke: var(--sb-outline); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.story-frame-lose .em-ring { stroke: var(--sb-danger); opacity: 0.9; stroke-width: 3; }
.em-dot { fill: var(--sb-outline); }
.em-sweep { stroke: var(--sb-outline); stroke-width: 3; stroke-linecap: round; transform-origin: 60px 60px; animation: em-sweep 3.2s linear infinite; }
.em-ping { fill: var(--sb-danger); animation: em-ping 3.2s ease-out infinite; }
.em-rays path { stroke: var(--sb-sun); stroke-width: 3; stroke-linecap: round; }
.em-rays { transform-origin: 60px 60px; animation: em-spin 40s linear infinite; }
.em-disc { fill: var(--sb-sun); stroke: var(--sb-outline); stroke-width: 3; }
.em-star { fill: var(--sb-gold); stroke: var(--sb-outline); stroke-width: 2.4; stroke-linejoin: round; }
@keyframes em-sweep { to { transform: rotate(360deg); } }
@keyframes em-spin { to { transform: rotate(360deg); } }
@keyframes em-ping { 0%, 30% { opacity: 0; } 40% { opacity: 1; } 100% { opacity: 0; } }
@keyframes story-sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
.story-frame-lose .story-porthole svg { transform-origin: 50% 20%; animation: story-sway 5s ease-in-out infinite; }

@media (max-width: 719px) {
  .story-frame { margin-top: calc(var(--badge) / 2 + 4px); padding-bottom: 0; }
  .story-badge.has-ring { margin-bottom: 24px; }
  .story-frame-tag { margin-bottom: 6px; }
  .story-frame-title { font-size: clamp(1.9rem, 9vw, 2.3rem); }
  .story-rule-row { grid-template-columns: 38px minmax(0, 1fr); gap: 12px; padding-block: 8px; font-size: 1.05rem; line-height: 1.3; }
  .story-rule-icon { width: 38px; height: 38px; }
  .story-rule-icon .sb-icon { width: 21px; height: 21px; }
  .story-rules { gap: 8px; margin-top: 14px; }
  .story-frame .story-actions {
    position: sticky;
    bottom: 0;
    margin: 16px calc(-1 * var(--pad)) 0;
    padding: 14px var(--pad) 18px;
  }
  .story-frame .story-actions .btn { flex: 1 1 100%; }
}

/* ---------- Chapter complete ---------- */

.story-done { max-width: 62rem; margin: 0 auto; padding-bottom: 32px; }
.story-beat { visibility: hidden; opacity: 0; }
.story-beat.is-in { visibility: visible; opacity: 1; animation: story-rise 0.6s var(--ease-out) both; }

.story-done-head { padding: 4px 0 18px; text-align: center; }
.story-done-head .story-eyebrow { margin: 0 0 10px; }
.story-done-head .sb-ribbon { font-size: 1.1rem; padding: 5px 28px; }
.story-done-title { margin: 0 0 0.2em; font-size: clamp(2.2rem, 6.4vw, 3.8rem); line-height: 1.05; text-wrap: balance; }
.story-star-summary { margin: 8px 0 0; color: var(--ink); font-size: 1.15rem; font-weight: 700; }

/* three big stars, popping in one by one */
.story-stars { display: flex; justify-content: center; gap: clamp(6px, 3vw, 28px); margin: 14px 0 6px; padding: 0; list-style: none; }
.story-star { --star: clamp(66px, 19vw, 100px); display: flex; flex-direction: column; align-items: center; width: clamp(96px, 28vw, 168px); }
.story-star-slot { position: relative; display: grid; place-items: center; width: var(--star); height: var(--star); }
.story-star-icon { display: block; width: 100%; height: 100%; }
.story-star-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.story-star-fill { fill: color-mix(in srgb, var(--sb-card) 55%, transparent); }
.story-star-line { fill: none; stroke: var(--pending); stroke-width: 1; stroke-dasharray: 2 2.2; stroke-linejoin: round; stroke-linecap: round; }
.story-star-shine { fill: none; stroke: white; stroke-width: 1.3; stroke-linecap: round; opacity: 0; }
.story-star-note { margin-top: 10px; color: var(--ink-muted); font-size: 0.9rem; font-weight: 700; line-height: 1.25; text-align: center; text-wrap: balance; }
.story-star.is-lit .story-star-fill { fill: var(--sb-gold); }
.story-star.is-lit .story-star-line { stroke: var(--sb-outline); stroke-width: 1.5; stroke-dasharray: none; }
.story-star.is-lit .story-star-shine { opacity: 0.9; }
.story-star.is-lit .story-star-svg { filter: drop-shadow(0 4px 0 var(--sb-outline)); }
.story-star.is-lit .story-star-icon { animation: story-stamp 0.65s var(--ease-spring) both; }
.story-star.is-lit .story-star-note { color: var(--ink); }
.story-star.is-lit .story-star-slot::after { /* the shock ring of the pop */
  content: '';
  position: absolute;
  inset: 4px;
  border: 4px solid var(--sb-gold);
  border-radius: 50%;
  opacity: 0;
  animation: story-shock 0.7s ease-out both;
}
@keyframes story-stamp {
  0% { opacity: 0; transform: scale(0.2) rotate(-35deg); }
  45% { opacity: 1; transform: scale(1.3) rotate(8deg); }
  70% { transform: scale(0.92) rotate(-3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes story-shock { 0% { opacity: 0.8; transform: scale(0.7); } 100% { opacity: 0; transform: scale(1.9); } }
.story-bub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  border: 2px solid var(--sb-outline);
  border-radius: 50%;
  background: var(--sb-sun);
  pointer-events: none;
  animation: story-burst 1s var(--ease-out) var(--d) both;
}
@keyframes story-burst {
  0% { opacity: 0; transform: translate(0, 0) scale(0.3); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), calc(var(--dy) - 16px)) scale(1); }
}

.story-done-grid { display: grid; gap: 28px; align-items: start; margin-top: 4px; }
@media (min-width: 840px) { .story-done-grid { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); } }

/* The postcard: the chapter's 1870 engraving as a collectible. A white-bordered card, tilted, with a
   stamp and a postmark, that flips into place. */
.story-done-plate { text-align: center; }
.pc-wrap { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; padding: 10px 16px 6px; }
.pc {
  --pc-paper: color-mix(in srgb, white 94%, var(--sb-sand));
  position: relative;
  width: min(300px, 78vw);
  margin: 0 auto;
  padding: 12px 12px 8px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 12px;
  background: var(--pc-paper);
  box-shadow: var(--sb-pop), 0 16px 24px color-mix(in srgb, var(--sb-outline) 22%, transparent);
  transform: rotate(-3deg);
}
.pc-photo { border: 2px solid var(--sb-outline); border-radius: 6px; overflow: hidden; background: white; }
.pc-photo .plate-frame { aspect-ratio: 0.7; }
.pc-photo .plate-img { object-fit: cover; object-position: 50% 30%; }
.pc .plate-caption { padding: 8px 6px 2px; color: color-mix(in srgb, var(--sb-outline) 78%, white); font: italic 700 0.85rem/1.25 var(--font-body); text-align: center; text-wrap: balance; }
.pc-stamp {
  position: absolute;
  top: 20px;
  right: 18px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 1px;
  width: 42px;
  height: 52px;
  border: 4px dotted var(--pc-paper);
  background: var(--sb-sea);
  color: var(--sb-outline);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--sb-outline) 40%, transparent);
  transform: rotate(5deg);
}
.pc-stamp-ico .sb-icon { width: 20px; height: 20px; display: block; }
.pc-stamp-yr { font: 700 0.7rem/1 var(--font-display); }
.pc-postmark {
  position: absolute;
  bottom: 64px;
  right: -14px;
  display: flex;
  align-items: center;
  gap: 4px;
  transform: rotate(-9deg);
  color: var(--sb-outline);
  pointer-events: none;
}
.pc-postmark-waves { display: block; width: 34px; margin-right: -6px; }
.pc-postmark-waves svg { display: block; width: 100%; height: auto; fill: none; stroke: var(--sb-outline); stroke-width: 1.4; stroke-linecap: round; opacity: 0.7; }
.pc-postmark-text {
  padding: 3px 11px 4px;
  border: 2.5px solid var(--sb-outline);
  border-radius: 999px;
  background: color-mix(in srgb, var(--pc-paper) 90%, transparent);
  font: 600 0.85rem/1.15 var(--font-display);
  white-space: nowrap;
}
/* Sharp Eyes: a round sticker slapped on the photo's lower-left corner (the top-left is the "New postcard!"
   ribbon's, the top-right the stamp's) */
.pc-sharp {
  position: absolute;
  bottom: 52px;
  left: -18px;
  z-index: 2;
  display: grid;
  place-items: center;
  align-content: center;
  width: 74px;
  height: 74px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: 50%;
  background: var(--sb-pink);
  color: var(--sb-outline);
  box-shadow: 0 3px 0 var(--sb-outline);
  transform: rotate(-12deg);
  text-align: center;
}
.pc-sharp-eye svg { display: block; width: 32px; height: 20px; }
.pc-sharp-lid { fill: white; stroke: var(--sb-outline); stroke-width: 2.2; stroke-linejoin: round; }
.pc-sharp-iris { fill: var(--sb-sea); stroke: var(--sb-outline); stroke-width: 2; }
.pc-sharp-glint { fill: white; }
.pc-sharp-text { font: 700 0.72rem/1 var(--font-display); margin-top: 2px; }
.pc-mini .pc-sharp { top: -9px; bottom: auto; left: -9px; width: 30px; height: 30px; border-width: 2px; box-shadow: none; }
.pc-mini .pc-sharp-eye svg { width: 18px; height: 11px; }
.pc-mini .pc-sharp-text { display: none; }
.pc.pc-mini { width: 100px; padding: 5px; border-width: 2.5px; border-radius: 8px; box-shadow: 0 3px 0 var(--sb-outline); }
.pc-mini .plate-caption { display: none; }
.pc-mini .pc-photo { border-width: 2px; border-radius: 4px; }
.pc.is-landing:not(.is-landed) { animation: pc-land 1.1s var(--ease-spring) both; }
@keyframes pc-land {
  0% { opacity: 0; transform: perspective(700px) rotateY(-100deg) rotate(-14deg) scale(0.6); }
  55% { opacity: 1; transform: perspective(700px) rotateY(12deg) rotate(1deg) scale(1.06); }
  100% { opacity: 1; transform: rotate(-3deg); }
}

.story-newplate {
  position: absolute;
  top: -6px;
  left: -2px;
  z-index: 2;
  padding: 6px 24px 6px 22px;
  font-size: 1.1rem;
  opacity: 0;
  transform: rotate(-6deg);
}
.pc.is-landing + .story-newplate { animation: story-ribbon 0.5s var(--ease-spring) 0.8s both; }
.pc.is-landed + .story-newplate { animation: none; opacity: 1; }
@keyframes story-ribbon {
  0% { opacity: 0; transform: rotate(-6deg) scale(0.4); }
  70% { opacity: 1; transform: rotate(-6deg) scale(1.1); }
  100% { opacity: 1; transform: rotate(-6deg) scale(1); }
}
.story-added { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 16px 0 0; color: var(--ink); font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
.story-added .sb-icon { color: var(--accent); }

/* The host's last word, and the log: a handwritten card. */
.done-notes { display: flex; flex-direction: column; gap: 22px; }
.done-host { --badge: 72px; padding: 12px 6px 0; }
.done-host .talk-bubble { font-size: clamp(1.05rem, 2vw, 1.25rem); }
.log-page {
  --fs: 1.3rem;
  position: relative;
  padding: 24px 26px 18px;
  transform: rotate(0.5deg);
  font-family: var(--font-body);
  font-style: italic;
}
.log-page::before { /* a strip of tape */
  content: '';
  position: absolute;
  top: -15px;
  left: 50%;
  width: 96px;
  height: 28px;
  margin-left: -48px;
  border: 2px solid color-mix(in srgb, var(--sb-outline) 28%, transparent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--sb-sun) 70%, transparent);
  transform: rotate(-3deg);
}
.log-heading { margin: 0 0 2px; color: var(--sb-card-muted); font-size: 0.9rem; font-weight: 700; }
.log-date { margin: 0 0 10px; color: var(--sb-card-ink); font-family: var(--font-body); font-size: 1.15rem; font-style: italic; font-weight: 800; }
.log-entry {
  margin: 0;
  padding: 0;
  color: var(--sb-card-ink);
  font-size: var(--fs);
  font-style: italic;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.log-typed { color: var(--sb-card-ink); }
.log-rest { color: transparent; user-select: none; }
.story-done:not(.is-complete) .log-typed::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 1em;
  margin-right: -2px;
  border-left: 3px solid var(--sb-danger);
  vertical-align: -0.12em;
  animation: story-blink 0.8s steps(1) infinite;
}
.log-sign { margin: 8px 0 0; color: var(--sb-card-muted); font-weight: 700; font-style: italic; text-align: right; }
.log-page-sm { --fs: 1.1rem; padding: 18px 18px 14px; transform: none; }
.log-page-sm::before { display: none; }
.log-page-sm .log-date { font-size: 1.05rem; margin-bottom: 6px; }

/* Numbers */
.story-statsline { margin-top: 26px; }
.story-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; max-width: 40rem; margin: 0 auto; padding: 0; list-style: none; }
.story-chip { flex-direction: column; justify-content: center; gap: 2px; min-height: 0; padding: 12px 8px 10px; border-radius: var(--radius); text-align: center; }
.story-chip .story-ico .sb-icon { width: 1.6em; height: 1.6em; color: var(--accent); }
.story-chip-value { color: var(--sb-chip-ink); font-family: var(--font-display); font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 600; line-height: 1.1; }
.story-chip-label { order: 3; color: var(--sb-card-muted); font-size: 0.9rem; font-weight: 700; line-height: 1.2; }
.story-beat.is-in .story-chip { animation: sb-pop 0.5s var(--ease-spring) both; animation-delay: calc(0.1s + var(--i, 0) * 0.12s); }
.story-goal { max-width: 40rem; margin: 16px auto 0; text-align: center; }
.story-goal p { margin: 8px 0 0; color: var(--ink-muted); font-size: 0.95rem; font-weight: 700; }
.story-goal-bar { height: 16px; overflow: hidden; border: var(--sb-outline-w) solid var(--sb-outline); border-radius: 999px; background: var(--sb-chip); box-shadow: 0 3px 0 var(--sb-outline); }
.story-goal-bar span { display: block; height: 100%; min-width: 6px; border-radius: 999px; background: linear-gradient(180deg, rgb(255 255 255 / 0.45) 0 38%, transparent 38%), var(--sb-sea); }

/* "Next time...": a deep-sea banner with the ribbon across its top edge */
.story-teaser {
  position: relative;
  margin-top: 44px;
  padding: 40px clamp(18px, 4vw, 40px) 28px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--sb-deep) 82%, var(--sb-sea)) 0%, var(--sb-deep) 100%);
  box-shadow: var(--sb-pop);
  color: white;
  text-align: center;
}
.story-teaser-tag { position: absolute; top: 0; left: 50%; width: max-content; margin: 0; transform: translate(-50%, -50%); white-space: nowrap; }
.story-teaser-tag .sb-ribbon { padding: 6px 28px; font-size: 1.15rem; }
.story-teaser-next { margin: 0 0 8px; font-family: var(--font-display); font-size: clamp(1.8rem, 5.4vw, 2.7rem); font-weight: 600; line-height: 1.1; text-wrap: balance; }
.story-teaser-text { max-width: 34rem; margin: 0 auto 24px; font-size: clamp(1.15rem, 2.4vw, 1.35rem); font-weight: 700; line-height: 1.45; text-wrap: pretty; }
.story-teaser .story-actions { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.story-teaser .story-continue { min-width: 14rem; min-height: 64px; padding: 10px 44px 14px; font-size: 1.6rem; }
.story-done.is-complete .story-continue { animation: story-beg 2.4s ease-in-out infinite; }
.story-secondary { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 12px; }
main[data-screen="campaign"] .story-teaser .btn.story-alt { min-height: 44px; font-size: 1rem; }
.story-skip { margin: 18px 0 0; color: var(--ink-muted); font-size: 0.9rem; text-align: center; }
.story-done.is-complete .story-skip { display: none; }

.story-end-title { margin: 0 0 6px; font-size: clamp(2.6rem, 9vw, 4.6rem); line-height: 1; color: white; }
.story-end-line { max-width: 32rem; margin: 0 auto 20px; font-size: 1.25rem; font-weight: 700; line-height: 1.45; }
.story-end-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 30px; margin: 0 0 24px; }
.story-end-stats dt { color: color-mix(in srgb, white 85%, var(--sb-sea)); font-size: 0.9rem; font-weight: 700; }
.story-end-stats dd { margin: 0; font-family: var(--font-display); font-size: 1.7rem; }

@media (max-width: 599px) {
  .story-star-note { font-size: 0.85rem; }
  .story-chip { padding-inline: 4px; }
  .log-page { padding: 22px 18px 14px; --fs: 1.2rem; }
  .log-page-sm { padding: 14px 14px 12px; --fs: 1.05rem; }
  .story-teaser .story-continue { width: 100%; min-width: 0; }
}

/* Reduced motion keeps every beat and drops the movement: the global rule zeroes durations, so
   delays are zeroed here too, or something would sit invisible waiting for its turn. */
.reduced-motion .story-line, .reduced-motion .story-rule-row, .reduced-motion .story-chip,
.reduced-motion .story-card, .reduced-motion .story-page, .reduced-motion .story-frame,
.reduced-motion .story-beat, .reduced-motion .card-pip { animation-delay: 0s; }
.reduced-motion .story-newplate { animation: none; opacity: 1; }
.reduced-motion .pc { animation: none; }
.reduced-motion .story-begin, .reduced-motion .story-done.is-complete .story-continue, .reduced-motion .cmp-pip.is-current { animation: none; }
.reduced-motion .scene-canvas { transition: none; }

/* ---------- Campaign entry points (Library, world page, title) ---------- */

.story-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.story-cta .btn-primary { text-align: center; text-wrap: balance; }
.story-cta-btn { flex-direction: column; gap: 1px; line-height: 1.15; }
.story-cta-main { display: block; }
.story-cta-sub { display: block; font-family: var(--font-body); font-size: 0.9rem; font-weight: 700; white-space: normal; text-align: center; }
.story-shelf-cta {
  margin: 4px 0 14px;
  padding: 14px 16px;
  border: var(--sb-outline-w) solid var(--sb-outline);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--sb-sun) 14%, var(--sb-card));
  box-shadow: var(--sb-pop);
}
.story-shelf-cta .eyebrow { margin: 0 0 8px; color: var(--accent); }
.story-shelf-note { margin: 10px 0 0; font-size: 0.95rem; }
.lib-actions-free { align-items: center; gap: 8px 10px; }
.lib-actions-free .btn { min-height: 44px; padding: 6px 16px; font-size: 0.95rem; }
.story-free-label { margin: 0 4px 0 0; }

.story-hub { padding: 0; overflow: hidden; display: grid; }
.story-hub-plate .plate-frame { aspect-ratio: 16 / 9; height: 100%; }
.story-hub-plate .plate-img { object-fit: cover; object-position: 50% 28%; }
.story-hub-plate .plate-caption { display: none; }
.story-hub-body { padding: 20px 24px 24px; }
.story-hub-body .eyebrow { color: var(--accent); margin-bottom: 4px; }
.story-hub-body h2 { margin-bottom: 0.3em; }
@media (min-width: 780px) {
  .story-hub { grid-template-columns: 1.1fr 1fr; align-items: stretch; }
  .story-hub-plate, .story-hub-plate .plate-frame { height: 100%; }
}

.world-freeplay.is-secondary { margin-top: 12px; padding-top: 16px; border-top: 3px dashed var(--border); }
.world-freeplay.is-secondary > h2 { font-size: 1.3rem; color: var(--ink-muted); margin-bottom: 0.1em; }
.world-freeplay.is-secondary > p { margin-bottom: 12px; }
.world-freeplay.is-secondary .card { box-shadow: none; background: color-mix(in srgb, var(--surface) 60%, transparent); }
.world-freeplay.is-secondary .card h2 { font-size: 1.3rem; }

.title-hero .row .btn-lg { box-shadow: var(--sb-pop); }

/* In campaign chapters the diorama takes the stage; the on-screen keyboard would push the
   text below the fold, so it stays in drills and free play only... */
.cmp-view .tv-kb { display: none; }
/* ...except the learn track's guide (createGuide in js/screens/campaign.js): a short keyboard under the
   line, with the stage squeezed to make room. The Settings toggle doesn't hide this one. */
.cmp-view.is-guide-open .tv-kb,
.hide-keyboard .cmp-view.is-guide-open .tv-kb { display: block; position: relative; margin-top: 10px; animation: guide-in 0.35s var(--ease-spring) both; }
@keyframes guide-in { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
.cmp-view.has-guide .kb { max-width: 660px; }
.cmp-view.has-guide .kb-key { height: clamp(24px, 4.3vh, 36px); }
/* letters, home row and space are enough (digits come last, after the guide has gone) */
.cmp-view.has-guide .kb-row:first-child { display: none; }
/* two lines of text while the keyboard is open, so the stage, the line and the keys share one screen */
main[data-screen="campaign"] .cmp-view.is-guide-open .tv-box.sb-card { padding-block: 10px; }
main[data-screen="campaign"] .cmp-view.is-guide-open .tv-text { height: calc(1.95em * 2); }
/* the stats chips step aside for the keyboard: the bar's Nautilus still shows how far along the line is */
main[data-screen="campaign"] .cmp-view.is-guide-open .tv-stats { display: none; }
.cmp-view.has-guide .kb-off { opacity: 0.4; filter: saturate(0.5); }
.cmp-view.has-guide .kb-new { box-shadow: 0 clamp(2px, 0.45vw, 4px) 0 var(--sb-outline), 0 0 0 3px color-mix(in srgb, var(--sb-glow-color) 70%, transparent); }
/* 'colours': finger colours only, so the eyes learn the zones and not the letters */
.cmp-view.guide-colours .kb-key:not(.kb-mod):not(.kb-thumb) { color: transparent; }
.cmp-view.guide-colours .kb-key .kb-top, .cmp-view.guide-colours .kb-key .kb-main { color: transparent; }
.cmp-stage.is-compact .dio { height: clamp(170px, 22vw, min(250px, 27vh)); transition: height 0.3s ease; }
html.reduced-motion .cmp-view.is-guide-open .tv-kb { animation: none; }
