:root {
  /* Black, white and gray, after the scribe's halo mark. */
  --ink: #141414;
  --muted: #5C5C5C;
  --faint: #8C8C8C;
  --line: #ECEBE7;
  --edge: #E2E0DB;
  --soft: #F4F3F0;
  --paper: #FAFAF8;
  --dark: #141414;          /* dark panels and headers */
  --dark-2: #2A2A2A;
  --on-dark: #FAFAF8;       /* text and marks on dark panels */
  --on-dark-quiet: #B8B8B8; /* secondary text on dark panels */
  --stamp: #141414;         /* passport stamp ring */
  --note: #F1EFEA;          /* soft callout cards */
  --accent: #141414;        /* links, sliders, focus */
  --tint-1: #E6E5E1;        /* lightest score fill */
  --tint-2: #C9C8C3;
  --ruby: #A33B2E;          /* errors and the one destructive button */
  --done: #141414;
  --serif: 'IM Fell English', Georgia, serif;
  --blackletter: 'UnifrakturMaguntia', 'IM Fell English', serif;
  --sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; }
a { color: var(--accent); text-decoration: none; font-weight: 600; }
button, input, textarea, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; font-weight: 400; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; position: relative; }

.splash { min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--dark); color: #fff; }
.wordmark { font-family: var(--blackletter); font-size: 28px; line-height: 1.1; }
.motto { font-family: 'IM Fell English SC', var(--serif); font-size: 15px; letter-spacing: 6px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding: calc(var(--top) + 8px) 12px 8px 18px; display: flex; align-items: center; gap: 8px; min-height: 56px; }
.topbar .title { flex: 1; font-size: 16px; font-weight: 700; }
.page { padding: 16px 16px calc(96px + var(--bottom)); }
.page.flush { padding-left: 0; padding-right: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.label { font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.serif { font-family: var(--serif); }
.center { text-align: center; }
.hidden { display: none !important; }

/* Tab bar */
.tabs { position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 520px; z-index: 10;
  background: #fff; border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 6px 0 calc(6px + var(--bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; min-height: 48px; justify-content: center; font-size: 10.5px; font-weight: 600; color: var(--muted); }
.tab.on { color: var(--ink); }
.tab .plus { display: flex; align-items: center; justify-content: center; width: 46px; height: 34px; border-radius: 12px; background: var(--ink); color: #fff; }
.icon { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 20px; height: 20px; }

/* Buttons and inputs */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 18px; border-radius: 14px; border: 0; background: var(--ink); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer; width: 100%; }
.btn.light { background: var(--soft); color: var(--ink); }
.btn.gold { background: var(--on-dark); color: var(--dark); }
.btn:disabled { opacity: .5; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; background: none; color: var(--ink); padding: 0; cursor: pointer; border-radius: 50%; }
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--edge); background: #fff; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.pill.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill.sm { min-height: 32px; padding: 0 11px; font-size: 12px; }
.linkbtn { border: 0; background: none; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; font-size: 13px; padding: 6px 0; cursor: pointer; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; font-weight: 700; }
.input, .ta, select.input { width: 100%; border: 1px solid var(--edge); border-radius: 12px; padding: 12px 14px; font-size: 16px; background: #fff; }
.ta { resize: vertical; line-height: 1.4; min-height: 64px; }
.input:focus, .ta:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; margin: 0; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: #F3F1EC; }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: none; font-weight: 600; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Cards */
.card { border: 1px solid var(--edge); border-radius: 16px; padding: 14px; }
.card.soft { background: var(--soft); border-color: transparent; }
.card.night { background: var(--dark); color: #fff; border-color: transparent; }
.card.cream { background: var(--note); border-color: transparent; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex: 0 0 auto; color: var(--ink); }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 999px; background: #F3F1EC; font-size: 12px; font-weight: 600; }
.chip b { color: var(--accent); font-weight: 800; }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 999px; font-weight: 800; font-size: 14px; white-space: nowrap; }
.badge small { font-size: 10px; letter-spacing: 1px; }
.tier-radiant { background: var(--dark); color: var(--on-dark); }
.tier-radiant small { color: #fff; }
.tier-luminous { background: #4A4A4A; color: #fff; }
.tier-warm { background: var(--tint-1); color: var(--ink); }
.tier-private { background: #F3F1EC; color: var(--ink); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty .serif { font-size: 26px; color: var(--ink); margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 30; max-width: 90vw; }
.error { color: var(--ruby); font-size: 13px; font-weight: 600; }

/* Feed */
.post { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 8px; }
.post-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.post-photo { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--dark); }
.photo-strip { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
.photo-strip img, .photo-strip .glass { flex: 0 0 100%; scroll-snap-align: center; }
.post-body { padding: 10px 16px 0; }
.caption { margin: 8px 0 6px; font-size: 14px; line-height: 1.45; }
.sealed { margin: 0 14px; padding: 18px; border-radius: 16px; background: var(--dark); color: #fff; }

/* Review form */
.score-head { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 66px; height: 52px; border-radius: 14px; flex: 0 0 auto; }
.score-head b { font-size: 21px; line-height: 1; }
.score-head small { font-size: 8.5px; font-weight: 800; letter-spacing: 1px; margin-top: 3px; }
.cat { padding: 10px 0; border-bottom: 1px solid #F0EDE7; }
.cat-name { font-size: 15px; font-weight: 700; }
.cat-val { width: 40px; text-align: right; font-size: 22px; font-weight: 800; }
.na { min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--edge); background: #fff; font-size: 11.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.na.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.thumbs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 0; padding: 0; background: var(--soft); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .star { position: absolute; left: 6px; top: 6px; padding: 3px 7px; border-radius: 999px; background: var(--dark); color: var(--on-dark); font-size: 10px; font-weight: 800; }
.thumb.add { border: 2px dashed #B9B3A8; background: #fff; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; font-weight: 600; }

/* Group grid */
.grid-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.grid { display: grid; gap: 3px; align-items: center; min-width: max-content; }
.cell { height: 32px; min-width: 36px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; border: 0; cursor: pointer; padding: 0 6px; position: relative; }
.cell.has-note::after { content: ''; position: absolute; right: 3px; top: 3px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }
.cell.avg { background: #fff; border: 1.5px solid var(--ink); cursor: default; }
.s10 { background: var(--dark); color: var(--on-dark); }
.s9 { background: #4A4A4A; color: #fff; }
.s8 { background: var(--tint-2); color: var(--ink); }
.s7 { background: var(--tint-1); color: var(--ink); }
.slow { background: #fff; color: var(--muted); box-shadow: inset 0 0 0 1.5px var(--edge); }
.snone { background: var(--soft); color: var(--faint); cursor: default; }

/* Passport */
.passport-head { background: var(--dark); color: #fff; padding: calc(var(--top) + 20px) 18px 18px; }
.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; }
.bar > div { height: 8px; border-radius: 4px; background: var(--on-dark); }
.stamps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 12px; }
.stamp { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--ink); }
.stamp .ring { width: 92px; height: 92px; border-radius: 50%; padding: 4px; border: 2.5px solid var(--stamp); }
.stamp .ring > * { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: flex; align-items: center; justify-content: center; background: var(--dark); color: var(--on-dark); font-family: var(--serif); font-size: 26px; }
.stamp .name { font-size: 12px; font-weight: 700; line-height: 1.2; }
.stamp .date { font-size: 11px; color: var(--muted); }

/* Sheet (note popup) */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + var(--bottom)); }

/* Stained glass placeholder when a post has no photo */
.glass { width: 100%; aspect-ratio: 1; background: var(--dark); display: block; }

/* Sign-in: the mark alone on black, the form at the foot. */
.threshold { min-height: 100dvh; display: flex; flex-direction: column; justify-content: space-between; padding-bottom: calc(28px + var(--bottom)); }
.threshold-mark { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.threshold h1.wordmark { font-weight: 400; }

/* Friends button on Home */
.friends-btn { position: relative; }
.friends-btn .dot { position: absolute; top: 9px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--ink); border: 2px solid #fff; }

/* Churches */
.search { display: flex; align-items: center; gap: 8px; background: #1F1F1F; border: 1px solid #333; border-radius: 12px; padding: 0 12px; color: var(--on-dark-quiet); }
.search input { flex: 1; min-width: 0; border: 0; background: none; color: var(--on-dark); font-size: 16px; padding: 12px 0; outline: none; }
.search input::placeholder { color: #8C8C8C; }
.filters { position: sticky; top: 0; z-index: 4; background: var(--paper); padding: 10px 0 8px; border-bottom: 1px solid var(--line); }
.lens-row, .chip-row { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
.lens-row::-webkit-scrollbar, .chip-row::-webkit-scrollbar { display: none; }
.lens-row button { flex: 0 0 auto; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--edge); background: #fff; font-weight: 700; font-size: 13px; cursor: pointer; }
.lens-row button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip-row { margin-top: 8px; }
.chip-row .chip { flex: 0 0 auto; border: 0; cursor: pointer; min-height: 30px; }
.chip.on { background: var(--ink); color: #fff; }
.crow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink); font-weight: 400; }
.crow .rank { width: 22px; flex: 0 0 auto; font-family: var(--serif); font-size: 22px; text-align: center; color: var(--muted); }
.medal { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--soft); color: var(--ink); font-family: var(--serif); font-size: 17px; }
.medal.historic { background: var(--dark); color: var(--on-dark); box-shadow: inset 0 0 0 3px var(--dark), inset 0 0 0 4.5px #8C8C8C; }
.medal.visited { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2.5px var(--stamp); }
.cname { display: block; font-weight: 700; font-size: 15px; line-height: 1.25; }
.csub { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.csub b { color: var(--ink); font-weight: 700; }
.cknown { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.35; font-style: italic; }
.cscore { flex: 0 0 auto; min-width: 44px; height: 32px; padding: 0 8px; border-radius: 10px; background: var(--dark); color: var(--on-dark); font-weight: 800; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; }
.church-hero { position: relative; }
.church-hero .glass { aspect-ratio: 16 / 10; }
.church-hero-text { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 18px 18px; color: #fff; background: linear-gradient(transparent, rgba(10,10,10,.92) 55%); }
.ebar { display: grid; grid-template-columns: 104px 1fr 34px; align-items: center; gap: 8px; padding: 5px 0; font-size: 13.5px; font-weight: 600; }
.ebar .track { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.ebar .track > span { display: block; height: 8px; border-radius: 4px; background: var(--ink); }
.ebar b { text-align: right; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.facts > div { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }

/* Passport edit mode */
button.stamp { border: 0; background: none; padding: 0; cursor: pointer; position: relative; font: inherit; }
.stamp.editing .ring { animation: settle 1.6s ease-in-out infinite; }
.stamp.editing .x { position: absolute; top: -2px; right: calc(50% - 50px); width: 28px; height: 28px; border-radius: 50%; background: var(--ruby); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 3px var(--paper); }
.stamp.editing .x .icon { width: 16px; height: 16px; stroke-width: 2.4; }
@keyframes settle { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }
@media (prefers-reduced-motion: reduce) { .stamp.editing .ring { animation: none; } }
.linkbtn.danger { color: var(--ruby); align-self: center; margin-top: 8px; }
.hero-back { position: absolute; left: 12px; top: calc(var(--top) + 12px); background: rgba(250,250,248,.92); color: var(--ink); z-index: 2; }
.church-hero .glass { aspect-ratio: 16 / 11; }
