:root {
  color-scheme: light;
  --paper: #f7efe2;
  --paper-deep: #ead9bc;
  --card: rgba(255, 250, 240, .92);
  --card-solid: #fffaf0;
  --ink: #211a14;
  --muted: #746657;
  --line: rgba(61, 45, 28, .14);
  --gold: #c38b3f;
  --gold-soft: #f2d9a9;
  --blue: #5268b5;
  --green: #567f53;
  --brown: #8f5a2a;
  --shadow: 0 24px 70px rgba(58, 39, 19, .18);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100dvh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 255, 255, .85), transparent 32%),
    linear-gradient(155deg, #f7efe2 0%, #ead8b7 58%, #f9f0df 100%);
  color: var(--ink);
}

button { font: inherit; -webkit-tap-highlight-color: transparent; cursor: pointer; }
button:focus-visible { outline: 3px solid rgba(82, 104, 181, .55); outline-offset: 2px; }
h1, h2, p { margin: 0; }
.hidden { display: none !important; }
.eyebrow { color: var(--brown); font: 800 11px/1.1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .14em; text-transform: uppercase; }

.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 24px;
  background: linear-gradient(155deg, #f7efe2, #e8d2ad);
  transition: opacity .28s ease, visibility .28s ease;
}
.app-ready .splash { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-icon { width: 132px; height: 132px; filter: drop-shadow(0 18px 32px rgba(75, 48, 20, .18)); }
.splash h1 { font-size: 38px; letter-spacing: -.05em; }
.splash p { color: var(--muted); font: 800 14px/1.35 ui-sans-serif, system-ui, sans-serif; }

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  width: min(720px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 13px max(14px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.reader-head {
  display: grid;
  gap: 7px;
  padding: 16px 16px 14px;
  border: 1px solid rgba(255, 255, 255, .56);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(255, 250, 240, .96), rgba(242, 217, 169, .56));
  box-shadow: 0 12px 32px rgba(58, 39, 19, .10);
}
.reader-head h1 { font-size: clamp(24px, 7vw, 36px); line-height: .96; letter-spacing: -.055em; }
.reader-subtitle { color: var(--muted); font: 750 14px/1.35 ui-sans-serif, system-ui, sans-serif; }
.book-picker { display: grid; gap: 8px; }
.book-picker select {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 900 clamp(24px, 7vw, 36px)/1 ui-serif, Georgia, "Times New Roman", serif;
  letter-spacing: -.055em;
  cursor: pointer;
}

.chapter-nav {
  display: flex;
  gap: 8px;
  min-height: 50px;
  padding: 4px 1px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chapter-nav::-webkit-scrollbar { display: none; }
.chapter-btn {
  min-width: 48px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(188, 143, 81, .32);
  color: #6b431e;
  font: 900 15px/1 ui-sans-serif, system-ui, sans-serif;
  box-shadow: 0 8px 18px rgba(58, 39, 19, .08);
}
.chapter-btn.active { background: #fffaf0; color: #4b2f18; border-color: rgba(129, 80, 31, .28); box-shadow: 0 10px 22px rgba(58, 39, 19, .13), inset 0 0 0 2px rgba(255,255,255,.8); }

.verse-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  padding: 0 1px 18px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.verse-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 10px;
  width: 100%;
  min-height: auto;
  height: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .58);
  border-radius: 24px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 10px 24px rgba(58, 39, 19, .09);
}
.verse-card:active { transform: scale(.99); }
.verse-number { color: var(--gold); font-weight: 900; }
.verse-text { display: block; overflow: visible; overflow-wrap: anywhere; white-space: normal; font-size: clamp(18px, 5vw, 24px); line-height: 1.38; }

.empty-state, .error-card {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 24px;
  background: rgba(255, 250, 240, .72);
  color: var(--muted);
}
.empty-state { display: grid; gap: 8px; }
.empty-state h2 { color: var(--ink); font-size: 24px; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(24, 18, 12, .28);
  backdrop-filter: blur(3px);
}
.verse-sheet {
  position: fixed;
  inset: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  gap: 14px;
  width: min(720px, 100%);
  height: 100dvh;
  max-height: none;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 15px max(16px, env(safe-area-inset-bottom));
  border-radius: 0;
  background: linear-gradient(180deg, rgba(255, 250, 240, .99), rgba(246, 235, 216, .99));
  box-shadow: var(--shadow);
  overflow: hidden;
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(.2,.8,.2,1);
}
.verse-sheet.open { transform: translateY(0); }
.sheet-handle { width: 58px; height: 24px; justify-self: center; display: grid; place-items: center; }
.sheet-handle::after { content: ""; width: 46px; height: 5px; border-radius: 999px; background: #d0b98e; }
.sheet-topline { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.sheet-topline h2 { margin-top: 4px; font-size: 22px; letter-spacing: -.035em; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: #ead8b7;
  color: #69401d;
  font: 900 28px/1 ui-sans-serif, system-ui, sans-serif;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 54px 54px 54px;
  gap: 8px;
}
.sheet-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 16px;
  font: 900 13px/1 ui-sans-serif, system-ui, sans-serif;
  transition: background .16s ease, color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.sheet-actions button:active { transform: scale(.97); }
.toggle-btn { background: #d7d2ca; color: #756f66; }
.toggle-btn.active { background: #2f7a4d; color: #f7fff4; border-color: transparent; }
.play-btn { background: linear-gradient(135deg, #5268b5, #334173); color: #fff; border-color: transparent !important; font-size: 19px !important; }
.play-btn.playing {
  background: linear-gradient(135deg, #a84b35, #6f241b);
  box-shadow: 0 0 0 4px rgba(168, 75, 53, .14), 0 10px 22px rgba(111, 36, 27, .18);
  animation: playbackPulse 1.15s ease-in-out infinite;
}

.ru-verse, .en-verse {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 15px;
  border: 1px solid rgba(61, 45, 28, .10);
  border-radius: 24px;
  background: rgba(255, 255, 255, .48);
}
.ru-verse p { font-size: 21px; line-height: 1.42; }
.en-verse { min-height: 0; background: rgba(255, 250, 240, .76); overflow: auto; -webkit-overflow-scrolling: touch; align-content: start; }
.token-list { display: inline; font-size: 20px; line-height: 1.95; }
.token {
  display: inline;
  min-height: 44px;
  margin: 0 1px 4px 0;
  padding: 5px 4px 7px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
}
.token:active { background: rgba(195, 139, 63, .13); }
.token.playing { background: rgba(168, 75, 53, .12); box-shadow: inset 0 0 0 1px rgba(168, 75, 53, .22); }
.token-word { color: var(--ink); font-weight: 900; }
.token-ipa { margin-left: 4px; color: var(--blue); font: 760 .78em/1.2 ui-sans-serif, system-ui, sans-serif; }
.token-gloss { margin-left: 4px; color: var(--green); font: 780 .78em/1.2 ui-sans-serif, system-ui, sans-serif; }
.token-suffix { color: var(--ink); font-weight: 900; }
.hide-ipa .token-ipa { display: none; }
.hide-gloss .token-gloss { display: none; }
.hide-analysis .en-verse { display: none; }
.audio-status { grid-row: 6; min-height: 22px; color: var(--muted); font: 800 13px/1.35 ui-sans-serif, system-ui, sans-serif; }

@keyframes playbackPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(.985); }
}

@media (max-width: 380px) {
  .app-shell { padding-left: 10px; padding-right: 10px; gap: 9px; }
  .reader-head { border-radius: 24px; padding: 14px; }
  .verse-card { padding: 14px; border-radius: 20px; }
  .verse-text { font-size: 17px; }
  .verse-sheet { border-radius: 0; padding-left: 11px; padding-right: 11px; }
  .token-list { font-size: 18px; line-height: 1.9; }
  .ru-verse p { font-size: 19px; }
}
