:root {
  color-scheme: light;
  --paper: #f3eee3;
  --paper-raised: #fffdf7;
  --paper-deep: #e7decc;
  --ink: #29271f;
  --muted: #6b675d;
  --line: #d4cab8;
  --accent: #722f37;
  --accent-deep: #4c1f24;
  --accent-soft: #f0e4c5;
  --scholar: #1d3042;
  --scholar-deep: #132230;
  --gold: #b59a61;
  --focus: #a24c45;
  --heading: #1d3042;
  --sticky: rgba(243, 238, 227, 0.96);
  --column-count: 3;
  --verse-font-size: 1rem;
  --transliteration-font-size: 0.76rem;
  font-family: "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171c21;
  --paper-raised: #20262c;
  --paper-deep: #2a3137;
  --ink: #e7dfd0;
  --muted: #aaa398;
  --line: #3c4650;
  --accent: #c07b83;
  --accent-deep: #d8a0a6;
  --accent-soft: #393528;
  --scholar: #9bb5ca;
  --gold: #bca66f;
  --focus: #d29a79;
  --heading: #dfd2b6;
  --sticky: rgba(23, 28, 33, 0.96);
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.6rem 0.8rem;
  color: white;
  background: var(--accent);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.passage-bar,
.version-picker,
.reader,
.app-footer {
  width: min(100%, 1500px);
  margin-inline: auto;
}

.app-footer a {
  color: inherit;
  text-underline-offset: 0.18rem;
}

.app-footer a:hover,
.app-footer a:focus-visible {
  color: var(--accent-deep);
}

.app-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 4.5rem);
  color: #f8f1e3;
  border-bottom: 3px solid var(--gold);
  background: var(--scholar-deep);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-logo {
  width: clamp(4.6rem, 8vw, 6.3rem);
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0.45rem 1.5rem rgba(0, 0, 0, 0.28);
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.1rem;
  color: #d5c6a6;
  font-family: system-ui, sans-serif;
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fffaf0;
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 0.95;
}

.tradition-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0.48rem 0 0;
  color: #c9d0d5;
  font-size: 0.72rem;
  letter-spacing: 0.045em;
}

.tradition-line span + span::before {
  margin-right: 0.85rem;
  color: var(--gold);
  content: "·";
}

.quiet-button {
  min-height: 2.35rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 0.35rem;
  color: #fffaf0;
  background: transparent;
  cursor: pointer;
}

.quiet-button:hover,
.quiet-button:focus-visible {
  border-color: var(--gold);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
}

.font-control {
  position: relative;
}

.font-popover {
  position: absolute;
  z-index: 15;
  top: calc(100% + 0.65rem);
  right: 0;
  width: min(19rem, calc(100vw - 2rem));
  padding: 1rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--paper-raised);
  box-shadow: 0 1rem 2.6rem rgba(0, 0, 0, 0.28);
  font-family: system-ui, sans-serif;
}

.font-popover::before {
  position: absolute;
  right: 1.2rem;
  bottom: 100%;
  width: 0.7rem;
  height: 0.7rem;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--paper-raised);
  content: "";
  transform: translateY(0.4rem) rotate(45deg);
}

.font-popover-heading,
.font-slider-row {
  display: flex;
  align-items: center;
}

.font-popover-heading {
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.font-popover output {
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}

.font-slider-row {
  gap: 0.7rem;
  margin-top: 0.9rem;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 0.8rem;
}

.font-slider-row .large-a {
  font-size: 1.25rem;
}

.font-slider-row input {
  width: 100%;
  accent-color: var(--accent);
}

.font-reset {
  margin-top: 0.8rem;
  padding: 0;
  color: var(--muted);
  border: 0;
  background: transparent;
  font: 0.7rem system-ui, sans-serif;
  text-decoration: underline;
  text-underline-offset: 0.18rem;
  cursor: pointer;
}

.font-reset:hover,
.font-reset:focus-visible {
  color: var(--accent-deep);
}

.passage-bar {
  display: flex;
  align-items: center;
  gap: 1.3rem;
  padding: 1rem clamp(1rem, 3vw, 2.5rem) 0.9rem;
  border-bottom: 1px solid var(--line);
  font-family: system-ui, sans-serif;
}

.passage-heading {
  min-width: 10rem;
  padding-right: 1.2rem;
  border-right: 1px solid var(--line);
}

.passage-heading p {
  margin: 0 0 0.15rem;
  color: var(--accent);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.passage-heading h2 {
  margin: 0;
  color: var(--heading);
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: clamp(1.35rem, 2.8vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.passage-controls {
  display: flex;
  align-items: end;
  gap: 0.75rem;
}

.passage-bar label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
}

select {
  min-height: 2.25rem;
  padding: 0.3rem 2rem 0.3rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  color: var(--ink);
  background: var(--paper-raised);
}

.sample-notice {
  margin: 0 0 0 auto;
  padding: 0.45rem 0.65rem;
  border-radius: 0.25rem;
  color: var(--scholar);
  border-left: 2px solid var(--gold);
  background: transparent;
  font-size: 0.72rem;
}

.version-picker {
  padding: 1rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  font-family: system-ui, sans-serif;
}

.version-picker fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.version-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.version-picker-header h2 {
  margin: 0;
  color: var(--heading);
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
}

.panel-close {
  padding: 0.38rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}

.panel-close:hover,
.panel-close:focus-visible {
  color: var(--accent-deep);
  border-color: var(--accent);
  outline: none;
}

.version-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.2rem;
}

.transliteration-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.version-options label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reader {
  padding: 0.9rem clamp(0.7rem, 3vw, 2.5rem) 3rem;
}

.column-headings,
.verse-row {
  display: grid;
  grid-template-columns: repeat(var(--column-count), minmax(0, 1fr));
}

.column-headings {
  position: sticky;
  z-index: 5;
  top: 0;
  border-bottom: 2px solid var(--scholar);
  background: var(--sticky);
  backdrop-filter: blur(8px);
}

.column-heading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.68rem 0.85rem;
  color: var(--scholar);
  font-family: system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.035em;
}

.language-code {
  min-width: 2rem;
  padding: 0.18rem 0.28rem;
  color: #fffaf0;
  border-radius: 0.15rem;
  background: var(--scholar);
  font-size: 0.57rem;
  letter-spacing: 0.08em;
  text-align: center;
}

.column-heading + .column-heading,
.verse-cell + .verse-cell {
  border-left: 1px solid var(--line);
}

.verse-grid {
  border: 0;
  background: var(--paper-raised);
  box-shadow: 0 0.7rem 2.5rem rgba(70, 53, 32, 0.07);
}

.verse-row {
  scroll-margin-top: 4rem;
  border-bottom: 1px solid var(--line);
}

.verse-row:last-child {
  border-bottom: 0;
}

.verse-row.is-active {
  background: var(--accent-soft);
  box-shadow: inset 4px 0 0 var(--accent), inset 0 1px 0 rgba(181, 154, 97, 0.45), inset 0 -1px 0 rgba(181, 154, 97, 0.45);
}

.verse-cell {
  position: relative;
  min-height: 6.5rem;
  padding: 0.85rem 0.9rem 0.95rem 2.45rem;
  cursor: pointer;
}

.verse-cell:focus-visible {
  z-index: 1;
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.verse-number {
  position: absolute;
  top: 0.95rem;
  left: 0.9rem;
  color: var(--scholar);
  font-family: system-ui, sans-serif;
  font-size: 0.66rem;
  font-weight: 800;
}

.verse-text {
  margin: 0;
  max-width: 42rem;
  font-size: var(--verse-font-size);
  line-height: 1.62;
  hanging-punctuation: first last;
}

.section-heading {
  margin: 0 0 0.55rem;
  color: var(--accent-deep);
  font-family: system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.025em;
}

.verse-cell[dir="rtl"] {
  padding: 0.85rem 2.45rem 0.95rem 0.9rem;
  text-align: right;
}

.verse-cell[dir="rtl"] .verse-number {
  right: 0.9rem;
  left: auto;
}

.transliteration {
  max-width: 42rem;
  margin: 0.6rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid color-mix(in srgb, var(--line), transparent 35%);
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: var(--transliteration-font-size);
  line-height: 1.5;
  direction: ltr;
  text-align: left;
}

.unavailable {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  font-style: italic;
}

.mobile-tabs {
  display: none;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2.5rem);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 0.75rem;
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    padding: 0.85rem 1rem;
  }

  .brand-logo {
    width: 4.35rem;
  }

  .header-actions {
    max-width: 8rem;
  }

  .quiet-button {
    width: 100%;
  }

  .font-control {
    width: 100%;
  }

  .tradition-line {
    display: none;
  }

  .passage-bar {
    flex-wrap: wrap;
  }

  .passage-heading {
    width: 100%;
    padding: 0 0 0.65rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .passage-controls {
    flex: 1;
  }

  .sample-notice {
    width: 100%;
    margin-left: 0;
  }

  .mobile-tabs {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    margin-bottom: 0.7rem;
    padding-bottom: 0.15rem;
  }

  .mobile-tab {
    flex: 0 0 auto;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: transparent;
  }

  .mobile-tab[aria-selected="true"] {
    border-color: var(--accent);
    color: white;
    background: var(--accent);
  }

  .column-headings {
    display: none;
  }

  .verse-row {
    display: block;
  }

  .verse-cell {
    display: none;
    min-height: 0;
    border-left: 0 !important;
  }

  .verse-text {
    font-size: var(--verse-font-size);
    line-height: 1.65;
  }

  .verse-cell.is-mobile-active {
    display: block;
  }

  .verse-row.is-active {
    box-shadow: inset 4px 0 0 var(--accent);
  }
}

@media (min-width: 1200px) {
  .verse-cell {
    padding-inline-end: 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
