/* ============ Breathe the Book: shared styles ============ */
:root {
  --bg: #0d0c0b; --ink: #ebe3d3; --muted: #9b917e; --accent: #e0b46a;
  --card: rgba(16, 13, 10, .74); --line: rgba(235, 227, 211, .14);
  --display: 'EB Garamond', Georgia, serif;
  --body: 'Literata', Georgia, 'Times New Roman', serif;
  --ui: 'Inter', system-ui, -apple-system, sans-serif;
}
body[data-theme='room']   { --bg: #17110c; --ink: #f0e5cf; --muted: #a8977c; --accent: #dba65a; --card: rgba(26, 19, 12, .76); }
body[data-theme='ash']    { --bg: #110d0d; --ink: #ece2d6; --muted: #9a8b80; --accent: #d1493c; --card: rgba(20, 13, 12, .78); }
body[data-theme='yellow'] { --bg: #16130b; --ink: #efe6c8; --muted: #a69a72; --accent: #d9b84a; --card: rgba(26, 22, 11, .8); }
body[data-theme='spring'] { --bg: #f3eee1; --ink: #20281d; --muted: #616b57; --accent: #3e7c48; --card: rgba(255, 252, 243, .84); --line: rgba(32, 40, 29, .14); }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--body); font-size: clamp(17px, 1.05rem + .25vw, 20px); line-height: 1.75;
  transition: background-color 1.4s ease, color 1.4s ease;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: inherit; }
::selection { background: var(--accent); color: var(--bg); }

/* ---------- top bar ---------- */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 50; height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 clamp(14px, 3vw, 36px); font-family: var(--ui); font-size: 13px; letter-spacing: .02em;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 88%, transparent), transparent);
  transition: background 1.4s;
}
.brand { font-family: var(--display); font-size: 24px; font-style: italic; font-weight: 600; text-decoration: none; letter-spacing: .01em; }
.brand b { color: var(--accent); font-weight: 400; font-size: .78em; margin: 0 .08em; }
.bar-mid { flex: 1; text-align: center; color: var(--muted); opacity: 0; transition: opacity .5s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-mid.on { opacity: 1; }
.langs { position: relative; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 11px/1 var(--ui); letter-spacing: .08em; padding: 7px 11px 7px 9px; border-radius: 99px; cursor: pointer;
  background: transparent; color: var(--muted); border: 1px solid var(--line); transition: color .25s, border-color .25s;
}
.lang-btn:hover, .langs.open .lang-btn { color: var(--ink); border-color: color-mix(in srgb, var(--ink) 40%, transparent); }
.lang-menu {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 70; width: min(420px, calc(100vw - 28px));
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; padding: 8px; border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 94%, var(--ink)); border: 1px solid var(--line); box-shadow: 0 24px 70px rgba(0,0,0,.45);
  opacity: 0; visibility: hidden; transform: translateY(-6px); transition: opacity .2s, transform .2s, visibility .2s;
}
.langs.open .lang-menu { opacity: 1; visibility: visible; transform: none; }
.lang-menu button {
  text-align: start; font: 500 14px/1.2 var(--ui); padding: 10px 12px; border-radius: 8px; border: 0; cursor: pointer;
  background: transparent; color: var(--ink); opacity: .82;
}
.lang-menu button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); opacity: 1; }
.lang-menu button.on { color: var(--accent); opacity: 1; }
.lang-menu button.on::after { content: ' ·'; }

.fallback {
  position: fixed; z-index: 55; top: 64px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 28px);
  display: flex; align-items: center; gap: 10px; padding: 9px 10px 9px 14px; border-radius: 99px;
  font: 500 13px/1.35 var(--ui); color: var(--ink); background: var(--card); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 14px 40px rgba(0,0,0,.3);
  animation: fbIn .6s .4s both;
}
.fallback svg { flex: none; color: var(--accent); }
.fallback button { flex: none; border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 6px; }
@keyframes fbIn { from { opacity: 0; transform: translate(-50%, -8px); } }
.progress { position: fixed; top: 0; left: 0; height: 2px; width: 100%; z-index: 60; transform-origin: 0 50%; transform: scaleX(0); background: var(--accent); }

/* ---------- side nav (parts) ---------- */
.dots { position: fixed; inset-inline-end: 18px; top: 50%; transform: translateY(-50%); z-index: 40; display: flex; flex-direction: column; gap: 14px; }
.dots a { display: flex; align-items: center; justify-content: flex-end; gap: 10px; text-decoration: none; font: 500 11px var(--ui); color: var(--muted); letter-spacing: .06em; }
.dots a span { opacity: 0; transform: translateX(6px); transition: all .3s; white-space: nowrap; }
.dots a:hover span { opacity: 1; transform: none; }
.dots a i { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--muted); transition: all .3s; }
.dots a.on i { background: var(--accent); border-color: var(--accent); transform: scale(1.35); }
@media (max-width: 760px) { .dots { display: none; } }

/* ---------- cover ---------- */
.cover { position: relative; height: 100vh; height: 100svh; min-height: 560px; overflow: hidden; }
.cover .art, .cover .art svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.cover::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg) 4%, rgba(13,12,11,.72) 34%, rgba(13,12,11,0) 70%); pointer-events: none; }
.cover-txt { position: absolute; z-index: 2; inset-inline: clamp(20px, 7vw, 120px) 20px; bottom: clamp(56px, 11vh, 120px); max-width: 900px; }
.kicker { font: 600 12px var(--ui); letter-spacing: .22em; text-transform: uppercase; color: var(--accent); }
.cover h1 { font-family: var(--display); font-weight: 500; font-style: italic; font-size: clamp(46px, 12vw, 190px); line-height: .9; margin: .18em 0 .16em -.04em; letter-spacing: -.01em; }
.cover .tag { font-size: clamp(18px, 1.2rem + .5vw, 26px); line-height: 1.45; max-width: 34ch; color: var(--ink); opacity: .9; margin: 0 0 1.1em; font-style: italic; font-family: var(--display); }
.meta { font: 500 12px var(--ui); color: var(--muted); letter-spacing: .06em; display: flex; flex-wrap: wrap; gap: .4em 1.4em; }
.meta i { font-style: italic; font-family: var(--display); font-size: 16px; letter-spacing: 0; color: var(--ink); opacity: .75; }
.hint { position: absolute; z-index: 2; left: 50%; bottom: 18px; transform: translateX(-50%); font: 600 10px var(--ui); letter-spacing: .3em; text-transform: uppercase; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hint::after { content: ''; width: 1px; height: 38px; background: linear-gradient(var(--muted), transparent); animation: hint 2.2s ease-in-out infinite; transform-origin: top; }
@keyframes hint { 0% { transform: scaleY(0); } 50% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }

/* ---------- reading flow ---------- */
.flow { padding: 0 clamp(20px, 5vw, 40px); }
.col { max-width: 37rem; margin-inline: auto; }
.p { margin: 0 auto 1.25em; max-width: 37rem; hyphens: auto; }
.p em { font-style: italic; }
.p.drop::first-letter {
  font-family: var(--display); font-weight: 600; float: left; font-size: 5.1em; line-height: .78;
  padding: .06em .1em 0 0; color: var(--accent);
}
.h { font-family: var(--display); font-weight: 600; font-size: clamp(30px, 1.4rem + 1.6vw, 44px); line-height: 1.1; max-width: 37rem; margin: 2.4em auto .7em; }
.h::before { content: ''; display: block; width: 36px; height: 1px; background: var(--accent); margin-bottom: .7em; }

.q { max-width: 46rem; margin: 3em auto; text-align: center; padding: 0 .5rem; }
.q blockquote { margin: 0; font-family: var(--display); font-style: italic; font-weight: 500; font-size: clamp(28px, 1.3rem + 2vw, 52px); line-height: 1.18; }
.q blockquote::before { content: '“'; display: block; font-size: 2.2em; line-height: .5; color: var(--accent); font-style: normal; height: .45em; }
.q figcaption { margin-top: 1.3em; font: 13px/1.6 var(--ui); color: var(--muted); }
.q figcaption .k { display: inline-block; font-weight: 600; font-size: 10px; letter-spacing: .2em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 99px; padding: 3px 9px; margin-inline-end: .6em; }
.q figcaption i { font-family: var(--display); font-size: 17px; color: var(--ink); opacity: .8; }
.q.hero { margin: 4em auto 3.5em; }
.q.hero blockquote { font-size: clamp(30px, 1.2rem + 2.6vw, 60px); }
.q.hero blockquote .ch { opacity: 0; transition: opacity .25s; }
.q.hero.in blockquote .ch { opacity: 1; }

.note { max-width: 40rem; margin: 3em auto; padding: 1.6em 1.8em; border: 1px solid var(--line); border-inline-start: 2px solid var(--accent); border-radius: 4px; background: color-mix(in srgb, var(--ink) 3%, transparent); }
.note .k { font: 600 10px var(--ui); letter-spacing: .22em; text-transform: uppercase; color: var(--accent); }
.note h4 { font-family: var(--display); font-size: 28px; font-weight: 600; margin: .25em 0 .35em; line-height: 1.15; }
.note p { margin: 0; font-size: .95em; }

/* ---------- part header ---------- */
.part { position: relative; min-height: 92vh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 18vh 20px 12vh; overflow: hidden; }
.part-n { position: absolute; inset: 50% 0 auto; transform: translateY(-55%); font-family: var(--display); font-weight: 300; font-size: clamp(220px, 42vw, 640px); line-height: 1; color: transparent; -webkit-text-stroke: 1px var(--line); pointer-events: none; user-select: none; }
.part .kicker { position: relative; }
.part h2 { position: relative; font-family: var(--display); font-weight: 500; font-style: italic; font-size: clamp(56px, 9vw, 140px); line-height: 1; margin: .2em 0 .25em; }
.part p { position: relative; max-width: 30ch; margin: 0 auto; font-family: var(--display); font-size: clamp(19px, 1.1rem + .6vw, 26px); line-height: 1.4; color: var(--muted); font-style: italic; }

/* ---------- scrollytelling scenes ---------- */
.scene { position: relative; margin: 3em calc(-1 * clamp(20px, 5vw, 40px)); }
.scene-sticky { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; }
.scene-sticky .art, .scene-sticky svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene-sticky::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(var(--bg), transparent 9%, transparent 91%, var(--bg)); transition: background 1.4s; }
.scene-steps { position: relative; z-index: 2; margin-top: -100vh; margin-top: -100svh; }
.step { min-height: 100vh; min-height: 100svh; display: flex; align-items: center; padding: 0 clamp(16px, 6vw, 100px); pointer-events: none; }
.step:first-child { align-items: flex-end; padding-bottom: 12vh; }
.card {
  pointer-events: auto; max-width: 27rem; padding: 1.25em 1.5em; border-radius: 6px; font-size: .96em; line-height: 1.65;
  background: var(--card); -webkit-backdrop-filter: blur(10px) saturate(1.2); backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  opacity: .25; transform: translateY(24px); transition: opacity .6s, transform .6s, background 1.4s;
}
.step.on .card { opacity: 1; transform: none; }
.scene.right .step { justify-content: flex-end; }
@media (max-width: 760px) {
  .step, .step:first-child { align-items: flex-end; padding-bottom: 7vh; }
  .card { max-width: none; font-size: .93em; }
  .scene-sticky svg { height: 64%; top: 3%; -webkit-mask-image: linear-gradient(#000 82%, transparent); mask-image: linear-gradient(#000 82%, transparent); }
}

/* ---------- infographic blocks ---------- */
.block { max-width: 64rem; margin: 5em auto; }
.block-h { text-align: center; margin-bottom: 2.2em; }
.block-h h3 { font-family: var(--display); font-weight: 500; font-style: italic; font-size: clamp(34px, 1.6rem + 2vw, 56px); margin: .15em 0 0; line-height: 1.05; }

.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.char { padding: 1.4em 1.3em 1.3em; border: 1px solid var(--line); border-radius: 6px; background: color-mix(in srgb, var(--ink) 3%, transparent); transition: transform .4s, border-color .4s; }
.char:hover { transform: translateY(-3px); border-color: var(--accent); }
.char svg { width: 40px; height: 40px; color: var(--accent); }
.char h5 { font-family: var(--display); font-size: 25px; font-weight: 600; margin: .45em 0 0; line-height: 1.1; }
.char .role { font: 600 10px var(--ui); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin: .45em 0 .7em; }
.char p { margin: 0; font-size: .86em; line-height: 1.6; }
.char.main { grid-column: span 2; display: grid; grid-template-columns: auto 1fr; gap: 0 1.2em; align-items: start; }
.char.main svg { width: 64px; height: 64px; grid-row: span 3; }
.char.main h5 { margin-top: 0; font-size: 34px; }
@media (max-width: 520px) { .char.main { grid-column: auto; display: block; } .char.main svg { width: 44px; height: 44px; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stat { background: var(--bg); padding: 1.6em 1.2em; text-align: center; transition: background 1.4s; }
.stat b { display: block; font-family: var(--display); font-weight: 500; font-size: clamp(54px, 5vw, 76px); line-height: 1; color: var(--accent); font-variant-numeric: lining-nums; }
.stat span { display: block; margin-top: .6em; font: 13px/1.45 var(--ui); color: var(--muted); }

.tl { position: relative; max-width: 44rem; margin: 0 auto; padding-inline-start: 34px; }
.tl::before { content: ''; position: absolute; inset-inline-start: 8px; top: 8px; bottom: 8px; width: 1px; background: linear-gradient(var(--accent), var(--line)); }
.tl-i { position: relative; padding: 0 0 2.1em; }
.tl-i::before { content: ''; position: absolute; inset-inline-start: -31px; top: 8px; width: 11px; height: 11px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); transition: background 1.4s; }
.tl-i .w { font: 600 11px var(--ui); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.tl-i h5 { font-family: var(--display); font-size: 26px; font-weight: 600; margin: .15em 0 .2em; line-height: 1.15; }
.tl-i p { margin: 0; font-size: .9em; color: var(--muted); }

.themes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.theme { position: relative; padding: 1.8em 1.6em 1.6em; border-radius: 6px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.theme .n { font-family: var(--display); font-size: 64px; font-weight: 300; line-height: .8; color: var(--accent); opacity: .9; }
.theme h5 { font-family: var(--display); font-size: 27px; font-weight: 600; margin: .45em 0 .35em; line-height: 1.15; }
.theme p { margin: 0; font-size: .9em; line-height: 1.65; }

.more { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.more-i { padding: 1.4em 1.3em; border-top: 2px solid var(--accent); }
.more-i .a { font: 600 10px var(--ui); letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.more-i h5 { font-family: var(--display); font-style: italic; font-size: 28px; font-weight: 500; margin: .2em 0 .3em; line-height: 1.1; }
.more-i p { margin: 0; font-size: .88em; }

.fin { text-align: center; padding: 14vh 20px 10vh; }
.fin .orn { font-family: var(--display); font-size: 30px; color: var(--accent); letter-spacing: .6em; margin-left: .6em; }
.fin h2 { font-family: var(--display); font-style: italic; font-weight: 500; font-size: clamp(54px, 7vw, 100px); margin: .2em 0 .3em; }
.fin p { font: 13px/1.6 var(--ui); color: var(--muted); max-width: 40ch; margin: 0 auto 2.2em; }
.btn { display: inline-flex; align-items: center; gap: .6em; font: 600 13px var(--ui); letter-spacing: .04em; text-decoration: none; padding: 13px 22px; border-radius: 99px; background: var(--ink); color: var(--bg); transition: transform .25s, background 1.4s, color 1.4s; }
.btn:hover { transform: translateY(-2px); }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .9s ease, transform .9s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .reveal, .card { opacity: 1 !important; transform: none !important; transition: none; }
  html { scroll-behavior: auto; }
  * { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
}

/* ---------- loading ---------- */
.loading { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--display); font-style: italic; font-size: 28px; color: var(--muted); }

/* ---------- scripts & right-to-left ---------- */
/* Latin text keeps EB Garamond / Literata; other scripts fall through to a matching serif. */
html[lang='zh'] { --display: 'EB Garamond', 'Noto Serif SC', serif; --body: 'Literata', 'Noto Serif SC', serif; }
html[lang='ja'] { --display: 'EB Garamond', 'Noto Serif JP', serif; --body: 'Literata', 'Noto Serif JP', serif; }
html[lang='ko'] { --display: 'EB Garamond', 'Noto Serif KR', serif; --body: 'Literata', 'Noto Serif KR', serif; }
html[lang='hi'] { --display: 'EB Garamond', 'Noto Serif Devanagari', serif; --body: 'Literata', 'Noto Serif Devanagari', serif; --ui: 'Inter', 'Noto Sans Devanagari', system-ui, sans-serif; }
html[lang='ar'] { --display: 'Amiri', 'EB Garamond', serif; --body: 'Noto Naskh Arabic', 'Literata', serif; --ui: 'Noto Sans Arabic', 'Inter', system-ui, sans-serif; }
/* these scripts have no true italics, and wide letter-spacing breaks them */
html:is([lang='zh'], [lang='ja'], [lang='ko'], [lang='hi'], [lang='ar']) * { font-style: normal !important; }
html:is([lang='zh'], [lang='ja'], [lang='ko'], [lang='hi'], [lang='ar']) body [lang]:not([lang='zh'], [lang='ja'], [lang='ko'], [lang='hi'], [lang='ar']) { font-style: italic !important; }
html:is([lang='hi'], [lang='ar']) :is(.kicker, .note .k, .char .role, .tl-i .w, .more-i .a, .hint, .q figcaption .k) { letter-spacing: 0; text-transform: none; }
html:is([lang='zh'], [lang='ja'], [lang='ko']) :is(.kicker, .note .k, .char .role, .tl-i .w, .more-i .a, .hint) { letter-spacing: .12em; }
html:is([lang='zh'], [lang='ja'], [lang='ko']) body { line-height: 1.9; }
html:is([lang='zh'], [lang='ja'], [lang='ko']) :is(.cover h1, .part h2, .lib-hero h1, .poster-txt h2) { line-height: 1.15; letter-spacing: .02em; }
html[lang='ar'] body { line-height: 1.95; }
html[lang='ar'] :is(.cover h1, .part h2, .lib-hero h1, .poster-txt h2, .q blockquote, .block-h h3) { line-height: 1.35; }
html[lang='hi'] :is(.cover h1, .part h2, .lib-hero h1, .poster-txt h2, .q blockquote) { line-height: 1.3; }
/* a floated first letter would tear joined/stacked letters apart */
html:is([lang='ar'], [lang='hi']) .p.drop::first-letter { float: none; font: inherit; color: inherit; padding: 0; }
[dir='rtl'] .progress { transform-origin: 100% 50%; }
[dir='rtl'] .q blockquote::before { content: '”'; }
[dir='rtl'] .dots a span { transform: translateX(-6px); }
[dir='rtl'] .dots a:hover span { transform: none; }
html:is([lang='zh'], [lang='ja'], [lang='ko'], [lang='hi'], [lang='ar']) body .lang-menu button[lang] { font-style: normal !important; }

/* illustrations are laid out in LTR coordinates; keep text-anchor stable in RTL pages */
html[dir=rtl] .art svg { direction: ltr; }
/* connected scripts break apart with tracking */
html[lang=hi] .art svg text, html[lang=ar] .art svg text { letter-spacing: 0 !important; }
/* SVG labels: use the script-aware font stacks instead of hardcoded Latin fonts */
html:is([lang=hi],[lang=ar],[lang=zh],[lang=ja],[lang=ko]) .art svg text[font-family^="Inter"] { font-family: var(--ui); }
html:is([lang=hi],[lang=ar],[lang=zh],[lang=ja],[lang=ko]) .art svg text[font-family^="'EB"],
html:is([lang=hi],[lang=ar],[lang=zh],[lang=ja],[lang=ko]) .art svg text[font-family^="EB"] { font-family: var(--display); }
