/* iPRAY — cosmic theme: a starfield background with frosted-glass surfaces.
   One dark theme (the background is dark in every mode). Contrast is checked
   against the darkest *and* brightest parts of the image (see Phase 8 audit). */
:root {
  --bg: #0d0a1f;                         /* behind the image while it loads */
  --surface: rgb(20 15 44 / .82);        /* frosted cards */
  --surface-solid: #17112f;
  --surface-2: rgb(255 255 255 / .08);
  --text: #f3f0fa;
  --muted: #c4bdd8;
  --line: rgb(255 255 255 / .16);
  --accent: #cbb0ff;                     /* lavender: links, highlights, focus */
  --accent-soft: rgb(140 82 255 / .24);
  --btn: #6413a7;                        /* violet from the landing design */
  --btn-hover: #7420bf;
  --btn-ink: #ffffff;
  --title: #d4dadd;                      /* silver wordmark */
  --night: #2b2540;
  --danger: #ff9b94;                     /* danger text on dark */
  --danger-bg: #a8231b;
  --ok: #8be0b0;
  --ok-bg: #1f6b43;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 10px 30px rgb(0 0 0 / .35);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Background art: the original tall starfield on phones/portrait screens, and an
   AI-outpainted widescreen extension of the same scene on landscape screens. */
:root { --bg-image: url('../assets/bg-cosmos.webp'); }
@media (min-aspect-ratio: 4/5) and (min-width: 600px) { :root { --bg-image: url('../assets/bg-cosmos-wide-1600.webp'); } }
@media (min-aspect-ratio: 4/5) and (min-width: 1601px),
       (min-aspect-ratio: 4/5) and (min-width: 900px) and (min-resolution: 2dppx) { :root { --bg-image: url('../assets/bg-cosmos-wide.webp'); } }

body { margin: 0; color: var(--text); font: 16px/1.6 var(--sans); padding-bottom: 72px; min-height: 100vh; background: var(--bg); }
/* Fixed full-viewport layer (works on iOS, where background-attachment: fixed doesn't),
   with a gentle scrim so body text stays readable over the brightest stars. */
body::before { content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, rgb(8 5 22 / .35), rgb(8 5 22 / .6)), var(--bg-image) center / cover no-repeat; }
@media (min-width: 860px) { body { padding-bottom: 0; } }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 1.2em 0 .5em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: 1.35rem; }
a { color: var(--accent); }
img { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
#main:focus { outline: none; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 99; }
.skip:focus { left: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 560px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.block { display: block; }
.lede { font-size: 1.125rem; color: var(--muted); max-width: 60ch; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 1rem 0; }
.stack { display: grid; gap: 14px; }
.loading { padding: 4rem 16px; text-align: center; color: var(--muted); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 16px; background: rgb(10 7 28 / .55);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text);
  font-family: var(--serif); font-size: 1.3rem; }
.brand b { color: var(--accent); font-weight: 600; }
.nav { display: none; align-items: center; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--text); font-weight: 500; font-size: .95rem; }
.nav a[aria-current="page"] { background: var(--accent-soft); }
.nav a:hover { background: var(--surface-2); }
.nav .btn { color: var(--text); }
@media (min-width: 860px) { .nav { display: flex; } }
@media (max-width: 859px) {
  .topbar .nav { display: flex; }
  .topbar .nav > a:not(.nav-account):not(.btn) { display: none; }
  .nav-account .lbl { display: none; }
}

/* Mobile tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar .tab { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; padding: 4px 0; }
.tabbar .tab .ico { font-size: 1.25rem; }
.tabbar .tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
@media (min-width: 860px) { .tabbar { display: none; } }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 600 .95rem var(--sans); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
.btn-primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: .875rem; }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 600; font-size: .9rem; }
.hint { color: var(--muted); font-size: .8rem; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin: 0 0 16px; }
.card h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid .card { margin: 0; }
@media (min-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.action, .tradition { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text); transition: transform .15s, border-color .15s; }
.action:hover, .tradition:hover { transform: translateY(-2px); border-color: var(--accent); }
.action-ico, .tradition-ico { font-size: 1.8rem; }
.notice { text-align: center; }

.category summary { cursor: pointer; list-style: none; }
.category summary::-webkit-details-marker { display: none; }
.category[open] summary { margin-bottom: 8px; }
.ideas { margin: 0; padding-left: 1.1rem; }
.ideas li { margin: 4px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 1rem 0; }
.chip { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); text-decoration: none; font-size: .9rem; }
a.chip:hover { border-color: var(--accent); }
.chip-static { background: var(--surface-2); }

/* Hero */
.hero { background: radial-gradient(1200px 400px at 50% -100px, var(--accent-soft), transparent 70%); padding: 2.5rem 0 1rem; }
.hero h1 { margin-top: .2em; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 600; color: var(--accent); margin: 0; }

.avatar { border-radius: 50%; object-fit: cover; flex: none; }
.avatar-fallback { display: inline-grid; place-items: center; background: var(--btn); color: #f7f3ec; font-weight: 600; font-size: .8rem; }

.prose p { max-width: 68ch; }
.auth h1 { margin-top: 1.5rem; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 420px); }
@media (min-width: 860px) { .toasts { bottom: 24px; } }
.toast { background: var(--surface-solid); border: 1px solid var(--line); color: #f7f3ec; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast-error { background: var(--danger-bg); }
.toast-success { background: var(--ok-bg); }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ── Phase 2: prayers ── */
[hidden] { display: none !important; }
.narrow-wide { max-width: 760px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.page-head .row { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: .5rem 0 1rem; }
.tab-link { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-link[aria-current="page"] { color: var(--text); border-color: var(--accent); }
.filters { display: grid; gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr 1fr 1fr; } }

.prayer-card { position: relative; display: flex; flex-direction: column; gap: 6px; }
.prayer-card h3 { margin: 0; font-size: 1.15rem; }
.prayer-card .stretched { color: var(--text); text-decoration: none; }
.prayer-card .stretched::after { content: ''; position: absolute; inset: 0; border-radius: var(--radius); }
.prayer-card:hover { border-color: var(--accent); }
.prayer-excerpt { margin: 0; white-space: pre-line; color: var(--muted); font-family: var(--serif); }
.meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.tag { font-size: .78rem; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.tag-ai { background: var(--accent-soft); }
.badge { font-size: .78rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); }
.badge-public { background: rgb(139 224 176 / .16); }
.badge-hidden { background: rgb(255 155 148 / .18); }
.warn { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

.prayer-page h1 { margin-bottom: .3em; }
.prayer-text { white-space: pre-wrap; font-family: var(--serif); font-size: 1.2rem; line-height: 1.75;
  margin: 1.25rem 0 1.5rem; padding: 1.5rem; background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.prayer-input { font-family: var(--serif); font-size: 1.1rem; line-height: 1.7; }
.counter { text-align: right; }
.author { display: flex; gap: 12px; align-items: center; margin-top: 1.5rem; }

.visibility { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.visibility legend { margin-bottom: 6px; }
@media (min-width: 640px) { .visibility { grid-template-columns: repeat(3, 1fr); } .visibility legend { grid-column: 1 / -1; } }
.vis-option { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; }
.vis-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.vis-option input { accent-color: var(--accent); margin-top: 4px; }
.vis-row { display: flex; align-items: center; gap: 12px; }
.vis-row select { width: auto; flex: 1; max-width: 240px; }
.share-box { display: flex; gap: 8px; margin-top: 12px; }
.share-box:empty { display: none; }
.share-box input { flex: 1; font-size: .85rem; }
.row-center { justify-content: center; }
.prayer-excerpt { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Phase 3: generate ── */
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); min-height: 44px; }
.segmented label { flex: 1; display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { flex: 1; display: grid; place-items: center; cursor: pointer; font-weight: 500; font-size: .92rem; }
.segmented label + label span { border-left: 1px solid var(--line); }
.segmented input:checked + span { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: -3px; }
.ideas-chips { margin: -4px 0 0; }
.ideas-chips .chip { cursor: pointer; font: inherit; font-size: .85rem; text-align: left; }
.generating { text-align: center; padding: 2rem; }
.pulse { font-size: 2.4rem; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.15); opacity: .7; } }
.result { display: grid; gap: 12px; margin-top: 1.5rem; border-color: var(--accent); }
.result .eyebrow { margin: 0; }
.result-title { font-family: var(--serif); font-size: 1.3rem !important; font-weight: 600; }
.support { border-color: var(--accent); margin-top: 1.5rem; }
.support li { margin: 6px 0; }

/* ── Phase 4: media ── */
.media { margin: 1rem 0; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.media img, .media video { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #000; }
.media img { background: transparent; }
.media-preview .media { max-width: 420px; margin: 4px 0; }
.media-preview .media img, .media-preview .media video { max-height: 280px; }
.btn.disabled { opacity: .6; pointer-events: none; }
.thumb { position: relative; margin: -18px -18px 6px; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; aspect-ratio: 16 / 9; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 2rem; text-shadow: 0 2px 8px rgb(0 0 0 / .6); }

/* ── Phase 5: AI images ── */
.media figcaption { padding: 6px 12px; background: var(--surface); }
.gen-panel { padding: 12px; border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); }
.gen-panel .row { margin: 0 0 6px; }
.gen-panel select { width: auto; min-width: 140px; }

/* ── Phase 7: community ── */
.feed { display: grid; gap: 16px; }
.filters-2 { grid-template-columns: 1fr 1fr; }
.byline { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.card-actions { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.reactions { display: flex; gap: 8px; flex-wrap: wrap; }
.reaction { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 500 .88rem var(--sans); cursor: pointer; }
.reaction:hover { border-color: var(--accent); }
.reaction.on { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.reaction .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.more { position: relative; }
.more summary { list-style: none; cursor: pointer; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; font-size: 1.2rem; }
.more summary::-webkit-details-marker { display: none; }
.more summary:hover { background: var(--surface-2); }
.more-menu { position: absolute; right: 0; bottom: 44px; z-index: 5; min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; }
.more-menu button { text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; font: inherit; color: var(--text); cursor: pointer; }
.more-menu button:hover { background: var(--surface-2); }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); width: min(92vw, 460px); padding: 20px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(5 3 15 / .7); }
.dialog { background: var(--surface-solid); }
.dialog h2 { margin-top: 0; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list .row { margin: 6px 0; }
.mod-item h3 { margin: 6px 0; }
.small-text { font-size: 1rem; padding: 1rem; margin: .75rem 0; }
.report-list { margin: 0 0 8px; padding-left: 1.1rem; }
/* Muted text sitting on the accent-soft tint needs a brighter grey to keep 4.5:1. */
:root { --muted-on-tint: #e6e0f2; }
.vis-option:has(input:checked) .muted, .gen-panel .hint { color: var(--muted-on-tint); }
.site-footer { text-align: center; padding: 2.5rem 16px 1.5rem; color: var(--muted); font-size: .85rem; }
.site-footer a { color: var(--muted); }

/* ── Cosmic theme: glass surfaces & landing page ── */
.card, .tabbar, .more-menu, .vis-option, .segmented, .chip, .reaction, .btn:not(.btn-primary) { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.tabbar { background: rgb(14 10 34 / .86); }
.btn:not(.btn-primary), .chip, .reaction, .segmented, .vis-option,
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { background: rgb(20 15 44 / .72); }
select option, select optgroup { background: var(--surface-solid); color: var(--text); }
.brand span { color: var(--title); font-family: var(--sans); font-weight: 800; letter-spacing: -.02em; }
.brand b { color: var(--title); }
h1, .lede, .page-head + .muted, section > .muted { text-shadow: 0 1px 12px rgb(0 0 0 / .55); }
.hero { background: none; }

/* Landing (home) — matches the supplied design */
.landing { min-height: calc(100svh - 64px); display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: clamp(3rem, 14vh, 9rem) 16px 3rem; }
.landing-title { font-family: var(--sans); font-weight: 800; font-size: clamp(4.5rem, 19vw, 9rem); line-height: .9;
  letter-spacing: -.035em; color: var(--title); margin: 0; text-shadow: 0 2px 18px rgb(0 0 0 / .35); }
.landing-sub { font-weight: 700; font-size: clamp(1.25rem, 4.6vw, 2rem); color: var(--title); margin: .35rem 0 0; text-shadow: 0 2px 10px rgb(0 0 0 / .45); }
.landing-tag { font-weight: 800; font-size: clamp(1.45rem, 5.2vw, 2.6rem); color: var(--title); margin: clamp(2rem, 9vh, 5.5rem) 0 0;
  text-shadow: 3px 4px 6px rgb(0 0 0 / .75); }
.landing-greeting { color: var(--text); margin: 1rem 0 0; text-shadow: 0 1px 10px rgb(0 0 0 / .7); }
.landing-cta { margin-top: clamp(3rem, 16vh, 10rem); display: inline-block; padding: 18px 40px; border-radius: 10px;
  background: var(--btn); color: #fff; font-weight: 700; font-size: clamp(1.35rem, 4.4vw, 1.9rem); text-decoration: none;
  box-shadow: 0 8px 30px rgb(100 19 167 / .45); transition: transform .15s, background .15s; }
.landing-cta:hover { background: var(--btn-hover); transform: translateY(-2px); }
.landing-secondary { margin-top: 1.25rem; color: var(--text); text-shadow: 0 1px 8px rgb(0 0 0 / .8); }
.landing-secondary a { color: var(--text); font-weight: 600; }
.scroll-cue { margin-top: auto; padding-top: 2rem; color: var(--muted); font-size: .85rem; text-decoration: none; text-shadow: 0 1px 8px rgb(0 0 0 / .8); }
/* The landing page shows the artwork at full brightness, as in the design; its text carries its own shadows. */
body[data-route="home"]::before { background: linear-gradient(180deg, rgb(8 5 22 / .05) 0%, rgb(8 5 22 / .15) 60%, rgb(8 5 22 / .55) 100%), var(--bg-image) center / cover no-repeat; }
body[data-route="home"] .topbar { background: rgb(10 7 28 / .25); border-bottom-color: transparent; }
/* Text that sits directly on the starfield gets a soft dark halo so it stays legible
   even over the brightest stars; inputs and buttons have their own solid backgrounds. */
body { text-shadow: 0 1px 3px rgb(0 0 0 / .7); }
input, select, textarea, .btn, .reaction, .chip, .toast, .segmented span { text-shadow: none; }
