:root {
  --ivory: #faf7f2;
  --parchment: #f4ecdd;
  --marian-blue: #1b365d;
  --marian-deep: #10233d;
  --gold: #c59b27;
  --gold-soft: #e8cc77;
  --wine: #6e1e2a;
  --green: #2f6b4f;
  --ink: #211d18;
  --muted: #6f665a;
  --line: rgba(27, 54, 93, 0.16);
  --card: rgba(255, 252, 247, 0.86);
  --shadow: 0 18px 50px rgba(27, 54, 93, 0.14);
  --radius: 22px;
  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --ivory: #121820;
  --parchment: #1a2432;
  --marian-blue: #9bb7d8;
  --marian-deep: #dce7f5;
  --gold: #d7b45c;
  --gold-soft: #f1dc9a;
  --wine: #d56b7a;
  --green: #72b58f;
  --ink: #f3ead9;
  --muted: #b7ad9d;
  --line: rgba(243, 234, 217, 0.16);
  --card: rgba(27, 36, 50, 0.86);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--ivory); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at top left, rgba(197, 155, 39, 0.16), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(27, 54, 93, 0.12), transparent 36rem),
    linear-gradient(145deg, var(--ivory), var(--parchment));
  transition: background-color 220ms ease, color 220ms ease;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100dvh; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
body.focus-mode .app-shell { padding-bottom: 0; }
body.focus-mode .topbar, body.focus-mode .bottom-nav, body.focus-mode .screen-header .back-button,
body.focus-mode .screen-header .header-actions { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.85rem + env(safe-area-inset-top)) 1rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--ivory) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff8e8;
  background: linear-gradient(145deg, var(--marian-blue), var(--marian-deep));
  box-shadow: inset 0 0 0 1px rgba(197, 155, 39, 0.45), var(--shadow);
  font-family: var(--font-body);
  font-size: 1.35rem;
}
.brand-name { font-family: var(--font-body); font-size: 1.15rem; font-weight: 700; letter-spacing: 0.01em; }
.brand-subtitle { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; }
.top-actions { display: flex; align-items: center; gap: 0.45rem; }
.icon-button, .button {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  min-height: 42px;
  padding: 0 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  box-shadow: 0 8px 24px rgba(27, 54, 93, 0.08);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.icon-button { width: 42px; padding: 0; font-size: 1rem; }
.icon-button:hover, .button:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(27, 54, 93, 0.14); }
.button.primary { background: linear-gradient(135deg, var(--marian-blue), var(--marian-deep)); color: #fff8e8; border-color: transparent; }
.button.gold { background: linear-gradient(135deg, var(--gold), #9f7b1d); color: #1c1608; border-color: rgba(197, 155, 39, 0.55); }
.button.ghost { background: transparent; box-shadow: none; }
.button.small { min-height: 36px; padding: 0 0.75rem; font-size: 0.85rem; }
.button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.main { width: min(1120px, 100%); margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.screen { animation: screenIn 260ms ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.screen-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.devotional-hero { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.25rem; }
.devotional-hero .hero-copy { flex: 1 1 auto; min-width: 0; }
.devotional-hero .hero-actions { margin-top: 0.9rem; }
.media-hero { flex: 0 0 auto; width: 132px; aspect-ratio: 3 / 4; border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.media-hero::after { display: none; }
.media-hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (min-width: 760px) {
  .media-hero { width: 180px; }
}
@media (max-width: 640px) {
  .devotional-hero { flex-direction: column; align-items: center; text-align: center; }
  .media-hero { width: min(230px, 74%); }
  .devotional-hero .hero-copy .lede { margin-inline: auto; }
  .devotional-hero .hero-actions { justify-content: center; }
}
.eyebrow { margin: 0 0 0.35rem; color: var(--gold); font-size: 0.76rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-family: var(--font-body); font-size: clamp(2rem, 7vw, 3.4rem); line-height: 1; margin-bottom: 0.6rem; }
h2 { font-family: var(--font-body); font-size: clamp(1.45rem, 4vw, 2.2rem); line-height: 1.1; }
h3 { font-family: var(--font-body); font-size: 1.2rem; }
.lede { color: var(--muted); font-size: 1.05rem; line-height: 1.55; max-width: 62ch; }
.muted { color: var(--muted); }
.mystery-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  background: color-mix(in srgb, var(--gold) 16%, transparent);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  font-weight: 700;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1.25rem;
}
.hero-card, .panel, .prayer-card, .rosary-step, .psalm-card, .devotion-card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card { padding: clamp(1.25rem, 4vw, 2.4rem); position: relative; overflow: hidden; }
.hero-card::before {
  content: "✠";
  position: absolute;
  right: 1.2rem;
  top: 0.8rem;
  color: color-mix(in srgb, var(--gold) 28%, transparent);
  font-size: 9rem;
  line-height: 1;
}
.hero-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0 1.3rem; }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.quick-link {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(255,255,255,0.5), rgba(197,155,39,0.08));
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.8rem;
  transition: transform 160ms ease, border-color 160ms ease;
}
.quick-link:hover { transform: translateY(-3px); border-color: var(--gold); }
.quick-icon { font-size: 1.7rem; color: var(--marian-blue); }
.quick-label { display: block; font-weight: 800; font-size: 0.92rem; }
.quick-hint { display: block; margin-top: 0.2rem; color: var(--muted); font-size: 0.78rem; line-height: 1.3; }
.mystery-card { padding: 1.25rem; display: flex; flex-direction: column; justify-content: space-between; gap: 1rem; }
.mystery-number { font-family: var(--font-body); font-size: 4.5rem; line-height: 0.8; color: var(--marian-blue); }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 0.9rem; }
.section-title h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.panel { padding: 1.25rem; }
.panel.compact { padding: 1rem; }
.panel h3 { margin-bottom: 0.45rem; }

.prayer-card, .devotion-card { overflow: hidden; text-decoration: none; color: inherit; transition: transform 160ms ease, border-color 160ms ease; }
.prayer-card:hover, .devotion-card:hover { transform: translateY(-3px); border-color: var(--gold); }
.media { position: relative; aspect-ratio: 4 / 3; background: linear-gradient(135deg, var(--marian-blue), var(--marian-deep)); overflow: hidden; }
.prayer-card .media, .devotion-card .media { aspect-ratio: 3 / 4; }
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 45%, rgba(0,0,0,0.35)); }
.card-body { padding: 1rem; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.7rem; }
.tag { border-radius: 999px; padding: 0.25rem 0.55rem; background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--ink); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.card-body p { color: var(--muted); line-height: 1.45; margin-bottom: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.search-box { flex: 1 1 240px; position: relative; }
.search-box input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  min-height: 44px;
  padding: 0.7rem 0.9rem;
}
.search-box input { padding-left: 2.6rem; }
.search-box::before { content: "⌕"; position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); font-size: 1.25rem; color: var(--muted); }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-weight: 700;
}
.chip.active { background: var(--marian-blue); color: #fff8e8; border-color: transparent; }

.reading-panel { padding: clamp(1.2rem, 4vw, 2.4rem); }
.prose { font-family: var(--font-body); font-size: var(--reading-size, 1.18rem); line-height: var(--reading-height, 1.75); color: var(--ink); }
.prose p { margin: 0 0 1.1em; }
.prose .verse { display: block; margin-bottom: 0.85em; }
.prose .verse-num { color: var(--gold); font-weight: 800; margin-right: 0.35em; }
.reading-controls { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; margin: 1rem 0; }
.reading-controls .label { font-size: 0.8rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-right: 0.25rem; }
.range-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 1.2rem; }

.rosary-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.rosary-progress { position: sticky; top: 92px; }
.progress-track { height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--gold) 18%, transparent); overflow: hidden; margin: 0.8rem 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--wine)); transition: width 220ms ease; }
.rosary-step { padding: 1rem; display: grid; grid-template-columns: auto 1fr auto; gap: 0.85rem; align-items: center; margin-bottom: 0.8rem; }
.step-index { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--marian-blue); font-weight: 900; }
.rosary-step.done { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.rosary-step.done .step-index { background: var(--green); color: #fff; }
.step-title { display: block; font-weight: 800; }
.step-subtitle { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.9rem; }
.decades { display: grid; gap: 0.7rem; }
.decade-card { border: 1px solid var(--line); border-radius: 16px; padding: 1rem; background: color-mix(in srgb, var(--ivory) 65%, transparent); }
.decade-card.active { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 18%, transparent); }
.decade-card h3 { margin-bottom: 0.3rem; }
.decade-card p { margin-bottom: 0; color: var(--muted); }

.psalm-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 1rem; align-items: start; }
.psalm-list { display: grid; gap: 0.55rem; max-height: 560px; overflow: auto; padding-right: 0.2rem; }
.psalm-item { border: 1px solid var(--line); border-radius: 14px; padding: 0.75rem 0.9rem; background: color-mix(in srgb, var(--ivory) 70%, transparent); text-align: left; }
.psalm-item.active { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, var(--card)); }
.psalm-item .num { font-weight: 900; color: var(--marian-blue); margin-right: 0.5rem; }
.psalm-item .preview { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.devotion-guide { border-left: 4px solid var(--gold); padding-left: 1rem; margin: 1rem 0; }
.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.8rem; }
.day-card { border: 1px solid var(--line); border-radius: 16px; padding: 1rem; background: var(--card); }
.day-card.active { border-color: var(--wine); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wine) 15%, transparent); }
.day-card .day-number { color: var(--wine); font-weight: 900; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state .big { font-size: 3rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  background: var(--marian-deep);
  color: #fff8e8;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  padding: 0.5rem 0.7rem calc(0.55rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--ivory) 90%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; text-decoration: none; color: var(--muted); font-size: 0.7rem; font-weight: 800; }
.nav-item .icon { font-size: 1.25rem; }
.nav-item.active { color: var(--marian-blue); }
[data-theme="dark"] .nav-item.active { color: var(--gold-soft); }

.counter { margin: 1rem 0; }
.counter-dots { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.75rem; }
.counter-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: transparent;
}
.counter-dot::after { content: "✠"; display: grid; place-items: center; height: 100%; color: var(--gold); font-size: 0.85rem; }
.counter-dot.filled { background: linear-gradient(135deg, var(--marian-blue), var(--marian-deep)); border-color: transparent; }
.counter-dot.filled::after { color: #fff8e8; }
.prayer-excerpt p, .prayer-full p { font-family: var(--font-body); font-size: 1.05rem; line-height: 1.75; }
.prayer-excerpt h3, .prayer-full h3 { font-family: var(--font-body); margin-top: 1.2rem; }

.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: 900px) {
  .home-hero, .rosary-layout, .psalm-layout { grid-template-columns: 1fr; }
  .rosary-progress { position: static; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .main { padding-inline: 0.8rem; }
  .quick-grid { grid-template-columns: 1fr; }
  .screen-header { align-items: stretch; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
}
