/* Jarvis: phone first, dark by default, readable in a dim room. No framework. */
:root {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #20242c;
  --line: #2c313b;
  --text: #ece8df;
  --muted: #a39d92;
  --accent: #e8b75d;
  --accent-ink: #1a1408;
  --good: #7fc79a;
  --warn: #e7a46b;
  --link: #9fc3ff;
  --radius: 14px;
  --tap: 48px;
  --tabbar: 64px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --line: #ddd8cd;
  --text: #1d1c19;
  --muted: #6c675e;
  --accent: #9a6a12;
  --accent-ink: #ffffff;
  --good: #2f7d4f;
  --warn: #a65a1c;
  --link: #1f5fbf;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 680px; margin: 0 auto; padding: 8px 16px 0; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 8px 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 14px 0 6px; }
a { color: var(--link); }
p { margin: 0 0 12px; }
code { font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px; padding: env(safe-area-inset-top) 8px 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.back { display: inline-flex; align-items: center; min-height: var(--tap); text-decoration: none; color: var(--accent);
  font-weight: 600; max-width: 75vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gear { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); color: var(--muted); }

/* Bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs.n7 { grid-template-columns: repeat(7, 1fr); }
.tabs.n6 { grid-template-columns: repeat(6, 1fr); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; min-height: var(--tap); }
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent); }

/* Search */
.searchbar { position: sticky; top: 52px; z-index: 5; padding: 8px 0; background: var(--bg); }
input, textarea, select {
  width: 100%; font: inherit; font-size: 17px; /* >=16px: no iOS zoom */
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; min-height: var(--tap);
}
input[type="search"] { font-size: 18px; padding: 14px 16px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { resize: vertical; line-height: 1.45; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label small { font-weight: 400; color: var(--muted); }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px;
  min-height: var(--tap); padding: 10px 18px; margin: 12px 0 0;
  font: inherit; font-weight: 600; color: var(--text); text-decoration: none; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: 8px 14px; margin: 0; font-size: .95rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn small { font-weight: 400; font-size: .78rem; color: var(--muted); }
.link { background: none; border: 0; color: var(--link); font: inherit; font-size: .9rem; padding: 10px 4px; min-height: 44px; cursor: pointer; }

/* Lists */
.list { list-style: none; margin: 0 0 8px; padding: 0; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 10px 14px; margin: 0 0 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main b { font-weight: 650; }
.sub { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.row .sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }
.chev { color: var(--muted); font-size: 1.4rem; }
.group-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font-size: .95rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); }
.count { color: var(--muted); font-weight: 500; font-size: .85rem; }
.topic-group { margin-bottom: 10px; }
.kids { margin-left: 16px; }
.kids .row { min-height: 50px; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; margin: 2px 6px 2px 0; }
.badge.gen { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card.empty p { font-size: 1.05rem; }
.flash { border-color: var(--good); }
.head { margin: 6px 0 4px; }
.role { color: var(--muted); font-size: 1.02rem; margin: 0 0 6px; }

/* Person anchors: big, read while walking up */
.anchor-list { margin: 0; padding-left: 1.6em; }
.anchor-list li { font-size: 1.22rem; line-height: 1.4; margin: 0 0 16px; padding-left: 4px; }
.anchor-list li::marker { color: var(--accent); font-weight: 700; }
.label { display: block; font-size: .78rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; }
.ctx { display: block; font-size: .92rem; color: var(--muted); margin-top: 4px; }

/* Prose (rendered markdown) */
.prose { overflow-wrap: anywhere; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 12px; }
.prose li { margin: 0 0 8px; }
.prose h2 { margin-top: 20px; }
.prose blockquote { margin: 0 0 12px; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.big { font-size: 1.2rem; line-height: 1.55; }
.unverified { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--warn); background: var(--surface-2); border-radius: 8px; font-size: .95rem; }
.unverified h3 { margin-top: 0; color: var(--warn); }
.sources { margin-top: 12px; }
.sources summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); font-weight: 600; }
.sources ul { padding-left: 1.2em; margin: 4px 0 0; }
.sources li { margin-bottom: 8px; }

/* Tables: scrollable on wide screens, stacked cards on phones */
.table-wrap { overflow-x: auto; margin: 0 0 14px; }
table.cards { border-collapse: collapse; width: 100%; font-size: .95rem; }
table.cards th, table.cards td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.cards th { color: var(--muted); font-weight: 600; }
@media (max-width: 720px) {
  .table-wrap { overflow: visible; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards thead { display: none; }
  table.cards tr { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin: 0 0 10px; }
  table.cards td { border: 0; padding: 4px 0; }
  table.cards td::before { content: attr(data-label); display: block; font-size: .75rem; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
  table.cards td:first-child { font-weight: 650; }
}

/* Notes */
.note-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.save-state { font-size: .88rem; color: var(--muted); }
.save-state.ok { color: var(--good); }
.save-state.err { color: var(--warn); }
.note-history { list-style: none; padding: 0; margin: 14px 0 0; }
.note-history li { border-top: 1px solid var(--line); padding: 8px 0 10px; }
.note-history li.editing { opacity: .55; }
.note-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .85rem; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.reply { margin-top: 8px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.met .save-state { display: block; margin-top: 8px; }

/* Anchors tab */
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
.pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.pinned summary h2, .group summary h2 { margin: 0; }
.pinned summary, .group > summary { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); gap: 10px; }
.pinned summary::after, .group > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.pinned:not([open]) summary::after, .group:not([open]) > summary::after { transform: rotate(-90deg); }
.pinned .prose { margin-top: 8px; }
.used-count { margin: 6px 2px; }
.qs { list-style: none; padding: 0; margin: 6px 0 0; }
.q { border-top: 1px solid var(--line); }
.q summary { padding: 14px 0; font-size: 1.15rem; line-height: 1.4; min-height: var(--tap); }
.q.used .qtext { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--good); }
.q.used summary::before { content: "✓ "; color: var(--good); font-weight: 700; }
.q .ctx { margin: 0 0 10px; }
.q .used-toggle { margin-bottom: 14px; }
.q .used-toggle[aria-pressed="true"] { color: var(--good); border-color: var(--good); }

/* Calm */
.calm-lines p { font-family: Georgia, "Times New Roman", serif; font-size: 1.22rem; line-height: 1.55; margin: 0 0 18px; }
.breathe { display: flex; flex-direction: column; align-items: center; }
.breath-circle {
  width: 150px; height: 150px; border-radius: 50%; margin: 10px auto 14px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 35%, transparent), transparent 70%);
  border: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  transform: scale(.6); transition-property: transform; transition-timing-function: ease-in-out;
}
.breath-circle span { font-weight: 700; font-size: 1.7rem; }
.breath-circle.in { transform: scale(1); transition-duration: 4s; }
.breath-circle.hold { transform: scale(1); transition-duration: 0s; }
.breath-circle.out { transform: scale(.6); transition-duration: 6s; }
@media (prefers-reduced-motion: reduce) { .breath-circle { transition: none !important; } }
.big-num { font-size: 2rem; font-weight: 700; margin: 0; }

/* Forms and misc */
.form h1 { margin-top: 0; }
.login { margin-top: 15vh; }
.error { color: var(--warn); margin: 8px 0 0; }
.preview { list-style: none; padding: 0; margin: 0; }
.preview li { border-top: 1px solid var(--line); padding: 8px 0; }
.preview .sub { display: block; }
.preview details summary { color: var(--link); min-height: 40px; display: flex; align-items: center; }
.indent { color: var(--muted); margin-right: 6px; }

/* Phase 2: generation progress and the background-jobs banner */
.gen { margin-top: 4px; }
.gen-status { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; }
.gen-status.err { border-color: var(--warn); color: var(--warn); font-weight: 500; }
.spinner { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line);
  border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.jobs { position: sticky; top: 52px; z-index: 9; max-width: 680px; margin: 0 auto; padding: 6px 16px 0; background: var(--bg); }
.job { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; padding: 8px 12px;
  margin-bottom: 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: .95rem;
  color: var(--text); text-decoration: none; }
.job.run { justify-content: flex-start; }
.job.ok { border-color: var(--good); color: var(--good); font-weight: 600; }
.job.bad { border-color: var(--warn); color: var(--warn); }

/* Notes tab and tonight's plan */
.tabs.n6 a, .tabs.n7 a { font-size: .66rem; }
.tabs.n7 a { font-size: .6rem; letter-spacing: -.01em; }
.tabs.n6 svg, .tabs.n7 svg { width: 23px; height: 23px; }
.plan { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-head h2 { margin: 0; }
.headline { font-size: 1.12rem; font-weight: 650; margin: 12px 0 6px; }
.tasks { list-style: none; padding: 0; margin: 8px 0 10px; }
.task { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.task-main { flex: 1; min-width: 0; }
.task .action { font-size: 1.08rem; font-weight: 600; line-height: 1.35; }
.task .why { color: var(--muted); font-size: .92rem; margin-top: 3px; }
.task .who { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; text-decoration: none; }
.task.p1 .action::before { content: "Next · "; color: var(--accent); }
.task.done .action { text-decoration: line-through; color: var(--muted); }
.task.done .action::before { content: ""; }
.tick { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: transparent;
  color: transparent; font-size: 1.2rem; font-weight: 700; cursor: pointer; }
.task.p1 .tick { border-color: var(--accent); }
.tick[aria-pressed="true"] { background: var(--good); border-color: var(--good); color: var(--accent-ink); }
.present-toggle { margin-top: 10px; }
.present-toggle.on { background: var(--good); color: var(--accent-ink); border-color: transparent; }
.note-history li textarea { margin-top: 6px; }

/* Offline */
.offline-bar { position: sticky; top: 52px; z-index: 11; padding: 8px 16px; text-align: center; font-size: .88rem;
  font-weight: 600; background: var(--warn); color: var(--accent-ink); }
.note-history li.pending { opacity: .75; }
.note-history li.pending .note-meta { color: var(--warn); }
.stale { color: var(--accent); font-weight: 600; font-size: .92rem; margin: 0 0 8px; }

/* Test tab */
.score-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.score-row .pips { flex: none; font-size: 1rem; letter-spacing: 2px; color: var(--accent); }
.score-row .pips .off { color: var(--line); }
.score-row b { display: block; }
.danger { padding: 12px 0; border-top: 1px solid var(--line); }
.danger .rank { color: var(--accent); font-weight: 700; margin-right: 6px; }
.danger .meter { height: 6px; border-radius: 3px; background: var(--surface-2); margin: 8px 0 6px; overflow: hidden; }
.danger .meter span { display: block; height: 100%; background: var(--warn); }
.danger .stat { color: var(--muted); font-size: .88rem; }
.drill-q { font-size: 1.2rem; line-height: 1.4; font-weight: 600; margin: 6px 0 14px; }
.drill-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; }
.opt { display: block; width: 100%; text-align: left; min-height: 52px; padding: 12px 14px; margin: 0 0 10px; font: inherit;
  color: var(--text); background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 18%, var(--surface-2)); }
.opt.wrong { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 18%, var(--surface-2)); }
.opt:disabled { cursor: default; }
.explain { margin-top: 6px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.explain .src { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.reading summary { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); }
.reading summary h2 { margin: 0; }
.reading summary::after { content: "▾"; color: var(--muted); }
.reading:not([open]) summary::after { transform: rotate(-90deg); }
.reading li { margin-bottom: 12px; }
