/* BHAGAVATA CODEX — the Reading Book.
   Adapted from the JINX book reader (Rajesh Kodaganti's own design):
   dark shell, stacked page edges, hidden-measure pagination, 3D leaf turns.
   Restyled in the Bhagavata Madhubani identity. */

.reader {
  --bk-line: #45423a;
  --bk-ink: #f7ead2;
  --bk-dim: #b9ac8f;
  --bk-accent: #e8a812;
  --bk-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  width: min(1080px, calc(100% - 32px));
  height: min(92svh, 1150px);
  max-height: 96svh;
  margin: 0 auto;
  background: #171b1b;
  color: var(--bk-ink);
  border: 1px solid #000;
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.reader-viewport { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 0; background: #171b1b; overflow: hidden; }
.reader-viewport:fullscreen { width: 100vw; height: 100dvh; }
.reader.reader-full-page { position: fixed; inset: 0; width: 100%; height: 100dvh; max-width: none; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; z-index: 200; }
.reader-full-page .book { width: min(840px, 100%); }
.reader-full-page .book-page-text { inset-inline: clamp(24px, 6vw, 84px); }

.reader-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 14px 24px; border-bottom: 1px solid var(--bk-line); }
.reader-header h2 { font-size: 1.2rem; margin: 2px 0 0; color: var(--bk-ink); font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600; letter-spacing: .01em; }
.reader-header > div:first-child { min-width: 0; }
.tiny-label { font: 10px/1.5 var(--bk-mono); text-transform: uppercase; letter-spacing: .14em; color: var(--bk-dim); }
.reader-window-controls { display: flex; align-items: center; gap: 10px; margin-left: 20px; flex-shrink: 0; }
.reader-fullscreen { display: inline-flex; align-items: center; gap: 7px; min-height: 43px; padding: 8px 12px; border: 1px solid var(--bk-line); background: transparent; color: var(--bk-ink); font: .72rem var(--bk-mono); cursor: pointer; border-radius: 4px; }
.reader-fullscreen:hover, .reader-fullscreen[aria-pressed="true"] { border-color: var(--bk-accent); background: #2b2413; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 43px; height: 43px; border: 1px solid var(--bk-line); background: transparent; color: var(--bk-ink); font-size: 1rem; cursor: pointer; border-radius: 4px; text-decoration: none; }
.icon-button:hover { border-color: var(--bk-accent); color: var(--bk-accent); }

.reader-toolbar { display: flex; align-items: center; padding: 10px 24px; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--bk-line); }
.reader-toolbar label { display: inline-flex; align-items: center; gap: 8px; font: .7rem var(--bk-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--bk-dim); min-width: 0; }
.reader-toolbar select { max-width: 340px; min-height: 38px; padding: 6px 8px; background: #101312; color: var(--bk-ink); border: 1px solid var(--bk-line); border-radius: 4px; font: .8rem Georgia, serif; text-transform: none; letter-spacing: 0; }
.reader-text-controls { margin-left: auto; display: inline-flex; gap: 8px; }
.reader-text-controls button { min-height: 38px; min-width: 44px; padding: 6px 10px; border: 1px solid var(--bk-line); background: transparent; color: var(--bk-ink); font: .8rem var(--bk-mono); cursor: pointer; border-radius: 4px; }
.reader-text-controls button:hover:not(:disabled) { border-color: var(--bk-accent); }
.reader-text-controls button:disabled { opacity: .35; cursor: default; }

.book-view-status { margin: 8px 24px 0; color: #ddc2a8; font-size: .7rem; }
.reader-advisory { margin: 10px 24px 0; font-size: .61rem; line-height: 1.5; color: var(--bk-dim); font-family: var(--bk-mono); }
#reader-state:not(:empty) { margin: 8px 24px; font-size: .8rem; max-height: 25svh; overflow-y: auto; color: var(--bk-ink); }
#reader-state .error-message { margin: 0; padding: 10px; border: 1px solid #d43d1a; border-radius: 4px; }
#reader-state .retry-button { margin-left: 12px; padding: 6px 12px; background: transparent; border: 1px solid var(--bk-accent); color: var(--bk-accent); cursor: pointer; border-radius: 4px; font: .75rem var(--bk-mono); }

.book-stage { flex: 1; min-height: 180px; padding: 18px 48px 14px; display: flex; justify-content: center; perspective: 1800px; overflow: hidden; }
.book { position: relative; width: min(590px, 100%); height: 100%; outline-offset: 9px; touch-action: pan-y; --book-size: 18px; }
.book::before, .book::after { content: ""; position: absolute; inset: 3px -4px -3px 4px; background: #bcb8a9; border-radius: 2px 5px 5px 2px; box-shadow: 2px 2px 0 #575b51; }
.book::after { inset: 6px -7px -6px 7px; z-index: -1; background: #8c9082; box-shadow: 10px 12px 30px #0008; }
.book-page { position: absolute; inset: 0; margin: 0; overflow: hidden; color: #252923; background: linear-gradient(90deg, #cec9b9, #efebdd 4%, #f4f0e5 12%, #f4f0e5 95%, #e8e3d6); border-radius: 2px 4px 4px 2px; box-shadow: inset 1px 0 2px #fff7; }
.book-running-title { position: absolute; left: 34px; right: 30px; top: 17px; color: #686e62; font: 10px/1.5 var(--bk-mono); text-transform: uppercase; letter-spacing: .08em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid #c8c5b6; padding-bottom: 9px; }
.book-page-text { position: absolute; inset: 57px 34px 43px 38px; overflow: hidden; font: var(--book-size)/1.65 Georgia, "Times New Roman", serif; overflow-wrap: anywhere; }
.book-page-text p { margin: 0 0 .8em; white-space: pre-wrap; }
.book-page-text .source-context { font-size: .8em; color: #61685a; margin-bottom: 1.5em; }
.book-page-text h3 { font: 1.6em/1.2 Georgia, "Times New Roman", serif; margin: 0 0 .85em; letter-spacing: -.025em; color: #353b30; }
.book-page-text .book-chapter-subtitle { color: #61685a; font-size: .8em; margin-top: -.6em; margin-bottom: 1.4em; }
.book-page-text .book-part { font: .62em/1.5 var(--bk-mono); text-transform: uppercase; letter-spacing: .16em; color: #a05a10; margin: 0 0 .9em; }
.book-page-text hr { width: 42px; border: 0; border-top: 1px solid #818874; margin: 1.2em auto; }
.book-folio { position: absolute; bottom: 13px; right: 30px; left: 34px; display: flex; justify-content: space-between; color: #68705e; font: 10px/1.5 var(--bk-mono); }
.book-measure { visibility: hidden; pointer-events: none; }
.book-leaf { position: absolute; inset: 0; transform-origin: left center; transform-style: preserve-3d; z-index: 3; pointer-events: none; }
.book-leaf > .book-page { backface-visibility: hidden; }
.book-leaf-back { position: absolute; inset: 0; backface-visibility: hidden; transform: rotateY(180deg); background: linear-gradient(90deg, #e2dccb, #f0ecdf 70%, #b4b2a2); box-shadow: -12px 0 24px #0002; }
.book-leaf::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, #0003, transparent 25%, #0001); pointer-events: none; }

/* ---- chapter plate (Madhubani scene / portrait medallion) ---- */
.book-plate { margin: 0 0 1.3em; }
.book-plate svg { display: block; width: 100%; height: auto; border-radius: 2px; }
.book-plate--portrait { text-align: center; }
.book-plate--portrait svg { width: min(190px, 52%); margin: 0 auto; }
.book-plate figcaption { margin-top: .5em; font: .58em/1.5 var(--bk-mono); text-transform: uppercase; letter-spacing: .12em; color: #8a7a4a; text-align: center; }

/* ---- the Madhubani cover ---- */
.book-page.cover-page { background: #f7ead2; }
.book-cover-open { display: block; padding: 0; border: 0; width: 100%; height: 100%; background: transparent; cursor: pointer; text-align: center; }
.book-cover-open:focus-visible { outline: 2px solid #d43d1a; outline-offset: -6px; }
.book-cover { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 26px 24px 22px; background:
  radial-gradient(circle at 50% 0%, rgba(232,168,18,.16), transparent 55%),
  #f7ead2;
  border: 3px solid #2e1608;
  outline: 10px solid #d43d1a;
  outline-offset: -16px;
  box-shadow: inset 0 0 0 13px #f7ead2, inset 0 0 0 15px #2e1608;
  color: #2e1608; font-family: Georgia, "Times New Roman", serif; overflow: hidden; }
.book-cover__caps { font: 10px/1.6 var(--bk-mono); text-transform: uppercase; letter-spacing: .22em; color: #a03c14; }
.book-cover__sa { font-family: "Noto Serif Devanagari", Georgia, serif; font-size: clamp(1.5rem, 5.4vw, 2.3rem); font-weight: 600; line-height: 1.25; }
.book-cover__art { width: min(400px, 92%); margin: 10px auto; }
.book-cover__art svg { display: block; width: 100%; height: auto; border: 2.4px solid #2e1608; }
.book-cover__title { font-size: clamp(1.4rem, 4.6vw, 2rem); line-height: 1.15; letter-spacing: -.01em; margin: 0; }
.book-cover__sub { font-size: .82rem; color: #6b543a; margin: 6px 0 0; font-style: italic; }
.book-cover__open { font: .72rem var(--bk-mono); text-transform: uppercase; letter-spacing: .18em; color: #d43d1a; border: 1.6px solid #d43d1a; padding: 9px 16px; border-radius: 3px; background: rgba(255,255,255,.35); }
.book-cover__foot { font: 9px/1.6 var(--bk-mono); text-transform: uppercase; letter-spacing: .18em; color: #8a7a4a; }

.book-reading-tools { display: flex; justify-content: center; align-items: center; gap: 24px; padding: 2px 24px; flex-shrink: 0; }
.text-link { background: none; border: 0; padding: 6px 2px; color: var(--bk-accent); font: .72rem var(--bk-mono); text-transform: uppercase; letter-spacing: .1em; cursor: pointer; text-decoration: none; }
.text-link:hover:not(:disabled) { text-decoration: underline; }
.text-link:disabled { opacity: .35; cursor: default; }
.book-reading-tools .text-link, .book-reading-tools a { font-size: .66rem; }
.reader-footer { display: flex; align-items: center; justify-content: space-between; padding: 9px 24px; gap: 12px; border-top: 1px solid var(--bk-line); }
.reader-footer .text-link { font-size: .76rem; min-height: 42px; display: inline-flex; align-items: center; }
#reader-position { text-align: center; font-size: .6rem; }

.book-intro { max-width: 760px; margin: 0 auto; text-align: center; }

@media (max-width: 600px) {
  .reader { width: 100%; height: 100svh; max-height: 100svh; margin: 0; border: 0; border-radius: 0; }
  .reader-header { padding: 10px 14px; }
  .reader-header h2 { font-size: 1rem; overflow-wrap: anywhere; }
  .reader-header .tiny-label { font-size: .55rem; }
  .reader-window-controls { gap: 6px; margin-left: 10px; }
  .reader-fullscreen { padding-inline: 8px; font-size: .62rem; max-width: 118px; }
  .reader-full-page .book-page-text { inset-inline: 24px 19px; }
  .book-view-status { margin-inline: 14px; font-size: .62rem; }
  .reader-toolbar { padding: 8px 14px; gap: 8px 12px; }
  .reader-toolbar label { flex: none; min-width: 0; gap: 5px; font-size: .65rem; }
  .reader-toolbar select { width: 120px; max-width: 120px; }
  .reader-toolbar .book-chapter-label { flex: 1 1 150px; }
  .book-chapter-label select { width: 100%; max-width: 220px; min-width: 70px; }
  .reader-text-controls { margin: 0; }
  .reader-text-controls button { min-height: 30px; min-width: 32px; }
  .reader-advisory { margin: 6px 14px 0; font-size: .53rem; }
  #reader-state:not(:empty) { margin: 6px 14px; }
  .book-stage { padding: 12px 18px; }
  .book-page-text { inset: 44px 19px 33px 24px; line-height: 1.55; }
  .book-running-title { top: 11px; left: 24px; right: 19px; font-size: 9px; padding-bottom: 6px; }
  .book-folio { bottom: 10px; left: 24px; right: 19px; font-size: 9px; }
  .book-reading-tools { gap: 14px; padding-inline: 14px; }
  .book-reading-tools .text-link, .book-reading-tools a { font-size: .58rem; }
  .reader-footer { padding: 5px 14px; gap: 6px; }
  .reader-footer .text-link { font-size: .65rem; }
  #reader-position { font-size: .52rem; }
  .book-cover { padding: 18px 14px 14px; }
}
@media (max-height: 540px) {
  .reader { height: 100svh; max-height: 100svh; }
  .reader-header { padding-block: 5px; }
  .reader-header .tiny-label, .reader-advisory, .book-reading-tools { display: none; }
  .reader-toolbar { padding-block: 5px; }
  .book-stage { min-height: 100px; padding-block: 7px; }
  .book-page-text { inset-block: 34px 24px; }
  .book-running-title { top: 6px; padding-bottom: 3px; }
  .book-folio { bottom: 5px; }
  .reader-footer { padding-block: 2px; }
}
