/* Bota's Journey — web-manga design system */
:root {
  --ink: #141414;
  --paper: #fcfaf4;
  --paper-2: #f1ede2;
  --desk: #2b2a33;
  --accent: #d62839;
  --accent-soft: #fbe3e5;
  --blue: #2b59c3;
  --green: #2a9d5c;
  --gold: #e9a93b;
  --muted: #5d5a55;
  --line: 3px;
  --radius: 4px;
  --font-title: "Bangers", "Impact", sans-serif;
  --font-bubble: "Comic Neue", "Comic Sans MS", cursive;
  --font-body: "Nunito", "Segoe UI", sans-serif;
  --font-code: "JetBrains Mono", Consolas, monospace;
  --shadow-hard: 5px 5px 0 var(--ink);
  --ease-pop: cubic-bezier(.2, .8, .2, 1.15);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}
::selection { background: var(--gold); color: var(--ink); }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--desk);
  background-image: radial-gradient(rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 14px 14px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.6;
}
a { color: var(--blue); }
img, svg { max-width: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--ink); color: #fff;
  border-bottom: 3px solid var(--accent);
}
.topbar .brand { font-family: var(--font-title); font-size: 24px; letter-spacing: 1px; color: #fff; text-decoration: none; }
.topbar .brand span { color: var(--accent); }
.topbar .chap-label { margin-left: auto; font-size: 14px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar button {
  background: none; border: 2px solid #fff; color: #fff; border-radius: var(--radius);
  font: 700 14px var(--font-body); padding: 4px 10px; cursor: pointer;
}
.progress {
  position: absolute; left: 0; bottom: -3px; height: 3px; width: 100%;
  background: linear-gradient(90deg, var(--gold), #ffd36b);
  transform-origin: 0 50%; transform: scaleX(0);
  box-shadow: 0 0 10px rgba(233,169,59,.6);
}
.topbar .brand { transition: transform .2s var(--ease-pop); }
.topbar .brand:hover { transform: rotate(-2deg) scale(1.04); }
.topbar button { transition: background .15s, color .15s; }
.topbar button:hover { background: #fff; color: var(--ink); }

.toc-drawer {
  position: fixed; inset: 0 auto 0 0; width: min(340px, 88vw); z-index: 60;
  background: var(--paper); border-right: var(--line) solid var(--ink);
  transform: translateX(-105%); transition: transform .25s ease;
  overflow-y: auto; padding: 16px;
}
.toc-drawer.open { transform: none; }
.toc-drawer h2 { font-family: var(--font-title); font-weight: 400; letter-spacing: 1px; margin: 0 0 8px; }
.toc-drawer ol { list-style: none; padding: 0; margin: 0; }
.toc-drawer li a {
  display: flex; gap: 10px; padding: 8px; border-bottom: 1px dashed #bbb;
  color: var(--ink); text-decoration: none;
}
.toc-drawer li a:hover, .toc-drawer li a[aria-current] { background: var(--accent-soft); }
.toc-drawer .num { font-family: var(--font-title); color: var(--accent); min-width: 28px; font-size: 20px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; display: none; }
.scrim.open { display: block; }

/* ---------- pages ---------- */
main { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }
.page {
  background: var(--paper);
  border: var(--line) solid var(--ink);
  box-shadow: 8px 8px 0 rgba(0,0,0,.45);
  padding: 22px;
  margin: 0 0 32px;
  position: relative;
}
/* halftone corner, like a screentone sheet peeking out */
.page::before {
  content: ""; position: absolute; top: 0; right: 0; width: 220px; height: 220px; pointer-events: none;
  background: radial-gradient(rgba(20,20,20,.16) 1.3px, transparent 1.6px) 0 0 / 8px 8px;
  -webkit-mask-image: radial-gradient(circle at 100% 0, #000 0, transparent 70%);
          mask-image: radial-gradient(circle at 100% 0, #000 0, transparent 70%);
}
.page-no {
  position: absolute; bottom: 6px; right: 12px;
  font-family: var(--font-title); color: var(--muted); font-size: 15px;
}

/* chapter title splash */
.splash {
  position: relative; overflow: hidden;
  border: var(--line) solid var(--ink);
  min-height: 260px; padding: 24px;
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 16px;
  background:
    repeating-conic-gradient(from 0deg at 80% 40%, rgba(0,0,0,.07) 0 4deg, transparent 4deg 12deg),
    var(--paper);
}
.splash > * { position: relative; z-index: 1; }
.splash[data-num]::before {
  content: attr(data-num); position: absolute; z-index: 0; right: 170px; top: -40px;
  font-family: var(--font-title); font-size: 300px; line-height: 1; letter-spacing: -6px;
  color: transparent; -webkit-text-stroke: 3px rgba(214,40,57,.16); pointer-events: none;
}
.splash::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 8px;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 8px, var(--accent) 8px 16px);
}
.splash .hero.char-icon { box-shadow: 6px 6px 0 var(--accent); animation: hero-bob 4s ease-in-out infinite; }
@keyframes hero-bob { 50% { transform: translateY(-6px) rotate(-1.5deg); } }
.splash .kicker { font-family: var(--font-title); color: var(--accent); font-size: 22px; letter-spacing: 2px; }
.splash h1 {
  font-family: var(--font-title); font-weight: 400; letter-spacing: 1.5px;
  font-size: clamp(38px, 7vw, 68px); line-height: .95; margin: 4px 0 10px;
  text-shadow: 3px 3px 0 var(--accent-soft);
}
.splash .sub { font-size: 18px; max-width: 520px; margin: 0; }
.splash .week-tag {
  display: inline-block; background: var(--ink); color: #fff;
  font: 700 13px var(--font-body); padding: 2px 10px; border-radius: 999px; margin-bottom: 6px;
}
.splash .hero { width: 200px; }

/* ---------- panels ---------- */
.row { display: grid; gap: 12px; margin: 12px 0; grid-template-columns: repeat(var(--cols, 2), 1fr); }
.row.c1 { --cols: 1; } .row.c3 { --cols: 3; }
.row.wide-left { grid-template-columns: 2fr 1fr; }
.row.wide-right { grid-template-columns: 1fr 2fr; }
.panel {
  position: relative; overflow: hidden;
  border: var(--line) solid var(--ink);
  background: #fff;
  min-height: 180px; padding: 14px;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 8px;
}
.panel.tilt { transform: rotate(-.6deg); }
.panel.tilt-r { transform: rotate(.6deg); }
.panel.center { justify-content: center; align-items: center; text-align: center; }
.tone { background: radial-gradient(#0002 1.2px, transparent 1.4px) 0 0 / 7px 7px, #fff; }
.tone-dark { background: radial-gradient(#0005 1.5px, transparent 1.7px) 0 0 / 6px 6px, #e9e6de; }
.tone-red { background: radial-gradient(#d6283933 1.5px, transparent 1.7px) 0 0 / 7px 7px, #fff6f6; }
.speed { background: repeating-conic-gradient(from 0deg at 50% 50%, #0000000d 0 3deg, transparent 3deg 9deg), #fff; }
.night { background: radial-gradient(#fff3 1px, transparent 1.3px) 0 0 / 9px 9px, #23222b; color: #fff; }
.panel .scene { display: flex; align-items: flex-end; justify-content: space-around; gap: 6px; flex: 1; }
.panel .scene > svg { height: 150px; width: auto; }
.panel .scene > svg.small { height: 110px; }
.panel .scene > svg.big { height: 190px; }

.caption {
  background: #fffbe0; border: 2px solid var(--ink);
  font: 700 14px/1.35 var(--font-body);
  padding: 6px 10px; align-self: flex-start; max-width: 92%;
  box-shadow: 2px 2px 0 var(--ink);
}
.caption.top { position: absolute; top: 10px; left: 10px; }

.bubble {
  position: relative; background: #fff;
  border: 2.5px solid var(--ink); border-radius: 22px;
  font: 700 16px/1.3 var(--font-bubble);
  padding: 9px 14px; max-width: 90%;
  align-self: flex-start;
}
.bubble::after {
  content: ""; position: absolute; bottom: -12px; left: 26px;
  border: 12px solid transparent; border-top-color: var(--ink); border-bottom: 0;
}
.bubble::before {
  content: ""; position: absolute; bottom: -8px; left: 28.5px; z-index: 1;
  border: 9.5px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.bubble.r { align-self: flex-end; }
.bubble.r::after { left: auto; right: 26px; }
.bubble.r::before { left: auto; right: 28.5px; }
.bubble.shout { border-radius: 4px; border-width: 3px; font-size: 18px; text-transform: uppercase; }
.bubble.think { border-style: dashed; border-radius: 40px; font-style: italic; }
.bubble b, .bubble strong { color: var(--accent); }
.who { font: 800 11px var(--font-body); letter-spacing: 1px; text-transform: uppercase; color: var(--muted); display: block; }

.sfx {
  position: absolute; font-family: var(--font-title); color: var(--accent);
  font-size: 46px; letter-spacing: 2px; transform: rotate(-12deg);
  -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; pointer-events: none;
}

/* ---------- generated manga pages ---------- */
.manga-page {
  margin: 16px auto; background: #fff;
  border: var(--line) solid var(--ink); box-shadow: 6px 6px 0 rgba(0,0,0,.35);
}
.manga-page.portrait { max-width: 660px; }
.manga-page img { display: block; width: 100%; height: auto; }
.char-icon { object-fit: contain; background: #fff; border: var(--line) solid var(--ink); border-radius: 50%; }
.panel .scene > img.char-icon { height: 120px; width: 120px; }
.splash .hero.char-icon { width: 180px; height: 180px; }

/* ---------- explanation blocks ---------- */
.lesson { margin: 18px 0; }
.lesson h2 {
  font-family: var(--font-title); font-weight: 400; letter-spacing: 1px;
  font-size: 30px; margin: 22px 0 6px;
  display: flex; align-items: center; gap: 10px;
}
.lesson h2::before {
  content: ""; width: 14px; height: 14px; background: var(--accent);
  transform: rotate(45deg); flex: none; box-shadow: 3px 3px 0 var(--ink);
}
.lesson h2 {
  background-image: linear-gradient(transparent 58%, var(--accent-soft) 58%, var(--accent-soft) 88%, transparent 88%);
  background-repeat: no-repeat; background-size: 100% 100%;
  width: fit-content; max-width: 100%;
}
.lesson h3 { font-size: 19px; margin: 18px 0 4px; }
.lesson p { margin: 8px 0; }
.lesson ul, .lesson ol { padding-left: 22px; }
.term { font-weight: 800; border-bottom: 2px solid var(--accent); }
.formula {
  font-family: var(--font-code); font-size: 16px;
  background: var(--paper-2); border-left: 5px solid var(--accent);
  padding: 10px 14px; margin: 10px 0; overflow-x: auto; white-space: pre;
}
pre.code {
  font-family: var(--font-code); font-size: 13.5px; line-height: 1.5;
  background: #1e1e24; color: #f2f2f2; border: var(--line) solid var(--ink);
  padding: 34px 14px 12px; overflow-x: auto; margin: 14px 0; position: relative;
  box-shadow: var(--shadow-hard);
  background-image: linear-gradient(#2c2c35, #2c2c35); background-size: 100% 24px; background-repeat: no-repeat;
}
pre.code::before {
  content: ""; position: absolute; top: 8px; left: 12px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 15px 0 0 var(--gold), 30px 0 0 var(--green);
}
pre.code .c { color: #8fbf8f; }
pre.code .k { color: #ff9e9e; }
table.t {
  border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 15px; background: #fff;
}
table.t th, table.t td { border: 2px solid var(--ink); padding: 6px 8px; text-align: left; vertical-align: top; }
table.t th { background: var(--ink); color: #fff; border-bottom: 4px solid var(--accent); }
table.t tr:nth-child(even) td { background: #faf7ef; }
table.t tr:hover td { background: #fff4d6; }
.table-wrap { overflow-x: auto; margin: 12px 0; padding: 0 6px 6px 0; }
.table-wrap > table.t { margin: 0; box-shadow: var(--shadow-hard); }

.box {
  border: var(--line) solid var(--ink); padding: 14px 14px 12px; margin: 22px 0 18px; background: #fff; position: relative;
  box-shadow: var(--shadow-hard);
}
.box > .label {
  position: absolute; top: -15px; left: 12px; background: var(--ink); color: #fff;
  font-family: var(--font-title); letter-spacing: 1px; font-size: 17px; padding: 1px 10px;
  border: 2px solid var(--ink); transform: rotate(-1.5deg); box-shadow: 2px 2px 0 var(--ink);
}
.box.route { background: radial-gradient(#2b59c322 1.4px, transparent 1.6px) 0 0 / 9px 9px, #f1f5ff; }
.box.route > .label { background: var(--green); }
.box.dyk { background: #fff8e6; }
.box.dyk > .label { background: var(--gold); color: var(--ink); }
.box.case > .label { background: var(--blue); }
.box.myth > .label { background: var(--accent); }
.box.simple { background: #eef6ff; }
.box.simple > .label { background: var(--blue); }
.box.warn > .label { background: var(--accent); }

.steps { counter-reset: s; list-style: none; padding: 0 !important; }
.steps li { counter-increment: s; position: relative; padding: 6px 0 6px 40px; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 6px;
  width: 28px; height: 28px; border: 2px solid var(--ink); border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; background: var(--accent-soft);
}

/* ---------- demos ---------- */
.demo { border: var(--line) solid var(--ink); background: #fff; margin: 18px 0; box-shadow: 7px 7px 0 var(--accent); }
.demo-head {
  background: var(--ink); color: #fff; padding: 6px 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.demo-head .tag { font-family: var(--font-title); letter-spacing: 1px; font-size: 18px; color: var(--gold); }
.demo-body { padding: 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.btn {
  font: 800 14px var(--font-body); cursor: pointer;
  background: #fff; color: var(--ink);
  border: 2.5px solid var(--ink); border-radius: var(--radius);
  padding: 6px 12px; box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover:not(:disabled) { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn[aria-pressed="true"] { background: var(--ink); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
select, input[type="text"], input[type="number"] {
  font: 600 15px var(--font-body); border: 2.5px solid var(--ink); border-radius: var(--radius);
  padding: 5px 8px; background: #fff;
}
input[type="range"] { accent-color: var(--accent); width: 180px; max-width: 100%; }
.readout { font-family: var(--font-code); font-size: 14px; background: var(--paper-2); padding: 8px 10px; border: 2px solid var(--ink); white-space: pre-wrap; }
.demo canvas, .demo svg.viz { display: block; width: 100%; height: auto; border: 2px solid var(--ink); background: #fff; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--ink); margin-right: 4px; vertical-align: -1px; }

.bar-row { display: grid; grid-template-columns: 110px 1fr 60px; gap: 8px; align-items: center; margin: 4px 0; font-size: 14px; }
.bar { height: 18px; border: 2px solid var(--ink); background: #fff; position: relative; }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width .3s; }
.bar.blue > span { background: var(--blue); }

/* ---------- quiz ---------- */
.quiz { border: var(--line) solid var(--ink); margin: 22px 0; background: #fff; box-shadow: 7px 7px 0 var(--ink); }
.quiz .q-head {
  background: var(--accent); color: #fff; font-family: var(--font-title); letter-spacing: 1px; font-size: 20px; padding: 4px 12px;
  display: flex; align-items: center; gap: 10px;
  background-image: repeating-linear-gradient(-45deg, transparent 0 10px, rgba(255,255,255,.08) 10px 20px);
}
.quiz .score {
  margin-left: auto; font: 800 14px var(--font-body); letter-spacing: 0;
  background: #fff; color: var(--ink); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px;
}
.quiz .score.perfect { background: var(--gold); animation: pop .5s var(--ease-pop); }
.quiz .q-head .stamp {
  font-size: 22px; color: var(--gold); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill;
  transform: rotate(-8deg); animation: pop .5s var(--ease-pop);
}
.quiz .q:not(.done) .opt:hover { background: var(--paper-2); transform: translateX(4px); }
.quiz .opt { transition: transform .12s, background .12s; }
.quiz .opt.right { animation: pop .4s var(--ease-pop); }
.quiz .opt.wrong { animation: shake .35s; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.04); } 100% { transform: none; } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.quiz .q { padding: 10px 14px; border-bottom: 2px dashed #ccc; }
.quiz .q:last-child { border-bottom: 0; }
.quiz .q p { margin: 4px 0 8px; font-weight: 700; }
.quiz .opts { display: grid; gap: 6px; }
.quiz .opt {
  text-align: left; font: 600 15px var(--font-body); padding: 7px 10px;
  border: 2px solid var(--ink); background: #fff; cursor: pointer; border-radius: var(--radius);
}
.quiz .opt.right { background: #dff5e7; border-color: var(--green); }
.quiz .opt.wrong { background: var(--accent-soft); border-color: var(--accent); text-decoration: line-through; }
.quiz .why { display: none; margin-top: 8px; font-size: 15px; background: var(--paper-2); padding: 6px 10px; border-left: 4px solid var(--green); }
.quiz .q.done .why { display: block; }
.quiz .result { margin: 8px 0 0; font-weight: 800; }
.quiz .result:empty { display: none; }
.quiz .opt:focus-visible, .btn:focus-visible, .flip:focus-visible, .toc-card:focus-visible, a:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 3px;
}

/* flip cards (myth vs fact) */
.flips { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 14px 0; }
.flip { perspective: 900px; min-height: 170px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; min-height: 170px; transition: transform .5s; transform-style: preserve-3d; }
.flip.on .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border: var(--line) solid var(--ink); padding: 12px; display: flex; flex-direction: column; justify-content: center;
}
.flip-face.front { background: var(--accent-soft); }
.flip-face.back { background: #e7f6ec; transform: rotateY(180deg); font-size: 15px; }
.flip-face b { font-family: var(--font-title); letter-spacing: 1px; font-weight: 400; font-size: 20px; }

/* ---------- chapter nav ---------- */
.chapnav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chapnav a {
  flex: 1 1 220px; text-decoration: none; color: var(--ink); background: var(--paper);
  border: var(--line) solid var(--ink); box-shadow: 5px 5px 0 rgba(0,0,0,.45); padding: 12px 16px;
  font-family: var(--font-title); font-size: 24px; letter-spacing: 1px; line-height: 1.1;
  transition: transform .15s var(--ease-pop), box-shadow .15s;
}
.chapnav a:hover, .chapnav a:focus-visible { transform: translate(-3px,-3px); box-shadow: 8px 8px 0 var(--accent); }
.chapnav a small { display: block; color: var(--accent); font: 800 13px var(--font-body); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 2px; }
.chapnav a.next { text-align: right; background: var(--ink); color: #fff; }
.chapnav a.next small { color: var(--gold); }

/* ---------- route strip: a metro-style line of stops ---------- */
.journey {
  display: flex; overflow-x: auto; margin: 14px 0 6px; padding: 4px 2px 6px;
  list-style: none; scrollbar-width: thin;
}
.journey li {
  flex: 1 0 86px; position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font: 800 12px var(--font-body); color: var(--muted); white-space: nowrap;
}
.journey li::before {
  content: ""; position: absolute; top: 9px; left: 0; right: 0; height: 4px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 6px, transparent 6px 11px);
}
.journey li:first-child::before { left: 50%; }
.journey li:last-child::before { right: 50%; }
.journey li.done::before, .journey li.here::before { background: var(--ink); }
.journey li.here::before { background: linear-gradient(90deg, var(--ink) 50%, transparent 50%), repeating-linear-gradient(90deg, var(--ink) 0 6px, transparent 6px 11px); }
.journey li:first-child.here::before { background: repeating-linear-gradient(90deg, var(--ink) 0 6px, transparent 6px 11px); }
.journey li:last-child.here::before { background: var(--ink); }
.journey .dot {
  position: relative; z-index: 1; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 3px solid var(--ink); display: grid; place-items: center;
  font-size: 11px; color: #fff; line-height: 1;
}
.journey li.done { color: var(--ink); }
.journey li.done .dot { background: var(--ink); }
.journey li.done .dot::after { content: "✓"; }
.journey li.here { color: var(--accent); font-size: 13px; }
.journey li.here .dot { background: var(--accent); transform: scale(1.25); box-shadow: 0 0 0 0 rgba(214,40,57,.55); animation: ping 1.8s infinite; }
.journey li.here .dot::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.journey li.here .name { background: var(--accent); color: #fff; padding: 0 8px; border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); }
@keyframes ping { 70% { box-shadow: 0 0 0 10px rgba(214,40,57,0); } 100% { box-shadow: 0 0 0 0 rgba(214,40,57,0); } }

/* ---------- manga page zoom ---------- */
.manga-page img { cursor: zoom-in; }
.manga-page { transition: transform .25s var(--ease-out), box-shadow .25s; }
.manga-page:hover { transform: translateY(-3px) rotate(-.3deg); box-shadow: 10px 10px 0 rgba(0,0,0,.35); }
dialog.lightbox {
  padding: 0; border: var(--line) solid var(--ink); background: #fff; max-width: min(96vw, 1100px); max-height: 94vh;
  overflow: auto; box-shadow: 10px 10px 0 var(--accent);
}
dialog.lightbox::backdrop { background: rgba(20,20,20,.82); backdrop-filter: blur(3px); }
dialog.lightbox[open] { animation: zoom-in .25s var(--ease-out); }
dialog.lightbox img { display: block; width: auto; max-width: 100%; height: auto; max-height: calc(94vh - 6px); cursor: zoom-out; }
dialog.lightbox .close {
  position: fixed; top: 14px; right: 14px; z-index: 2; width: 44px; height: 44px; border-radius: 50%;
  font: 800 22px var(--font-body); background: #fff; border: var(--line) solid var(--ink); cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
}
@keyframes zoom-in { from { transform: scale(.94); opacity: 0; } }

/* ---------- scroll reveal (only when JS is on and motion is allowed) ---------- */
.js-motion .rv:not(.in) { opacity: 0; }
.js-motion .rv.in { animation: rise .6s var(--ease-out) backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(22px); } }

/* ---------- back to top ---------- */
.to-top {
  position: fixed; right: 18px; bottom: 18px; z-index: 40; width: 48px; height: 48px;
  border: var(--line) solid var(--ink); border-radius: 50%; background: var(--accent); color: #fff;
  font: 400 24px var(--font-title); cursor: pointer; box-shadow: 3px 3px 0 var(--ink);
  opacity: 0; transform: translateY(16px) scale(.8); pointer-events: none; transition: opacity .2s, transform .2s var(--ease-pop);
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { transform: translateY(-2px) rotate(-6deg); }

/* ---------- responsive ---------- */
.viz-scroll { position: relative; }
@media (max-width: 720px) {
  .viz-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0; }
  .viz-scroll > svg.viz { min-width: 560px; }
  .viz-scroll::after {
    content: "⟷ swipe to see the whole diagram"; display: block;
    font: 800 12px var(--font-body); color: var(--muted); margin-top: 4px; position: sticky; left: 0;
  }
  body { font-size: 16px; }
  .topbar .chap-label { display: none; }
  .topbar button, .topbar .brand { white-space: nowrap; }
  main { padding: 16px 10px 48px; }
  .page { padding: 14px; box-shadow: 5px 5px 0 rgba(0,0,0,.45); }
  .row, .row.c3, .row.wide-left, .row.wide-right { grid-template-columns: 1fr; }
  .splash { grid-template-columns: 1fr; }
  .splash .hero { width: 140px; justify-self: end; }
  .panel.tilt, .panel.tilt-r { transform: none; }
  .bar-row { grid-template-columns: 80px 1fr 52px; }
  .sfx { font-size: 34px; }
  .splash[data-num]::before { font-size: 190px; right: -10px; top: -24px; }
  .splash .hero.char-icon { width: 130px; height: 130px; }
  .page::before { width: 130px; height: 130px; }
  .quiz { box-shadow: 5px 5px 0 var(--ink); }
  .demo { box-shadow: 5px 5px 0 var(--accent); }
  .box, pre.code, .table-wrap > table.t { box-shadow: 4px 4px 0 var(--ink); }
  .journey li { flex-basis: 78px; }
  .to-top { width: 42px; height: 42px; right: 12px; bottom: 12px; }
  .chapnav a { font-size: 20px; }
  .manga-page:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .toc-drawer, .scrim, .to-top { display: none; }
  body { background: #fff; }
  .page { box-shadow: none; break-inside: avoid; }
  .js-motion .rv:not(.in) { opacity: 1; }
}
