:root {
  --bg: #f6f1e7; --card: #fffdf8; --ink: #2a251f; --muted: #6f675c; --line: #e2d9c8;
  --accent: #2f5d50; --accent-ink: #fff; --accent-soft: #e3eee9; --gold: #a97f2f; --danger: #a5402d;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171512; --card: #211e1a; --ink: #ece5d8; --muted: #a39a8b; --line: #37322b; --accent: #7fbfa9; --accent-ink: #10201b; --accent-soft: #23332e; --gold: #d2a95a; --danger: #e08a76; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); padding-bottom: 32px; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 6vw, 2.3rem); }
h2 { font-size: 1.2rem; }
p { margin: 0; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--serif); font-weight: 600; color: var(--ink); text-decoration: none; cursor: pointer; user-select: none; }
.brand:hover { opacity: .9; }
.gear { font-size: .88rem; font-weight: 600; text-decoration: none; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); background: var(--card); transition: background .15s, color .15s, border-color .15s; cursor: pointer; min-height: 0; }
.gear:hover { border-color: var(--accent); color: var(--accent); }
.gear.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
main { max-width: 760px; margin: 0 auto; padding: 4px 16px 24px; outline: none; display: grid; gap: 16px; }

.tabs { display: flex; justify-content: center; background: var(--bg); border-bottom: 1px solid var(--line); border-top: none; max-width: 760px; margin: 0 auto 12px; width: 100%; position: sticky; top: 0; z-index: 10; }
.tabs .tab-btn { flex: 1; max-width: 175px; text-align: center; padding: 10px 4px 12px; background: none; border: none; border-radius: 0; min-height: 0; color: var(--muted); font: 600 .95rem var(--sans); border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer; transition: color .15s, border-color .15s; }
.tabs .tab-btn:hover { color: var(--ink); background: none; }
.tabs .tab-btn[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.link { color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; display: inline; }
.link:hover { color: var(--ink); }
.wk { font-weight: 700; color: var(--accent); cursor: pointer; user-select: none; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.wk:hover { text-decoration: underline; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: grid; gap: 12px; }
.hero { padding: 24px 20px; gap: 14px; border-top: 4px solid var(--accent); }
.kicker { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

button, .btn { font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.quiet { border-color: transparent; background: none; color: var(--accent); padding: 8px 10px; }
button.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
label.field { display: grid; gap: 4px; font-size: .88rem; font-weight: 600; color: var(--muted); }
.form { display: grid; gap: 14px; }
.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* Checkboxes, like the printed plan */
.tick { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; min-height: 44px; }
.tick input { appearance: none; width: 26px; height: 26px; min-height: 0; flex: none; border: 2px solid var(--accent); border-radius: 7px; background: var(--card); padding: 0; display: grid; place-content: center; cursor: pointer; }
.tick input:checked { background: var(--accent); }
.tick input:checked::after { content: ""; width: 7px; height: 13px; border: solid var(--accent-ink); border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.tick input.skipped { border-style: dashed; border-color: var(--muted); }
.tick .label { font-family: var(--serif); font-size: 1.08rem; }
.tick.done .label { color: var(--muted); }
.tag { font: 700 .68rem var(--sans); letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.list > * + * { border-top: 1px solid var(--line); }
.days { display: grid; gap: 0; }
.days .day { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.days .day input[type="checkbox"] { appearance: none; width: 22px; height: 22px; min-height: 0; flex: none; border: 2px solid var(--accent); border-radius: 6px; background: var(--card); padding: 0; display: grid; place-content: center; cursor: pointer; margin: 0; }
.days .day input[type="checkbox"]:checked { background: var(--accent); }
.days .day input[type="checkbox"]:checked::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.days .n { width: 48px; color: var(--muted); font-size: .85rem; font-weight: 700; flex: none; }
.days .today { font-weight: 700; }
.days .done .link { color: var(--muted); text-decoration: line-through; }

/* Plan table */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 40px; background: var(--card); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.plan-row { display: grid; grid-template-columns: 44px 1fr 1fr; gap: 8px; align-items: center; padding: 2px 0; }
.plan-row .wk { color: var(--muted); font-weight: 700; font-size: .85rem; text-decoration: none; }
.plan-row.current { background: var(--accent-soft); margin: 0 -10px; padding: 2px 10px; border-radius: 8px; }
.plan-row .tick { padding: 6px 0; gap: 8px; }
.plan-row .tick .label { font-size: .95rem; }
@media (max-width: 480px) { .plan-row { grid-template-columns: 34px 1fr; } .plan-row .tick:last-child { grid-column: 2; } }

/* Progress */
.bar { height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font: 600 1.7rem var(--serif); }

/* Reader */
.scripture { font-family: var(--serif); font-size: 1.14rem; line-height: 1.75; }
.scripture h3 { margin: 22px 0 6px; font-size: 1.05rem; color: var(--gold); }
.verse { cursor: pointer; border-radius: 4px; padding: 1px 0; }
.verse sup { font: 700 .62em var(--sans); color: var(--muted); margin-right: 3px; }
.verse.sel { background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.askbar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: 0 6px 24px rgb(0 0 0 / .14); }

/* Chat */
.chat { display: grid; gap: 12px; }
.msg { padding: 12px 14px; border-radius: 14px; max-width: 92%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--accent); color: var(--accent-ink); justify-self: end; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; font-family: var(--serif); font-size: 1.05rem; }
.cite { font: 600 .82rem var(--sans); min-height: 0; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); border-color: transparent; color: var(--accent); margin: 0 2px; vertical-align: baseline; }
.cited { white-space: normal; margin-top: 10px; padding: 10px 12px; border-left: 3px solid var(--gold); background: var(--bg); border-radius: 0 8px 8px 0; font-size: 1rem; }
.cited .ref { font: 700 .8rem var(--sans); color: var(--gold); display: flex; justify-content: space-between; gap: 8px; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 48px; max-height: 160px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { font-weight: 500; font-size: .9rem; border-radius: 999px; min-height: 36px; padding: 6px 12px; }

.notice { background: var(--accent-soft); border-color: transparent; }
.error { color: var(--danger); font-weight: 600; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .88em; overflow-wrap: anywhere; }
.keybox { background: var(--bg); border: 1px dashed var(--gold); border-radius: 10px; padding: 10px; }
#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
.auth { max-width: 420px; margin: 4vh auto 0; width: 100%; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
