:root {
  color-scheme: light;
  --bg: #eef3f7;
  --panel: #f8f5ee;
  --panel-strong: #ffffff;
  --ink: #13243a;
  --muted: #65758a;
  --line: #d8d2c4;
  --accent: #0c3a61;
  --accent-strong: #08223d;
  --gold: #c9962e;
  --gold-soft: rgba(201, 150, 46, 0.16);
  --danger: #b91c1c;
  --shadow: 0 24px 70px rgba(8, 34, 61, 0.18);
}

body.night-reading {
  color-scheme: dark;
  --bg: #06182b;
  --panel: #0b2138;
  --panel-strong: #102b46;
  --ink: #edf4fb;
  --muted: #a8b7c8;
  --line: rgba(224, 190, 104, 0.22);
  --accent: #e0b64f;
  --accent-strong: #f3d47a;
  --gold: #f1c75b;
  --gold-soft: rgba(241, 199, 91, 0.14);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(201, 150, 46, 0.14), transparent 28%),
    linear-gradient(135deg, rgba(8, 34, 61, 0.1), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 180ms ease, color 180ms ease;
}

button, input, select { font: inherit; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: min(340px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
  transform: translateX(-102%);
  transition: transform 180ms ease;
}

.sidebar.open { transform: translateX(0); }

.side-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  border: 0;
  background: rgba(5, 18, 33, 0.58);
  backdrop-filter: blur(5px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 12px 30px rgba(8, 34, 61, 0.28);
}

.brand strong { display: block; font-size: 1.12rem; }
.brand span:last-child { display: block; color: var(--muted); font-size: 0.86rem; }

.menu-section { display: grid; gap: 10px; }

.field-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

.control:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

.menu-action {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-weight: 800;
}

.menu-action.primary {
  border-color: color-mix(in srgb, var(--gold) 55%, transparent);
  background: var(--gold-soft);
  color: var(--accent-strong);
}

.reader {
  min-width: 0;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 26px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; line-height: 1.08; }
h1 { font-size: clamp(2rem, 4vw, 4.2rem); }
h2 { font-size: 1.35rem; }

.top-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.header-logo {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  object-fit: cover;
  filter: drop-shadow(0 14px 28px rgba(8, 34, 61, 0.2));
}

.top-actions { display: flex; gap: 8px; flex-shrink: 0; }

.icon-button, .ai-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
}

.icon-button { width: 42px; font-size: 1.35rem; font-weight: 800; }
.menu-button { color: var(--accent-strong); }

.book-panel, .chapter-panel {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--shadow);
}

.book-panel { display: grid; gap: 12px; }

.book-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 4px;
}

.book-button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  padding: 8px 12px;
  white-space: nowrap;
}

.book-button:hover, .book-button.active {
  border-color: var(--gold);
  background: var(--gold-soft);
  color: var(--accent-strong);
}

.chapter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.chapter-button {
  width: 42px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
}

.chapter-button.active { border-color: var(--gold); background: var(--gold); color: #08223d; }

.verse-list { display: grid; gap: 12px; padding-top: 18px; }

.verse-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-strong);
}

.verse-number {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 900;
}

.verse-text { margin: 0; font-size: 1.12rem; line-height: 1.75; }
.night-reading .verse-text { font-size: 1.18rem; line-height: 1.9; }

.ai-button {
  justify-self: end;
  min-height: 34px;
  padding: 0 12px;
  border-color: color-mix(in srgb, var(--gold) 45%, transparent);
  background: var(--gold-soft);
  color: var(--accent-strong);
  font-size: 0.88rem;
  font-weight: 750;
}

.ai-button:hover { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 24%, transparent); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 18px;
}

.modal.open { display: grid; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 18, 33, 0.62); backdrop-filter: blur(8px); }

.modal-card {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  max-height: min(760px, 88vh);
  overflow: auto;
  padding: 22px;
  border-radius: 12px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.settings-card { width: min(520px, 100%); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }

.ai-reference {
  margin-bottom: 16px;
  padding: 14px;
  border-left: 4px solid var(--gold);
  background: var(--gold-soft);
  line-height: 1.55;
}

.ai-content { color: var(--ink); font-size: 1.02rem; line-height: 1.75; white-space: pre-wrap; }

.talita-intro { margin: 14px 0 0; color: var(--muted); font-size: 0.92rem; line-height: 1.5; }
.talita-intro p { margin: 0 0 12px; }
.talita-intro p:last-child { margin-bottom: 0; }
.talita-intro a { color: var(--accent-strong); font-weight: 800; }
.share-actions {
  flex-wrap: wrap;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid color-mix(in srgb, var(--gold) 62%, transparent);
  border-radius: 8px;
  background: var(--gold);
  color: #08223d;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(8, 34, 61, 0.18);
}

.share-button span[aria-hidden="true"] {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(8, 34, 61, 0.14);
  font-size: 1rem;
  line-height: 1;
}

.share-button:disabled {
  cursor: progress;
  opacity: 0.72;
  filter: grayscale(0.25);
}

.share-status {
  flex-basis: 100%;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.share-button:hover:not(:disabled) {
  filter: brightness(1.05);
}
.empty, .error { padding: 24px; border-radius: 10px; background: var(--panel-strong); color: var(--muted); }
.error { color: var(--danger); }

.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: var(--gold);
  color: #08223d;
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: var(--shadow);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.back-to-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.back-to-top:hover { filter: brightness(1.06); }

@media (max-width: 860px) {
  .reader { padding: 18px; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; }
  .top-side { justify-content: flex-end; gap: 10px; }
  .top-actions { order: 1; }
  .header-logo { order: 2; width: 58px; height: 58px; }
  h1 { font-size: clamp(2rem, 10vw, 3.1rem); }
  .book-panel, .chapter-panel { padding: 14px; }
  .verse-card { display: block; }
  .verse-number { margin-bottom: 12px; }
  .ai-button { margin-top: 14px; width: auto; }
}
