:root {
  --bg: #0b0b0c;
  --ink: #f1f1ef;
  --soft: #a1a1aa;
  --line: #26262b;
  --accent: #33adff;
  --paper: #f1e9d8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 "Plus Jakarta Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* One WebGL canvas and one particle canvas sit fixed behind the page. Each chapter's stage is a transparent
   window onto them; the intro and the closing section are opaque and cover them. */
.layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  display: block;
  z-index: 0;
  pointer-events: none;
}
.fallback .layer { display: none; }
main { position: relative; z-index: 1; }

/* ---------- intro ---------- */
.intro {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 96px max(16px, calc((100% - 760px) / 2)) 72px;
}
.intro .back { position: absolute; top: 16px; left: 16px; }
.lede { color: #d4d4d8; font-size: clamp(17px, 2.2vw, 20px); margin: 0 0 32px; max-width: 620px; }
.lede a, .after a { color: var(--accent); }

.chapters { display: flex; flex-wrap: wrap; gap: 10px; }
.chapters a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 12px;
  border: 1px solid #2a2a2f;
  border-radius: 999px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.chapters a span {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #0b0b0c;
  background: var(--c);
  border-radius: 999px;
  padding: 2px 7px;
}
.chapters a:hover, .chapters a:focus-visible { border-color: var(--c); outline: none; }
.cue { position: absolute; left: max(16px, calc((100% - 760px) / 2)); bottom: 24px; margin: 0; color: var(--soft); font-size: 13px; }

/* ---------- chapters ---------- */
.track { position: relative; height: 380vh; }

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: transparent;
  touch-action: pan-y;
  cursor: crosshair;
}

/* In WebGL mode the two drawings are only textures. The fallbacks show them directly. */
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  visibility: hidden;
}
.stage.fallback { background: var(--paper); cursor: auto; }
.stage.fallback canvas { visibility: visible; }

.pill {
  margin: 0;
  background: rgba(14, 14, 16, .74);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
}
a.pill:hover, a.pill:focus-visible { border-color: var(--accent); outline: none; }

.hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.chap i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 8px;
  vertical-align: 1px;
}
.pct { font-variant-numeric: tabular-nums; }

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity .5s ease;
}
.hint.gone { opacity: 0; }
.fine, .coarse { display: none; }
@media (hover: hover) and (pointer: fine) { .fine { display: inline; } }
@media not ((hover: hover) and (pointer: fine)) { .coarse { display: inline; } }
@media (max-width: 560px) { .hint .extra { display: none; } }
.stage.fallback .hint .extra { display: none; }

/* ---------- closing section ---------- */
.after {
  position: relative;
  background: var(--bg);
  padding: 120px max(16px, calc((100% - 680px) / 2)) 72px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin: 0 0 8px;
}

h1, h2 {
  font-size: clamp(36px, 7vw, 56px);
  line-height: 1.05;
  letter-spacing: -.03em;
  font-weight: 800;
  margin: 0 0 28px;
}

.after p { color: #d4d4d8; margin: 0 0 18px; }

.elements { margin: 32px 0; display: grid; gap: 22px; }
.elements div { border-left: 2px solid var(--c); padding-left: 16px; }
.elements dt { font-weight: 700; color: var(--c); margin-bottom: 4px; }
.elements dd { margin: 0; color: #d4d4d8; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 32px 0 40px; }

.btn {
  font: 600 15px/1 "Plus Jakarta Sans", system-ui, sans-serif;
  padding: 14px 20px;
  border-radius: 999px;
  border: 1px solid #2e2e33;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); outline: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121c; }
.btn.primary:hover, .btn.primary:focus-visible { background: #5cc0ff; }

.after .small { font-size: 14px; color: var(--soft); }
.after .foot { margin-top: 48px; }

/* ?capture=<chapter> renders one chapter full screen, without the page around it. */
.capture .intro, .capture .after, .capture .track:not(.cap), .capture .hud, .capture .hint { display: none; }
.capture .cap { height: 100vh; }

/* On an element's own page */
.others-label { margin: 8px 0 12px !important; font-size: 13px; color: var(--soft) !important; }
.elements dt a { color: inherit; text-decoration: none; }
.elements dt a:hover, .elements dt a:focus-visible { text-decoration: underline; }

/* ---------- sound ---------- */
.hud-r { display: flex; align-items: center; gap: 8px; }
.snd {
  pointer-events: auto;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 13px;
}
.hud .snd { width: 34px; height: 34px; padding: 0; }
.snd:hover, .snd:focus-visible { border-color: var(--c, var(--accent)); outline: none; }
.snd svg .w, .snd.on svg .x { display: none; }
.snd.on svg .w { display: inline; }
.snd.on { color: var(--c, var(--accent)); }
.intro .snd { margin-top: 20px; align-self: flex-start; padding: 9px 16px 9px 13px; font-size: 14px; }
.snd[hidden] { display: none; }
.pct b { font-weight: inherit; }
@media (max-width: 420px) { .pct .lbl { display: none; } }

/* ---------- shinobi pack ---------- */
/* The shinobi pages (body.shinobi) take an orange accent and their own ink: a wash behind the intro, a big brushed
   glyph bleeding off the edge, and a red seal by the title. */
.shinobi { --accent: #ff8a3d; }
.shinobi .btn.primary { color: #2a1204; }
.shinobi .btn.primary:hover, .shinobi .btn.primary:focus-visible { background: #ffa566; }
/* ---------- ink ---------- */
/* A wash of sumi ink behind the intro, a big brushed glyph bleeding off the edge, and a red seal by the title. */
.shinobi .intro { overflow: hidden; isolation: isolate; }
.shinobi .intro::before {
  content: "";
  position: absolute;
  inset: -10%;
  z-index: -1;
  background:
    radial-gradient(42% 34% at 82% 28%, rgba(255, 138, 61, .10), transparent 70%),
    radial-gradient(38% 30% at 74% 72%, rgba(90, 209, 255, .09), transparent 70%),
    radial-gradient(60% 50% at 10% 90%, rgba(255, 255, 255, .035), transparent 70%);
}
.shinobi .glyph {
  position: absolute;
  right: -0.08em;
  top: 50%;
  transform: translateY(-50%) rotate(-4deg);
  z-index: -1;
  margin: 0;
  font: 400 clamp(260px, 52vw, 620px)/1 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "Noto Serif JP", serif;
  color: rgba(241, 241, 239, .045);
  pointer-events: none;
  user-select: none;
}
.shinobi .title-row { display: flex; align-items: center; gap: 18px; margin: 0 0 28px; }
.shinobi .title-row h1 { margin: 0; }
.shinobi .seal {
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(44px, 7vw, 58px);
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--seal, #c8372d);
  color: #fbeee6;
  font: 700 clamp(24px, 4vw, 32px)/1 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "Noto Serif JP", serif;
  transform: rotate(6deg);
  box-shadow: inset 0 0 0 3px rgba(251, 238, 230, .25);
}
.shinobi .intro .chapters a { background: rgba(11, 11, 12, .6); }
.shinobi .credit { margin-top: 20px !important; }

/* ---------- landing ---------- */
.packs .pack { padding: 28px 0 8px; border-top: 1px solid var(--line); }
.packs .pack:first-child { border-top: 0; padding-top: 0; }
.packs .pack h2 { margin: 6px 0 10px; }
.packs .pack h2 a { color: inherit; text-decoration: none; }
.packs .pack h2 a:hover, .packs .pack h2 a:focus-visible { color: var(--c); }
.packs .pack .eyebrow { color: var(--c); }
.packs .pack .chapters { margin: 16px 0 4px; }
