/* ============================================================
   Gitavivruti — Sacred Reader
   Themes: Day · Sepia · Night
   ============================================================ */

:root {
  --bg: #f1e9d8;
  --bg-glow-1: rgba(21, 94, 99, 0.14);
  --bg-glow-2: rgba(138, 51, 72, 0.10);
  --bg-glow-3: rgba(201, 133, 37, 0.12);
  --surface: #fffdf7;
  --surface-2: #f6efe0;
  --surface-glass: rgba(255, 253, 247, 0.78);
  --ink: #20262a;
  --muted: #6a7472;
  --subtle: #94a09f;
  --line: rgba(31, 38, 39, 0.13);
  --line-strong: rgba(31, 38, 39, 0.22);
  --accent: #15706c;
  --accent-strong: #0c4b49;
  --accent-soft: #d8efed;
  --rose: #9a3a4f;
  --rose-soft: #f6dde3;
  --gold: #c2841f;
  --gold-soft: #f7e8cd;
  --hl-bg: linear-gradient(transparent 10%, #ffe39a 10%, #ffe39a 86%, transparent 86%);
  --hl-edge: rgba(194, 132, 31, 0.55);
  --hl-glow: rgba(194, 132, 31, 0.20);
  --paper-texture: 0.04;
  --shadow-sm: 0 4px 14px rgba(31, 38, 39, 0.08);
  --shadow-md: 0 16px 40px rgba(31, 38, 39, 0.13);
  --shadow-lg: 0 32px 80px rgba(31, 38, 39, 0.22);
  --shadow-play: 0 14px 32px rgba(21, 94, 99, 0.32);
  --reader-size: 1.35rem;
  --ease-soft: cubic-bezier(0.22, 0.7, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
}

html[data-theme="sepia"] {
  --bg: #e6d4b3;
  --bg-glow-1: rgba(23, 107, 95, 0.12);
  --bg-glow-2: rgba(154, 74, 58, 0.12);
  --bg-glow-3: rgba(181, 119, 42, 0.16);
  --surface: #f5e9cf;
  --surface-2: #ecdcbb;
  --surface-glass: rgba(245, 233, 207, 0.80);
  --ink: #463623;
  --muted: #836b4c;
  --subtle: #a08a68;
  --line: rgba(70, 54, 35, 0.16);
  --line-strong: rgba(70, 54, 35, 0.26);
  --accent: #176b5f;
  --accent-strong: #0e4940;
  --accent-soft: #d8e9df;
  --rose: #9a4636;
  --rose-soft: #efd8cc;
  --gold: #ab6e22;
  --gold-soft: #ecd9b3;
  --hl-bg: linear-gradient(transparent 10%, #ecce86 10%, #ecce86 86%, transparent 86%);
  --hl-edge: rgba(171, 110, 34, 0.6);
  --hl-glow: rgba(171, 110, 34, 0.22);
  --shadow-sm: 0 4px 14px rgba(70, 54, 35, 0.12);
  --shadow-md: 0 16px 40px rgba(70, 54, 35, 0.16);
  --shadow-play: 0 14px 32px rgba(23, 107, 95, 0.30);
}

html[data-theme="night"] {
  --bg: #14171a;
  --bg-glow-1: rgba(95, 201, 194, 0.10);
  --bg-glow-2: rgba(224, 138, 154, 0.09);
  --bg-glow-3: rgba(230, 184, 96, 0.08);
  --surface: #1c2127;
  --surface-2: #232a31;
  --surface-glass: rgba(28, 33, 39, 0.82);
  --ink: #ebe5d8;
  --muted: #9aa4a3;
  --subtle: #6f7b7a;
  --line: rgba(255, 255, 255, 0.10);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #54c8c0;
  --accent-strong: #8fe4dc;
  --accent-soft: rgba(84, 200, 192, 0.16);
  --rose: #e995a5;
  --rose-soft: rgba(233, 149, 165, 0.16);
  --gold: #e6b860;
  --gold-soft: rgba(230, 184, 96, 0.16);
  --hl-bg: rgba(230, 184, 96, 0.20);
  --hl-edge: rgba(230, 184, 96, 0.50);
  --hl-glow: rgba(230, 184, 96, 0.28);
  --paper-texture: 0;
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.40);
  --shadow-md: 0 18px 44px rgba(0, 0, 0, 0.50);
  --shadow-lg: 0 32px 80px rgba(0, 0, 0, 0.60);
  --shadow-play: 0 14px 32px rgba(84, 200, 192, 0.28);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  position: relative;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  height: 100dvh;
  overflow: hidden;
  transition: background-color 0.5s ease, color 0.5s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 0% 0%, var(--bg-glow-1), transparent 42%),
    radial-gradient(120% 90% at 100% 0%, var(--bg-glow-3), transparent 44%),
    radial-gradient(130% 100% at 50% 120%, var(--bg-glow-2), transparent 46%);
  transition: opacity 0.5s ease;
}

body > * {
  position: relative;
  z-index: 1;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
}

svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Book progress bar ---------- */
.book-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 50;
  background: transparent;
  pointer-events: none;
}

.book-progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold), var(--rose));
  box-shadow: 0 0 10px var(--hl-glow);
  border-radius: 0 3px 3px 0;
  transition: width 0.55s var(--ease-soft);
}

/* ---------- Landing (book cover) ---------- */
.landing {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--bg-glow-3), transparent 50%),
    radial-gradient(120% 100% at 50% 120%, var(--bg-glow-1), transparent 52%),
    var(--bg);
  opacity: 1;
  transition: opacity 0.65s var(--ease-soft);
}

.landing[hidden] {
  display: none;
}

.landing.is-leaving {
  opacity: 0;
}

.landing-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  perspective: 2000px;
  perspective-origin: 50% 40%;
}

.book3d {
  position: relative;
  width: clamp(216px, 62vw, 320px);
  aspect-ratio: 1 / 1.42;
  border: 0;
  padding: 0;
  background: transparent;
  transform-style: preserve-3d;
  transform: rotateX(6deg) rotateY(-26deg);
  transition: transform 0.9s var(--ease-soft);
}

.book3d:hover,
.book3d:focus-visible {
  outline: none;
  transform: rotateX(4deg) rotateY(-16deg) translateY(-4px);
}

.book3d.is-opening,
.book3d.is-opening:hover {
  transform: translateZ(380px) rotateX(2deg) rotateY(-4deg);
}

.book3d-shadow {
  position: absolute;
  left: 50%;
  bottom: -10%;
  width: 78%;
  height: 9%;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.42), transparent 78%);
  filter: blur(7px);
  opacity: 0.7;
  transition: opacity 0.9s var(--ease-soft), width 0.9s var(--ease-soft);
}

.book3d.is-opening .book3d-shadow {
  width: 96%;
  opacity: 0.5;
}

.book3d-leaf {
  position: absolute;
  inset: 0;
  border-radius: 5px 9px 9px 5px;
  transform: translateZ(-1px);
}

.book3d-leaf-paper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 5px 9px 9px 5px;
  background: var(--surface);
  box-shadow:
    inset 0 0 0 1px var(--line),
    var(--shadow-md);
}

.book3d-leaf-paper img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.book3d-leaf-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 14%);
}

.book3d-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  transform: translateZ(-2px);
  border-radius: 5px 0 0 5px;
  background: linear-gradient(90deg, #07302f, var(--accent-strong));
  box-shadow: inset -2px 0 6px rgba(0, 0, 0, 0.45);
}

.book3d-cover {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: left center;
  transform: rotateY(0deg);
  transition: transform 1.05s var(--ease-soft);
}

.book3d.is-opening .book3d-cover {
  transform: rotateY(-162deg);
  transition-delay: 0.62s;
}

.book3d-face {
  position: absolute;
  inset: 0;
  border-radius: 5px 9px 9px 5px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.book3d-face-front {
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.10), transparent 60%),
    linear-gradient(150deg, var(--accent), var(--accent-strong) 60%, #07302f);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.10),
    var(--shadow-lg);
}

.book3d-face-front::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 9px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), transparent);
}

.book3d-face-back {
  transform: rotateY(180deg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.book-cover-frame {
  position: absolute;
  inset: 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  border: 1px solid rgba(230, 184, 96, 0.55);
  border-radius: 4px;
  padding: 18px 14px;
  color: #fff;
}

.book-cover-mark {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 14px;
  padding: 2px;
  background: linear-gradient(145deg, var(--gold), var(--rose));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

.book-cover-mark img {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  object-fit: cover;
  object-position: center 38%;
  display: block;
}

.book-cover-kicker {
  color: var(--gold);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.book-cover-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: 0.01em;
  color: #fdf6e6;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
}

.book-cover-rule {
  color: var(--gold);
  font-size: 1.1rem;
  opacity: 0.85;
  line-height: 1;
}

.book-cover-count {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: rgba(253, 246, 230, 0.78);
}

.book-cover-count strong {
  color: var(--gold);
  font-weight: 700;
}

.landing-hint {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  animation: landing-hint-pulse 2.4s var(--ease-soft) infinite;
  transition: opacity 0.4s var(--ease-soft);
}

.book3d.is-opening ~ .landing-hint {
  opacity: 0;
}

@keyframes landing-hint-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* ---------- Top bar ---------- */
.topbar {
  align-items: center;
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex: 0 0 auto;
  gap: 16px;
  justify-content: space-between;
  padding: 13px 20px;
  z-index: 5;
}

.brand {
  align-items: center;
  display: flex;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  display: block;
  flex: 0 0 46px;
  height: 46px;
  width: 46px;
  border-radius: 12px;
  padding: 2px;
  background: linear-gradient(145deg, var(--gold), var(--rose));
  box-shadow: var(--shadow-sm);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
  object-position: center 38%;
  display: block;
}

.brand-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-kicker {
  color: var(--gold);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.title {
  color: var(--ink);
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.05;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  align-items: center;
  display: flex;
  gap: 12px;
}

.cover-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-sm);
  color: var(--accent);
  display: inline-flex;
  flex: 0 0 auto;
  height: 40px;
  justify-content: center;
  padding: 9px;
  width: 40px;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s var(--ease-spring);
}

.cover-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cover-btn:hover {
  background: var(--accent-soft);
}

.cover-btn:active {
  transform: scale(0.9);
}

/* ---------- Theme switch ---------- */
.theme-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  transition: color 0.2s ease, background-color 0.25s ease, transform 0.2s var(--ease-spring);
}

.theme-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-btn:hover {
  color: var(--ink);
}

.theme-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

/* ---------- Page nav ---------- */
.page-nav {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-sm);
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
  padding: 4px;
}

.page-label {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--accent-strong);
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.1;
  min-height: 40px;
  min-width: 122px;
  padding: 4px 16px;
  transition: background-color 0.2s ease;
}

.page-label-main {
  font-size: 0.92rem;
  font-weight: 700;
}

.page-label-sub {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-step {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--accent);
  display: inline-flex;
  height: 38px;
  justify-content: center;
  padding: 9px;
  width: 38px;
  transition: background-color 0.2s ease, transform 0.15s var(--ease-spring);
}

.page-step svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-step:hover:not(:disabled),
.page-label:hover:not(:disabled) {
  background: var(--accent-soft);
}

.page-step:active:not(:disabled) {
  transform: scale(0.9);
}

.page-step:disabled,
.page-label:disabled {
  opacity: 0.4;
}

/* ---------- Reader layout ---------- */
.reader {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  padding: 20px;
}

.reader-layout {
  display: grid;
  flex: 1 1 auto;
  gap: 20px;
  grid-template-columns: minmax(210px, 264px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1440px;
  min-height: 0;
  width: 100%;
}

.reader[data-tab="image"] .reader-layout {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1140px;
}

.reader[data-tab="image"] .reader-aside {
  display: none;
}

/* ---------- Aside ---------- */
.reader-aside {
  align-content: start;
  display: grid;
  gap: 16px;
  min-height: 0;
}

.page-preview {
  color: var(--ink);
  display: grid;
  gap: 11px;
  padding: 13px;
  text-align: left;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s var(--ease-soft), box-shadow 0.3s var(--ease-soft), border-color 0.3s ease;
}

.page-preview:hover {
  border-color: color-mix(in srgb, var(--accent) 36%, transparent);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}

.preview-label,
.status-label {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.preview-art {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.preview-art img {
  display: block;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  width: 100%;
  transition: transform 0.6s var(--ease-soft);
}

.page-preview:hover .preview-art img {
  transform: scale(1.05);
}

.preview-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.42) 50%, transparent 65%);
  transform: translateX(-120%);
  transition: transform 0.7s var(--ease-soft);
}

.page-preview:hover .preview-shine {
  transform: translateX(120%);
}

.preview-footer {
  align-items: center;
  color: var(--accent-strong);
  display: flex;
  font-size: 0.78rem;
  font-weight: 700;
  justify-content: space-between;
}

.preview-open {
  align-items: center;
  color: var(--accent);
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 700;
  gap: 2px;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.preview-open svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-preview:hover .preview-open {
  opacity: 1;
  transform: translateX(0);
}

.reader-status {
  align-items: center;
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.status-icon {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 11px;
  background: var(--rose-soft);
  color: var(--rose);
}

.status-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.status-value {
  color: var(--rose);
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.2;
}

/* ---------- Workspace ---------- */
.reader-workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.reader-tabs {
  position: relative;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
  overflow-x: auto;
  padding: 9px;
  scrollbar-width: none;
}

.reader-tabs::-webkit-scrollbar {
  display: none;
}

.tab-indicator {
  position: absolute;
  top: 9px;
  left: 0;
  height: calc(100% - 18px);
  width: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 32%, transparent);
  transform: translateX(0);
  transition: transform 0.4s var(--ease-spring), width 0.4s var(--ease-spring);
  z-index: 0;
}

.reader-tab {
  position: relative;
  z-index: 1;
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  gap: 7px;
  font-size: 0.9rem;
  font-weight: 650;
  min-height: 42px;
  padding: 0 18px;
  white-space: nowrap;
  transition: color 0.25s ease, transform 0.15s var(--ease-spring);
}

.tab-ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}

.reader-tab:hover {
  color: var(--ink);
}

.reader-tab:active {
  transform: scale(0.96);
}

.reader-tab.is-active {
  color: #fff;
}

html[data-theme="night"] .reader-tab.is-active {
  color: #0f1417;
}

/* ---------- Panels ---------- */
.tab-panels {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
}

.tab-panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: color-mix(in srgb, var(--accent) 42%, transparent) transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tab-panel[hidden] {
  display: none;
}

.panel-image {
  align-items: flex-start;
  background:
    radial-gradient(80% 60% at 50% 0%, var(--accent-soft), transparent 60%),
    var(--surface-2);
  justify-content: center;
  padding: 28px;
}

.panel-image:not([hidden]) {
  display: flex;
}

.image-frame {
  max-width: 880px;
  width: 100%;
}

.page-image {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: block;
  height: auto;
  width: 100%;
}

.panel-script {
  background:
    radial-gradient(90% 50% at 50% 0%, var(--accent-soft), transparent 55%),
    var(--surface-2);
  padding: 30px;
}

.script-block {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), var(--shadow-sm);
  margin: 0 auto;
  max-width: 880px;
  min-height: 100%;
  padding: 46px 48px 56px;
  overflow: hidden;
}

.script-block::before {
  content: "";
  position: absolute;
  top: 22px;
  bottom: 22px;
  left: 0;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--gold), var(--rose));
}

.script-ornament {
  display: block;
  color: var(--gold);
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 18px;
  opacity: 0.7;
  text-align: center;
}

.script-text {
  font-size: var(--reader-size);
  margin: 0;
}

.kannada-text {
  font-family: "Noto Sans Kannada", system-ui, sans-serif;
  line-height: 2.1;
}

.english-text {
  color: var(--ink);
  font-family: Spectral, Georgia, serif;
  line-height: 1.9;
}

.script-text .ln {
  display: block;
}

.script-text .seg {
  border-radius: 5px;
  cursor: pointer;
  padding: 0 1px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.script-text .seg:hover {
  background: var(--accent-soft);
}

.script-text .seg.is-active {
  background: var(--hl-bg);
  box-shadow: 0 0 0 1px var(--hl-edge), 0 3px 12px var(--hl-glow);
}

.gap {
  display: block;
  height: 0.9em;
}

/* page reveal animation */
@keyframes pageReveal {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes ornamentReveal {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.9);
  }
  to {
    opacity: 0.7;
    transform: translateY(0) scale(1);
  }
}

.tab-panel.is-entering .script-block,
.tab-panel.is-entering .image-frame {
  animation: pageReveal 0.5s var(--ease-soft) both;
}

.tab-panel.is-entering .script-ornament {
  animation: ornamentReveal 0.5s var(--ease-soft) 0.08s both;
}

/* ---------- Player ---------- */
.player {
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-top: 1px solid var(--line);
  box-shadow: 0 -14px 44px rgba(0, 0, 0, 0.08);
  flex: 0 0 auto;
  padding: 14px 20px calc(26px + env(safe-area-inset-bottom));
  z-index: 4;
}

.player-inner {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(180px, 1fr) minmax(300px, 540px) minmax(200px, 1fr);
  margin: 0 auto;
  max-width: 1240px;
}

.player-meta {
  min-width: 0;
}

.audio-mode {
  align-items: center;
  background: var(--rose-soft);
  border: 1px solid color-mix(in srgb, var(--rose) 24%, transparent);
  border-radius: 999px;
  color: var(--rose);
  display: inline-flex;
  font-size: 0.84rem;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  padding: 8px 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-center {
  display: grid;
  gap: 11px;
  justify-items: center;
  min-width: 0;
  width: 100%;
}

.seek-wrap {
  min-width: 0;
  width: 100%;
}

.seek {
  appearance: none;
  background: transparent;
  display: block;
  margin: 0;
  width: 100%;
  --p: 0%;
}

.seek::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, var(--accent), var(--rose)) no-repeat,
    var(--line-strong);
  background-size: var(--p) 100%;
  border-radius: 999px;
  height: 7px;
}

.seek::-webkit-slider-thumb {
  appearance: none;
  background: var(--surface);
  border: 3px solid var(--accent);
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  height: 19px;
  margin-top: -6px;
  width: 19px;
  transition: transform 0.15s var(--ease-spring), border-color 0.2s ease;
}

.seek::-webkit-slider-thumb:hover {
  transform: scale(1.18);
}

.seek:active::-webkit-slider-thumb {
  transform: scale(1.28);
  border-color: var(--rose);
}

.seek::-moz-range-track {
  background: var(--line-strong);
  border-radius: 999px;
  height: 7px;
}

.seek::-moz-range-progress {
  background: linear-gradient(90deg, var(--accent), var(--rose));
  border-radius: 999px;
  height: 7px;
}

.seek::-moz-range-thumb {
  background: var(--surface);
  border: 3px solid var(--accent);
  border-radius: 999px;
  height: 14px;
  width: 14px;
}

.seek:disabled {
  opacity: 0.5;
}

.times {
  color: var(--muted);
  display: flex;
  font-size: 0.74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  justify-content: space-between;
  margin-top: 5px;
}

.controls {
  align-items: center;
  display: flex;
  gap: 11px;
  justify-content: center;
}

.ctrl {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  color: var(--accent-strong);
  display: inline-flex;
  height: 46px;
  justify-content: center;
  padding: 11px;
  position: relative;
  width: 46px;
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.ctrl svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#prev svg,
#next svg {
  fill: currentColor;
  stroke-width: 1.4;
}

.ctrl-seek small {
  position: absolute;
  bottom: 12px;
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.ctrl:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  color: var(--accent);
  transform: translateY(-2px);
}

.ctrl:active:not(:disabled) {
  transform: scale(0.92);
}

.ctrl:disabled {
  opacity: 0.4;
}

.ctrl-play {
  background: linear-gradient(135deg, var(--accent), var(--rose));
  border: 0;
  box-shadow: var(--shadow-play);
  color: #fff;
  height: 62px;
  padding: 17px;
  width: 62px;
}

html[data-theme="night"] .ctrl-play {
  color: #0f1417;
}

.ctrl-play svg {
  fill: currentColor;
  stroke: none;
}

.ctrl-play:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 18px 40px color-mix(in srgb, var(--accent) 40%, transparent);
}

.ctrl-play:active:not(:disabled) {
  transform: scale(0.94);
}

.ctrl-play .ico-pause {
  display: none;
}

.ctrl-play.is-playing .ico-play {
  display: none;
}

.ctrl-play.is-playing .ico-pause {
  display: block;
}

.extras {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.84rem;
  gap: 12px;
  justify-content: flex-end;
  min-width: 0;
}

.speed,
.autoplay,
.fontsize {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  white-space: nowrap;
}

.speed {
  color: var(--muted);
  font-weight: 600;
}

.speed select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  min-height: 36px;
  padding: 0 26px 0 12px;
  transition: border-color 0.2s ease;
}

.speed select:hover {
  border-color: var(--line-strong);
}

.fontsize {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  gap: 0;
  overflow: hidden;
}

.font-btn {
  background: transparent;
  border: 0;
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 700;
  height: 36px;
  min-width: 40px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.font-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.font-btn:active {
  transform: scale(0.92);
}

.font-btn + .font-btn {
  border-left: 1px solid var(--line);
}

.autoplay {
  color: var(--muted);
  font-weight: 600;
  position: relative;
}

.autoplay input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.autoplay-track {
  background: var(--line-strong);
  border-radius: 999px;
  display: inline-block;
  height: 24px;
  position: relative;
  transition: background-color 0.25s ease;
  width: 44px;
}

.autoplay-track::before {
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  content: "";
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform 0.25s var(--ease-spring);
  width: 18px;
}

.autoplay input:checked + .autoplay-track {
  background: var(--accent);
}

.autoplay input:checked + .autoplay-track::before {
  transform: translateX(20px);
}

.pooja-note {
  align-items: center;
  bottom: calc(14px + env(safe-area-inset-bottom));
  color: var(--rose);
  display: inline-flex;
  font-family: "Playfair Display", serif;
  font-size: 0.98rem;
  font-style: italic;
  font-weight: 500;
  gap: 7px;
  line-height: 1.1;
  margin: 0;
  opacity: 0.92;
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  white-space: nowrap;
}

.pooja-heart {
  animation: heartBeat 2.6s var(--ease-soft) infinite;
  color: var(--rose);
  display: inline-block;
  font-size: 1.55em;
  font-style: normal;
  line-height: 1;
  transform: translateY(-0.02em);
}

@keyframes heartBeat {
  0%, 100% { transform: translateY(0.06em) scale(1); }
  18% { transform: translateY(0.06em) scale(1.28); }
  32% { transform: translateY(0.06em) scale(1.05); }
  46% { transform: translateY(0.06em) scale(1.18); }
}

/* ---------- Page dialog ---------- */
.page-dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  max-height: calc(100dvh - 40px);
  overflow: hidden;
  padding: 0;
  width: min(92vw, 560px);
}

.page-dialog[open] {
  animation: dialogIn 0.32s var(--ease-soft);
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.page-dialog::backdrop {
  background: rgba(12, 16, 17, 0.5);
  backdrop-filter: blur(4px);
}

.page-drawer {
  display: grid;
  gap: 20px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 24px;
}

.page-drawer-header {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.page-drawer-kicker {
  color: var(--gold);
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.page-drawer-header h2 {
  color: var(--ink);
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.8rem;
  line-height: 1.1;
  margin: 2px 0 0;
}

.page-close {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  height: 40px;
  justify-content: center;
  padding: 11px;
  width: 40px;
  transition: transform 0.18s var(--ease-spring), color 0.2s ease, background-color 0.2s ease;
}

.page-close svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-close:hover {
  background: var(--rose-soft);
  color: var(--rose);
}

.page-close:active {
  transform: scale(0.9);
}

.page-section {
  display: grid;
  gap: 11px;
}

.page-section h3,
.page-exact label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  margin: 0;
  text-transform: uppercase;
}

.nearby-pages {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  max-height: min(40vh, 340px);
  overflow-y: auto;
  padding: 2px;
}

.page-chip {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  justify-content: center;
  min-height: 54px;
  padding: 8px 10px;
  transition: transform 0.18s var(--ease-spring), background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.page-button-label {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.page-button-detail {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
}

.page-chip:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 34%, transparent);
  transform: translateY(-2px);
}

.page-chip:active:not(:disabled) {
  transform: scale(0.95);
}

.page-chip.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 30%, transparent);
}

html[data-theme="night"] .page-chip.is-active {
  color: #0f1417;
}

.page-chip.is-active .page-button-detail {
  color: rgba(255, 255, 255, 0.8);
}

html[data-theme="night"] .page-chip.is-active .page-button-detail {
  color: rgba(15, 20, 23, 0.7);
}

.page-exact {
  display: grid;
  gap: 9px;
}

.page-exact-row {
  display: grid;
  gap: 9px;
  grid-template-columns: 1fr auto;
}

.page-exact input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  font-size: 1rem;
  min-width: 0;
  padding: 11px 13px;
  transition: border-color 0.2s ease;
}

.page-exact input:focus {
  border-color: var(--accent);
  outline: none;
}

.page-exact button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: 0;
  border-radius: 11px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0 22px;
  transition: transform 0.18s var(--ease-spring), filter 0.2s ease;
}

html[data-theme="night"] .page-exact button {
  color: #0f1417;
}

.page-exact button:hover {
  filter: brightness(1.08);
}

.page-exact button:active {
  transform: scale(0.95);
}

/* ---------- Focus ---------- */
.theme-btn:focus-visible,
.page-step:focus-visible,
.page-label:focus-visible,
.page-preview:focus-visible,
.reader-tab:focus-visible,
.ctrl:focus-visible,
.font-btn:focus-visible,
.speed select:focus-visible,
.autoplay:focus-within,
.page-close:focus-visible,
.page-chip:focus-visible,
.page-exact input:focus-visible,
.page-exact button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--gold) 70%, transparent);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .reader {
    padding: 14px;
  }

  .reader-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .reader-aside {
    display: none;
  }

  .player-inner {
    gap: 10px;
    grid-template-columns: minmax(0, 1fr);
  }

  .player-meta {
    display: none;
  }

  .extras {
    justify-content: center;
  }
}

@media (max-width: 560px) {
  :root {
    --reader-size: 1.46rem;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px 12px;
  }

  .brand {
    gap: 8px;
    min-width: 0;
  }

  .brand-mark {
    flex: 0 0 34px;
    height: 34px;
    width: 34px;
    border-radius: 10px;
  }

  .brand-kicker {
    display: none;
  }

  .title {
    font-size: 1.06rem;
  }

  .topbar-actions {
    flex: 0 0 auto;
    gap: 6px;
  }

  .page-label-sub {
    display: none;
  }

  .theme-btn {
    width: 28px;
    height: 28px;
    padding: 6px;
  }

  .cover-btn {
    width: 34px;
    height: 34px;
    padding: 8px;
  }

  .page-nav {
    flex: 0 1 auto;
    min-width: 0;
  }

  .page-label {
    min-height: 34px;
    min-width: 0;
    padding: 3px 8px;
  }

  .page-label-main {
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .page-step {
    flex: 0 0 auto;
    height: 32px;
    width: 32px;
    padding: 8px;
  }

  .reader {
    padding: 8px;
  }

  .reader-workspace {
    border-radius: 14px;
  }

  .reader-tabs {
    gap: 3px;
    padding: 6px;
  }

  .tab-indicator {
    top: 6px;
    height: calc(100% - 12px);
  }

  .reader-tab {
    font-size: 0.8rem;
    gap: 5px;
    min-height: 34px;
    padding: 0 12px;
  }

  .tab-ico {
    width: 16px;
    height: 16px;
  }

  .panel-script {
    padding: 8px;
  }

  .script-block {
    border-radius: 11px;
    padding: 26px 20px 34px;
  }

  .kannada-text {
    line-height: 1.95;
  }

  .english-text {
    line-height: 1.75;
  }

  .panel-image {
    padding: 10px;
  }

  .player {
    padding: 9px 12px calc(16px + env(safe-area-inset-bottom));
  }

  .player-center {
    gap: 10px;
  }

  .seek-wrap {
    max-width: 360px;
  }

  .controls {
    gap: 14px;
  }

  .ctrl {
    height: 44px;
    width: 44px;
    padding: 10px;
  }

  .ctrl-play {
    height: 56px;
    width: 56px;
    padding: 15px;
  }

  .extras {
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
    justify-content: flex-start;
    padding-right: 80px;
    width: 100%;
  }

  .speed {
    gap: 6px;
  }

  .speed select {
    min-height: 34px;
    padding: 0 22px 0 10px;
  }

  .autoplay {
    display: none;
  }

  .pooja-note {
    bottom: calc(13px + env(safe-area-inset-bottom));
    font-size: 0.76rem;
    gap: 5px;
    right: calc(8px + env(safe-area-inset-right));
  }

  .pooja-heart {
    font-size: 1.38em;
  }

  .page-dialog {
    border-radius: 20px 20px 0 0;
    margin: auto 0 0;
    max-height: 86dvh;
    max-width: none;
    width: 100vw;
  }

  .page-drawer {
    max-height: 86dvh;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .page-drawer-header h2 {
    font-size: 1.55rem;
  }

  .nearby-pages {
    grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
    max-height: 36vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
