:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --surface-2: #ebe7dc;
  --text: #1d2a35;
  --muted: #68747d;
  --primary: #183f5c;
  --primary-2: #245e82;
  --accent: #bd8a2f;
  --border: #d8d2c5;
  --danger: #a23c3c;
  --shadow: 0 14px 34px rgba(27, 38, 48, 0.10);
  --greek-size: 2rem;
  --topbar-height: 72px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111a22;
  --surface: #17242e;
  --surface-2: #20313d;
  --text: #edf2f4;
  --muted: #aab6bf;
  --primary: #8dc8ea;
  --primary-2: #aeddf6;
  --accent: #e2b65f;
  --border: #344955;
  --danger: #ff9d9d;
  --shadow: 0 15px 38px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% -10%, rgba(189,138,47,.12), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 2px;
}
.skip-link {
  position: fixed; left: 1rem; top: -5rem; z-index: 100;
  padding: .7rem 1rem; border-radius: .6rem; background: var(--surface); color: var(--text);
}
.skip-link:focus { top: .8rem; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-height);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 1.2rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--primary); color: var(--surface);
  font: 700 1.65rem Georgia, serif;
  box-shadow: var(--shadow);
}
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; margin-top: .1rem; color: var(--muted); white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: .35rem; }
.icon-button {
  min-width: 42px; height: 42px; padding: 0 .65rem;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); color: var(--text);
}
.icon-button:hover, .icon-button[aria-pressed="true"] { border-color: var(--primary); color: var(--primary); }
.text-icon { width: auto; font-size: .82rem; font-weight: 700; }
.mobile-only { display: none; }

.app-shell { display: grid; grid-template-columns: 294px minmax(0, 1fr); min-height: calc(100vh - var(--topbar-height)); }
.sidebar {
  position: sticky; top: var(--topbar-height); align-self: start;
  height: calc(100vh - var(--topbar-height)); overflow: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-header { position: sticky; top: 0; z-index: 2; padding: 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.sidebar-header label:not(.check-row), .field-label, .select-group label, .edition-select span {
  display: block; margin-bottom: .35rem; color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
input[type="search"], select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: .72rem .8rem; background: var(--surface); color: var(--text);
}
.check-row { display: flex; align-items: center; gap: .55rem; margin-top: .8rem; font-size: .84rem; color: var(--muted); }
.check-row input { accent-color: var(--primary); }
.book-list { padding: .65rem; }
.book-group { margin-bottom: .7rem; }
.book-group-title { margin: .7rem .55rem .35rem; color: var(--accent); font-size: .72rem; letter-spacing: .09em; text-transform: uppercase; }
.book-button {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  margin: .16rem 0; padding: .7rem .75rem; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); text-align: left;
}
.book-button:hover { background: var(--surface-2); }
.book-button.active { background: color-mix(in srgb, var(--primary) 13%, var(--surface)); color: var(--primary); font-weight: 800; }
.book-grc { font-family: Georgia, "Times New Roman", serif; color: var(--muted); font-size: .84rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .76rem; line-height: 1.5; }
.sidebar-footer p { margin: .35rem 0; }

.content { width: min(1080px, 100%); margin: 0 auto; padding: 1.4rem clamp(1rem, 3vw, 2.4rem) 4rem; }
.reader-toolbar {
  display: grid; grid-template-columns: minmax(220px, 1fr) 130px auto; gap: .8rem; align-items: end;
  padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.primary-button, .secondary-button, .text-button {
  border-radius: 10px; padding: .72rem 1rem; font-weight: 750;
}
.primary-button { border: 1px solid var(--primary); background: var(--primary); color: var(--surface); }
.primary-button:hover { background: var(--primary-2); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.secondary-button:hover { border-color: var(--primary); color: var(--primary); }
.text-button { border: 0; background: transparent; color: var(--primary); }
.small { padding: .55rem .75rem; font-size: .83rem; }
button:disabled { opacity: .45; cursor: not-allowed; }

.edition-panel, .audio-panel {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: .85rem; padding: .85rem 1rem;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  border: 1px solid var(--border); border-radius: 14px;
}
.edition-panel strong { font-size: .93rem; }
.edition-select { width: min(330px, 100%); }
.edition-select span { margin-bottom: .25rem; }
.edition-select select { padding: .55rem .7rem; }

.chapter-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 2.2rem .15rem 1rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--accent); font-weight: 850; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font: 750 clamp(2rem, 5vw, 3.6rem)/1.05 Georgia, "Times New Roman", serif; }
.greek-title { margin: .5rem 0 0; color: var(--muted); font: 1.25rem Georgia, "Times New Roman", serif; }
.chapter-actions { display: flex; gap: .5rem; }

.audio-copy { display: flex; align-items: center; gap: .75rem; }
.audio-copy strong, .audio-copy small { display: block; }
.audio-copy small { margin-top: .15rem; color: var(--muted); }
.audio-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: var(--surface); }
.audio-actions { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; justify-content: end; }
#chapterAudio { width: min(410px, 100%); height: 38px; }

.chapter-tools { display: flex; align-items: center; gap: .7rem; margin: 1rem 0; }
.chapter-search-wrap {
  flex: 1; display: flex; align-items: center; gap: .55rem; padding-left: .85rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.chapter-search-wrap input { border: 0; background: transparent; }
.chapter-search-wrap input:focus { outline: 0; }
.result-count { color: var(--muted); font-size: .84rem; white-space: nowrap; }
.status { min-height: 1.4rem; margin: .5rem 0; color: var(--muted); font-size: .86rem; }
.status.error { color: var(--danger); }
.notice { padding: .9rem 1rem; border-radius: 12px; line-height: 1.5; }
.warning { background: color-mix(in srgb, #d79a27 15%, var(--surface)); border: 1px solid color-mix(in srgb, #d79a27 55%, var(--border)); }
.notice code { padding: .1rem .3rem; border-radius: 4px; background: var(--surface-2); }

.verses { display: grid; gap: .8rem; }
.verse-card {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: .8rem;
  padding: 1rem 1.05rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 5px 15px rgba(27,38,48,.035);
}
.verse-card:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.verse-card.highlight { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.verse-number {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 50%; background: var(--surface-2); color: var(--primary); font-weight: 850; font-size: .82rem;
}
.verse-text {
  margin: 0; font: 400 var(--greek-size)/1.65 Georgia, "Times New Roman", serif;
  letter-spacing: .008em; overflow-wrap: anywhere;
}
.verse-portuguese { margin: .65rem 0 0; padding-top: .65rem; border-top: 1px solid var(--border); font-size: 1.05rem; line-height: 1.65; }
.verse-transliteration { margin: .55rem 0 0; color: var(--muted); font-size: .98rem; line-height: 1.6; font-style: italic; }
.hide-transliteration .verse-transliteration { display: none; }
.hide-portuguese .verse-portuguese { display: none; }
.verse-actions { display: flex; flex-direction: column; align-items: stretch; gap: .3rem; }
.verse-action { border: 0; border-radius: 8px; padding: .48rem .62rem; background: transparent; color: var(--muted); font-size: .77rem; white-space: nowrap; }
.verse-action:hover { background: var(--surface-2); color: var(--primary); }
.verse-action.active { color: var(--accent); font-weight: 800; }
.content-heading { margin: 1.2rem 0 .25rem; padding: .6rem .9rem; border-left: 4px solid var(--accent); color: var(--primary); font-family: Georgia, serif; }
.empty-state { padding: 1.4rem; text-align: center; color: var(--muted); }
.loading-card { height: 145px; border-radius: 14px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 45%, var(--surface) 65%); background-size: 250% 100%; animation: pulse 1.3s infinite; }
@keyframes pulse { to { background-position: -250% 0; } }

.bottom-navigation { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: 1.5rem; }
.overlay { position: fixed; inset: var(--topbar-height) 0 0; z-index: 19; background: rgba(0,0,0,.42); }

.favorites-dialog {
  width: min(780px, calc(100% - 2rem)); max-height: 84vh; padding: 0;
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.favorites-dialog::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(3px); }
.dialog-header { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; }
.favorites-list { display: grid; gap: .7rem; padding: 1rem; }
.favorite-card { padding: 1rem; border: 1px solid var(--border); border-radius: 12px; }
.favorite-card h3 { margin: 0 0 .5rem; font-size: .9rem; color: var(--accent); }
.favorite-card .greek-favorite { margin: 0; font: 1.35rem/1.55 Georgia, serif; }
.favorite-card .translit-favorite { margin: .45rem 0; color: var(--muted); font-style: italic; }
.favorite-card .portuguese-favorite { margin: .55rem 0 0; padding-top: .55rem; border-top: 1px solid var(--border); line-height: 1.55; }
.favorite-controls { display: flex; gap: .4rem; justify-content: end; }
.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 80; transform: translateY(130%); opacity: 0; padding: .75rem 1rem; border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 900px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: var(--topbar-height); z-index: 20; width: min(330px, 88vw); transform: translateX(-105%); transition: transform .25s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .content { padding-top: 1rem; }
}

@media (max-width: 700px) {
  :root { --topbar-height: 64px; --greek-size: 1.65rem; }
  .topbar { padding: 0 .65rem; gap: .4rem; }
  .brand small { display: none; }
  .brand-mark { width: 38px; height: 38px; }
  .top-actions { gap: .2rem; }
  .icon-button { min-width: 37px; height: 37px; padding: 0 .45rem; }
  .reader-toolbar { grid-template-columns: 1fr 95px; }
  .reader-toolbar .primary-button { grid-column: 1 / -1; }
  .edition-panel, .audio-panel, .chapter-header { align-items: stretch; flex-direction: column; }
  .chapter-actions, .audio-actions { justify-content: stretch; }
  .chapter-actions button, .audio-actions button { flex: 1; }
  .chapter-tools { flex-wrap: wrap; }
  .chapter-search-wrap { flex-basis: 100%; }
  .verse-card { grid-template-columns: 36px minmax(0, 1fr); padding: .85rem; }
  .verse-actions { grid-column: 2; flex-direction: row; flex-wrap: wrap; }
  .verse-number { width: 32px; height: 32px; }
  .bottom-navigation { flex-wrap: wrap; }
  .bottom-navigation button { flex: 1 1 45%; }
  #backToTop { order: 3; flex-basis: 100%; }
}

@media print {
  .topbar, .sidebar, .reader-toolbar, .edition-panel, .audio-panel, .chapter-tools, .chapter-actions, .verse-actions, .bottom-navigation { display: none !important; }
  .app-shell { display: block; }
  .content { width: 100%; padding: 0; }
  .verse-card { break-inside: avoid; box-shadow: none; }
}
