:root {
  --bg: #f5f4fb;
  --card: #ffffff;
  --ink: #23223a;
  --body: #2f2e47;
  --muted: #6b6a85;
  --line: #e6e4f0;
  --brand: #4f4d8a;
  --brand-deep: #3b3a6b;
  --accent: #c98a3a;
  --good: #2e9e6b;
  --danger: #c0504d;
  --shadow: 0 1px 3px rgba(40, 38, 80, .08), 0 6px 18px rgba(40, 38, 80, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App bar */
#appbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: var(--shadow);
}
#appbar h1 { font-size: 1.25rem; font-weight: 650; margin: 0; letter-spacing: .2px; }
#brand-logo { height: 36px; width: auto; display: block; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
#appbar-extra { font-size: .85rem; opacity: .92; text-align: right; }
#appbar-extra .appbar-btn {
  background: rgba(255,255,255,.16); color: #fff;
  border: 1px solid rgba(255,255,255,.4); font-weight: 650; opacity: 1;
}
.card.answered { border-left: 3px solid var(--good); }
.praise {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(46,158,107,.1); color: var(--body); font-size: .92rem;
}
.praise-label { font-weight: 700; color: var(--good); margin-right: 6px; }

/* Main scroll area */
#view {
  padding: 16px 14px calc(96px + var(--safe-bot));
  max-width: 680px; margin: 0 auto;
}
.loading { text-align: center; color: var(--muted); padding: 60px 0; }

/* Bottom tab bar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bot);
}
.tab {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 8px 0 6px; font-size: .68rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-weight: 600;
}
.tab .ico { font-size: 1.32rem; line-height: 1; filter: grayscale(.4); opacity: .7; }
.tab img.ico { height: 1.5rem; width: auto; object-fit: contain; }
.tab.active { color: var(--brand-deep); }
.tab.active .ico { filter: none; opacity: 1; transform: translateY(-1px); }

/* Cards */
.card {
  background: var(--card); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--line);
}
.card.pinned { border-color: #f0d9b5; box-shadow: 0 0 0 2px #f6e7cf inset, var(--shadow); }

.section-label {
  font-size: .72rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 22px 4px 10px;
}
.section-label:first-child { margin-top: 4px; }

.cat-chip {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--brand); background: #ecebf7;
  padding: 3px 9px; border-radius: 999px; margin-bottom: 8px;
}
.cat-chip.scripture { color: var(--accent); background: #f8efe1; }

/* Scripture card */
.mem-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.mem-all-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.mem-move { display: flex; gap: 6px; flex: 0 0 auto; }
.mem-move .btn { padding: 4px 9px; }
.cat-manage { gap: 6px; }
.cat-manage .btn { padding: 6px 8px; }
.count-bubble {
  flex: 0 0 auto; min-width: 24px; text-align: center;
  background: var(--line); color: var(--muted); border-radius: 999px;
  padding: 3px 8px; font-size: .78rem; font-weight: 700;
}
.verse-ref { font-weight: 700; font-size: 1.02rem; margin: 2px 0 6px; color: var(--brand-deep); }
.verse-text { font-size: 1.06rem; white-space: pre-wrap; color: var(--body); }

/* Request card */
.req-who { font-weight: 700; font-size: 1.06rem; margin: 0 0 2px; }
.req-text { color: var(--body); }
.req-meta { font-size: .78rem; color: var(--muted); margin-top: 8px; }
.req-updates { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.req-update { font-size: .86rem; color: var(--body); padding: 3px 0; }
.req-update .when { color: var(--muted); font-size: .74rem; }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Buttons */
button.btn {
  appearance: none; cursor: pointer; font-weight: 650; font-size: .86rem;
  border-radius: 10px; padding: 9px 14px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); transition: transform .05s ease;
}
button.btn:active { transform: scale(.97); }
button.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
button.btn.ghost { background: transparent; }
button.btn.small { padding: 6px 10px; font-size: .8rem; }
button.btn.danger { color: var(--danger); border-color: #eccfce; }
button.btn.icon { padding: 6px 9px; }
button.btn:disabled { opacity: .5; cursor: default; }
button.linklike { background: none; border: 0; color: var(--brand); font-weight: 650; cursor: pointer; padding: 4px; font-size: .86rem; }

/* Pray-today bar */
.pray-done {
  position: sticky; bottom: calc(72px + var(--safe-bot)); margin-top: 18px; z-index: 10;
}
.pray-done .btn { width: 100%; padding: 16px; font-size: 1.05rem; border-radius: 14px;
  box-shadow: 0 8px 22px rgba(46, 158, 107, .35); }
.pray-banner {
  text-align: center; color: var(--good); font-weight: 700; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
}

/* Forms */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
label.check { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; font-weight: 650; color: var(--body); cursor: pointer; }
label.check input { width: auto; flex: 0 0 auto; margin: 0; }
input, select, textarea {
  width: 100%; font: inherit; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #cdcbef; border-color: var(--brand); }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; }
.row .shrink { flex: 0 0 auto; }
.hint { font-size: .78rem; color: var(--muted); margin-top: -8px; margin-bottom: 12px; }
.warn { color: var(--danger); }

/* List rows (manage views) */
.list-row {
  display: flex; align-items: center; gap: 10px; padding: 11px 4px;
  border-bottom: 1px solid var(--line);
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow .t1 { font-weight: 650; }
.list-row .grow .t2 { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Collapsible category sections (Scripture tab) */
.cat-section { border-bottom: 1px solid var(--line); }
.cat-section > summary {
  cursor: pointer; list-style: none; padding: 13px 4px;
  font-weight: 700; color: var(--accent);
  display: flex; align-items: center; gap: 9px;
}
.cat-section > summary::-webkit-details-marker { display: none; }
.cat-section > summary::before {
  content: '▸'; color: var(--muted); font-size: .9em;
  transition: transform .15s ease;
}
.cat-section[open] > summary::before { transform: rotate(90deg); }
.cat-section .list-row:last-child { border-bottom: 0; }
.cat-section.req > summary { color: var(--brand); }

/* Calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal-dow { text-align: center; font-size: .68rem; font-weight: 700; color: var(--muted); }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; font-size: .9rem; color: var(--ink); background: #eceaf5;
}
.cal-day.empty { background: transparent; }
.cal-day.prayed { background: var(--good); color: #fff; font-weight: 700; }
.cal-day.today { box-shadow: 0 0 0 2px var(--brand); }
.streaks { display: flex; gap: 12px; margin: 4px 0 18px; }
.streak-box { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.streak-box .n { font-size: 1.8rem; font-weight: 800; color: var(--brand-deep); }
.streak-box .l { font-size: .74rem; color: var(--muted); font-weight: 600; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(28,26,55,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + var(--safe-bot)); box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

/* Auth screen */
body.signed-out #appbar, body.signed-out #view, body.signed-out #tabbar { display: none !important; }
body.onboarding #tabbar { display: none !important; }
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 48px) 20px calc(var(--safe-bot) + 40px); }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px 20px; box-shadow: var(--shadow); }
.auth-brand { font-size: 1.5rem; font-weight: 800; color: var(--brand-deep); text-align: center; }
.auth-logo { display: block; width: 190px; max-width: 72%; margin: 2px auto 14px; border-radius: 16px; box-shadow: var(--shadow); }
.auth-sub { color: var(--muted); text-align: center; margin: 6px 0 18px; font-size: .92rem; }
.auth-msg { background: rgba(127,125,201,.16); color: var(--brand); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .88rem; line-height: 1.45; }
.auth-msg.error { background: rgba(192,80,77,.14); color: var(--danger); font-weight: 700; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--brand); font-weight: 650; font-size: .82rem; cursor: pointer; padding: 6px 8px; }
.auth-switch { text-align: center; margin-top: 12px; color: var(--muted); font-size: .9rem; }
.auth-privacy { margin-top: 18px; color: var(--muted); font-size: .74rem; line-height: 1.5; text-align: center; }
#au-forgot { display: block; margin: 8px auto 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + var(--safe-bot)); z-index: 60;
  background: var(--brand-deep); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-weight: 650; font-size: .9rem; box-shadow: var(--shadow); max-width: 90%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151f; --card: #201f2c; --ink: #ecebf5; --body: #d7d5ea; --muted: #9a98b5;
    --line: #2e2c3e; --brand: #8785c9; --brand-deep: #6b69b0;
  }
  .verse-ref, .streak-box .n { color: #b3b1e6; }
  .tab.active { color: #b3b1e6; }
  /* dark nav icons (#1a1a1a) would vanish on the dark tab bar — invert to light */
  .tab img.ico { filter: invert(1) grayscale(.2); }
  .tab.active img.ico { filter: invert(1); }
  .cat-chip { background: #2c2a44; }
  .cat-chip.scripture { background: #36302147; color: #e0b87e; }
  input, select, textarea, button.btn { background: #2a2838; color: var(--ink); }
  button.btn.primary { background: var(--brand-deep); }
  .cal-day { background: #2a2838; }
  #tabbar { background: rgba(32, 31, 44, .96); }
}
