/* Sacred HQ. Tokens from brief section 10 (contrast re-checked by tests/unit/contrast.test.mjs). */
:root {
  --bg: #0E0F13; --surface: #16181D; --surface-2: #1E2128; --pressed: #252932;
  --text: #ECE8E0; --text-2: #A9A49B; --hairline: #262932;
  --error: #E5484D; --warning: #F5A524; --ok: #46A758; --crimson: #C41230; --on-crimson: #FFFFFF;
  --scrim: rgba(0, 0, 0, .55); --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --focus: #ECE8E0;
  --r: 14px; --r-sm: 10px; --tab-h: 62px; --gap: 1rem; --dur: 180ms;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F6F4EF; --surface: #FFFFFF; --surface-2: #EEEAE2; --pressed: #E3DED4;
  --text: #1B1A17; --text-2: #5C5850; --hairline: #E3DED4;
  --error: #C62A2F; --warning: #935A00; --ok: #2A7E3B; --crimson: #C41230; --on-crimson: #FFFFFF;
  --scrim: rgba(20, 18, 15, .45); --shadow: 0 8px 28px rgba(40, 32, 20, .18); --focus: #1B1A17;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F6F4EF; --surface: #FFFFFF; --surface-2: #EEEAE2; --pressed: #E3DED4;
    --text: #1B1A17; --text-2: #5C5850; --hairline: #E3DED4;
    --error: #C62A2F; --warning: #935A00; --ok: #2A7E3B;
    --scrim: rgba(20, 18, 15, .45); --shadow: 0 8px 28px rgba(40, 32, 20, .18); --focus: #1B1A17;
    color-scheme: light;
  }
}

/* Type: follow iOS Text Size. Non-WebKit browsers ignore the -apple-system-body value. */
html { font-size: 106.25%; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; }
html { font: -apple-system-body; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font-size: 1rem; line-height: 1.45; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-wrap: anywhere; -webkit-hyphens: auto; hyphens: auto;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden; min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
a { color: inherit; text-decoration: underline; text-underline-offset: .15em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--text-2); }
.small { font-size: .8125rem; }
.tabular { font-variant-numeric: tabular-nums; }
svg.icon { width: min(1.4rem, 26px); height: min(1.4rem, 26px); flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Sign-in gate (ported markup ids from CC v3) ---------- */
#loginGate { min-height: 100dvh; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 1.5rem) 1.25rem calc(env(safe-area-inset-bottom) + 1.5rem); }
.lg-card { width: 100%; max-width: 24rem; }
.lg-mark { display: flex; align-items: center; gap: .6rem; color: var(--text-2); font-size: .875rem; letter-spacing: .04em; text-transform: uppercase; }
.lg-mark img { width: 36px; height: 36px; border-radius: 22%; }
#loginGate h1 { font-size: 1.75rem; margin: 1.25rem 0 .35rem; }
#loginGate p { color: var(--text-2); margin: 0 0 1.25rem; }
#lgForm { display: grid; gap: .75rem; }
#loginGate label { font-size: .875rem; color: var(--text-2); }
#loginGate input { width: 100%; min-height: 3rem; padding: .7rem .9rem; font-size: max(1rem, 16px);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-sm); }
#lgSubmit { min-height: 3.1rem; border: 0; border-radius: var(--r-sm); background: var(--crimson); color: var(--on-crimson); font-weight: 600; }
#lgSubmit:disabled { opacity: .6; }
.lg-err { color: var(--error); min-height: 1.2em; font-size: .9375rem; }
.lg-alt { margin-top: 1rem; width: 100%; min-height: 2.9rem; background: transparent; border: 1px solid var(--hairline); border-radius: var(--r-sm); }
.lg-note { margin-top: .75rem; color: var(--text-2); font-size: .9375rem; min-height: 1.2em; }
.lg-note.ok { color: var(--text); }
.lg-foot { margin-top: 2rem; color: var(--text-2); font-size: .8125rem; }

/* ---------- App shell ---------- */
#app { min-height: 100dvh; }
.top { position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(env(safe-area-inset-top) + .5rem) 1rem .5rem; border-bottom: 1px solid var(--hairline); }
.top-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-height: 44px; }
.top-row h1 { font-size: 1.5rem; flex: 1; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 50%; color: var(--text); }
.icon-btn:active { background: var(--pressed); }
.sync-chip { font-size: .8125rem; padding: .2rem .6rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.sync-chip.warn { color: var(--warning); }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.5rem), 1fr)); gap: .25rem; padding: .25rem; margin-top: .5rem;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; }
.seg button { min-height: 2.75rem; border: 0; border-radius: 9px; background: transparent; color: var(--text-2); font-weight: 600; overflow-wrap: anywhere; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--hairline); }

main { padding: 1rem 1rem calc(var(--tab-h) + env(safe-area-inset-bottom) + 96px); max-width: 40rem; margin: 0 auto; }
.section { margin-bottom: 1.5rem; }
.section-h { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem .75rem; margin: 0 0 .5rem; }
.section-h h2 { font-size: 1.125rem; }
.section-h .count { color: var(--text-2); font-size: .9375rem; }
.disclose { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 2.75rem;
  padding: 0 .25rem; border: 0; background: transparent; color: var(--text-2); font-weight: 600; }
.disclose svg { transition: transform var(--dur) ease-out; }
.disclose[aria-expanded="true"] svg { transform: rotate(180deg); }

.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r); }
.list { list-style: none; margin: 0; padding: 0; }
.empty { padding: 1rem; color: var(--text-2); }
.empty strong { color: var(--text); display: block; margin-bottom: .25rem; }

/* rows with swipe */
.row-wrap { position: relative; overflow: hidden; border-bottom: 1px solid var(--hairline); }
.row-wrap:last-child { border-bottom: 0; }
.row-under { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem; font-weight: 600; font-size: min(1rem, 18px); }
.row-under .l { color: var(--ok); } .row-under .r { color: var(--warning); }
.row { position: relative; display: flex; align-items: flex-start; gap: .75rem; padding: .75rem .5rem .75rem 1rem;
  background: var(--surface); touch-action: pan-y; user-select: none; -webkit-user-select: none; min-height: 3.5rem; }
.row.dragging { transition: none; }
.row:not(.dragging) { transition: transform var(--dur) ease-out; }
.row-main { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: .25rem 0; color: var(--text); }
.row-title { overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .3rem; }
.done .row-title { text-decoration: line-through; color: var(--text-2); }
.check { width: 48px; height: 48px; flex: none; display: grid; place-items: center; border: 0; background: transparent; border-radius: 50%; }
.check span { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--text-2); display: grid; place-items: center; }
.check[aria-pressed="true"] span { background: var(--ok); border-color: var(--ok); color: #fff; }
.check:active { background: var(--pressed); }

.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .8125rem; line-height: 1.2; padding: .25rem .55rem;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--hairline); max-width: 100%; overflow-wrap: anywhere; }
.chip.p1 { color: var(--text); border-color: var(--text-2); font-weight: 600; }
.chip.warn { color: var(--warning); }
.chip.err { color: var(--error); }
.chip svg.icon { width: min(1rem, 18px); height: min(1rem, 18px); }
button.chip { min-height: 2.75rem; padding: .4rem .8rem; font-size: .9375rem; }
button.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* numbers */
.nums { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.5rem), 1fr)); gap: .5rem; }
.num { min-height: 5rem; padding: .75rem .5rem; border-radius: var(--r); border: 1px solid var(--hairline); background: var(--surface); text-align: center; }
.num b { display: block; font-size: 1.75rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.num span { color: var(--text-2); font-size: .875rem; overflow-wrap: anywhere; }
.num:active { background: var(--pressed); }
.num[disabled] { opacity: 1; cursor: default; }

.linkrow { display: flex; align-items: center; justify-content: space-between; gap: .75rem; width: 100%; min-height: 3.5rem;
  padding: .75rem 1rem; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r); text-align: left; }
.linkrow:active { background: var(--pressed); }
.linkrow small { display: block; color: var(--text-2); font-size: .875rem; margin-top: .15rem; }

/* tab bar + capture button */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--hairline); }
/* Tab bar and capture button keep native-like fixed sizes at the largest text sizes (iOS does the same). */
.tabbar a { min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-2); text-decoration: none; font-size: clamp(13px, .8125rem, 14px); line-height: 1.1; font-weight: 600; min-width: 0; }
.tabbar a svg.icon { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--text); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.4; }
.badge { min-width: 1.15rem; height: 1.15rem; padding: 0 .3rem; border-radius: 999px; background: var(--crimson); color: var(--on-crimson);
  font-size: .75rem; line-height: 1.15rem; position: absolute; transform: translate(.8rem, -.9rem); }
.fab { position: fixed; z-index: 31; right: 16px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--crimson); color: var(--on-crimson);
  display: grid; place-items: center; box-shadow: var(--shadow); }
.fab:active { transform: scale(.96); }
.fab svg.icon { width: 28px; height: 28px; }

/* sheets */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--dur) ease-out; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: .5rem 1rem calc(env(safe-area-inset-bottom) + 1rem); transform: translateY(105%); transition: transform 200ms ease-out;
  max-width: 40rem; margin: 0 auto; visibility: hidden; }
.sheet.open { transform: translateY(0); visibility: visible; }
.sheet.full { height: 92dvh; display: flex; flex-direction: column; }
.grabber { width: 2.5rem; height: .3rem; border-radius: 999px; background: var(--hairline); margin: .25rem auto .75rem; }
.sheet-h { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.sheet-h h2 { flex: 1; font-size: 1.25rem; }
.field { width: 100%; min-height: 3rem; padding: .75rem .9rem; font-size: max(1rem, 16px); background: var(--bg);
  border: 1px solid var(--hairline); border-radius: var(--r-sm); }
textarea.field { resize: none; line-height: 1.45; }
.field:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.hint { color: var(--text-2); font-size: .875rem; margin: .5rem 0 0; }
.err { color: var(--error); font-size: .9375rem; margin: .5rem 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 7rem), 1fr)); gap: .5rem; margin-top: 1rem; }
.btn { min-height: 3rem; padding: .6rem 1rem; overflow-wrap: anywhere; border-radius: var(--r-sm); border: 1px solid var(--hairline); background: var(--surface-2); color: var(--text); font-weight: 600; }
.btn:active { background: var(--pressed); }
.btn.primary { background: var(--crimson); border-color: var(--crimson); color: var(--on-crimson); }
.btn.danger { color: var(--error); }
.btn:disabled { opacity: .5; cursor: default; }
.stepper { display: grid; grid-template-columns: minmax(3rem, 4rem) minmax(0, 1fr) minmax(3rem, 4rem); gap: .5rem; align-items: center; }
.stepper input { text-align: center; font-size: 2rem; font-variant-numeric: tabular-nums; }
.stepper .btn { min-height: 4rem; font-size: 1.75rem; }
.setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; min-height: 3.25rem; padding: .5rem 0; border-bottom: 1px solid var(--hairline); }
.setting:last-child { border-bottom: 0; }
.setting label { flex: 1; }
.switch { appearance: none; -webkit-appearance: none; width: 3.25rem; height: 2rem; border-radius: 999px; background: var(--hairline); position: relative; border: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: .2rem; left: .2rem; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: #fff; transition: transform var(--dur) ease-out; }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(1.25rem); }
input[type="time"].field, input[type="date"].field { width: auto; min-width: min(8rem, 100%); max-width: 100%; }

/* toast */
.toast { position: fixed; z-index: 50; left: 1rem; right: 1rem; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 88px);
  max-width: 30rem; margin: 0 auto; display: flex; align-items: center; gap: .75rem; padding: .6rem .6rem .6rem 1rem;
  background: var(--text); color: var(--bg); border-radius: 12px; box-shadow: var(--shadow); }
.toast span { flex: 1; }
.toast button { min-height: 2.75rem; padding: 0 1rem; border: 0; border-radius: 9px; background: transparent; color: var(--bg); font-weight: 700; text-decoration: underline; }

.ptr { height: 0; overflow: hidden; display: grid; place-items: center; color: var(--text-2); font-size: .875rem; }
.search { position: relative; margin-bottom: .75rem; }
.search svg { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--text-2); }
.search .field { padding-left: 2.6rem; }
.note-row { display: block; width: 100%; text-align: left; border: 0; background: var(--surface); padding: .85rem 1rem; color: var(--text); }
.note-row:active { background: var(--pressed); }
.note-first { font-weight: 600; overflow-wrap: anywhere; }
.note-prev { color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.status-line { display: flex; gap: .5rem; align-items: flex-start; padding: .75rem 1rem; border-radius: var(--r); border: 1px solid var(--hairline); background: var(--surface); }
.status-line.warn { border-color: var(--warning); }
.status-line.err { border-color: var(--error); }
.md h1, .md h2, .md h3 { margin: 1rem 0 .5rem; }
.md p, .md ul { margin: 0 0 .75rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
@media (min-width: 48rem) { main { padding-left: 1.5rem; padding-right: 1.5rem; } }
