@font-face { font-family: "Tiro Sanskrit"; src: url("/assets/fonts/tiro-sanskrit.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Literata"; src: url("/assets/fonts/literata.woff2") format("woff2"); font-weight: 200 900; font-display: swap; }
@font-face { font-family: "Literata"; src: url("/assets/fonts/literata-italic.woff2") format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }

:root {
  --paper: #f5f0e6;
  --paper-2: #ede6d8;
  --paper-3: #e5dccb;
  --ink: #1f1a15;
  --ink-2: #574e44;
  --ink-3: #887d70;
  --rule: #d9cfbe;
  --rubric: #9f2f1a;
  --rubric-soft: #9f2f1a1a;
  --hi: #ebe2d1;
  --wood: #6b4528;
  --leaf: #dcc79b;
  --leaf-edge: #b99c66;

  --deva: "Tiro Sanskrit", "Noto Serif Devanagari", serif;
  --text: "Literata", "Iowan Old Style", Georgia, serif;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.4375rem;
  --step-3: 1.75rem;
  --step-4: 2.125rem;
  --verse: clamp(1.5rem, 1.15rem + 1vw, 1.875rem);

  --bar: 3.5rem;
  --player: 4.25rem;
  --side: 18.5rem;
  --measure: 40rem;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #181512; --paper-2: #1e1a16; --paper-3: #27211b;
    --ink: #ece4d5; --ink-2: #b9ae9e; --ink-3: #8a8073; --rule: #332c25;
    --rubric: #e0866a; --rubric-soft: #e0866a1f; --hi: #231e19;
    --wood: #4a311d; --leaf: #b8a275; --leaf-edge: #8c7448;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--text); font-size: 1.0625rem; line-height: 1.6;
  font-optical-sizing: auto; font-variant-numeric: oldstyle-nums proportional-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--rubric); outline-offset: 2px; border-radius: 3px; }
button, input { font: inherit; color: inherit; }
[lang="sa"] { font-family: var(--deva); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 50; background: var(--paper); padding: .5rem .75rem; }

/* ── library ─────────────────────────────────────────────── */
.lib { max-width: 72rem; margin: 0 auto; padding: 0 1.5rem 4rem; }
.lib-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 1.4rem 0 1.2rem; border-bottom: 1px solid var(--rule); }
.mark { display: inline-flex; align-items: baseline; gap: .55rem; text-decoration: none; }
.mark [lang="sa"] { font-size: 1.6rem; line-height: 1; }
.mark span:last-child { font-size: var(--step-1); font-style: italic; color: var(--ink-2); }
.lib-head nav { display: flex; gap: 1.25rem; font-size: var(--step-0); color: var(--ink-2); }
.lib-intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 3rem; padding: 4.5rem 0 3.5rem; align-items: end; }
.lib-intro h1 { font-weight: 420; font-size: clamp(2rem, 1.4rem + 2vw, 2.75rem); line-height: 1.12; letter-spacing: -0.01em; margin: 0; max-width: 16ch; }
.lib-intro p { margin: 0; color: var(--ink-2); max-width: 34rem; font-size: var(--step-1); line-height: 1.55; }
.lib h2 { font-weight: 500; font-size: var(--step-2); margin: 0 0 1.25rem; }
.shelf { border-top: 1px solid var(--ink); padding-top: 1.5rem; }
.book { display: grid; grid-template-columns: 19rem minmax(0, 1fr); gap: 3rem; padding: 1rem 0 3rem; border-bottom: 1px solid var(--rule); }
.book-stage { height: 15rem; display: grid; place-items: center; perspective: 70rem; cursor: pointer; }
.book h3 { margin: 0; font-weight: 400; }
.book h3 [lang="sa"] { display: block; font-size: var(--step-4); line-height: 1.3; }
.book h3 .t { display: block; font-size: var(--step-2); font-style: italic; color: var(--ink-2); margin-top: .1rem; }
.book .about { margin: 1rem 0 1.25rem; max-width: 38rem; }
.facts { margin: 0 0 1.5rem; color: var(--ink-2); }
.open { display: inline-block; background: var(--ink); color: var(--paper); text-decoration: none; padding: .55rem 1.05rem; border-radius: 999px; font-size: var(--step-0); }
.open:hover { background: var(--rubric); }
.toc { margin-top: 2rem; border-top: 1px solid var(--rule); }
.toc a { display: grid; grid-template-columns: 2.25rem minmax(0, 1fr) auto; gap: 1rem; align-items: baseline; padding: .7rem 0; border-bottom: 1px solid var(--rule); text-decoration: none; }
.toc a:hover { background: var(--hi); }
.toc .n { color: var(--ink-3); font-variant-numeric: lining-nums tabular-nums; }
.toc [lang="sa"] { font-size: 1.25rem; }
.toc .c { color: var(--ink-3); font-size: var(--step--1); }
.toc .heard { color: var(--rubric); }
.notes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2.5rem; padding: 3rem 0 0; color: var(--ink-2); font-size: var(--step--1); line-height: 1.6; }
.notes h2 { font-size: var(--step-1); color: var(--ink); margin-bottom: .5rem; }
.notes p { margin: 0 0 .75rem; }

/* the one dimensional element: a palm-leaf pothī, drawn in CSS 3D */
.pothi { position: relative; width: 16rem; height: 3rem; transform-style: preserve-3d;
  transform: rotateX(var(--rx, 56deg)) rotateZ(var(--rz, -18deg)); transition: transform .9s cubic-bezier(.2, .7, .2, 1); }
.pothi > i { position: absolute; inset: 0; border-radius: .45rem / 1.3rem; transform: translateZ(calc(var(--z) * 1px)); }
.pothi .board { background: linear-gradient(90deg, #00000026, transparent 12% 88%, #00000026), var(--wood);
  box-shadow: inset 0 0 0 1px #0000002a; }
.pothi .leaf { background: linear-gradient(180deg, #ffffff1f, transparent 40%), var(--leaf); box-shadow: inset 0 0 0 1px var(--leaf-edge); translate: var(--dx, 0) 0; filter: brightness(var(--b, 1)); }
.pothi .leaf::before, .pothi .leaf::after, .pothi .top::before, .pothi .top::after { content: ""; position: absolute; top: 50%; width: .5rem; height: .5rem; margin-top: -.25rem; border-radius: 50%; background: #0000004a; }
.pothi .leaf::before, .pothi .top::before { left: 27%; }
.pothi .leaf::after, .pothi .top::after { right: 27%; }
.pothi .top { transition: transform .9s cubic-bezier(.2, .7, .2, 1); }
.pothi .cord { position: absolute; left: 27%; top: 50%; width: 46%; height: 2px; margin-top: -1px; background: #8f2d1c; transform: translateZ(calc(var(--z) * 1px + 1px)); border-radius: 2px; }
.book:hover .pothi .top, .book:focus-within .pothi .top { transform: translateZ(calc(var(--z) * 1px + 14px)) rotateX(-6deg); }
.pothi-shadow { position: absolute; inset: 8% 4%; transform: translateZ(-6px); background: #0000; box-shadow: 0 30px 40px -10px #00000040; border-radius: 1rem; }
@media (prefers-reduced-motion: reduce) { .pothi, .pothi .top { transition: none; } }

.lib-foot { margin-top: 4rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); color: var(--ink-3); font-size: var(--step--1); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

@media (max-width: 860px) {
  .lib-intro { grid-template-columns: 1fr; gap: 1.25rem; padding: 2.75rem 0 2.25rem; }
  .book { grid-template-columns: 1fr; gap: 1rem; }
  .book-stage { height: 10rem; }
  .pothi { width: 13rem; height: 2.5rem; }
  .notes { grid-template-columns: 1fr; gap: 1rem; }
}

/* ── reader: a fixed frame; only the text pane scrolls ───────── */
body.reader { height: 100vh; height: 100dvh; overflow: hidden; }
.app { height: 100%; display: grid; grid-template-rows: var(--bar) minmax(0, 1fr) var(--player); grid-template-columns: var(--side) minmax(0, 1fr); grid-template-areas: "bar bar" "side pane" "side player"; }
.bar { grid-area: bar; display: flex; align-items: center; gap: 1rem; padding: 0 1rem 0 1.25rem; border-bottom: 1px solid var(--rule); background: var(--paper); min-width: 0; }
.bar .mark [lang="sa"] { font-size: 1.3rem; }
.bar .mark span:last-child { font-size: var(--step-0); }
.crumbs { display: flex; align-items: baseline; gap: .5rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); font-size: var(--step-0); }
.crumbs a { text-decoration: none; }
@media (max-width: 900px) { .crumbs .up { display: none; } }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { color: var(--ink-3); }
.find { margin-left: auto; position: relative; flex: 0 1 19rem; }
.find input { width: 100%; height: 2.25rem; padding: 0 .9rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper-2); font-size: var(--step--1); }
.find input::placeholder { color: var(--ink-3); }
.menu { display: none; margin-left: auto; flex: none; border: 1px solid var(--rule); background: transparent; border-radius: 999px; padding: .3rem .8rem; font-size: var(--step--1); cursor: pointer; }

.side { grid-area: side; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); background: var(--paper-2); }
.side-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 1.25rem 1.25rem 2rem; flex: 1; }
.side h2 { font-size: var(--step--1); font-weight: 600; color: var(--ink-2); margin: 1.5rem 0 .5rem; }
.side h2:first-child { margin-top: 0; }
.chapters { list-style: none; margin: 0; padding: 0; }
.chapters a { display: grid; grid-template-columns: 1.75rem minmax(0, 1fr) auto; gap: .5rem; align-items: baseline; padding: .4rem .5rem; margin: 0 -.5rem; border-radius: .4rem; text-decoration: none; }
.chapters a:hover { background: var(--paper-3); }
.chapters a[aria-current] { background: var(--ink); color: var(--paper); }
.chapters a[aria-current] .c, .chapters a[aria-current] .n { color: inherit; opacity: .75; }
.chapters .n { color: var(--ink-3); font-variant-numeric: lining-nums tabular-nums; font-size: var(--step--1); }
.chapters [lang="sa"] { font-size: 1.05rem; line-height: 1.5; }
.chapters .c { font-size: var(--step--1); color: var(--ink-3); font-variant-numeric: lining-nums tabular-nums; }
.chapters .dot { display: inline-block; width: .4rem; height: .4rem; border-radius: 50%; background: var(--rubric); margin-left: .35rem; vertical-align: middle; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.35rem, 1fr)); gap: 2px; }
.grid a { text-align: center; padding: .3rem 0; border-radius: .3rem; text-decoration: none; font-size: var(--step--1); color: var(--ink-2); font-variant-numeric: lining-nums tabular-nums; }
.grid a:hover { background: var(--paper-3); color: var(--ink); }
.grid a.heard { color: var(--rubric); }
.grid a[aria-current] { background: var(--ink); color: var(--paper); }
.results { list-style: none; margin: 0; padding: 0; }
.results a { display: block; padding: .55rem .5rem; margin: 0 -.5rem; border-radius: .4rem; text-decoration: none; }
.results a:hover { background: var(--paper-3); }
.results b { font-weight: 600; font-size: var(--step--1); font-variant-numeric: lining-nums; }
.results span { display: block; font-size: var(--step--1); color: var(--ink-2); font-style: italic; }
.results mark { background: var(--rubric-soft); color: inherit; border-radius: 2px; }
.side .meta { color: var(--ink-2); font-size: var(--step--1); line-height: 1.55; }
.side .meta p { margin: 0 0 .6rem; }

.pane { grid-area: pane; position: relative; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; background: var(--paper); min-height: 0; }
.pane:focus { outline: none; }
.page { max-width: calc(var(--measure) + 8rem); margin: 0 auto; padding: 3rem 2rem 6rem 6rem; }
.ch-head { margin: 0 0 2.5rem; padding-bottom: 1.25rem; border-bottom: 1px solid var(--rule); }
.ch-head p { margin: 0; color: var(--ink-2); }
.ch-head h1 { margin: .25rem 0 .35rem; font-weight: 400; font-size: var(--step-3); line-height: 1.35; }
.ch-head .sub { font-style: italic; }
.verse { position: relative; padding: 1.1rem 1.25rem 1.25rem; margin: 0 -1.25rem .35rem; border-radius: .6rem; scroll-margin-top: 1.5rem; transition: background-color .3s; }
.verse.is-target { background: var(--hi); }
.verse.is-playing { background: var(--hi); }
.verse .num { position: absolute; left: -3.25rem; top: 1.55rem; width: 3.25rem; text-align: right; padding-right: .9rem; color: var(--ink-3); text-decoration: none; font-size: var(--step--1); font-variant-numeric: lining-nums tabular-nums; }
.verse .num:hover { color: var(--rubric); }
.verse .sa { margin: 0; font-size: var(--verse); line-height: 1.72; font-feature-settings: "kern"; }
.verse .sa span.l { display: block; }
.verse .sa .end { color: var(--ink-3); white-space: nowrap; }
.verse .iast { margin: .55rem 0 0; font-style: italic; color: var(--ink-2); font-size: var(--step-0); line-height: 1.55; }
.verse .iast span { display: block; }
.verse.heard .sa .l { cursor: pointer; }
.w { transition: color .12s; }
.is-playing .w { color: var(--ink-3); }
.is-playing .w.sung { color: var(--rubric); }
.verse .play-from { position: absolute; right: .5rem; top: 1.25rem; border: 0; background: transparent; color: var(--rubric); font-size: var(--step--1); cursor: pointer; padding: .2rem .45rem; border-radius: .4rem; opacity: .75; }
.verse .play-from:hover { opacity: 1; background: var(--rubric-soft); }
.ch-foot { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 1rem; }
.overview h1 { font-weight: 400; margin: 0; }
.overview h1 [lang="sa"] { display: block; font-size: var(--step-4); line-height: 1.3; }
.overview h1 .t { display: block; font-size: var(--step-2); font-style: italic; color: var(--ink-2); }
.overview .lede { font-size: var(--step-1); color: var(--ink-2); margin: 1.25rem 0 2rem; max-width: 36rem; }
.overview .toc { margin-top: 0; }
.overview .film { margin: 2.5rem 0 0; }
.overview video { width: 100%; border-radius: .6rem; background: #000; display: block; }
.overview .film figcaption { font-size: var(--step--1); color: var(--ink-2); margin-top: .6rem; }
.credits { margin-top: 3rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); color: var(--ink-2); font-size: var(--step--1); }
.credits p { margin: 0 0 .6rem; max-width: 40rem; }

.player { grid-area: player; display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; border-top: 1px solid var(--rule); background: var(--paper); min-width: 0; }
.player .pp { flex: none; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: 0; background: var(--ink); color: var(--paper); display: grid; place-items: center; cursor: pointer; }
.player .pp:disabled { background: var(--paper-3); color: var(--ink-3); cursor: default; }
.player .pp svg { width: 1rem; height: 1rem; }
.player .now { min-width: 0; flex: 0 1 15rem; line-height: 1.3; }
.player .now b { display: block; font-weight: 500; font-size: var(--step--1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .now span { display: block; font-size: var(--step--1); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .scrub { flex: 1; min-width: 4rem; display: flex; align-items: center; gap: .75rem; font-size: var(--step--1); color: var(--ink-2); font-variant-numeric: lining-nums tabular-nums; }
.player input[type=range] { flex: 1; min-width: 0; accent-color: var(--rubric); height: 1.25rem; }
.player .rate { border: 1px solid var(--rule); background: transparent; border-radius: 999px; padding: .2rem .65rem; font-size: var(--step--1); cursor: pointer; font-variant-numeric: lining-nums; }
.player.empty .scrub, .player.empty .rate { display: none; }
.player.empty .now { flex: 1; }
.player.empty .now span { white-space: normal; }

.scrim { display: none; }

@media (max-width: 900px) {
  :root { --bar: 3.25rem; --player: 4rem; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "bar" "pane" "player"; }
  .menu { display: inline-block; }
  .bar { padding: 0 .75rem; gap: .6rem; }
  .bar .mark span:last-child { display: none; }
  .find { display: none; }
  .side { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: min(78dvh, 40rem); border-right: 0; border-top: 1px solid var(--rule); border-radius: 1rem 1rem 0 0; transform: translateY(102%); transition: transform .3s cubic-bezier(.2, .7, .2, 1); box-shadow: 0 -20px 40px -20px #0000004d; }
  .side .find { display: block; margin: 0 0 1rem; flex: none; }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: #00000040; }
  .side-grip { display: block; width: 2.5rem; height: 4px; border-radius: 2px; background: var(--rule); margin: .6rem auto 0; }
  .page { padding: 1.75rem 1.1rem 4rem 1.1rem; }
  .verse { padding: 1rem .9rem 1.1rem; margin: 0 -.9rem .25rem; }
  .verse .num { position: static; display: block; width: auto; text-align: left; padding: 0 0 .2rem; }
  .verse .play-from { top: .85rem; }
  .player { padding: 0 .85rem; gap: .7rem; }
  .player .now { flex: 1; }
  .player .scrub span { display: none; }
  .player .scrub { flex: 0 1 7rem; }
}
@media (min-width: 901px) { .side-grip { display: none; } }
