@font-face {
  font-family: "Arial";
  src: url("assets/fonts/NotoSans-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "Georgia";
  src: url("assets/fonts/NotoSerif-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "Times New Roman";
  src: url("assets/fonts/NotoSerif-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif Hebrew";
  src: url("assets/fonts/NotoSerifHebrew-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #1e2924;
  --muted: #68716c;
  --forest: #17251f;
  --forest-soft: #263b31;
  --gold: #b28a49;
  --gold-soft: #e6d7b8;
  --paper: #fbf8ef;
  --paper-deep: #f2ebda;
  --canvas: #e9e4d8;
  --line: rgba(46, 57, 51, 0.18);
  --shadow: 0 24px 70px rgba(31, 35, 32, 0.15);
  --verse-scale: 1;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 255, 255, 0.9), transparent 34rem),
    linear-gradient(145deg, #eee9df, var(--canvas));
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid #bd8b37;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  left: 1rem;
  top: -4rem;
  padding: 0.75rem 1rem;
  color: white;
  background: var(--forest);
  border-radius: 0.35rem;
}

.skip-link:focus {
  top: 1rem;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 74px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem clamp(1rem, 4vw, 4rem);
  color: #f8f3e8;
  background: rgba(23, 37, 31, 0.97);
  border-bottom: 1px solid rgba(230, 215, 184, 0.2);
  backdrop-filter: blur(12px);
}

.brand {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--forest);
  background: var(--gold-soft);
  border: 1px solid #f1e4ca;
  border-radius: 50%;
  font-size: 1.55rem;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.08rem;
  letter-spacing: 0.04em;
}

.brand small {
  margin-top: 0.08rem;
  color: #cfc9bb;
  font-family: Arial, sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.current-reference {
  margin: 0;
  font-size: 1.04rem;
  letter-spacing: 0.05em;
}

.top-actions,
.font-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.top-actions {
  justify-self: end;
}

.reader-menu-toggle,
.reader-mobile-menu {
  display: none;
}

.button,
.icon-button,
.listen-button,
.nav-button,
.dialog-close {
  border: 0;
}

.button {
  min-height: 40px;
  padding: 0.65rem 1rem;
  border-radius: 0.35rem;
  font-family: Arial, sans-serif;
  font-weight: 700;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button-quiet {
  color: #f8f3e8;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.button-quiet:hover {
  background: rgba(255, 255, 255, 0.08);
}

.button-dark {
  color: white;
  background: var(--forest);
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 0.35rem;
  font-family: Arial, sans-serif;
  font-weight: 700;
}

main {
  width: min(1240px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.reader-tools {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.selectors,
.search {
  display: flex;
  gap: 0.65rem;
}

.selectors label {
  display: grid;
  gap: 0.32rem;
}

.selectors label span {
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

select,
.search input {
  min-height: 43px;
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 0.35rem;
}

.search {
  flex: 1;
  justify-content: end;
}

.search input {
  width: min(330px, 100%);
  padding-right: 0.75rem;
  font-family: Arial, sans-serif;
}

.search-results {
  margin-bottom: 1.2rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  box-shadow: 0 10px 30px rgba(31, 35, 32, 0.08);
}

.results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.results-heading p {
  margin: 0;
  font-family: Arial, sans-serif;
  font-weight: 700;
}

.results-list {
  max-height: 22rem;
  overflow: auto;
  display: grid;
  gap: 0.55rem;
  padding-top: 0.75rem;
}

.result-button {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 1rem;
  width: 100%;
  padding: 0.75rem;
  text-align: left;
  color: var(--ink);
  background: #faf8f1;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
}

.result-button:hover {
  border-color: var(--gold);
}

.result-reference {
  color: #7b5e2e;
  font-weight: 700;
}

.result-excerpt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-shell {
  padding: clamp(1rem, 3vw, 2.25rem);
  background: rgba(32, 46, 39, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.55rem;
  box-shadow: var(--shadow);
}

.book-title-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.2rem;
  color: #f5efe2;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--gold);
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.book-title-row h1,
.dialog-header h2 {
  margin: 0;
  font-weight: 500;
}

.book-title-row h1 {
  font-size: clamp(1.65rem, 4vw, 2.8rem);
}

.hebrew-book-name {
  margin: 0;
  color: var(--gold-soft);
  font-size: clamp(1.5rem, 4vw, 2.5rem);
}

.book-spread {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 435px;
  background: var(--paper);
  border-radius: 0.25rem;
  overflow: hidden;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.3);
}

.book-spread::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  width: 28px;
  transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(58, 45, 26, 0.13), transparent);
}

.page {
  display: flex;
  flex-direction: column;
  padding: clamp(1.3rem, 4vw, 3.25rem);
  background:
    linear-gradient(rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0)),
    var(--paper);
}

.page-hebrew {
  border-right: 1px solid rgba(75, 62, 42, 0.14);
}

.page-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 60px;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.language-label,
.edition {
  margin: 0;
}

.language-label {
  color: var(--forest);
  font-size: 1.1rem;
  font-weight: 700;
}

.edition {
  margin-top: 0.2rem;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
}

.listen-button {
  padding: 0.55rem 0.7rem;
  color: #6d552d;
  background: transparent;
  border: 1px solid #c9ac78;
  border-radius: 999px;
  font-family: Arial, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
}

.listen-button:hover,
.listen-button.is-speaking {
  color: white;
  background: #816334;
}

.verse-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: start;
  margin: auto 0;
  padding: 2.25rem 0;
}

.verse-body-hebrew {
  grid-template-columns: 1fr auto;
}

.verse-body-hebrew sup {
  order: 2;
}

.verse-body sup {
  color: var(--gold);
  font-family: Arial, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
}

.verse-body p {
  margin: 0;
  font-size: calc(clamp(1.35rem, 2.3vw, 2rem) * var(--verse-scale));
  line-height: 1.72;
}

.verse-body-hebrew p {
  font-family: "Noto Serif Hebrew", "Times New Roman", serif;
  font-size: calc(clamp(1.55rem, 2.65vw, 2.3rem) * var(--verse-scale));
  line-height: 1.9;
}

.verse-navigation {
  display: grid;
  grid-template-columns: 1fr minmax(150px, 0.6fr) 1fr;
  align-items: center;
  gap: 1rem;
  margin-top: 1.1rem;
}

.nav-button {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.9rem;
  color: #f8f3e8;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.35rem;
  text-align: left;
}

.nav-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.nav-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.nav-button small,
.nav-button strong {
  display: block;
}

.nav-button small {
  margin-bottom: 0.15rem;
  color: #bbb8ad;
  font-family: Arial, sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-button-next {
  justify-content: end;
  text-align: right;
}

.position {
  color: #d6d0c4;
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  text-align: center;
}

.progress-track {
  height: 3px;
  margin-top: 0.55rem;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gold);
  transition: width 180ms ease;
}

.about-text {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding: 1rem 0;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
}

.about-text p {
  margin: 0;
}

.index-dialog {
  width: min(920px, calc(100% - 2rem));
  max-height: min(780px, calc(100vh - 2rem));
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid #b8a780;
  border-radius: 0.6rem;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
}

.index-dialog::backdrop {
  background: rgba(13, 22, 18, 0.78);
  backdrop-filter: blur(4px);
}

.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.4rem;
  color: white;
  background: var(--forest);
}

.dialog-header p:last-child {
  margin: 0.35rem 0 0;
  color: #cfc9bb;
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
}

.dialog-close {
  width: 42px;
  height: 42px;
  color: white;
  background: transparent;
  font-size: 1.8rem;
}

.index-content {
  display: grid;
  gap: 1.5rem;
  padding: 1.4rem;
}

.index-book {
  display: grid;
  grid-template-columns: minmax(150px, 0.32fr) 1fr;
  gap: 1rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.index-book:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.index-book h3,
.index-book p {
  margin: 0;
}

.index-book h3 {
  font-size: 1.3rem;
}

.index-hebrew {
  margin-top: 0.25rem !important;
  color: #7b5e2e;
  font-size: 1.1rem;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 0.4rem;
}

.chapter-button {
  min-height: 40px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
}

.chapter-button:hover,
.chapter-button.is-current {
  color: white;
  background: var(--forest-soft);
}

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 1.5rem;
  max-width: min(440px, calc(100% - 2rem));
  padding: 0.8rem 1rem;
  color: white;
  background: #111c17;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.4rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 1rem);
  transition: 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.noscript {
  position: fixed;
  inset: auto 1rem 1rem;
  z-index: 100;
  padding: 1rem;
  color: white;
  background: #8a2d25;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .current-reference {
    display: none;
  }

  .reader-page .top-actions > .button-link,
  .reader-page .top-actions > .font-controls {
    display: none;
  }

  .reader-page .top-actions {
    gap: 0.45rem;
  }

  .index-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    white-space: nowrap;
  }

  .reader-menu-toggle {
    width: 42px;
    height: 42px;
    display: grid;
    align-content: center;
    gap: 5px;
    padding: 0 10px;
    color: #f8f3e8;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 0.35rem;
  }

  .reader-menu-toggle span {
    display: block;
    width: 100%;
    height: 1px;
    background: currentColor;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .reader-menu-toggle.is-open span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .reader-menu-toggle.is-open span:nth-child(2) {
    opacity: 0;
  }

  .reader-menu-toggle.is-open span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .reader-mobile-menu {
    position: fixed;
    z-index: 19;
    top: 74px;
    right: clamp(0.7rem, 4vw, 2rem);
    width: min(340px, calc(100% - 1.4rem));
    display: block;
    padding: 0.6rem 1rem;
    color: #f8f3e8;
    background: #17251f;
    border: 1px solid rgba(230, 215, 184, 0.24);
    border-top: 0;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.3);
  }

  .reader-mobile-menu[hidden] {
    display: none;
  }

  .reader-mobile-menu nav {
    display: grid;
  }

  .reader-mobile-menu a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0.25rem;
    color: inherit;
    border-bottom: 1px solid rgba(230, 215, 184, 0.16);
    font-family: Arial, sans-serif;
    text-decoration: none;
  }

  .reader-mobile-menu a:last-child {
    border-bottom: 0;
  }

  .reader-mobile-menu a span {
    color: var(--gold);
    font-size: 0.65rem;
    letter-spacing: 0.08em;
  }

  .reader-tools,
  .about-text {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    justify-content: stretch;
  }

  .search input {
    width: 100%;
  }

  .book-spread {
    grid-template-columns: 1fr;
  }

  .book-spread::after {
    display: none;
  }

  .page-hebrew {
    border-right: 0;
    border-bottom: 1px solid rgba(75, 62, 42, 0.2);
  }

  .page {
    min-height: 310px;
  }

}

@media (max-width: 560px) {
  main {
    width: min(100% - 1rem, 1240px);
    padding-top: 0.8rem;
  }

  .topbar {
    min-height: 64px;
    padding: 0.55rem 0.7rem;
  }

  .reader-mobile-menu {
    top: 64px;
    right: 0.7rem;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand small {
    display: none;
  }

  .button-quiet {
    padding-inline: 0.7rem;
  }

  .index-trigger {
    min-height: 42px;
    padding-inline: 0.75rem;
  }

  .reader-tools {
    gap: 0.7rem;
  }

  .selectors {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .selectors label:first-child {
    grid-column: 1 / -1;
  }

  select {
    width: 100%;
    min-height: 48px;
    padding-right: 1.6rem;
  }

  .search {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .search input,
  .search .button {
    min-height: 48px;
  }

  .book-shell {
    padding: 0.7rem;
  }

  .book-title-row {
    padding: 0.4rem;
  }

  .page {
    padding: 1.2rem;
  }

  .page-heading {
    min-height: auto;
  }

  .verse-body {
    padding: 1.5rem 0;
  }

  .verse-navigation {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .nav-button {
    min-width: 0;
    min-height: 64px;
    padding: 0.65rem 0.75rem;
  }

  .nav-button strong {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .position {
    grid-column: 1 / -1;
    grid-row: 1;
    font-size: 0.65rem;
    text-align: left;
  }

  .progress-track {
    display: none;
  }

  .result-button,
  .index-book {
    grid-template-columns: 1fr;
  }

  .index-dialog {
    width: calc(100% - 1rem);
    max-height: calc(100vh - 1rem);
  }

  .dialog-header,
  .index-content {
    padding: 1rem;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
