:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-2: #eee7d8;
  --text: #1d2924;
  --muted: #66746d;
  --primary: #0f4c3a;
  --primary-strong: #0a392c;
  --accent: #c99a3d;
  --border: #d9d0c0;
  --danger: #9d3c32;
  --shadow: 0 12px 32px rgba(35, 42, 38, 0.09);
  --hebrew-size: 2rem;
  --sidebar-width: 292px;
}

[data-theme="dark"] {
  --bg: #101713;
  --surface: #17221c;
  --surface-2: #1e2d25;
  --text: #edf4ef;
  --muted: #a9bbb0;
  --primary: #79c5a8;
  --primary-strong: #9bd8c1;
  --accent: #e1b85f;
  --border: #304339;
  --danger: #f09a8f;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.26);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: 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 { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}
.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 1000;
  padding: .75rem 1rem;
  color: white;
  background: var(--primary-strong);
  border-radius: .6rem;
}
.skip-link:focus { top: 1rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: .8rem; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: white;
  background: var(--primary);
  font-family: "Times New Roman", "Noto Serif Hebrew", serif;
  font-size: 1.7rem;
  box-shadow: var(--shadow);
}
.brand strong, .brand small { display: block; }
.brand small { margin-top: .15rem; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: .35rem; }
.icon-button {
  min-width: 42px;
  height: 42px;
  padding: 0 .7rem;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
}
.icon-button:hover { background: var(--surface-2); border-color: var(--border); }
.transliteration-toggle { min-width: 84px; font-size: .78rem; font-weight: 800; }
.transliteration-toggle.active { color: var(--primary-strong); background: var(--surface-2); border-color: var(--border); }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: calc(100vh - 72px); }
.sidebar {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow: auto;
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar-header { position: sticky; top: -1rem; z-index: 2; padding: 1rem 0 .75rem; background: var(--surface); }
.sidebar-header label, .select-group label { display: block; margin-bottom: .38rem; color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.sidebar input, .select-group select, .chapter-search-wrap input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  background: var(--bg);
}
.sidebar input { padding: .7rem .8rem; }
.book-group { margin: .8rem 0 1.2rem; }
.book-group-title { margin: .65rem .5rem; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .09em; }
.book-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .68rem .75rem;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.book-button:hover { background: var(--surface-2); }
.book-button.active { color: white; background: var(--primary); }
.book-button .book-he { font-family: "Times New Roman", "Noto Serif Hebrew", serif; font-size: 1.05rem; }
.sidebar-footer { padding: .75rem .45rem 1.5rem; color: var(--muted); font-size: .76rem; line-height: 1.5; }
.sidebar-footer p { margin: .5rem 0; }

.content { width: min(100%, 1120px); margin: 0 auto; padding: 1.5rem clamp(1rem, 3vw, 3rem) 4rem; }
.reader-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(120px, 180px) auto;
  align-items: end;
  gap: .8rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.select-group select { padding: .65rem .8rem; }
.primary-button, .secondary-button, .text-button {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 700;
}
.primary-button { padding: .65rem 1.2rem; border: 1px solid var(--primary); color: white; background: var(--primary); }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { padding: .65rem .9rem; border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.secondary-button:hover { border-color: var(--primary); color: var(--primary-strong); }
.text-button { padding: .45rem .7rem; border: 0; color: var(--primary-strong); background: transparent; }
.text-button:hover { text-decoration: underline; }

.chapter-header { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 2.2rem .2rem 1.2rem; }
.chapter-header h1 { margin: .2rem 0; font-size: clamp(2rem, 5vw, 3.4rem); letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 800; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; }
.hebrew-title { margin: .2rem 0 0; color: var(--muted); font-family: "Times New Roman", "Noto Serif Hebrew", serif; font-size: 1.45rem; }
.chapter-actions { display: flex; gap: .5rem; }
.chapter-tools { display: flex; align-items: center; gap: .7rem; margin-bottom: 1rem; }
.chapter-search-wrap { flex: 1; position: relative; }
.chapter-search-wrap span { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.chapter-search-wrap input { padding: .72rem .9rem .72rem 2.3rem; background: var(--surface); }
.result-count { color: var(--muted); font-size: .88rem; white-space: nowrap; }

.notice { margin: 1rem 0; padding: 1rem; border-radius: 12px; line-height: 1.55; }
.notice.warning { border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border)); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.status { min-height: 1.4rem; margin: .5rem 0; color: var(--muted); }
.status.error { color: var(--danger); }
.loading-card {
  height: 118px;
  margin: .75rem 0;
  border-radius: 14px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: pulse 1.4s infinite;
}
@keyframes pulse { to { background-position: -200% 0; } }

.verses { display: grid; gap: .8rem; }
.verse-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: .7rem 1rem;
  padding: 1.15rem 1.15rem .85rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(35, 42, 38, .04);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.verse-card:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); box-shadow: var(--shadow); }
.verse-card.favorite { border-left: 5px solid var(--accent); }
.verse-card.search-hidden { display: none; }
.verse-number {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--primary-strong);
  background: var(--surface-2);
  font-weight: 800;
}
.verse-content { min-width: 0; }
.verse-text {
  margin: 0;
  color: var(--text);
  font-family: "Times New Roman", "Noto Serif Hebrew", "David Libre", serif;
  font-size: var(--hebrew-size);
  line-height: 1.85;
  text-align: right;
  unicode-bidi: plaintext;
}
.verse-text mark { padding: 0 .12em; border-radius: .2em; color: inherit; background: color-mix(in srgb, var(--accent) 40%, transparent); }
.verse-transliteration {
  margin: .7rem 0 0;
  padding-top: .65rem;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: clamp(1rem, calc(var(--hebrew-size) * .62), 1.6rem);
  font-style: italic;
  line-height: 1.65;
  letter-spacing: .01em;
  text-align: left;
  overflow-wrap: anywhere;
}
html[data-transliteration="hidden"] .verse-transliteration { display: none; }
.verse-actions { grid-column: 2; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; opacity: .72; }
.verse-card:hover .verse-actions, .verse-card:focus-within .verse-actions { opacity: 1; }
.verse-action { padding: .35rem .55rem; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: .79rem; }
.verse-action:hover { color: var(--primary-strong); background: var(--surface-2); }
.favorite-action.active { color: var(--accent); font-weight: 800; }

.bottom-navigation { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-top: 1.5rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }

.favorites-dialog {
  width: min(720px, calc(100% - 2rem));
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.favorites-dialog::backdrop { background: rgba(0, 0, 0, .48); backdrop-filter: blur(3px); }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.dialog-header h2 { margin: .2rem 0 0; }
.favorites-list { display: grid; gap: .75rem; padding: 1rem 1.2rem 1.4rem; }
.favorite-item { padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.favorite-item-header { display: flex; justify-content: space-between; gap: .75rem; margin-bottom: .55rem; }
.favorite-item p { margin: 0; font-family: "Times New Roman", serif; font-size: 1.35rem; line-height: 1.7; text-align: right; }
.favorite-item .favorite-transliteration { margin-top: .55rem; color: var(--muted); font-family: inherit; font-size: 1rem; font-style: italic; line-height: 1.55; text-align: left; }
.favorite-item button { border: 0; color: var(--danger); background: transparent; }
.empty-state { padding: 2rem 1rem; color: var(--muted); text-align: center; }

.toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 500; max-width: min(420px, calc(100% - 2rem)); padding: .8rem 1rem; border-radius: 10px; color: white; background: #17221c; box-shadow: var(--shadow); opacity: 0; transform: translateY(16px); pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.overlay { position: fixed; inset: 72px 0 0; z-index: 70; background: rgba(0, 0, 0, .42); }
.mobile-only { display: none; }

@media (max-width: 860px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 72px; z-index: 80; width: min(88vw, 330px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .content { padding-top: 1rem; }
  .chapter-header { align-items: flex-start; }
  .chapter-actions { flex-direction: column; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 .7rem; }
  .brand small { display: none; }
  .top-actions { gap: 0; }
  .icon-button { min-width: 38px; padding: 0 .45rem; }
  .transliteration-toggle { min-width: 68px; font-size: .7rem; }
  .reader-toolbar { grid-template-columns: 1fr 110px; }
  .reader-toolbar .primary-button { grid-column: 1 / -1; }
  .chapter-header { display: block; padding-top: 1.5rem; }
  .chapter-actions { flex-direction: row; margin-top: 1rem; }
  .chapter-actions button { flex: 1; }
  .chapter-tools { flex-wrap: wrap; }
  .result-count { width: 100%; }
  .verse-card { grid-template-columns: 32px 1fr; padding: .9rem .85rem .65rem; }
  .verse-number { width: 30px; height: 30px; font-size: .82rem; }
  .verse-actions { grid-column: 1 / -1; }
  .bottom-navigation { flex-wrap: wrap; }
  .bottom-navigation .secondary-button { flex: 1; }
  #backToTop { order: 3; width: 100%; }
}

@media print {
  .topbar, .sidebar, .reader-toolbar, .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; }
}

/* Editorial redesign */
:root { --bg:#f3efe6; --surface:#fbf9f4; --surface-2:#e9e2d4; --text:#25241f; --muted:#777166; --primary:#174d43; --primary-strong:#0e3b34; --accent:#b8873d; --border:#d9d0c0; --shadow:0 22px 60px rgba(53,45,32,.1); --sidebar-width:306px; }
[data-theme="dark"] { --bg:#101816; --surface:#17211e; --surface-2:#23302b; --text:#f3efe6; --muted:#aaa69b; --primary:#8fc9b7; --primary-strong:#b4dece; --accent:#d6aa64; --border:#34433e; }
body { background-image:radial-gradient(circle at 80% 8%,color-mix(in srgb,var(--accent) 9%,transparent),transparent 25%),linear-gradient(90deg,transparent 49.95%,color-mix(in srgb,var(--border) 22%,transparent) 50%,transparent 50.05%); background-size:auto,44px 44px; }
.page-ornament { position:fixed; z-index:-1; border:1px solid color-mix(in srgb,var(--accent) 22%,transparent); border-radius:50%; pointer-events:none; }
.ornament-one { width:420px; height:420px; right:-250px; top:18vh; }
.ornament-two { width:180px; height:180px; left:22%; bottom:-105px; }
.topbar { height:82px; padding:0 clamp(1rem,3vw,2.5rem); background:color-mix(in srgb,var(--surface) 88%,transparent); border-bottom-color:color-mix(in srgb,var(--border) 72%,transparent); }
.brand { gap:1rem; }
.brand-mark { width:48px; height:48px; border-radius:50%; background:var(--primary-strong); font-size:1.9rem; box-shadow:0 0 0 4px var(--surface),0 0 0 5px var(--accent); }
.brand strong { font-family:Georgia,"Times New Roman",serif; font-size:1.08rem; letter-spacing:.02em; }
.brand small { font-size:.7rem; letter-spacing:.08em; text-transform:uppercase; }
.top-actions { gap:.3rem; padding:.25rem; border:1px solid var(--border); border-radius:14px; background:var(--surface); }
.icon-button { border-radius:9px; }
.app-shell { min-height:calc(100vh - 82px); }
.sidebar { top:82px; height:calc(100vh - 82px); padding:1.35rem 1rem; background:color-mix(in srgb,var(--surface) 94%,transparent); }
.sidebar-header { top:-1.35rem; padding:1.25rem .25rem 1rem; }
.sidebar input,.select-group select,.chapter-search-wrap input { border-radius:12px; background:color-mix(in srgb,var(--bg) 72%,var(--surface)); }
.book-group-title { display:flex; align-items:center; gap:.6rem; margin-top:1.2rem; color:var(--accent); font-size:.67rem; letter-spacing:.16em; }
.book-group-title::after { content:""; flex:1; height:1px; background:var(--border); }
.book-button { padding:.72rem .8rem; border-radius:11px; }
.book-button.active { background:var(--primary-strong); box-shadow:0 8px 18px color-mix(in srgb,var(--primary-strong) 22%,transparent); }
.content { width:min(100%,1160px); padding-top:1.2rem; }
.welcome-line { display:flex; align-items:center; justify-content:center; gap:.85rem; margin:.2rem 0 1.2rem; color:var(--muted); font-family:Georgia,"Times New Roman",serif; font-size:.82rem; letter-spacing:.12em; }
.welcome-line i { width:4px; height:4px; border-radius:50%; background:var(--accent); }
.reader-toolbar { position:relative; padding:.85rem; border-radius:18px; box-shadow:0 8px 30px rgba(53,45,32,.07); }
.reader-toolbar::before { content:""; position:absolute; inset:-1px auto -1px -1px; width:5px; border-radius:18px 0 0 18px; background:var(--accent); }
.primary-button { border-radius:11px; background:var(--primary-strong); }
.chapter-header { position:relative; align-items:center; padding:3.1rem .2rem 2rem; }
.chapter-header h1 { font-family:Georgia,"Times New Roman",serif; font-weight:500; font-size:clamp(2.8rem,6vw,5.2rem); line-height:.95; }
.chapter-header .eyebrow { margin-bottom:.9rem; }
.hebrew-title { margin-top:.8rem; font-size:clamp(1.3rem,2.5vw,1.85rem); }
.chapter-seal { flex:0 0 auto; width:100px; height:100px; display:grid; place-content:center; text-align:center; border:1px solid var(--accent); border-radius:50%; color:var(--primary-strong); background:color-mix(in srgb,var(--surface) 75%,transparent); box-shadow:inset 0 0 0 6px var(--bg),inset 0 0 0 7px color-mix(in srgb,var(--accent) 45%,transparent); }
.chapter-seal span { font-family:Georgia,"Times New Roman",serif; font-size:2rem; line-height:1; }
.chapter-seal small { margin-top:.3rem; color:var(--accent); font-size:.65rem; letter-spacing:.12em; }
.secondary-button { border-radius:11px; background:color-mix(in srgb,var(--surface) 85%,transparent); }
.secondary-button:disabled { opacity:.4; cursor:not-allowed; }
.chapter-tools { margin-bottom:1.4rem; }
.chapter-search-wrap input { min-height:48px; background:var(--surface); }
.audio-toolbar { display:flex; align-items:center; gap:.8rem; margin:-.4rem 0 1.4rem; padding:.75rem .85rem; border:1px solid var(--border); border-radius:14px; background:color-mix(in srgb,var(--surface) 86%,transparent); }
.audio-toolbar-title { display:flex; align-items:center; gap:.7rem; margin-right:auto; }
.audio-toolbar-title strong,.audio-toolbar-title small { display:block; }
.audio-toolbar-title small { margin-top:.15rem; color:var(--muted); font-size:.76rem; }
.audio-icon { width:36px; height:36px; display:grid; place-items:center; border-radius:50%; color:white; background:var(--primary-strong); font-size:1.1rem; }
.audio-toolbar label { color:var(--muted); font-size:.72rem; font-weight:800; letter-spacing:.06em; text-transform:uppercase; }
.audio-toolbar select { min-height:40px; padding:.4rem 2rem .4rem .65rem; border:1px solid var(--border); border-radius:9px; color:var(--text); background:var(--surface); }
.audio-stop { min-height:40px; }
.audio-credit { margin:1.5rem auto 0; color:var(--muted); font-size:.72rem; line-height:1.55; text-align:center; }
.audio-credit a { color:var(--primary-strong); }
.verses { gap:.65rem; }
.verse-card { grid-template-columns:48px 1fr; gap:.8rem 1.15rem; padding:1.4rem 1.5rem 1rem; border-color:color-mix(in srgb,var(--border) 78%,transparent); border-radius:4px 18px 18px 4px; border-left:3px solid var(--accent); box-shadow:0 5px 22px rgba(53,45,32,.045); }
.verse-card:hover { transform:translateX(3px); }
.verse-card.favorite { border-left-width:6px; }
.verse-number { width:40px; height:40px; border:1px solid color-mix(in srgb,var(--accent) 45%,var(--border)); border-radius:50%; color:var(--accent); background:transparent; font-family:Georgia,serif; font-weight:500; }
.verse-text { line-height:1.95; }
.verse-transliteration { margin-top:.85rem; padding-top:.8rem; border-top-style:solid; font-family:Georgia,"Times New Roman",serif; }
.verse-actions { gap:.2rem; }
.verse-action { padding:.4rem .65rem; border-radius:99px; }
.speak-action.playing { color:white; background:var(--primary-strong); animation:audio-pulse 1.4s ease-in-out infinite; }
@keyframes audio-pulse { 50% { box-shadow:0 0 0 5px color-mix(in srgb,var(--primary) 15%,transparent); } }
.bottom-navigation { margin-top:2rem; padding-top:1.5rem; }
.favorites-dialog { border-radius:22px; }
.toast { border-radius:12px; background:var(--primary-strong); }
@media (max-width:860px) { .sidebar{top:82px} .overlay{inset:82px 0 0} .chapter-seal{width:82px;height:82px} }
@media (max-width:620px) {
  .topbar{height:72px} .brand-mark{width:40px;height:40px} .top-actions{border:0;padding:0;background:transparent}
  .welcome-line{margin-bottom:.8rem} .chapter-header{padding:2.2rem 0 1.4rem} .chapter-header h1{font-size:clamp(2.7rem,14vw,4.2rem)}
  .chapter-header>div:first-child{padding-right:76px} .chapter-seal{position:absolute;top:2rem;right:.2rem;width:68px;height:68px} .chapter-seal span{font-size:1.45rem} .chapter-seal small{font-size:.55rem}
  .verse-card{grid-template-columns:34px 1fr;padding:1rem .9rem .75rem} .verse-number{width:31px;height:31px}
  .audio-toolbar{flex-wrap:wrap} .audio-toolbar-title{width:100%} .audio-toolbar label{margin-left:auto}
}
