/* ════════════════════════════════════════════════════════════
   CATENA ÁUREA — Stylesheet
   ════════════════════════════════════════════════════════════ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
  --bg:          #0d0d0f;
  --surface:     #141418;
  --surface2:    #1c1c22;
  --border:      rgba(255, 255, 255, .08);
  --border2:     rgba(255, 255, 255, .14);
  --text:        #e8e6e0;
  --text-dim:    rgba(232, 230, 224, .55);
  --text-faint:  rgba(232, 230, 224, .32);

  /* Book accent colours — overridden via JS per active book */
  --book-bg1:    #1a2744;
  --book-bg2:    #243662;
  --book-accent: #7a9fe0;
  --book-gold:   #d4b86a;
  --book-symbol: #7a9fe0;
  --book-glow:   rgba(106, 143, 216, .18);

  --hdr-h:   64px;
  --sidebar-w: 260px;
  --radius:  10px;
  --radius-lg: 16px;
  --transition: .2s ease;
}

:root[data-color-mode="dark"] {
  color-scheme: dark;
}

:root[data-color-mode="light"] {
  color-scheme: light;
  --bg:          #f4f0e8;
  --surface:     #fbf7ef;
  --surface2:    #ede6d9;
  --border:      rgba(45, 37, 28, .12);
  --border2:     rgba(45, 37, 28, .2);
  --text:        #231f19;
  --text-dim:    rgba(35, 31, 25, .68);
  --text-faint:  rgba(35, 31, 25, .42);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Lora', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Layout grid ────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--hdr-h) 1fr;
  height: 100vh;
  height: 100dvh;
}

@supports (padding: max(0px)) {
  #app {
    grid-template-columns: max(0px, var(--sidebar-w)) 1fr;
  }
}

/* ── Header ─────────────────────────────────────────────────── */
#header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: rgba(13, 13, 15, .92);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
  transition: border-color .4s;
  padding-top: max(0px, env(safe-area-inset-top));
}
:root[data-color-mode="light"] #header {
  background: rgba(244, 240, 232, .92);
}

.logo-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background var(--transition);
  text-decoration: none;
  min-height: 44px;
  touch-action: manipulation;
}
.logo-btn:hover { background: rgba(255, 255, 255, .06); }

.chapter-toggle {
  display: none;
  border: none;
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  font-size: 1.15rem;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  touch-action: manipulation;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chapter-toggle:hover {
  background: rgba(255, 255, 255, .1);
}
.chapter-toggle[hidden] {
  display: none !important;
}

@media (min-width: 601px) {
  .chapter-toggle { display: none; }
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--book-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--book-accent);
  padding: 2px;
  flex-shrink: 0;
  transition: all .4s;
  box-shadow: 0 0 16px var(--book-glow);
}

.logo-symbol {
  display: block;
  width: 100%;
  height: 100%;
  opacity: .92;
}
.logo-symbol .evangelist-symbol {
  width: 100%;
  height: 100%;
  transform: scale(1.1);
  transform-origin: center;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.logo-title {
  font-family: 'Cinzel', serif;
  font-size: .88rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .12em;
}
.logo-sub {
  font-family: 'Inter', sans-serif;
  font-size: .65rem;
  font-weight: 300;
  color: var(--text-faint);
  letter-spacing: .2em;
  text-transform: uppercase;
}

.header-divider {
  width: 1px;
  height: 28px;
  background: var(--border2);
  margin: 0 8px;
  flex-shrink: 0;
}

/* ── Book tabs ──────────────────────────────────────────────── */
#book-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#book-tabs::-webkit-scrollbar { display: none; }

.book-tab {
  position: relative;
  background: none;
  border: none;
  padding: 6px 14px 6px 10px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  letter-spacing: .07em;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
  min-height: 32px;
  min-width: 44px;
  touch-action: manipulation;
}
.book-tab::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  transition: opacity var(--transition);
  background: var(--book-glow);
}
.book-tab:hover { color: var(--text); }
.book-tab:hover::before { opacity: 1; }
.book-tab.active { color: var(--book-symbol); font-weight: 600; }
.book-tab.active::before { opacity: 1; }
.book-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%; right: 10%;
  height: 2px;
  background: var(--book-accent);
  border-radius: 2px 2px 0 0;
}

.tab-symbol {
  width: 20px;
  height: 20px;
  color: currentColor;
  opacity: .7;
  flex-shrink: 0;
}
.tab-symbol svg,
.book-card-symbol svg,
.chapter-header-icon svg,
.evangelist-symbol {
  display: block;
  width: 100%;
  height: 100%;
}
.evangelist-symbol {
  background: currentColor;
  -webkit-mask-image: var(--symbol-src);
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-image: var(--symbol-src);
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
}
.book-tab.active .tab-symbol { opacity: 1; }

.liturgy-tab {
  margin-left: auto;
}
.liturgy-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: .92rem;
}

.theme-mode-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  border: 1px solid var(--border);
}
.theme-mode-btn .mode-icon,
.theme-mode-btn svg {
  display: block;
  width: 18px;
  height: 18px;
}
.theme-mode-btn svg {
  stroke: currentColor;
}

:root[data-color-mode="light"] .liturgy-section {
  background: var(--surface);
  border-color: rgba(45, 37, 28, .16);
}

:root[data-color-mode="light"] .book-tab::before,
:root[data-color-mode="light"] .logo-btn:hover {
  background: rgba(45, 37, 28, .06);
}

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  transition: background .4s, opacity .3s, visibility .3s;
}
body:not(.book-active) #sidebar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
/* Collapse the sidebar column when no book is active (desktop only) */
@media (min-width: 601px) {
  body:not(.book-active) #app {
    grid-template-columns: 0 1fr;
  }
}

.sidebar-header {
  padding: 16px 16px 10px;
  font-family: 'Inter', sans-serif;
  font-size: .6rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#chapter-list { padding: 6px 0; flex: 1; }

.ch-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  padding: 7px 16px;
  font-family: 'Lora', serif;
  font-size: .88rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all .15s;
  min-height: 44px;
  touch-action: manipulation;
}
.ch-btn:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.ch-btn.active {
  color: var(--book-symbol);
  font-weight: 600;
  background: rgba(255, 255, 255, .05);
  border-left-color: var(--book-accent);
}
:root[data-color-mode="light"] .ch-btn:hover {
  color: var(--text);
  background: rgba(35, 31, 25, .08);
}
:root[data-color-mode="light"] .ch-btn.active {
  background: color-mix(in srgb, var(--book-accent) 12%, transparent);
}
:root[data-color-mode="light"] .ch-btn.active:hover {
  background: color-mix(in srgb, var(--book-accent) 18%, rgba(35, 31, 25, .06));
}
.ch-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--book-accent);
  opacity: .5;
  flex-shrink: 0;
}

/* ── Main content area ──────────────────────────────────────── */
#main {
  overflow-y: auto;
  background: var(--bg);
  position: relative;
}

/* ── Welcome / Book gallery ─────────────────────────────────── */
#welcome {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  gap: 32px;
}

.welcome-title { text-align: center; }
.welcome-title h1 {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--text);
  letter-spacing: .1em;
  margin-bottom: 4px;
}
.welcome-title p {
  font-family: 'Inter', sans-serif;
  font-size: .8rem;
  color: var(--text-faint);
  letter-spacing: .18em;
  text-transform: uppercase;
}

.welcome-liturgy-link {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--book-accent) 48%, transparent);
  background: color-mix(in srgb, var(--book-accent) 10%, transparent);
  color: var(--book-accent);
  min-height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: 'Inter', sans-serif;
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s, transform .2s;
}

.welcome-liturgy-link:hover,
.welcome-liturgy-link:focus-visible {
  border-color: var(--book-accent);
  background: color-mix(in srgb, var(--book-accent) 16%, transparent);
  color: var(--text);
  transform: translateY(-1px);
  outline: none;
}

:root[data-color-mode="light"] .welcome-liturgy-link {
  border-color: color-mix(in srgb, var(--book-accent) 36%, var(--border2));
  background: color-mix(in srgb, var(--surface2) 82%, white);
  color: var(--book-accent);
  box-shadow: 0 1px 0 rgba(45, 37, 28, .06);
}

:root[data-color-mode="light"] .welcome-liturgy-link:hover,
:root[data-color-mode="light"] .welcome-liturgy-link:focus-visible {
  border-color: color-mix(in srgb, var(--book-accent) 58%, var(--border2));
  background: color-mix(in srgb, var(--book-accent) 12%, var(--surface));
  color: var(--text);
}

.welcome-liturgy-icon {
  font-size: .9rem;
  line-height: 1;
}

.book-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 900px;
}

.book-card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform .3s, box-shadow .3s;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}
.book-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .7);
}

.book-card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center top;
  transition: transform .4s;
}
.book-card:hover .book-card-bg { transform: scale(1.06); }

.book-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, .95) 0%,
    rgba(0, 0, 0, .5) 45%,
    rgba(0, 0, 0, .1) 100%
  );
}

.book-card-body {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-card-symbol {
  width: 28px;
  height: 28px;
  margin-bottom: 2px;
  filter: drop-shadow(0 0 5px color-mix(in srgb, currentColor 55%, transparent));
}

.book-card-vol {
  font-family: 'Inter', sans-serif;
  font-size: .62rem;
  font-weight: 400;
  letter-spacing: .22em;
  text-transform: uppercase;
  opacity: .7;
  color: #fff;
}

.book-card-name {
  font-family: 'Cinzel', serif;
  font-size: .95rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.book-card-cta {
  font-family: 'Inter', sans-serif;
  font-size: .68rem;
  color: rgba(255, 255, 255, .5);
  letter-spacing: .1em;
  margin-top: 2px;
}

/* ── Chapter view ───────────────────────────────────────────── */
#chapter-view {
  padding: 40px 52px 80px;
  max-width: 860px;
  margin: 0 auto;
  padding-bottom: calc(80px + max(0px, env(safe-area-inset-bottom)));
}

.chapter-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 36px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.chapter-header-icon {
  width: 40px;
  height: 40px;
  color: var(--book-accent);
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px var(--book-glow));
}

.chapter-header-text .book-name {
  font-family: 'Inter', sans-serif;
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--book-accent);
  margin-bottom: 3px;
}
.chapter-header-text .chapter-label {
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Verse rows ─────────────────────────────────────────────── */
.verse-row {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background .15s;
  cursor: default;
  min-height: 44px;
  align-content: center;
  touch-action: manipulation;
}
.verse-row.has-commentary { cursor: pointer; }
.verse-row.has-commentary:hover { background: rgba(255, 255, 255, .04); }
:root[data-color-mode="light"] .verse-row.has-commentary:hover {
  background: rgba(35, 31, 25, .06);
}
.verse-row.highlighted {
  background: color-mix(in srgb, var(--book-accent) 12%, transparent);
}

.v-num {
  font-family: 'Cinzel', serif;
  font-size: .72rem;
  font-weight: 600;
  color: var(--book-accent);
  padding-top: 5px;
  text-align: right;
  opacity: .7;
  user-select: none;
  letter-spacing: .04em;
}

.v-text {
  font-size: 1.02rem;
  line-height: 1.85;
  color: var(--text-dim);
  -webkit-user-select: text;
  user-select: text;
}
.verse-row.has-commentary .v-text { color: var(--text); }

.comm-pip {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--book-accent);
  margin-left: 6px;
  vertical-align: middle;
  opacity: .55;
  flex-shrink: 0;
  position: relative;
  top: -2px;
}

.illuminated {
  float: left;
  font-family: 'Cinzel', serif;
  font-size: 4rem;
  line-height: .82;
  color: var(--book-symbol);
  margin-right: 6px;
  margin-top: 6px;
  filter: drop-shadow(0 0 16px color-mix(in srgb, var(--book-symbol) 40%, transparent));
}

.chapter-ornament {
  text-align: center;
  padding: 36px 0 8px;
  font-family: 'Cinzel', serif;
  font-size: .7rem;
  letter-spacing: .4em;
  color: var(--text-faint);
  user-select: none;
}

/* ── Daily liturgy ───────────────────────────────────────────────────── */
#liturgy-view {
  padding: 28px 40px 80px;
  max-width: 980px;
  margin: 0 auto;
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

#liturgy-view * {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

#liturgy-view button,
#liturgy-view input,
#liturgy-view label {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.liturgy-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.liturgy-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 0 12px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
}

.liturgy-day-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: color-mix(in srgb, var(--surface2) 82%, transparent);
  color: var(--book-gold);
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.liturgy-day-btn:hover {
  background: color-mix(in srgb, var(--book-accent) 16%, var(--surface2));
  border-color: color-mix(in srgb, var(--book-accent) 48%, var(--border2));
  transform: translateY(-1px);
}
#liturgy-prev { justify-self: start; }
#liturgy-next { justify-self: end; }

.liturgy-date-picker {
  min-width: min(320px, 58vw);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border2);
  background: rgba(255, 255, 255, .04);
  font-family: 'Inter', sans-serif;
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.liturgy-date-picker input {
  min-width: 148px;
  border: none;
  background: transparent;
  color: var(--text);
  font: 500 .9rem 'Inter', sans-serif;
  color-scheme: dark;
  outline: none;
}

.liturgy-hero {
  padding: 28px 0 18px;
  border-bottom: 1px solid var(--border);
}
.liturgy-eyebrow,
.liturgy-kicker {
  font-family: 'Inter', sans-serif;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--book-accent);
}
.liturgy-hero h1 {
  max-width: 760px;
  margin-top: 8px;
  font-family: 'Cinzel', serif;
  font-size: clamp(1.45rem, 3vw, 2.35rem);
  line-height: 1.18;
  color: var(--text);
}
.liturgy-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-family: 'Inter', sans-serif;
  font-size: .82rem;
  color: var(--text-dim);
}
.liturgy-color {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--book-gold) 32%, transparent);
  color: var(--book-gold);
  background: color-mix(in srgb, var(--book-gold) 8%, transparent);
}

.liturgy-section {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--book-bg1) 18%, transparent), transparent 48%),
    rgba(255, 255, 255, .025);
}
.liturgy-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.liturgy-collapse-summary {
  margin-bottom: 0;
  cursor: pointer;
  list-style: none;
}
.liturgy-collapse-summary::-webkit-details-marker {
  display: none;
}
.liturgy-collapse-summary::marker {
  content: '';
}
.liturgy-collapsible[open] > .liturgy-collapse-summary {
  margin-bottom: 16px;
}
.liturgy-collapse-icon {
  width: 34px;
  height: 34px;
  margin-top: 2px;
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--book-accent) 52%, transparent);
  border-radius: 999px;
  position: relative;
  color: var(--book-accent);
  transition: border-color .2s, background .2s, transform .2s;
}
.liturgy-collapse-icon::before,
.liturgy-collapse-icon::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 13px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: translate(-50%, -50%);
  transition: transform .2s, opacity .2s;
}
.liturgy-collapse-icon::after {
  transform: translate(-50%, -50%) rotate(90deg);
}
.liturgy-collapse-summary:hover .liturgy-collapse-icon,
.liturgy-collapse-summary:focus-visible .liturgy-collapse-icon {
  border-color: var(--book-accent);
  background: color-mix(in srgb, var(--book-accent) 10%, transparent);
}
.liturgy-collapse-summary:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--book-accent) 55%, transparent);
  outline-offset: 6px;
}
.liturgy-collapsible[open] .liturgy-collapse-icon {
  transform: rotate(180deg);
}
.liturgy-collapsible[open] .liturgy-collapse-icon::after {
  opacity: 0;
}
.liturgy-section h2 {
  margin-top: 5px;
  font-family: 'Cinzel', serif;
  font-size: 1.08rem;
  line-height: 1.35;
  color: var(--text);
}
.liturgy-reference {
  margin-top: 7px;
  font-family: 'Cinzel', serif;
  font-size: .95rem;
  font-weight: 700;
  color: var(--book-gold);
}

.liturgy-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.liturgy-mini,
.liturgy-prayer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.liturgy-mini h3,
.liturgy-prayer h3 {
  margin-bottom: 8px;
  font-family: 'Inter', sans-serif;
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.liturgy-mini p,
.liturgy-prayer p {
  color: var(--text-dim);
  line-height: 1.75;
}
.liturgy-prayers {
  display: grid;
  gap: 16px;
}

.liturgy-text,
.liturgy-gospel-text {
  font-size: 1.03rem;
  line-height: 1.88;
  color: var(--text-dim);
}
.liturgy-gospel-text {
  color: var(--text);
}
.liturgy-gospel {
  border-color: color-mix(in srgb, var(--book-accent) 34%, var(--border));
  box-shadow: 0 18px 60px color-mix(in srgb, var(--book-glow) 80%, transparent);
}
.liturgy-gospel-intro {
  margin-bottom: 14px;
  color: var(--text-dim);
  font-style: italic;
}
.liturgy-verse-flow {
  color: var(--text);
}
.liturgy-verse {
  border-radius: 4px;
  padding: 1px 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: background .15s, color .15s;
}
.liturgy-verse.has-commentary {
  cursor: pointer;
}
.liturgy-verse.has-commentary:hover {
  background: rgba(255, 255, 255, .06);
}
:root[data-color-mode="light"] .liturgy-verse.has-commentary:hover {
  background: rgba(35, 31, 25, .08);
}
.liturgy-verse.highlighted {
  background: color-mix(in srgb, var(--book-accent) 20%, transparent);
  color: var(--text);
}
.lit-v-num {
  margin-right: 3px;
  font-family: 'Cinzel', serif;
  font-size: .66em;
  font-weight: 700;
  line-height: 0;
  color: var(--book-accent);
  vertical-align: super;
}
.liturgy-psalm-response {
  margin-bottom: 14px;
  padding-left: 14px;
  border-left: 2px solid var(--book-accent);
  color: var(--book-gold);
  font-style: italic;
  line-height: 1.7;
}
.liturgy-hint {
  margin-top: 18px;
  font-family: 'Inter', sans-serif;
  font-size: .75rem;
  color: var(--text-faint);
  letter-spacing: .04em;
}
.liturgy-error p {
  color: var(--text-dim);
  line-height: 1.7;
}

/* ── Loading indicator ──────────────────────────────────────── */
#loading-indicator {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-faint);
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  letter-spacing: .1em;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border2);
  border-top-color: var(--book-accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

/* ── Commentary panel ───────────────────────────────────────── */
#comm-panel {
  position: fixed;
  right: 0;
  top: var(--hdr-h);
  width: clamp(360px, 40vw, 720px);
  min-width: 320px;
  max-width: 860px;
  height: calc(100vh - var(--hdr-h));
  height: calc(100dvh - var(--hdr-h));
  background: var(--surface);
  border-left: 1px solid var(--border2);
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.4, 0, .2, 1), width .2s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 200;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}
#comm-panel.open { transform: translateX(0); }

#comm-panel.is-maximized {
  left: 0;
  right: 0;
  top: 0;
  width: 100% !important;
  min-width: 0;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  background: color-mix(in srgb, var(--surface) 88%, #000 12%);
  border-left: none;
  z-index: 400;
}

#comm-panel.is-maximized #comm-resize {
  display: none;
}

#comm-panel.is-maximized #comm-header {
  padding-left: max(24px, calc((100vw - 980px) / 2));
  padding-right: max(24px, calc((100vw - 980px) / 2));
}

#comm-panel.is-maximized #comm-body {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 28px 40px 48px;
  background: var(--surface);
}

:root[data-color-mode="light"] #comm-panel.is-maximized {
  background: color-mix(in srgb, var(--surface) 90%, #000 10%);
}

#comm-resize {
  position: absolute;
  left: 0; top: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  transition: background .15s;
}
#comm-resize:hover,
#comm-resize.dragging { background: var(--book-accent); }

#comm-header {
  border-bottom: 1px solid var(--border);
  padding: 18px 20px 16px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  transition: background .4s;
}

.comm-meta {
  min-width: 0;
}

.comm-book-label {
  font-family: 'Inter', sans-serif;
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--book-accent);
  margin-bottom: 4px;
}
.comm-ref {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: .04em;
}

.comm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.comm-control {
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .15s;
  min-width: 44px;
  min-height: 44px;
  touch-action: manipulation;
}

.comm-control:hover { background: rgba(255, 255, 255, .12); color: var(--text); }

.comm-maximize-icon {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
}

.comm-maximize-icon::before,
.comm-maximize-icon::after {
  content: '';
  position: absolute;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.comm-maximize-icon::before {
  inset: 1px;
}

.comm-maximize-icon::after {
  display: none;
}

#comm-panel.is-maximized .comm-maximize-icon::before {
  width: 10px;
  height: 10px;
  left: 1px;
  top: 5px;
  right: auto;
  bottom: auto;
}

#comm-panel.is-maximized .comm-maximize-icon::after {
  display: block;
  width: 10px;
  height: 10px;
  left: 5px;
  top: 1px;
}

#comm-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  font-size: .96rem;
  line-height: 1.85;
  -webkit-user-select: text;
  user-select: text;
}
#comm-body p { margin-bottom: 1em; color: var(--text-dim); }
#comm-body p:last-child { margin-bottom: 0; }

#comm-body strong.father {
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--book-accent);
  margin-right: 4px;
  padding: 1px 6px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--book-accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--book-accent) 20%, transparent);
}

#comm-body .vs-num {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  font-weight: 700;
  color: var(--book-accent);
  margin-right: 4px;
}

/* ── Panel visibility (controlled by JS via .is-hidden class) ── */
/*
 * We do NOT rely on the HTML `hidden` attribute + UA stylesheet because
 * the author's display:flex on #welcome overrides the UA display:none.
 * Instead we use an explicit class with !important.
 */
.is-hidden { display: none !important; }

/* Default display for panels when visible */
#welcome      { display: flex; }
#chapter-view { display: block; }
#liturgy-view { display: block; }
#loading-indicator { display: flex; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .2); }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}
.fade-up  { animation: fadeUp .4s ease both; }
.scale-in { animation: scaleIn .3s ease both; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { display: none; }
  #comm-panel { width: 100%; top: var(--hdr-h); }
  #chapter-view { padding: 24px 20px 60px; }
  #liturgy-view { padding: 18px 16px 60px; }
  .book-cards { grid-template-columns: repeat(2, 1fr); }
  .liturgy-tab { margin-left: 0; }
  .liturgy-tab .tab-label { display: none; }
  .theme-mode-btn {
    width: 34px;
    height: 34px;
  }
  .liturgy-nav {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 10px;
  }
  .liturgy-date-picker {
    min-width: 0;
    gap: 6px;
    padding: 7px 8px;
  }
  .liturgy-date-picker span { display: none; }
  .liturgy-date-picker input {
    min-width: 0;
    width: 100%;
    text-align: center;
  }
  .liturgy-section { padding: 18px; }
  .liturgy-two-col { grid-template-columns: 1fr; }
  #book-tabs .book-tab span:not(.tab-symbol) { display: none; }

/* ---- Tablet (≤ 900px) ---- */
@media (max-width: 900px) {
  :root { --sidebar-w: 200px; }

  .logo-sub    { display: none; }
  .header-divider { display: none; }

  #book-tabs { gap: 2px; }
  .book-tab  { padding: 6px 10px 6px 8px; font-size: .7rem; gap: 6px; }
}

/* ---- Mobile (≤ 600px) ---- */
@media (max-width: 600px) {
  :root {
    --sidebar-w: 0px;
    --hdr-h: 56px;
    --radius: 8px;
  }

  /* ── Layout: single column, header shrinks ── */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--hdr-h) 1fr;
    height: 100dvh;
  }

  /* ── Header: icon only for logo, tabs icon-only ── */
  #header {
    padding: max(0px, env(safe-area-inset-top)) 8px 0 8px;
    gap: 4px;
    overflow: hidden;
    flex-wrap: nowrap;
    min-height: var(--hdr-h);
  }

  .logo-text,
  .logo-sub,
  .header-divider { display: none; }

  .logo-mark {
    width: 32px;
    height: 32px;
    font-size: .75rem;
    flex-shrink: 0;
  }

  .logo-btn {
    padding: 0;
  }

  /* ── Tabs: icon + short label, scroll if needed ── */
  #book-tabs {
    display: flex;
    flex: 1;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 18px 0 4px;
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 34px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 34px), transparent 100%);
  }
  #book-tabs::-webkit-scrollbar { display: none; }

  .book-tab {
    padding: 6px 8px;
    font-size: .66rem;
    gap: 4px;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 96px;
    border-radius: 6px;
  }
  #book-tabs .tab-symbol { display: none; }
  .tab-symbol { width: 16px; height: 16px; }
  .liturgy-tab {
    margin-left: 2px;
    justify-content: center;
    gap: 0;
    width: 36px;
    min-width: 36px;
    height: 34px;
    min-height: 34px;
    padding-inline: 0;
  }
  .theme-mode-btn {
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: 8px;
  }
  .theme-mode-btn .mode-icon,
  .theme-mode-btn svg {
    width: 15px;
    height: 15px;
  }

  /* ── Sidebar: hidden by default on mobile; open via chapter toggle ── */
  #sidebar {
    position: fixed;
    left: 0;
    top: var(--hdr-h);
    bottom: 0;
    width: min(320px, 85vw);
    max-width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 24px 0 64px rgba(0, 0, 0, .5);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 160;
    display: flex;
    flex-direction: column;
  }
  body.sidebar-open #sidebar {
    transform: translateX(0);
  }
  .chapter-toggle { display: inline-flex; }

  /* ── Main content: full width ── */
  #main {
    width: 100%;
    overflow-x: hidden;
  }

  body.sidebar-open #main {
    pointer-events: none;
  }

  /* ── Welcome screen: center content ── */
  #welcome {
    padding: 20px 16px;
    gap: 24px;
    min-height: calc(100dvh - var(--hdr-h));
  }

  .welcome-title {
    padding: 0 8px;
  }

  .welcome-title h1 {
    font-size: clamp(1.3rem, 6vw, 1.8rem);
    margin-bottom: 8px;
  }

  .welcome-title p {
    font-size: .68rem;
  }

  /* ── Book cards: responsive grid ── */
  .book-cards {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 100%;
    padding: 0 4px;
  }

  .book-card {
    border-radius: 8px;
    aspect-ratio: 2.2 / 3;
  }

  .book-card-symbol {
    width: 24px;
    height: 24px;
  }

  .book-card-name { font-size: .78rem; }
  .book-card-vol  { font-size: .52rem; }
  .book-card-cta  { display: none; }

  /* ── Chapter view ── */
  #chapter-view {
    padding: 20px 16px 80px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: calc(80px + max(0px, env(safe-area-inset-bottom)));
    max-width: 100%;
  }

  .chapter-header {
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
  }

  .chapter-header-icon {
    width: 36px;
    height: 36px;
  }

  .chapter-header-text .chapter-label {
    font-size: 1.2rem;
  }

  .verse-row {
    grid-template-columns: 38px 1fr;
    gap: 6px;
    padding: 6px 8px;
  }

  .v-num {
    font-size: .65rem;
    padding-top: 3px;
  }

  .v-text {
    font-size: .96rem;
    line-height: 1.7;
  }

  .illuminated {
    font-size: 2.8rem;
    line-height: .8;
    margin-right: 4px;
  }

  .chapter-ornament {
    padding: 28px 0 6px;
    font-size: .65rem;
  }

  /* ── Commentary panel: full-screen overlay ── */
  #comm-panel {
    position: fixed;
    right: 0;
    top: var(--hdr-h);
    width: 100% !important;
    max-width: 100%;
    height: calc(100dvh - var(--hdr-h));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(.4, 0, .2, 1);
  }

  #comm-panel.is-maximized {
    top: 0;
    height: 100dvh;
    border-radius: 0;
  }

  #comm-panel.open {
    transform: translateY(0);
  }

  #comm-resize { display: none; }

  #comm-header {
    padding: 14px 16px 12px;
    border-radius: 16px 16px 0 0;
  }

  #comm-panel.is-maximized #comm-header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    border-radius: 0;
  }

  .comm-actions {
    gap: 6px;
  }

  #comm-maximize {
    display: none;
  }

  .comm-control {
    width: 44px;
    height: 44px;
    font-size: .9rem;
  }

  #comm-body {
    padding: 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: calc(16px + max(0px, env(safe-area-inset-bottom)));
    font-size: .93rem;
    line-height: 1.7;
  }

  #comm-panel.is-maximized #comm-body {
    width: 100%;
    padding: 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: calc(16px + max(0px, env(safe-area-inset-bottom)));
  }

  /* ── Loading indicator ── */
  #loading-indicator {
    gap: 12px;
    font-size: .8rem;
  }

  .loading-spinner {
    width: 28px;
    height: 28px;
  }
}

/* ---- Very small phones (≤ 360px) ---- */
@media (max-width: 360px) {
  :root {
    --hdr-h: 52px;
  }

  #header {
    padding: 0 8px;
    gap: 6px;
  }

  .logo-mark {
    width: 28px;
    height: 28px;
    font-size: .65rem;
  }

  .book-tab {
    padding: 5px 6px;
    font-size: .6rem;
  }

  .tab-symbol { width: 14px; height: 14px; }

  #welcome {
    padding: 16px 12px;
    gap: 16px;
  }

  .welcome-title h1 {
    font-size: 1.2rem;
  }

  .book-cards {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    padding: 0 2px;
  }

  .book-card-name { font-size: .7rem; }

  #chapter-view {
    padding: 16px 12px 72px;
  }

  .verse-row {
    grid-template-columns: 32px 1fr;
    gap: 4px;
    padding: 5px 6px;
  }

  .v-text {
    font-size: .92rem;
    line-height: 1.65;
  }

  .illuminated {
    font-size: 2.2rem;
    margin-right: 3px;
  }
}

/* ---- Landscape orientation (all widths) ---- */
@media (max-height: 500px) {
  :root {
    --hdr-h: 48px;
  }

  #header {
    padding: 0 8px;
  }

  .logo-mark {
    width: 28px;
    height: 28px;
  }

  .book-tab {
    padding: 4px 6px;
    font-size: .6rem;
  }

  #welcome {
    padding: 12px 16px;
    gap: 12px;
  }

  .welcome-title h1 {
    font-size: 1.1rem;
  }

  .book-cards {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
  }

  #chapter-view {
    padding: 16px 16px 40px;
  }

  .chapter-header {
    margin-bottom: 12px;
    padding-bottom: 8px;
  }

  .v-text {
    font-size: .9rem;
    line-height: 1.6;
  }
}
