:root {
  color-scheme: dark;
  --night: #10141c;
  --ivory: #fff9ec;
  --text: #f3ede1;
  --muted: #e1e2da;
  --gold: #f2d58f;
  --gold-light: #ffe9b6;
  --line: rgba(244, 222, 175, .4);
  --reading-scale: 1;
  --page-gutter: 16px;
  --text-shadow: 0 1px 2px #000, 0 2px 5px #000, 0 0 12px rgba(0, 0, 0, .95);
  --serif: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --devanagari: "Kohinoor Devanagari", "Noto Serif Devanagari", "Nirmala UI", Mangal, serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--night); scroll-padding-top: 20px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100svh; margin: 0; color: var(--text); font-family: var(--serif); -webkit-font-smoothing: antialiased; isolation: isolate; }
button, select { font: inherit; }
button, a, select, summary { -webkit-tap-highlight-color: transparent; outline-offset: 4px; }
button, select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
:focus-visible { outline: 2px solid var(--gold-light); }
a { color: var(--gold); text-decoration-color: currentColor; text-underline-offset: 4px; }
a:hover { color: var(--gold-light); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 20; top: -100px; left: 16px; padding: 14px 20px; background: var(--ivory); color: var(--night); border-radius: 3px; font: 14px var(--sans); }
.skip-link:focus { top: max(16px, env(safe-area-inset-top, 0px)); }

/* The painting is unfiltered. Reading contrast comes from the glyph shadows. */
.artwork { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--night); pointer-events: none; }
.artwork img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 40% 48%; opacity: 0; transition: opacity .35s ease; }
.artwork img.loaded { opacity: 1; }
.masthead, .reader, .verse-navigation { text-shadow: var(--text-shadow); }

/* Phone layout is the base; wider layouts are added below. */
.masthead { max-width: 1660px; padding: max(16px, env(safe-area-inset-top, 0px)) max(var(--page-gutter), env(safe-area-inset-right, 0px)) 16px max(var(--page-gutter), env(safe-area-inset-left, 0px)); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px 10px; }
.wordmark { display: inline-flex; align-items: center; gap: 9px; min-width: 0; min-height: 44px; color: var(--ivory); text-decoration: none; }
.wordmark > span:last-child { min-width: 0; }
.emblem { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold-light); font: 22px var(--devanagari); padding-top: 2px; }
.wordmark strong { display: block; font-weight: 400; font-size: clamp(15px, 4.1vw, 21px); line-height: 1.3; overflow-wrap: anywhere; }
.wordmark small { display: block; margin-top: 5px; font: 8px/1.5 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--text); }
.library-selectors { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: end; gap: 16px; min-width: 0; }
.library-selectors label { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.library-selectors label > span { font: 10px/1.5 var(--sans); color: var(--text); text-transform: uppercase; letter-spacing: .12em; }
.library-selectors select { width: 100%; min-width: 0; min-height: 44px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--ivory); padding: 8px 22px 8px 5px; font: 16px/1.5 var(--sans); text-shadow: var(--text-shadow); text-overflow: ellipsis; }
.library-selectors option { background: var(--night); color: var(--ivory); text-shadow: none; }
.selector-divider { display: none; }
.type-controls { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 5px; }
.type-controls button { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--ivory); font-size: 18px; text-shadow: var(--text-shadow); }
.type-controls button + button { border-left: 1px solid var(--line); }
.type-controls button span { font: 10px var(--sans); vertical-align: 3px; margin-left: 2px; }
.type-controls button:hover:not(:disabled) { color: var(--gold-light); }

.reader { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 max(var(--page-gutter), env(safe-area-inset-right, 0px)) calc(150px + env(safe-area-inset-bottom, 0px)) max(var(--page-gutter), env(safe-area-inset-left, 0px)); }
.painting-side { min-width: 0; padding: 14px 0 32px; }
.eyebrow { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; color: var(--gold-light); font: 11px/1.5 var(--sans); letter-spacing: .15em; text-transform: uppercase; }
.chapter-name { margin: 0; font-size: clamp(32px, 8vw, 48px); line-height: 1.17; font-weight: 400; color: var(--ivory); overflow-wrap: anywhere; }
.chapter-subtitle { margin: 10px 0 0; font-size: 17px; line-height: 1.6; color: var(--text); max-width: 500px; }
.painting-caption { display: flex; flex-direction: column; align-items: flex-start; margin-top: 22px; min-width: 0; }
.small-rule { display: block; flex: 0 0 32px; height: 1px; background: var(--gold); }
.painting-caption h1 { color: var(--ivory); font-weight: 400; font-size: clamp(29px, 7vw, 40px); line-height: 1.2; letter-spacing: -.018em; margin: 0 0 14px; text-wrap: balance; overflow-wrap: anywhere; }
.scene-description { color: var(--text); font-size: 16px; line-height: 1.75; margin: 0; overflow-wrap: anywhere; }
.art-button { order: -1; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; width: 100%; min-width: 0; min-height: 44px; margin: 0 0 28px; padding: 0; text-align: left; border: 0; background: transparent; color: var(--ivory); text-shadow: var(--text-shadow); }
.art-thumbnail { display: block; width: 100%; aspect-ratio: 3 / 2; overflow: hidden; border-radius: 3px; }
.art-thumbnail img { width: 100%; height: 100%; object-fit: contain; display: block; }
.art-button strong { display: block; font-size: 17px; font-weight: 400; }
.art-button small { display: block; font: 12px/1.6 var(--sans); color: var(--text); margin-top: 4px; }
.art-button small span { color: var(--gold); margin-left: 8px; }
.art-button:hover:not(:disabled) strong { color: var(--gold-light); }
.visual-note { margin: 14px 0 0; color: var(--muted); font: 12px/1.6 var(--sans); }
.art-unavailable { font: 14px var(--sans); color: var(--muted); }

/* No panel fill, blur, shadow, tint or decorative overlay obscures the art. */
.reading-panel { min-width: 0; padding: 18px 0 24px; background: transparent; border: 0; border-radius: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; overflow-wrap: anywhere; }
.reading-panel:focus-visible { outline: 2px solid var(--gold-light); }
.verse-heading-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 28px; }
.verse-heading-row h2 { color: var(--gold); font: 12px/1.6 var(--sans); letter-spacing: .12em; text-transform: uppercase; margin: 0; }
.source-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--text); font: 13px var(--sans); text-decoration: none; white-space: nowrap; }
.source-link span { margin-left: 7px; color: var(--gold); }
.section-label { color: var(--gold-light); font: 11px/1.6 var(--sans); text-transform: uppercase; letter-spacing: .14em; font-weight: 600; margin: 0 0 14px; }
.sanskrit-section .section-label, .transliteration-section .section-label { text-align: center; }
.sanskrit { color: var(--ivory); font: calc(clamp(21px, 5.8vw, 27px) * var(--reading-scale))/1.95 var(--devanagari); text-align: center; white-space: pre-line; overflow-wrap: anywhere; }
.transliteration-section { padding-top: 26px; }
.transliteration { color: var(--gold-light); font: italic calc(17px * var(--reading-scale))/1.85 var(--serif); text-align: center; white-space: pre-line; overflow-wrap: anywhere; }
.glossary-section { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.glossary { margin: 0; font: calc(16px * var(--reading-scale))/1.9 var(--serif); color: var(--text); }
.glossary-term { color: var(--gold-light); font-style: italic; }
.glossary-separator { color: var(--ivory); padding: 0 3px; }
.translation-section { margin-top: 30px; }
.translation { color: var(--ivory); font: calc(21px * var(--reading-scale))/1.75 var(--serif); }
.translation p, .reading-note p, #chapter-introduction p { margin: 0; }
.translation p + p, .reading-note p + p, #chapter-introduction p + p { margin-top: 1em; }
.note-section { margin-top: 29px; padding-top: 25px; border-top: 1px solid var(--line); }
.reading-note { color: var(--text); font: calc(16px * var(--reading-scale))/1.9 var(--serif); }
.chapter-context { margin-top: 27px; border-top: 1px solid var(--line); padding-top: 10px; }
.chapter-context summary { min-height: 44px; padding: 12px 0; color: var(--text); font: 14px/1.6 var(--sans); cursor: pointer; }
.chapter-context[open] summary { margin-bottom: 8px; color: var(--gold); }
#chapter-introduction { color: var(--text); font: 16px/1.85 var(--serif); }
.edition-note { margin-top: 25px; color: var(--muted); font: 12px/1.8 var(--sans); }
.edition-note p { margin: 0 0 8px; }
.edition-note a { display: inline-flex; align-items: center; min-height: 44px; color: var(--gold-light); }

/* Compact navigation stays reachable with a thumb and respects device insets. */
.verse-navigation { position: fixed; z-index: 5; left: 0; bottom: 0; right: 0; padding: 10px max(10px, env(safe-area-inset-right, 0px)) calc(9px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px)); border-top: 1px solid var(--line); background: rgba(12,18,26,.84); }
.navigation-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 6px; }
.direction-button { display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; gap: 10px; padding: 8px; min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--gold-light); font: 14px var(--sans); text-shadow: var(--text-shadow); }
.direction-button > span[aria-hidden] { font-size: 23px; }
.direction-label { display: none; }
.direction-button:hover:not(:disabled) { color: white; }
.verse-strip-wrap { min-width: 0; flex: 1; }
.verse-strip { display: flex; justify-content: space-between; gap: 4px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; padding: 4px; scroll-padding-inline: 4px; }
.verse-strip::-webkit-scrollbar { display: none; }
.verse-number { display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 44px; border: 1px solid transparent; border-radius: 50%; color: var(--text); background: transparent; font: 16px var(--serif); text-shadow: var(--text-shadow); transition: background .2s, color .2s; }
.verse-number:hover { border-color: var(--gold); color: var(--gold-light); }
.verse-number[aria-current="page"] { background: var(--gold); color: #1b211d; border-color: var(--gold-light); text-shadow: none; }
.navigation-caption { max-width: 1400px; margin: 5px auto 0; display: flex; align-items: center; justify-content: center; gap: 16px; color: var(--text); font: 11px/1.5 var(--sans); text-align: center; }
.keyboard-hint { display: none; }

.art-dialog { --dialog-gutter: max(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)); max-width: none; width: calc(100% - var(--dialog-gutter) - var(--dialog-gutter)); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); padding: 0; border: 1px solid #6f6246; border-radius: 6px; background: #0c1116; color: var(--ivory); overflow: auto; overscroll-behavior: contain; box-shadow: 0 24px 100px #0009; }
.art-dialog::backdrop { background: rgba(3,8,13,.94); }
.art-dialog-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; padding: 12px; border-bottom: 1px solid var(--line); }
.art-dialog-toolbar p { flex: 1 1 220px; min-width: 0; margin: 0; font: 16px/1.5 var(--serif); overflow-wrap: anywhere; }
.art-dialog-actions { display: flex; flex: 1 1 200px; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
.art-dialog-actions a { display: inline-flex; align-items: center; min-height: 44px; font: 14px/1.5 var(--sans); }
.art-dialog-actions button { flex: 0 0 44px; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; color: var(--ivory); background: transparent; font: 29px var(--sans); }
.art-dialog figure { margin: 0; }
.art-dialog figure > img { display: block; width: 100%; height: auto; max-height: 70vh; max-height: 70dvh; object-fit: contain; background: #080c10; }
.art-dialog figcaption { padding: 16px; max-width: 900px; margin: 0 auto; color: var(--text); text-align: center; font: 15px/1.75 var(--serif); overflow-wrap: anywhere; }
.art-dialog .art-details { max-width: 900px; margin: 0 auto; padding: 0 16px 20px; overflow-wrap: anywhere; }
.art-dialog .art-details summary { min-height: 44px; padding: 12px 0; border-top: 1px solid var(--line); color: var(--gold-light); font: 14px/1.6 var(--sans); cursor: pointer; }
.art-dialog .art-details dl { margin: 8px 0 0; }
.art-dialog .art-details dt { color: var(--gold-light); font: italic 16px/1.75 var(--serif); }
.art-dialog .art-details dd { margin: 3px 0 18px; color: var(--text); font: 15px/1.75 var(--serif); }
.art-dialog .art-details dd:last-child { margin-bottom: 0; }
.dialog-open { overflow: hidden; }
.load-error { width: calc(100% - 32px); max-width: 600px; margin: 10vh auto; padding: 24px; background: var(--night); border: 1px solid var(--line); line-height: 1.7; overflow-wrap: anywhere; }

/* Tablets keep the complete painting and reading in a comfortable single column. */
@media (min-width: 640px) {
  :root { --page-gutter: 28px; }
  .masthead { max-width: 960px; gap: 20px 24px; padding-top: max(24px, env(safe-area-inset-top, 0px)); }
  .wordmark { gap: 14px; }
  .wordmark strong { font-size: 24px; }
  .wordmark small { font-size: 10px; }
  .emblem { flex-basis: 42px; width: 42px; height: 42px; font-size: 26px; }
  .library-selectors { grid-template-columns: minmax(100px, 150px) minmax(0, 1fr); gap: 24px; }
  .painting-side { padding-top: 24px; }
  .chapter-name { font-size: 50px; }
  .painting-caption { margin-top: 28px; }
  .reading-panel { padding-top: 26px; }
  .navigation-inner { gap: 14px; }
  .verse-navigation { padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); }
  .art-dialog { --dialog-gutter: max(20px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)); width: min(1400px, calc(100% - var(--dialog-gutter) - var(--dialog-gutter))); }
  .art-dialog-toolbar { padding: 14px 20px; }
  .art-dialog-actions { flex: 0 1 auto; justify-content: flex-end; gap: 24px; }
}

/* Wide tablets in landscape and desktops have room for two flexible columns. */
@media (min-width: 1024px) {
  :root { --page-gutter: 36px; }
  .masthead { max-width: 1660px; display: flex; gap: 26px; min-height: 105px; padding-bottom: 24px; }
  .wordmark { flex: 1; }
  .library-selectors { display: flex; flex: 0 1 420px; align-items: center; gap: 18px; }
  .library-selectors label:first-child { flex: 0 0 58px; }
  .library-selectors label:last-child { flex: 1; }
  .type-controls { flex-shrink: 0; }
  .reader { max-width: 1564px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: clamp(32px, 5vw, 80px); align-items: start; padding-top: 16px; }
  .painting-side { position: sticky; top: max(24px, env(safe-area-inset-top, 0px)); min-height: min(740px, calc(100svh - 190px)); display: flex; flex-direction: column; justify-content: space-between; padding: 16px 0 24px; }
  .chapter-name { font-size: clamp(40px, 4vw, 56px); }
  .painting-caption { margin-top: 100px; max-width: 480px; }
  .painting-caption h1 { font-size: clamp(32px, 3vw, 43px); }
  .art-button { order: 0; flex-direction: row; align-items: center; width: auto; gap: 16px; margin: 24px 0 0; }
  .art-thumbnail { flex: 0 0 92px; width: 92px; height: auto; }
  .reading-panel { padding: 22px 0 32px; }
  .sanskrit { font-size: calc(26px * var(--reading-scale)); }
  .direction-label { display: inline; }
  .navigation-caption { justify-content: space-between; text-align: left; }
  .keyboard-hint { display: inline; }
}
@media (min-width: 1440px) {
  :root { --page-gutter: 48px; }
  .reader { grid-template-columns: minmax(0, 1fr) minmax(0, 700px); }
  .reading-panel { padding: 30px 24px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .painting-side { position: static; min-height: 0; }
  .painting-caption { margin-top: 28px; }
  .art-dialog { max-height: calc(100dvh - 12px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
@media print {
  html, body { color: #111; background: white; }
  .artwork, .masthead, .verse-navigation, .painting-side, .source-link, .skip-link { display: none !important; }
  .reader { display: block; padding: 0; max-width: none; text-shadow: none; }
  .reading-panel { padding: 0; }
  .reading-panel * { color: #111 !important; text-shadow: none !important; }
  .chapter-context { display: none; }
}
