:root {
  --paper: #f7f3e9;
  --paper-strong: #fffdf8;
  --ink: #29261f;
  --muted: #756e61;
  --line: #d9d1c3;
  --accent: #63724d;
  --accent-soft: #e8ecdf;
  --accent-deep: #46523a;
  --nav: rgba(255, 253, 248, .91);
  --shadow: 0 18px 50px rgba(64, 53, 36, .12);
  --radius: 22px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

body[data-theme="white"] {
  --paper: #f8f4e9;
  --paper-strong: #fffdfa;
  --accent: #9a7d39;
  --accent-soft: #f1ead7;
  --accent-deep: #6d5725;
}
body[data-theme="purple"] {
  --paper: #f6f0f4;
  --paper-strong: #fffafd;
  --accent: #73506f;
  --accent-soft: #eadfe8;
  --accent-deep: #553850;
}
body[data-theme="red"] {
  --paper: #f8f0ec;
  --paper-strong: #fffaf7;
  --accent: #8b4a43;
  --accent-soft: #f0dfdb;
  --accent-deep: #69332e;
}
body[data-theme="rose"] {
  --paper: #f9f1f1;
  --paper-strong: #fffafa;
  --accent: #a66b72;
  --accent-soft: #f2e0e2;
  --accent-deep: #7c4d53;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 50% -80px, color-mix(in srgb, var(--accent-soft) 70%, transparent), transparent 44%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
  transition: background-color .25s ease, color .25s ease;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 42%, transparent); outline-offset: 3px; }

.app-shell { min-height: 100vh; padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
.topbar {
  min-height: 78px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  max-width: 920px;
  margin: 0 auto;
  position: relative;
  z-index: 10;
}
.brand-button { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; }
.brand-kicker { display: block; font-size: 11px; letter-spacing: .15em; color: var(--accent-deep); font-weight: 800; margin-bottom: 2px; }
.brand-button strong { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 26px; font-weight: 600; line-height: 1; }
.theme-trigger { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: var(--paper-strong); color: var(--accent-deep); font-size: 19px; cursor: pointer; }
.theme-menu { position: absolute; right: 16px; top: calc(72px + env(safe-area-inset-top)); width: min(310px, calc(100vw - 32px)); padding: 16px; background: var(--paper-strong); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.theme-menu p { margin: 0 0 10px; font-weight: 750; }
.theme-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.theme-options button { border: 0; min-height: 42px; border-radius: 12px; background: var(--accent-soft); cursor: pointer; font-weight: 700; font-size: 12px; }
.theme-menu small { display: block; color: var(--muted); margin-top: 10px; line-height: 1.4; }

.page { width: min(100%, 920px); margin: 0 auto; padding: 18px 18px 44px; }
.hero { padding: 26px 0 18px; }
.eyebrow { margin: 0 0 8px; color: var(--accent-deep); font-size: 12px; letter-spacing: .12em; font-weight: 800; text-transform: uppercase; }
.hero h1, .page-title, .serif { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; }
.hero h1 { font-size: clamp(39px, 11vw, 66px); line-height: .98; letter-spacing: -.035em; margin: 0; font-weight: 600; max-width: 700px; }
.hero .liturgical-line { margin: 16px 0 0; color: var(--muted); font-size: 15px; }
.hero .liturgical-line strong { color: var(--accent-deep); }

.section { margin-top: 34px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading h2, .page-title { margin: 0; font-size: 28px; line-height: 1.08; }
.section-heading button, .text-link { background: none; border: 0; color: var(--accent-deep); font-weight: 750; padding: 9px 0; cursor: pointer; }

.next-event { width: 100%; border: 0; border-left: 3px solid var(--accent); background: transparent; text-align: left; cursor: pointer; padding: 4px 0 4px 17px; }
.next-event .date { color: var(--accent-deep); font-weight: 800; font-size: 13px; letter-spacing: .08em; }
.next-event h3 { font-family: "Iowan Old Style", Georgia, serif; margin: 6px 0 5px; font-size: 27px; font-weight: 600; }
.next-event p { margin: 0; color: var(--muted); line-height: 1.5; }

.family-feature, .story-feature {
  width: 100%; border: 0; text-align: left; cursor: pointer; padding: 0; background: transparent;
}
.family-portrait, .story-image {
  min-height: 230px; border-radius: var(--radius); overflow: hidden; position: relative; display: flex; align-items: end; padding: 20px;
  background:
    linear-gradient(0deg, rgba(29,27,22,.45), rgba(29,27,22,.02) 62%),
    radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--accent-soft) 88%, white), transparent 38%),
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 38%, #d9c7aa), #c9b491);
  color: #fff;
}
.family-portrait::before { content: "HT"; position: absolute; right: 24px; top: 20px; font-family: Georgia, serif; font-size: 74px; opacity: .15; }
.family-portrait strong, .story-image strong { font-family: "Iowan Old Style", Georgia, serif; font-size: 26px; font-weight: 600; }
.family-feature .feature-copy { padding: 14px 2px 0; }
.feature-copy strong { display: block; font-size: 18px; }
.feature-copy p { margin: 5px 0 0; color: var(--muted); line-height: 1.5; }
.feature-copy .go { display: inline-block; color: var(--accent-deep); font-weight: 800; margin-top: 9px; }

.story-image { min-height: 195px; background: linear-gradient(0deg, rgba(30,25,20,.48), transparent 72%), linear-gradient(140deg, #8d765f, color-mix(in srgb, var(--accent) 50%, #c8ac8c)); }
.story-feature h3 { font-family: "Iowan Old Style", Georgia, serif; font-size: 25px; margin: 13px 0 4px; font-weight: 600; }
.story-feature p { margin: 0; color: var(--muted); line-height: 1.5; }

.event-list, .story-list { display: grid; gap: 4px; }
.event-row, .story-row, .person-row {
  width: 100%; border: 0; background: transparent; display: grid; grid-template-columns: 64px 1fr auto; gap: 13px; align-items: center; padding: 14px 0; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line);
}
.event-day { width: 58px; height: 58px; border-radius: 17px; background: var(--accent-soft); display: grid; place-content: center; text-align: center; color: var(--accent-deep); }
.event-day strong { font-size: 21px; line-height: 1; }
.event-day small { font-size: 10px; font-weight: 800; margin-top: 3px; }
.event-row h3, .story-row h3 { margin: 0 0 3px; font-size: 17px; }
.event-row p, .story-row p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.chevron { color: var(--muted); font-size: 20px; }

.page-head { padding: 26px 0 8px; }
.page-head .page-title { font-size: 38px; }
.page-head p { margin: 9px 0 0; color: var(--muted); line-height: 1.5; }
.search { margin: 18px 0 6px; display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 50px; border-radius: 16px; background: var(--paper-strong); border: 1px solid var(--line); }
.search input { flex: 1; width: 100%; border: 0; background: transparent; font-size: 16px; color: var(--ink); outline: 0; }
.search span { color: var(--muted); font-size: 20px; }

.tree-intro { margin-top: 18px; padding: 16px 0; color: var(--muted); line-height: 1.5; }
.focus-tree { margin-top: 10px; }
.tree-level { text-align: center; }
.tree-label { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .12em; margin: 8px 0 12px; }
.node-row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.tree-node { min-width: 128px; max-width: 190px; border: 1px solid var(--line); background: var(--paper-strong); border-radius: 18px; padding: 12px; cursor: pointer; text-align: center; }
.tree-node.current { border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent-soft) 48%, var(--paper-strong)); padding: 17px 15px; min-width: 170px; }
.tree-node small { display: block; color: var(--accent-deep); font-size: 10px; font-weight: 800; letter-spacing: .08em; margin-bottom: 4px; }
.tree-node strong { display: block; font-family: "Iowan Old Style", Georgia, serif; font-size: 19px; font-weight: 600; }
.tree-node em { display: block; font-size: 12px; color: var(--muted); font-style: normal; margin-top: 3px; }
.tree-node.deceased strong::after { content: "  †"; color: var(--muted); font-family: Georgia, serif; font-weight: 400; }
.connector { width: 1px; height: 27px; margin: 0 auto; background: var(--accent); opacity: .55; }
.couple-line { display: flex; justify-content: center; align-items: center; gap: 8px; }
.couple-line::after { content: ""; width: 25px; height: 1px; background: var(--accent); order: 1; }
.couple-line .tree-node:nth-child(1) { order: 0; }
.couple-line .tree-node:nth-child(2) { order: 2; }
.branch-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.branch-card { border: 1px solid var(--line); background: var(--paper-strong); border-radius: 17px; padding: 13px 12px; text-align: left; min-height: 86px; cursor: pointer; }
.branch-card small { display: block; color: var(--accent-deep); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.branch-card strong { display: block; font-family: "Iowan Old Style", Georgia, serif; font-size: 17px; margin-top: 5px; font-weight: 600; }
.branch-card span { color: var(--muted); display: block; margin-top: 3px; font-size: 12px; }
.branch-card.deceased strong::after { content: "  †"; color: var(--muted); }
.branch-note { margin: 12px 2px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.person-row { grid-template-columns: 48px 1fr auto; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-content: center; background: var(--accent-soft); color: var(--accent-deep); font-family: Georgia, serif; font-weight: 700; }
.person-row small { color: var(--accent-deep); font-size: 10px; font-weight: 800; letter-spacing: .07em; }
.person-row strong { display: block; font-family: "Iowan Old Style", Georgia, serif; font-size: 17px; margin-top: 2px; font-weight: 600; }
.person-row.deceased strong::after { content: " †"; color: var(--muted); }
.person-row p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: 0; width: min(100%, 720px); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); background: var(--nav); backdrop-filter: blur(18px) saturate(1.2); border-top: 1px solid color-mix(in srgb, var(--line) 75%, transparent); }
.bottom-nav button { min-height: 54px; border: 0; background: transparent; color: var(--muted); border-radius: 15px; cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; }
.bottom-nav button span { font-size: 21px; line-height: 1; }
.bottom-nav button b { font-size: 11px; }
.bottom-nav button.active { color: var(--accent-deep); background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }

.sheet-layer { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; border: 0; background: rgba(28, 24, 18, .36); }
.sheet { position: relative; width: min(100%, 680px); max-height: min(88vh, 820px); overflow-y: auto; background: var(--paper-strong); border-radius: 28px 28px 0 0; padding: 12px 20px calc(28px + env(safe-area-inset-bottom)); box-shadow: 0 -20px 60px rgba(30, 25, 18, .18); }
.sheet-grabber { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 18px; }
.sheet-close { position: absolute; right: 16px; top: 14px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent-deep); font-size: 25px; cursor: pointer; }
.sheet h2 { font-family: "Iowan Old Style", Georgia, serif; font-size: 32px; font-weight: 600; margin: 6px 50px 4px 0; }
.sheet .saint { color: var(--accent-deep); font-family: Georgia, serif; font-style: italic; margin: 0 0 6px; }
.sheet .meta { margin: 0; color: var(--muted); line-height: 1.5; }
.sheet-divider { height: 1px; background: var(--line); margin: 22px 0; }
.sheet h3 { margin: 0 0 10px; font-size: 17px; }
.sheet p { line-height: 1.58; }
.fact-list { display: grid; gap: 11px; }
.fact { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.fact span { color: var(--muted); }
.fact strong { text-align: right; }
.sheet-action { width: 100%; min-height: 50px; margin-top: 16px; border: 0; border-radius: 15px; background: var(--accent); color: white; font-weight: 800; cursor: pointer; }

.empty { color: var(--muted); padding: 28px 0; text-align: center; }
.prototype-note { margin: 38px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }

@media (min-width: 700px) {
  .page { padding-left: 32px; padding-right: 32px; }
  .branch-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .family-portrait { min-height: 330px; }
  .story-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 30px; align-items: start; }
  .bottom-nav { bottom: 14px; border: 1px solid var(--line); border-radius: 24px; padding-bottom: 8px; box-shadow: var(--shadow); }
  .app-shell { padding-bottom: 118px; }
  .sheet { border-radius: 28px; margin-bottom: 18px; }
}

@media (prefers-reduced-motion: no-preference) {
  .page { animation: pageIn .22s ease; }
  .sheet { animation: sheetIn .24s ease; }
  @keyframes pageIn { from { opacity: .3; transform: translateY(5px); } }
  @keyframes sheetIn { from { transform: translateY(24px); opacity: .7; } }
}
