/* The story: chapters as plain sections (the still version, also what reduced motion shows), and,
   under html.story-on, one pinned stage of stacked layers that the scroll moves (see js/story/stage.js). */

/* ---------- chapters as plain sections ---------- */
.ch { position: relative; padding: calc(var(--hdr) + 20px) var(--gutter) 36px; }
.ch.dark { background: var(--ink); color: var(--white); }
.beat { position: relative; padding: 28px 0; }
.beat + .beat { border-top: 2px dashed var(--mute); }
#japan .beat:first-child { padding-top: 0; }

.copy { position: relative; z-index: 2; min-width: 0; }
.copy h2 { margin-top: 10px; }
.copy p { color: var(--grey-text); max-width: 34rem; }
.dark .copy p { color: var(--mute); }
.copy.center { text-align: center; }
.copy.center p { margin-left: auto; margin-right: auto; }
.copy .fine { font-size: 0.85rem; }

.scene {
  position: relative; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: var(--ink); border: var(--border); box-shadow: 6px 6px 0 var(--lavender); overflow: hidden;
}
.scene canvas { display: block; flex: none; }
.scene.pick { box-shadow: 6px 6px 0 var(--orange); }
.scene.passport { box-shadow: 6px 6px 0 var(--blue); }

/* intro: a dark globe with the wordmark over it */
#intro { min-height: 100vh; min-height: 100svh; display: grid; place-items: center; text-align: center; overflow: hidden; }
#intro .scene.globe { position: absolute; inset: var(--hdr) 0 0; background: none; border: 0; box-shadow: none; overflow: visible; }
#intro .scene.globe canvas { width: min(92vw, 70vh); height: min(92vw, 70vh); }
.intro-copy { position: relative; z-index: 2; padding: 0 max(var(--gutter), 20px); max-width: 100%; }
.wordmark { position: relative; margin: 0; font-size: clamp(3.2rem, 14vw, 9rem); line-height: 0.9; color: var(--white); text-shadow: 6px 6px 0 var(--blue); }
.where { margin: 34px auto 14px; font: 400 clamp(1rem, 3vw, 1.5rem)/1 var(--font-pixel); color: var(--lime); text-transform: uppercase; }
.where::after { content: "_"; animation: blink 0.8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.intro-copy .sub { margin: 0 auto; max-width: 26rem; color: var(--mute); }
.intro-copy .req { margin: 10px auto 0; color: var(--lime); }
#intro .hint { position: absolute; bottom: 20px; left: 0; right: 0; margin: 0 auto; text-align: center; font: 400 0.7rem/1 var(--font-pixel); text-transform: uppercase; opacity: 0.7; }

/* pick: the journal, the "Issued" tag and the hidden stamp */
.issued {
  position: absolute; right: 6%; bottom: 10%; margin: 0; padding: 10px 14px 6px; background: var(--lime); color: var(--ink);
  border: var(--border); box-shadow: 5px 5px 0 var(--ink); font: 400 clamp(1.4rem, 4vw, 2.4rem)/1 var(--font-display);
}
.hidden-stamp {
  position: absolute; right: 6px; bottom: 6px; width: 26px; height: 26px; padding: 0; border: 0; background: none; opacity: 0.35; cursor: pointer;
  transition: transform 0.3s steps(4);
}
.hidden-stamp:hover, .hidden-stamp:focus-visible { opacity: 1; }
.hidden-stamp img { width: 100%; height: 100%; }
.hidden-stamp.found { opacity: 1; background: var(--lime); border: var(--border); transform: rotateY(360deg) scale(1.5); }

/* walk: full-bleed over the sky, the copy on a card */
.scene.walk { background: #6DBDEE; /* hok SKY3 */ align-items: flex-end; border-left: 0; border-right: 0; box-shadow: none; }
.copy.over { background: var(--white); border: var(--border); box-shadow: 5px 5px 0 var(--ink); padding: 12px 14px; margin-bottom: 12px; max-width: 30rem; }
.copy.over h2 { font-size: clamp(1.3rem, 3.4vw, 2rem); }
.copy.over p { margin: 4px 0 0; font-size: 0.95rem; }

/* alerts: the data bar and the alert line */
.databar { display: flex; align-items: center; gap: 10px; margin: 14px 0 8px; }
.databar i { display: block; flex: 1; max-width: 280px; height: 18px; padding: 2px; border: var(--border); background: var(--white); }
.databar b { display: block; height: 100%; width: 100%; background: var(--lime); }
.databar b.low { background: var(--orange); }
.alert { display: inline-block; margin: 0; padding: 8px 10px; background: var(--orange); border: var(--border); box-shadow: 4px 4px 0 var(--ink); font-weight: 700; color: var(--ink) !important; }

/* world */
.scene.worldmap { width: 100%; margin: 18px 0 10px; padding: 8px 0; border: 0; box-shadow: none; background: none; }
.counter { margin: 10px 0; text-align: center; font: 400 1rem/1 var(--font-pixel); text-transform: uppercase; color: var(--lime); }
.counter b { font: 400 2rem/1 var(--font-display); color: var(--white); }
.bought { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
.bought li { padding: 0.45em 0.7em; border: 2px solid var(--mute); color: var(--mute); font: 400 0.75rem/1 var(--font-pixel); text-transform: uppercase; }
.bought li[data-state="visited"] { background: var(--lime); color: var(--ink); border-color: var(--lime); }

/* dex */
.dex { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; align-items: start; max-width: 64rem; margin: 18px auto 0; }
.badges { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.badge-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px 8px; background: var(--white); border: var(--border); box-shadow: var(--shadow-sm); text-align: center; font: 400 0.75rem/1.2 var(--font-pixel); text-transform: uppercase; }
.badge-card canvas { width: 72px; height: 72px; object-fit: contain; }
.mhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.mhead h3 { margin: 0 0 8px; }
.mhead span { font: 400 0.8rem/1 var(--font-pixel); }
.medal-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.medal { display: flex; align-items: center; gap: 12px; padding: 8px 10px; background: var(--white); border: var(--border); }
.medal.earned { box-shadow: 4px 4px 0 var(--ink); }
.medal canvas { flex: none; width: 42px; height: 52px; }
.medal p { margin: 0; font-size: 0.85rem; line-height: 1.35; color: var(--grey-text); }
.medal .mt { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; color: var(--ink); }
.medal .mt b { font-weight: 700; }
.medal .g { font: 400 0.65rem/1 var(--font-pixel); text-transform: uppercase; font-style: normal; color: var(--grey-text); }
.medal .g.bronze { color: var(--ink); background: var(--orange); padding: 3px 5px; }
.medal .pg { font: 400 0.65rem/1 var(--font-pixel); color: var(--grey-text); }
.medal:not(.earned) { background: var(--mute); }
.more { text-align: center; margin: 14px auto 0; font-size: 0.85rem; color: var(--grey-text); }
.toast {
  position: absolute; left: 50%; bottom: 64px; transform: translate(-50%, 12px); margin: 0; z-index: 5; max-width: calc(100% - 32px);
  padding: 10px 14px; background: var(--ink); color: var(--lime); border: 2px solid var(--lime); text-align: center;
  font: 400 0.8rem/1.2 var(--font-pixel); text-transform: uppercase; opacity: 0; transition: opacity 0.15s steps(3), transform 0.15s steps(3);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .dex { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .badges { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .badge-card { padding: 6px 2px; font-size: 0.55rem; }
  .badge-card canvas { width: 48px; height: 48px; }
  .medal { padding: 5px 8px; gap: 8px; }
  .medal canvas { width: 21px; height: 26px; }
  .medal p:not(.mt), .medal .togo { display: none; }
  .medal-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .medal .mt { font-size: 0.72rem; }
}

/* ---------- the pinned stage ---------- */
html.story-on .story { position: relative; height: 100vh; height: 100lvh; overflow: hidden; }
/* every chapter, and every Japan beat, is one layer; #japan itself only groups its beats */
html.story-on .story > .ch, html.story-on #japan > .beat {
  position: absolute; inset: 0; margin: 0; border: 0; will-change: transform; background: var(--paper); color: var(--ink);
  padding: calc(var(--hdr) + 10px) max(16px, calc((100% - 1200px) / 2)) 20px;
  display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr); gap: 32px; align-items: center;
}
html.story-on .story > .ch.dark { background: var(--ink); color: var(--white); }
html.story-on .story > #japan { display: contents; }
html.story-on #intro { grid-template-columns: minmax(0, 1fr); place-items: center; padding-top: var(--hdr); }
html.story-on .story .scene { align-self: stretch; }
html.story-on .story .scene[style*="--ar"] { align-self: center; width: 100%; max-height: 100%; aspect-ratio: var(--ar); }
html.story-on #world, html.story-on #dex { display: flex; flex-direction: column; justify-content: center; gap: 10px; }
html.story-on #world { padding-top: calc(var(--hdr) + 6px); padding-bottom: 12px; }
html.story-on #world .scene.worldmap { flex: 1 1 auto; margin: 6px 0; }
html.story-on #world .copy p, html.story-on #dex .copy p { display: none; }
html.story-on #dex { justify-content: flex-start; padding-top: calc(var(--hdr) + 14px); }
html.story-on .beat[data-beat="walk"] { display: block; padding: 0; }
html.story-on .scene.walk { position: absolute; inset: var(--hdr) 0 0; }
html.story-on .copy.over { position: absolute; z-index: 3; top: calc(var(--hdr) + 12px); left: 16px; right: 16px; margin: 0; }
html.story-on .toast { bottom: 28px; }
html.story-on .issued, html.story-on .alert { visibility: hidden; }
html.story-on .issued.show, html.story-on .alert.show { visibility: visible; }
html.story-on .badge-card, html.story-on .medal { opacity: 0; }
html.story-on #intro .hint { z-index: 3; }

/* the staircase edge rides on top of each incoming layer; the dim covers the layer it slides over */
.edge { position: absolute; left: 0; z-index: 1; image-rendering: pixelated; pointer-events: none; }
.dim { position: absolute; inset: 0; z-index: 30; background: var(--ink); opacity: 0; pointer-events: none; }

@media (max-width: 820px) {
  html.story-on .story > .ch:not(#intro), html.story-on #japan > .beat {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-content: start; gap: 14px;
    padding-left: var(--gutter); padding-right: var(--gutter);
  }
  html.story-on #world, html.story-on #dex { display: flex; }
  html.story-on .beat[data-beat="walk"] { display: block; }
  html.story-on .copy p { font-size: 0.95rem; margin: 6px 0; }
  /* the intro keeps its own spacing: the wordmark shadow, the typed label and the lede never touch */
  html.story-on .intro-copy p.where { margin: 34px auto 14px; font-size: clamp(1rem, 3vw, 1.5rem); }
  html.story-on .intro-copy p.sub { margin: 0 auto; }
  html.story-on .intro-copy p.req { margin: 10px auto 0; font-size: 0.875rem; }
}
@media (max-height: 560px) {
  html.story-on .copy p { display: none; }
}

/* intro motion (classes added by js/story/introfx.js; none of this runs under reduced motion or ?still=1) */
.wordmark.glitch-run { clip-path: inset(0 -6px -6px 0); } /* the slices never paint beyond the text and its shadow, so LCP does not see a bigger element */
.wordmark.glitch-run::before, .wordmark.glitch-run::after {
  content: attr(data-text) / ""; position: absolute; inset: 0; text-shadow: none; pointer-events: none;
}
.wordmark.glitch-run::before { color: var(--lime); animation: slice-a 0.56s steps(2) 1 both; }
.wordmark.glitch-run::after { color: var(--lavender); animation: slice-b 0.56s steps(2) 1 both; }
@keyframes slice-a { 0% { clip-path: inset(10% 0 62% 0); transform: translateX(-30px); } 60% { clip-path: inset(30% 0 40% 0); transform: translateX(8px); } 100% { clip-path: inset(10% 0 62% 0); transform: translateX(0); opacity: 0; } }
@keyframes slice-b { 0% { clip-path: inset(58% 0 14% 0); transform: translateX(30px); } 60% { clip-path: inset(40% 0 30% 0); transform: translateX(-8px); } 100% { clip-path: inset(58% 0 14% 0); transform: translateX(0); opacity: 0; } }
.where.typing { animation: type-in 0.9s steps(var(--chars)) 1 both; }
@keyframes type-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
