/* Selah. Every colour is a token so the palette swaps in one place.
   Warm paper, deep ink, a slate-blue accent, gold kept for scripture only. */
:root {
  color-scheme: light;
  --bg: #f6f4f0; --card: #fffefb; --ink: #20242c; --muted: #6a6e78; --line: #e6e1d8;
  --brand: #46618a; --brand-2: #37506f; --brand-ink: #ffffff; --brand-soft: #e7edf6;
  --gold: #8a6a35; --gold-soft: #f6efe1; --gold-line: #e2d3b4;
  --good: #33735f; --good-soft: #e2efea; --warn: #8a6516; --warn-soft: #f8f0dd;
  --bad: #a8412f; --bad-soft: #f8e6e2;
  --ring-track: #e9e4db; --top: #20242c; --top-ink: #f7f5f1;
  --shadow: 0 6px 20px rgba(32, 28, 20, .05);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14171c; --card: #1d2128; --ink: #eceef2; --muted: #9aa0ab; --line: #2e333c;
    --brand: #8fb0dd; --brand-2: #a9c4e9; --brand-ink: #0f1520; --brand-soft: #232d3c;
    --gold: #d6b478; --gold-soft: #2a2418; --gold-line: #3c3322;
    --good: #5fbc9c; --good-soft: #172b26; --warn: #d9ab5c; --warn-soft: #2d2617;
    --bad: #e08b79; --bad-soft: #33201c;
    --ring-track: #2a2f37; --top: #0e1116; --top-ink: #eceef2; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14171c; --card: #1d2128; --ink: #eceef2; --muted: #9aa0ab; --line: #2e333c;
  --brand: #8fb0dd; --brand-2: #a9c4e9; --brand-ink: #0f1520; --brand-soft: #232d3c;
  --gold: #d6b478; --gold-soft: #2a2418; --gold-line: #3c3322;
  --good: #5fbc9c; --good-soft: #172b26; --warn: #d9ab5c; --warn-soft: #2d2617;
  --bad: #e08b79; --bad-soft: #33201c;
  --ring-track: #2a2f37; --top: #0e1116; --top-ink: #eceef2; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
       font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.55rem; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.015em; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
h3 { font-size: .98rem; margin: 0 0 4px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lede { color: var(--muted); margin: 0 0 18px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.tight { gap: 6px; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* top bar + tabs */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--top); color: var(--top-ink);
          padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
.topbar-inner { max-width: 820px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--top-ink); text-decoration: none;
         font-weight: 700; font-size: 1.05rem; white-space: nowrap; font-family: var(--serif); letter-spacing: .01em; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); flex: none; }
.topnav { display: flex; gap: 2px; margin-left: auto; }
.topnav a { color: var(--top-ink); opacity: .72; text-decoration: none; padding: 7px 10px; border-radius: 9px;
            font-size: .88rem; white-space: nowrap; position: relative; }
.topnav a.active { background: rgba(255,255,255,.13); opacity: 1; font-weight: 700; }
.app-refresh { display: inline-flex; align-items: center; gap: 5px; color: var(--top-ink); text-decoration: none; white-space: nowrap;
               padding: 7px 10px; border-radius: 9px; background: rgba(255,255,255,.1); font-size: .84rem; font-weight: 700; }
.app-refresh:hover { background: rgba(255,255,255,.18); }
.top-more { display: none; color: var(--top-ink); text-decoration: none; line-height: 0; margin-left: auto;
            padding: 8px; opacity: .85; position: relative; }
.top-more svg { width: 24px; height: 24px; }
.tabbar { display: none; }
.dot-badge { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%;
             background: var(--gold); }
@media (max-width: 760px) {
  .topnav { display: none; }
  .app-refresh { margin-left: auto; }
  .top-more { display: block; margin-left: 0; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card);
            border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
            justify-content: space-around; }
  .tabbar a { flex: 1; text-align: center; color: var(--muted); text-decoration: none; font-size: .68rem;
              font-weight: 700; padding: 3px 0; position: relative; }
  .tabbar a svg { display: block; margin: 0 auto 2px; width: 23px; height: 23px; }
  .tabbar a.active { color: var(--brand); }
  .shell { padding-bottom: 96px !important; }
}
.shell { max-width: 820px; margin: 0 auto; padding: 20px 16px 60px; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
        box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card.tight { padding: 13px 15px; }
.card.soft { background: var(--brand-soft); border-color: transparent; box-shadow: none; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 620px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
                            .grid-2.stack-sm { grid-template-columns: minmax(0, 1fr); } }
.grid > .card { margin-bottom: 0; }
.label { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em;
         color: var(--muted); margin: 0 0 5px; }
.kpi { font-size: 1.55rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 999px;
        background: var(--line); color: var(--ink); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.notice { border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; background: var(--good-soft);
          color: var(--ink); border: 1px solid transparent; }
.notice.bad { background: var(--bad-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.info { background: var(--brand-soft); }

/* the verse and quote card */
.daily { background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: var(--radius);
         padding: 18px 20px; margin-bottom: 16px; box-shadow: none; }
.daily .verse { font-family: var(--serif); font-size: 1.12rem; line-height: 1.5; margin: 0 0 8px; }
.daily .ref { font-size: .8rem; font-weight: 700; color: var(--gold); letter-spacing: .03em; }
.daily .rule { height: 1px; background: var(--gold-line); margin: 14px 0; border: 0; }
.daily .quote { font-family: var(--serif); font-style: italic; margin: 0 0 4px; }
.daily .who { font-size: .8rem; color: var(--muted); }

/* forms + buttons */
button, .btn { appearance: none; border: 0; border-radius: 13px; background: var(--brand); color: var(--brand-ink);
               font: inherit; font-weight: 700; padding: 11px 17px; min-height: 46px; cursor: pointer;
               text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:active, .btn:active { transform: scale(.98); }
/* Inline SVGs have no intrinsic size once viewBox is the only sizing hint, so
   they collapse to nothing inside a flex button unless told otherwise. */
button svg, .btn svg { width: 20px; height: 20px; flex: none; }
button.small svg, .btn.small svg { width: 17px; height: 17px; }
button.ghost, .btn.ghost { background: transparent; color: var(--brand); border: 2px solid var(--brand); }
button.quiet, .btn.quiet { background: var(--bg); color: var(--ink); border: 1px solid var(--line); font-weight: 600; }
button.small, .btn.small { min-height: 34px; padding: 5px 11px; font-size: .85rem; border-radius: 10px; }
button.link { background: none; color: var(--brand); padding: 0; min-height: 0; font-weight: 700; }
button.danger { background: var(--bad); color: #fff; }
button.full, .btn.full { width: 100%; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
label { display: block; font-weight: 700; margin: 12px 0 6px; font-size: .92rem; }
label.inline-label { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; margin: 0; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card);
                          border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px; }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 21px; height: 21px; min-height: 0; accent-color: var(--brand);
                                          margin: 0; flex: none; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1; min-width: 110px; }
form.inline { display: inline; }
.field-note { font-size: .82rem; color: var(--muted); margin: 5px 0 0; }

/* the writing box: the most important element in the product */
.writer textarea { font-family: var(--serif); font-size: 1.08rem; line-height: 1.62; min-height: 46vh;
                   border-radius: 14px; padding: 16px; background: var(--card); }
.writer textarea::placeholder { color: var(--muted); opacity: .75; font-style: italic; }
.writer .bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.writer .bar .grow { min-width: 60px; }
.entry-read { font-family: var(--serif); font-size: 1.06rem; line-height: 1.62; white-space: pre-wrap;
              word-wrap: break-word; }

/* day navigation */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav .btn { min-height: 40px; padding: 6px 12px; }
.daynav .title { flex: 1; text-align: center; min-width: 0; }
.daynav .title strong { display: block; font-size: 1.12rem; font-family: var(--serif); }
.daynav .title span { font-size: .8rem; color: var(--muted); }
.scale { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
         padding: 3px; margin-bottom: 14px; }
.scale a { flex: 1; text-align: center; padding: 7px 4px; border-radius: 9px; text-decoration: none;
           color: var(--muted); font-size: .86rem; font-weight: 700; }
.scale a.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* heat grid */
/* Square cells across a wide container get huge, so cap the grid and centre it;
   on a phone it still fills the width, which is where it is actually used. */
.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; max-width: 430px; margin: 0 auto; }
.heat .cell { aspect-ratio: 1; border-radius: 7px; background: var(--ring-track); display: flex;
              align-items: center; justify-content: center; font-size: .7rem; color: var(--muted);
              text-decoration: none; }
/* Written, but nothing said about how it felt: tinted, so it never gets confused
   with the solid colour that means "Good". */
.heat .cell.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.heat .cell.today { outline: 2px solid var(--gold); outline-offset: 1px; }
/* A written day is filled; a day with a mood on it is filled in that mood's colour,
   so the grid says how the month went, not only that it happened. */
.heat .cell.mood { color: #fff; font-weight: 700; }
.heat .cell.mood.m1 { background: var(--bad); }
.heat .cell.mood.m2 { background: var(--warn); }
.heat .cell.mood.m3 { background: var(--muted); }
.heat .cell.mood.m4 { background: var(--brand); }
.heat .cell.mood.m5 { background: var(--good); }
.heat .cell.blank { background: transparent; }
.heat .head { aspect-ratio: auto; background: transparent; font-size: .66rem; font-weight: 800;
              text-transform: uppercase; letter-spacing: .04em; padding-bottom: 2px; }
.months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 520px) { .months { grid-template-columns: repeat(3, 1fr); } }
.months a { text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: 12px;
            padding: 10px 8px; text-align: center; background: var(--card); }
.months a .n { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.months a .m { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 7px; height: 86px; margin: 6px 0 4px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars .bar i { display: block; background: var(--brand); border-radius: 6px 6px 3px 3px; min-height: 3px;
               width: 100%; max-width: 46px; margin: 0 auto; }
.bars .bar.now i { background: var(--gold); }
.barlabels { display: flex; gap: 7px; }
.barlabels span { flex: 1; text-align: center; font-size: .7rem; color: var(--muted); font-weight: 700; }

/* expandable panels on the overview.
   <details> so opening one needs no JavaScript and survives a script failing. */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
         box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.panel > summary { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer;
                   list-style: none; user-select: none; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::marker { content: ""; }
.panel > summary:hover { background: var(--bg); }
.panel > summary .label { margin: 0 0 2px; }
.panel > summary .kpi { font-size: 1.45rem; }
.panel .chev { color: var(--muted); line-height: 0; transition: transform .15s ease; flex: none; }
.panel .chev svg { width: 20px; height: 20px; }
.panel[open] .chev { transform: rotate(90deg); }
.panel[open] > summary { border-bottom: 1px solid var(--line); }
.panel-body { padding: 14px 16px 16px; }
.panel-body .list { margin-bottom: 14px; }
.panel-add { margin: 0; }
.panel-add input { min-height: 44px; }
.panel-foot { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: .86rem; font-weight: 700; }

/* inline editors and the emoji palette */
.editor { display: inline-block; }
.editor > summary { list-style: none; display: inline-flex; }
.editor > summary::-webkit-details-marker { display: none; }
.editor > summary::marker { content: ""; }
.editor[open] > summary { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.editor-body { background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
               padding: 14px 16px 16px; margin-top: 10px; width: 100%; }
.editor-body label { margin-top: 10px; }
.editor-body label:first-of-type { margin-top: 0; }
.editor[open] { display: block; width: 100%; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.swatch { margin: 0; display: inline-flex; }
.swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch span { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
               font-size: 1.15rem; line-height: 1; border-radius: 11px; background: var(--card);
               border: 1.5px solid var(--line); cursor: pointer; }
.swatch input:checked + span { border-color: var(--brand); background: var(--brand-soft);
                               box-shadow: inset 0 0 0 1px var(--brand); }
.swatch input:focus-visible + span { outline: 3px solid var(--brand-2); outline-offset: 2px; }

/* the emoji in a list row */
.rowmoji { font-size: 1.15rem; line-height: 1.3; flex: none; width: 1.6em; text-align: center; }

/* mood over time */
.moodbar { display: flex; align-items: flex-end; gap: 3px; height: 62px; margin: 10px 0 6px; }
.moodbar .d { flex: 1; min-width: 3px; border-radius: 3px; background: var(--ring-track); align-self: stretch;
              display: flex; flex-direction: column; justify-content: flex-end; }
.moodbar .d i { display: block; border-radius: 3px; min-height: 4px; }
.m1 { background: var(--bad); } .m2 { background: var(--warn); } .m3 { background: var(--muted); }
.m4 { background: var(--brand); } .m5 { background: var(--good); }
.moodkey { display: flex; gap: 12px; flex-wrap: wrap; font-size: .76rem; color: var(--muted); }
.moodkey span { display: inline-flex; align-items: center; gap: 5px; }
.moodkey i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); padding: 12px 0; }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.item-text { font-size: 1rem; line-height: 1.4; }
.item-text.done { text-decoration: line-through; color: var(--muted); }
.evidence { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: .9rem;
            border-left: 3px solid var(--line); padding-left: 11px; margin: 7px 0 0; }
.meta { font-size: .78rem; color: var(--muted); margin-top: 5px; }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big { font-size: 1.02rem; color: var(--ink); font-weight: 700; margin-bottom: 4px; }

/* On a phone, let the buttons drop below the text instead of squeezing it into
   three wrapped lines beside them. The emoji stays alongside the text. */
@media (max-width: 620px) {
  /* The emoji and the text share the first line; the buttons take the next one,
     forced there by a 100% basis rather than by guessing at the text's width. */
  .list li > .row.between > .grow { flex: 1 1 0; min-width: 0; }
  .list li > .row.between > .row.tight { flex: 1 1 100%; margin-top: 10px; }
  .list li > .row.between > .row.tight form { flex: 1; }
  .list li > .row.between > .row.tight button { width: 100%; }
  .list li > .editor { display: block; width: 100%; margin-top: 8px; }
  .list li > .editor > summary { width: 100%; }
}

/* mood */
.moods { display: flex; gap: 6px; }
.moods button { flex: 1; min-height: 42px; background: var(--bg); color: var(--muted); border: 1px solid var(--line);
                font-size: 1.15rem; padding: 0; }
.moods button.on { background: var(--brand-soft); border-color: var(--brand); color: var(--ink); }

/* recorder */
.rec { display: flex; align-items: center; gap: 10px; }
.rec .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--bad); flex: none; }
.rec.live .dot { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.spinner { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent;
           border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* auth pages */
.auth { max-width: 400px; margin: 7vh auto; padding: 0 16px 60px; }
.auth .mark { text-align: center; margin-bottom: 20px; }
.auth .mark .name { font-family: var(--serif); font-size: 2rem; letter-spacing: .01em; }
.auth .mark .tag { color: var(--muted); font-size: .92rem; }
.auth .card { padding: 22px; }
.auth .alt { text-align: center; margin-top: 16px; font-size: .9rem; }

/* tap-to-open sections, made by fold.js from cards that start with a label */
details.fold-panel { padding: 0; overflow: hidden; }
details.fold-panel > summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 12px 18px;
                               cursor: pointer; list-style: none; user-select: none; -webkit-tap-highlight-color: transparent; }
details.fold-panel > summary::-webkit-details-marker { display: none; }
details.fold-panel > summary::marker { content: ""; }
details.fold-panel > summary:hover { background: var(--bg); }
details.fold-panel > summary > .label, details.fold-panel > summary > h2 { flex: 1; min-width: 0; margin: 0;
                                                                           color: var(--ink); overflow-wrap: anywhere; }
details.fold-panel > summary > .pill { flex: none; }
details.fold-panel[open] > summary { border-bottom: 1px solid var(--line); }
.section-chevron { flex: none; font-size: 1.4rem; line-height: 1; color: var(--muted); transition: transform .15s ease; }
details.fold-panel[open] > summary .section-chevron { transform: rotate(90deg); }
details.fold-panel > .section-body { padding: 14px 18px 18px; min-width: 0; }
details.fold-panel.tight > summary { padding: 10px 15px; }
details.fold-panel.tight > .section-body { padding: 12px 15px 14px; }
details.fold-panel.center > .section-body { text-align: center; }
@media (prefers-reduced-motion: reduce) { .section-chevron { transition: none; } }

@media print {
  .section-chevron { display: none; }
  .topbar, .tabbar, .scale, .daynav, form, button, .btn { display: none !important; }
  body, .card { background: #fff; box-shadow: none; border: 0; }
  .shell { max-width: none; padding: 0; }
}
