:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d8;
  --ink: #2a241e;
  --ink-2: #5d5347;
  --muted: #857868;
  --line: #e2d8c6;
  --accent: #a9561a;
  --accent-ink: #fffaf3;
  --accent-soft: #f4e2cc;
  --good: #3c7a4b;
  --h0: #ebe3d4;
  --h1: #f1dcbf;
  --h2: #e6bd8a;
  --h3: #d59a58;
  --h4: #bb7433;
  --h5: #8f4f17;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 14px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171411; --surface: #211d19; --surface-2: #2b2621; --ink: #eee6d8; --ink-2: #c3b7a6;
    --muted: #978b7b; --line: #3a332c; --accent: #e39352; --accent-ink: #1b130b; --accent-soft: #3a2a1b;
    --good: #7cc08d; --h0: #2b2621; --h1: #3d2e20; --h2: #624227; --h3: #8e5c2e; --h4: #c17d3d; --h5: #eeac68;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171411; --surface: #211d19; --surface-2: #2b2621; --ink: #eee6d8; --ink-2: #c3b7a6;
  --muted: #978b7b; --line: #3a332c; --accent: #e39352; --accent-ink: #1b130b; --accent-soft: #3a2a1b;
  --good: #7cc08d; --h0: #2b2621; --h1: #3d2e20; --h2: #624227; --h3: #8e5c2e; --h4: #c17d3d; --h5: #eeac68;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header + tabs */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-weight: 600; font-size: 1.1rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand .mark { color: var(--accent); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a { padding: 8px 14px; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: .95rem; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
.sync { border: 0; background: none; padding: 6px; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; cursor: pointer; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-state="synced"]::before { background: var(--good); }
.sync[data-state="syncing"]::before { background: var(--accent); }
.sync[data-state="error"]::before { background: #c0392b; }

@media (max-width: 720px) {
  .top { backdrop-filter: none; background: var(--bg); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 30; justify-content: space-around;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabs a { flex: 1; text-align: center; padding: 10px 4px; font-size: .9rem; }
  .sync { margin-left: auto; }
  .sync span { display: none; }
}

main { max-width: 880px; margin: 0 auto; padding: 20px 16px 40px; outline: none; }

/* Common */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.eyebrow { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 999px; cursor: pointer;
  font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 1.1rem; padding: 8px; min-width: 44px; min-height: 44px; color: var(--ink-2); border-radius: 50%; }
.icon-btn:hover { background: var(--surface-2); }
.why { font-size: .85rem; color: var(--accent); text-decoration: none; border-bottom: 1px dotted currentColor; white-space: nowrap; cursor: pointer; background: none; border-top: 0; border-left: 0; border-right: 0; padding: 0; }
input[type="text"], input[type="time"], input[type="number"], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-weight: 500; margin-bottom: 6px; font-size: .95rem; }

/* Now: header */
.now-head { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 14px; }
@media (max-width: 480px) { .now-head h1 { font-size: 1.4rem; } }
.now-head h1 { margin: 0; }
.datenav { display: flex; align-items: center; gap: 0; margin-left: auto; flex: none; }
.phases { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 16px; }
.phase { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; cursor: pointer; min-height: 40px; font-weight: 500; color: var(--ink-2); }
.phase[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.phase .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); margin-left: 6px; vertical-align: middle; }
.banner { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); margin-bottom: 14px; font-size: .95rem; }
.banner strong { font-weight: 600; }

/* Resolves */
.resolves { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.resolve { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; padding: 14px 14px 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); transition: background .2s; }
.resolve.done { background: var(--accent-soft); border-color: transparent; }
.resolve .kw { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; }
.resolve .kw small { font-family: var(--sans); color: var(--muted); font-weight: 500; margin-right: 6px; }
.resolve p { margin: 2px 0 0; color: var(--ink-2); grid-column: 1; }
.offer { grid-row: 1 / span 2; grid-column: 2; width: 52px; height: 52px; border-radius: 50%; border: 1px dashed var(--muted); background: transparent; cursor: pointer; font-size: 1.35rem; display: grid; place-items: center; }
.resolve.done .offer { border-style: solid; border-color: var(--accent); background: var(--surface); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0 16px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* Keywords (segment reminder) */
.keywords { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.kwchip { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; cursor: pointer; min-height: 44px; }
.kwchip b { display: block; font-family: var(--serif); font-size: 1rem; }
.kwchip span { display: block; font-size: .82rem; color: var(--ink-2); line-height: 1.35; margin-top: 2px; }
.kwchip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; }
.kwchip[aria-pressed="true"] b::after { content: " ✓"; color: var(--accent); }
.seglist { list-style: none; padding: 0; margin: 10px 0 0; }
.seglist li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); align-items: baseline; }
.seglist time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; font-size: .9rem; }
.seglist .x { margin-left: auto; }

.moments { display: flex; flex-wrap: wrap; gap: 8px; }
.moment-panel { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.moment-panel ol { margin: 6px 0 12px; padding-left: 1.2em; }
.moment-panel li { margin: 4px 0; }

/* Evening */
.q { padding: 14px 0; border-top: 1px solid var(--line); }
.q:first-of-type { border-top: 0; padding-top: 4px; }
.q-head { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.q-text { font-weight: 500; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin-top: 8px; max-width: 480px; }
.scale button { min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-variant-numeric: tabular-nums; padding: 0; }
.scale button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.scale-ends { display: flex; justify-content: space-between; max-width: 480px; font-size: .75rem; color: var(--muted); margin-top: 2px; }
.avg { font-family: var(--serif); font-size: 2.4rem; line-height: 1; }

/* Silence */
.timer { font-family: var(--serif); font-size: 3.2rem; font-variant-numeric: tabular-nums; text-align: center; margin: 10px 0; }
.checks { list-style: none; padding: 0; margin: 10px 0; }
.checks li { padding: 6px 0; }
.checks label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.checks input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Journal */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .v { font-family: var(--serif); font-size: 1.8rem; line-height: 1.1; }
.tile .l { font-size: .8rem; color: var(--muted); }
@media (max-width: 600px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.heat-wrap { overflow-x: auto; }
.heat { display: block; width: 100%; max-width: 620px; height: auto; }
.legend { display: flex; align-items: center; gap: 4px; font-size: .75rem; color: var(--muted); margin-top: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.mini h4 { font-family: var(--sans); font-size: .9rem; font-weight: 600; margin: 0 0 2px; display: flex; justify-content: space-between; }
.mini h4 span { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.mini svg { display: block; width: 100%; height: auto; overflow: hidden; }
.axis { stroke: var(--line); stroke-width: 1; }
.axis-t { fill: var(--muted); font-size: 10px; }
.line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.hit { fill: transparent; cursor: crosshair; }
.xh { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.days { list-style: none; padding: 0; margin: 0; }
.day { border-top: 1px solid var(--line); }
.day summary { display: flex; gap: 12px; align-items: center; padding: 12px 4px; cursor: pointer; list-style: none; }
.day summary::-webkit-details-marker { display: none; }
.day .d { font-weight: 600; min-width: 7.5em; }
.day .badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.on { background: var(--accent-soft); color: var(--ink); }
.day .score { margin-left: auto; font-family: var(--serif); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.day-body { padding: 0 4px 14px; font-size: .95rem; }
.day-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 6px 0; }
.day-body dt { color: var(--muted); }
.day-body dd { margin: 0; }
.day-body blockquote { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--line); white-space: pre-wrap; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
table.data th:first-child, table.data td:first-child { text-align: left; }

/* Theory */
.theory { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; }
.toc { position: sticky; top: 72px; font-size: .9rem; max-height: calc(100vh - 90px); overflow: auto; }
.toc h5 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 4px; }
.toc a { display: block; padding: 4px 8px; border-radius: 8px; color: var(--ink-2); text-decoration: none; }
.toc a[aria-current="true"] { background: var(--accent-soft); color: var(--ink); }
.toc-select { display: none; margin-bottom: 14px; }
@media (max-width: 720px) {
  .theory { grid-template-columns: 1fr; }
  .toc { display: none; }
  .toc-select { display: block; }
}
.prose { max-width: 65ch; }
.prose p, .prose li { color: var(--ink); }
.prose h4 { font-size: 1.02rem; margin-top: 1.3em; }
.prose .lede { font-family: var(--serif); font-size: 1.15rem; line-height: 1.5; }
.prose .aside { color: var(--ink-2); font-size: .92rem; border-top: 1px solid var(--line); padding-top: 10px; }
.prose .key { background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin: 14px 0; }
.prose .formula { font-family: var(--serif); text-align: center; color: var(--ink-2); }
.prose .steps { padding-left: 1.3em; }
.prose .steps li { margin: 8px 0; }
.prose table.t { border-collapse: collapse; width: 100%; font-size: .95rem; margin: 10px 0; }
.prose table.t th, .prose table.t td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose table.t th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.gloss { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.gloss dt { font-weight: 600; font-family: var(--serif); }
.gloss dd { margin: 0; color: var(--ink-2); }
@media (max-width: 480px) { .gloss { grid-template-columns: 1fr; } .gloss dd { margin-bottom: 8px; } }
.chain { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 18px 0; padding: 16px 10px; border-radius: 14px; background: var(--surface-2); }
.chain .link { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: center; font-weight: 600; font-size: .92rem; }
.chain small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); }
.chain .arrow { color: var(--muted); text-align: center; font-size: 1.1rem; }
.chain .arrow.cut { color: var(--accent); font-size: 1.3rem; }
.chain .arrow.cut small { color: var(--accent); font-weight: 600; }
.section-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); }

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, .35); }
.drawer-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(520px, 100%); background: var(--surface); overflow-y: auto;
  padding: 12px 22px 40px; box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide .2s ease-out;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -12px; background: var(--surface); padding: 6px 0; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@media (max-width: 600px) {
  .drawer-panel { top: auto; left: 0; height: 88vh; width: 100%; border-radius: 18px 18px 0 0; animation: rise .2s ease-out; }
  @keyframes rise { from { transform: translateY(40px); opacity: 0; } }
}

.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--bg); font-size: .8rem; padding: 6px 9px; border-radius: 8px; max-width: 220px; line-height: 1.35; }
.toast { position: fixed; left: 50%; bottom: calc(90px + 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; transition: opacity .2s; pointer-events: none; z-index: 70; }
.toast.show { opacity: 1; }

.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.radio-cards label { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-cards input { accent-color: var(--accent); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 480px) {
  .chain { flex-direction: column; gap: 2px; }
  .chain .link { width: 100%; max-width: 260px; }
  .chain .arrow:not(.cut) { transform: rotate(90deg); }
  .chain .arrow.cut { display: flex; align-items: center; gap: 6px; }
}
