/* Quantum Disciple web app — shared theme and components.
   Colors are the app's design tokens (QDDesignTokens/Tokens.swift). Ivory is the default (INBOX-347265, theme revision
   2026-11: everyone is moved to Ivory once, then their own pick is kept); Dark, Light and Warm stay available.
   Header and navigation tokens (every palette): --nav-top (the .app-top header), --nav-bg (the #tabbar), --nav-text,
   --nav-text-2, --nav-active (selected tab, wordmark), --nav-accent (links in the header), --nav-sep, --nav-raised. Dark,
   Light and Warm map them to the values the header and tab bar already had; Ivory maps them to navy #102A3D / ivory #FFF8ED /
   gold #E9B949. --gold-fill is a gold BACKGROUND under --on-gold text (Ivory: #E9B949 with dark text; elsewhere = --gold).
   --card-shadow: the soft card shadow (none outside Ivory). */

:root, [data-theme="dark"] {
  --bg: #050F1E; --surface: #0A192F; --raised: #112441; --text: #E6F1FF; --text-2: #A9BCD5;
  --accent: #00CCFF; --on-accent: #03101F; --gold: #C0A062; --live: #00FF99; --live-surface: #12382E;
  --sep: #1E3558; --verse-num: #8FA4C0; --selection: #0D3A57; --disabled: #7D8CA3; --warning: #FFB547; --danger: #FF7A7A;
  --hl-keyVerse: #3A3220; --hl-promise: #123B2E; --hl-command: #16305A; --hl-insight: #3D3312; --hl-question: #2E2448; --hl-prayer: #40202E;
  --gold-grad: linear-gradient(rgb(242, 204, 122), #C0A062, rgb(158, 120, 56));
  --on-gold: #050F1E; --gold-fill: #C0A062;
  --glow: 0 0 18px rgba(0, 204, 255, 0.18);
  --gold-glow: 0 0 16px rgba(192, 160, 98, 0.35);
  --card-shadow: none;
  --nav-top: color-mix(in srgb, #050F1E 94%, transparent); --nav-bg: #0A192F; --nav-text: #E6F1FF; --nav-text-2: #A9BCD5;
  --nav-active: #C0A062; --nav-accent: #00CCFF; --nav-sep: #1E3558; --nav-raised: #112441;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #F6F8FB; --surface: #FFFFFF; --raised: #E9EFF6; --text: #0B1B30; --text-2: #4A5A70;
  --accent: #006A8A; --on-accent: #FFFFFF; --gold: #7A5B1C; --live: #00704A; --live-surface: #DDF3E8;
  --sep: #D3DCE8; --verse-num: #56667C; --selection: #D3ECF6; --disabled: #6B778A; --warning: #8A5A00; --danger: #B3261E;
  --hl-keyVerse: #F4E4B5; --hl-promise: #D3F0E0; --hl-command: #DAE5F8; --hl-insight: #FFF0B3; --hl-question: #E7DEF6; --hl-prayer: #F8DCE5;
  --gold-grad: #7A5B1C; --on-gold: #FFFFFF; --gold-fill: #7A5B1C; --glow: none; --gold-glow: none; --card-shadow: none;
  --nav-top: color-mix(in srgb, #F6F8FB 94%, transparent); --nav-bg: #FFFFFF; --nav-text: #0B1B30; --nav-text-2: #4A5A70;
  --nav-active: #7A5B1C; --nav-accent: #006A8A; --nav-sep: #D3DCE8; --nav-raised: #E9EFF6;
  color-scheme: light;
}
[data-theme="warm"] {
  --bg: #F4ECD8; --surface: #FBF6EA; --raised: #EADFC6; --text: #2E2213; --text-2: #5C4A32;
  --accent: #00667A; --on-accent: #FFFFFF; --gold: #74561A; --live: #2B6637; --live-surface: #DCE9CF;
  --sep: #DCCFB2; --verse-num: #6A563C; --selection: #D8E8E2; --disabled: #72654F; --warning: #7F5200; --danger: #A1281F;
  --hl-keyVerse: #EBD6A0; --hl-promise: #D2E4C5; --hl-command: #D3DCEA; --hl-insight: #F1E09C; --hl-question: #DFD4E9; --hl-prayer: #EDD0D0;
  --gold-grad: #74561A; --on-gold: #FFFFFF; --gold-fill: #74561A; --glow: none; --gold-glow: none; --card-shadow: none;
  --nav-top: color-mix(in srgb, #F4ECD8 94%, transparent); --nav-bg: #FBF6EA; --nav-text: #2E2213; --nav-text-2: #5C4A32;
  --nav-active: #74561A; --nav-accent: #00667A; --nav-sep: #DCCFB2; --nav-raised: #EADFC6;
  color-scheme: light;
}
/* Ivory (Megan's p.6 tokens, INBOX-347265; every text pairing checked for WCAG AA in tests/home-ivory.test.mjs).
   live/warning/danger/selection/highlights reuse the Light theme's values (they pass on ivory). */
[data-theme="ivory"] {
  --bg: #FFF8ED; --surface: #FFFFFF; --raised: #F6EEDF; --text: #172B3A; --text-2: #52616B;
  --accent: #0B5C73; --on-accent: #FFFFFF; --gold: #88600B; --live: #00704A; --live-surface: #DDF3E8;
  --sep: #E6DCC8; --verse-num: #56667C; --selection: #D3ECF6; --disabled: #5E6A7C; --warning: #8A5A00; --danger: #B3261E;
  --hl-keyVerse: #F4E4B5; --hl-promise: #D3F0E0; --hl-command: #DAE5F8; --hl-insight: #FFF0B3; --hl-question: #E7DEF6; --hl-prayer: #F8DCE5;
  --gold-grad: #E9B949; --on-gold: #172B3A; --gold-fill: #E9B949;
  --glow: 0 1px 2px rgba(23, 43, 58, .06), 0 6px 18px rgba(23, 43, 58, .07); --gold-glow: none;
  --card-shadow: 0 1px 2px rgba(23, 43, 58, .06), 0 6px 18px rgba(23, 43, 58, .07);
  --nav-top: #102A3D; --nav-bg: #102A3D; --nav-text: #FFF8ED; --nav-text-2: #C9D3DA;
  --nav-active: #E9B949; --nav-accent: #FFF8ED; --nav-sep: #2A4356; --nav-raised: #1A3A52;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.55;
  overflow-x: hidden;
}
h1, h2, h3, h4, .serif { font-family: Georgia, 'Iowan Old Style', 'Times New Roman', serif; font-weight: 600; line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; top: 0; z-index: 1000; background: var(--surface); padding: 8px 12px; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Shell ---- */
.app-top {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--nav-top); border-bottom: 1px solid var(--nav-sep); color: var(--nav-text);
  backdrop-filter: blur(8px);
}
/* Inside the header and the tab bar every token comes from the nav set (same values as before in Dark, Light, Warm). */
.app-top, .tabbar { --text: var(--nav-text); --text-2: var(--nav-text-2); --gold: var(--nav-active); --accent: var(--nav-accent);
  --raised: var(--nav-raised); --sep: var(--nav-sep); }
.wordmark { display: inline-flex; flex-direction: column; align-items: center; text-decoration: none; color: var(--gold); font-family: Georgia, serif; line-height: 1.05; }
.wm-the { display: inline-flex; align-items: center; gap: 6px; font-size: .62rem; letter-spacing: .2em; }
.wm-the i { display: inline-block; width: 18px; height: 1px; background: var(--gold); }
.wm-name { font-size: 1.05rem; font-weight: 700; letter-spacing: .04em; }
.site-link { margin-left: 8px; font-size: .78rem; color: var(--text-2); text-decoration: none; border: 1px solid var(--sep); padding: 4px 10px; border-radius: 999px; }
.site-link:hover { color: var(--text); border-color: var(--gold); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.top-btn { background: var(--raised); border: 1px solid var(--sep); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: .85rem; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.top-btn:hover { border-color: var(--gold); }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--raised); border: 1px solid var(--sep); color: var(--text); cursor: pointer; text-decoration: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tabbar { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--nav-bg); border-bottom: 1px solid var(--nav-sep); position: sticky; top: 61px; z-index: 40; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; min-height: 49px; color: var(--text-2); text-decoration: none; font-size: .72rem; font-weight: 600; border-bottom: 2px solid transparent; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab:hover { color: var(--text); }
@media (max-width: 720px) {
  .site-link { display: none; }
  .tabbar { position: fixed; bottom: 0; left: 0; right: 0; top: auto; border-bottom: 0; border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom); }
  .tab { border-bottom: 0; border-top: 2px solid transparent; font-size: .66rem; padding: 6px 2px; }
  .tab.active { border-top-color: var(--gold); }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.keyboard-open .tabbar { display: none; }
}

.outlet { max-width: 860px; margin: 0 auto; padding: 20px 16px 40px; outline: none; min-height: 60vh; }
.outlet.wide { max-width: 1100px; }
.app-foot { max-width: 860px; margin: 0 auto; padding: 16px 16px 32px; border-top: 1px solid var(--sep); color: var(--text-2); }
.foot-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; }
.foot-links a { color: var(--text-2); font-size: .85rem; }

/* ---- Typography helpers ---- */
.page-head { margin-bottom: 18px; }
.page-head .sub { color: var(--text-2); }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.eyebrow, .sec-label { color: var(--gold); font-family: 'Montserrat', sans-serif; font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; margin: 0 0 6px; }
.sec { margin: 26px 0; }
.sec-label { font-size: .75rem; margin-bottom: 10px; }
.fine { font-size: .78rem; color: var(--text-2); }
.muted { color: var(--text-2); }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* ---- Cards ---- */
.card { display: block; background: var(--surface); border: 1px solid var(--sep); border-radius: 14px; padding: 16px; margin: 0 0 12px; color: var(--text); text-align: left; width: 100%; box-shadow: var(--card-shadow); }
.card.glow { border-color: color-mix(in srgb, var(--accent) 45%, transparent); box-shadow: var(--glow); }
.card.gold { border-color: var(--gold); box-shadow: var(--gold-glow); }
.card-link { text-decoration: none; cursor: pointer; font: inherit; transition: border-color .15s, transform .15s; }
.card-link:hover { border-color: var(--accent); }
.card h3 { margin-bottom: .3em; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.grid > .card { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }

/* ---- Buttons & controls ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 700; font-size: .92rem; text-decoration: none; text-align: center; }
.btn-primary { background: var(--gold-grad); color: var(--on-gold); border-radius: 999px; box-shadow: var(--gold-glow); }
.btn-secondary { background: var(--raised); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--sep); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.chip { border: 1px solid var(--sep); background: var(--raised); color: var(--text-2); border-radius: 999px; padding: 5px 12px; font-size: .84rem; cursor: pointer; }
.chip.active { background: var(--gold-fill); color: var(--on-gold); border-color: var(--gold-fill); font-weight: 700; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: .7rem; font-weight: 700; letter-spacing: .04em; vertical-align: middle; }
.tone-gold { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--gold); }
.tone-accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.tone-live { background: var(--live-surface); color: var(--live); }
.tone-warning { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.tone-muted { background: var(--raised); color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; background: var(--raised); border: 1px solid var(--sep); border-radius: 10px; padding: 10px 12px; color: var(--text); min-height: 44px;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--sep); }
.toggle input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--gold); }
/* Select All / Clear All above a list of ticks (core/select-all.js): count on the left, the link-style button on the right
   with a 44 px tap target; wraps on narrow screens. */
.select-all-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; min-width: 0; margin: 0 0 6px; }
.select-all-bar .select-all-btn { margin-left: auto; min-height: 44px; padding: 0 2px; }
.select-all-bar .select-all-btn:disabled { opacity: .5; cursor: not-allowed; }

.progress { height: 8px; background: var(--raised); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.stat { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; flex: 1; min-width: 90px; }
.stat strong { font-size: 1.6rem; font-family: Georgia, serif; color: var(--gold); line-height: 1.1; }
.stat span { font-size: .75rem; color: var(--text-2); }

.empty { text-align: center; padding: 28px 16px; color: var(--text-2); border: 1px dashed var(--sep); border-radius: 14px; margin: 12px 0; }
.empty h3 { color: var(--text); }
.empty .row { justify-content: center; }
.error-panel { border: 1px solid var(--warning); background: color-mix(in srgb, var(--warning) 8%, transparent); border-radius: 12px; padding: 14px; margin: 12px 0; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-2); padding: 18px 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--sep); border-top-color: var(--gold); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } * { transition: none !important; } }

.art { display: grid; place-items: center; border-radius: 12px; flex: none; font-size: 1.6rem; overflow: hidden; }

/* ---- Scripture ---- */
.scripture { font-family: Georgia, 'Iowan Old Style', serif; font-size: 1.08rem; line-height: 1.75; }
.scripture sup, .verse-num { color: var(--verse-num); font-size: .7em; font-family: 'Montserrat', sans-serif; margin-right: 3px; }
.esv-tag { display: inline-block; font-size: .65rem; font-weight: 800; letter-spacing: .08em; color: var(--text-2); border: 1px solid var(--sep); border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: middle; }
.esv-attr { font-size: .74rem; color: var(--text-2); margin-top: 8px; }

/* ---- Sheets & toast ---- */
.sheet-wrap { position: fixed; inset: 0; background: rgba(2, 8, 18, .62); z-index: 200; display: grid; place-items: center; padding: 16px; }
.sheet { background: var(--surface); border: 1px solid var(--sep); border-radius: 16px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; outline: none; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.sheet.wide { width: min(900px, 100%); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--sep); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-body { padding: 16px; }
body.sheet-open { overflow: hidden; }
@media (max-width: 720px) { .sheet-wrap { place-items: end center; padding: 0; } .sheet { border-radius: 16px 16px 0 0; max-height: 92vh; } }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--raised); color: var(--text); border: 1px solid var(--gold); border-radius: 999px; padding: 10px 18px; opacity: 0; pointer-events: none; transition: .2s; z-index: 300; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---- Scored quiz (core/quiz.js) ---- */
.quiz-q { border: 1px solid var(--sep); border-radius: 12px; padding: 12px 14px; margin: 0 0 12px; }
.quiz-q legend { font-weight: 600; padding: 0 4px; }
.quiz-opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 8px; cursor: pointer; }
.quiz-opt:hover { background: var(--raised); }
.quiz-opt input { margin-top: 5px; accent-color: var(--gold); }
.quiz-opt .letter { font-weight: 800; color: var(--gold); min-width: 1.2em; }
.quiz-review .ok { color: var(--live); font-weight: 700; }
.quiz-review .bad { color: var(--danger); font-weight: 700; }

/* ---- Giver message (core/giver.js) and the AI gate cards (core/ai-gate.js): free-AI CONTRACT §3.3–§3.5, 2026-11-18.
   Inline in the page flow (never a modal, never over the input). The one-line links are real 44 x 44 px controls; their
   negative vertical margins keep a wrapped line compact. ---- */
.giver { margin: 0 0 14px; min-width: 0; }
.giver-card { border-color: var(--gold); margin: 0; }
.giver-title { font-size: 1.2rem; overflow-wrap: anywhere; }
.giver-body p { margin: 0 0 .7em; }
.giver-actions { margin-top: 2px; }
.giver-line { display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 2px; margin: 0; padding: 8px 0; font-size: .86rem;
  line-height: 1.35; color: var(--text-2); }
.giver-lead { font-weight: 600; }
.giver-links { display: inline-flex; align-items: center; column-gap: 6px; white-space: nowrap; }
.giver-link { display: inline-flex; align-items: center; justify-content: flex-start; min-height: 44px; min-width: 44px; margin: -8px 0; padding: 0 2px;
  background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.giver-thanks { margin: 4px 0 0; font-size: .86rem; font-weight: 700; color: var(--gold); }
.giver-thanks:empty { margin: 0; }
.giver-title:focus, .giver-line:focus { outline: none; }
.giver-title:focus-visible, .giver-line:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.empty .giver-line { justify-content: center; }
.ai-gate { min-width: 0; }
.ai-gate > .card { margin-bottom: 8px; }
.ai-gate > .giver { margin: 6px 0 0; }
.ai-age-card .row, .ai-account-card .row { margin-top: 4px; }
.ai-age-card h2, .ai-age-card h3, .ai-account-card h2, .ai-account-card h3 { overflow-wrap: anywhere; }
.ai-age-error:empty { min-height: 0; }
.hm-giver { margin: -12px 0 16px; }
.hm-giver .giver, .gm-giver .giver, .ch-giver .giver { margin: 0; }
.gm-giver { margin: 14px 0 0; }
.ch-giver { margin: 0 0 12px; }
.ch-age .ai-age-card { margin: 0 0 8px; }
