:root {
  --bg: #f6f1e7;
  --card: #fffdf8;
  --ink: #1f2a24;
  --muted: #6b7068;
  --line: #e3dccd;
  --accent: #d9773a;
  --accent-ink: #fff;
  --rec: #c8412f;
  --ok: #3f7a52;
  --chip: #efe7d6;
  --shadow: 0 1px 2px rgba(31, 42, 36, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131815;
    --card: #1c2420;
    --ink: #ece4d6;
    --muted: #9aa197;
    --line: #2c3631;
    --accent: #e88c4a;
    --accent-ink: #1b130c;
    --rec: #e2604c;
    --ok: #7cbf8f;
    --chip: #26302b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131815; --card: #1c2420; --ink: #ece4d6; --muted: #9aa197; --line: #2c3631;
  --accent: #e88c4a; --accent-ink: #1b130c; --rec: #e2604c; --ok: #7cbf8f; --chip: #26302b;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
[hidden] { display: none !important; }

/* ---- capture panel ---- */
#capture {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.big {
  width: 100%; min-height: 64px; border: 0; border-radius: 18px;
  font-size: 20px; font-weight: 600; display: flex; align-items: center;
  justify-content: center; gap: 10px;
}
.talk { background: var(--ink); color: var(--bg); }
.talk svg { width: 26px; height: 26px; fill: currentColor; }
.done { background: var(--rec); color: #fff; min-height: 76px; font-size: 22px; }
.quiet {
  background: none; border: 0; color: var(--muted); padding: 10px;
  font-size: 15px; text-decoration: underline; text-underline-offset: 3px;
}
#cancel { display: block; margin: 4px auto 0; }

.rec-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.dot {
  width: 14px; height: 14px; border-radius: 50%; background: var(--rec);
  animation: pulse 1.2s ease-in-out infinite; flex: none;
}
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }
#rec-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 20px; flex: none; }
#meter { flex: 1; min-width: 0; height: 40px; width: 100%; }

#typeform { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
#note {
  flex: 1; min-width: 0; resize: none; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); border-radius: 14px;
  padding: 11px 14px; font: inherit; max-height: 40vh;
}
#save {
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; padding: 0 18px; min-height: 48px;
}
#status { margin: 8px 2px 0; min-height: 1.2em; font-size: 14px; color: var(--muted); }
#status.ok { color: var(--ok); }
#status a { color: var(--accent); }

/* ---- tabs ---- */
#tabs {
  display: flex; gap: 6px; padding: 10px 16px 4px; overflow-x: auto;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
#tabs button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 14px; white-space: nowrap; font-size: 15px;
}
#tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
#tabs .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

main { padding: 6px 16px calc(env(safe-area-inset-bottom) + 80px); max-width: 720px; margin: 0 auto; }
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 22px 2px 8px; font-weight: 600;
}
.empty { color: var(--muted); text-align: center; padding: 36px 8px; }

/* ---- list rows ---- */
.row {
  display: flex; gap: 12px; align-items: flex-start; background: var(--card);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.check {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--muted); background: none; padding: 0; margin-top: 1px;
  display: grid; place-items: center;
}
.check svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; opacity: 0; }
.row.done .check { background: var(--ok); border-color: var(--ok); color: var(--card); }
.row.done .check svg { opacity: 1; }
.row.done .text { text-decoration: line-through; color: var(--muted); }
.body { flex: 1; min-width: 0; }
.text { overflow-wrap: anywhere; }
.meta { font-size: 13.5px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.meta .due { color: var(--accent); font-weight: 600; }
.from {
  background: none; border: 0; padding: 0; color: var(--muted); font-size: 13.5px;
  text-decoration: underline; text-underline-offset: 2px;
}
.row.maybe { background: none; border: 1px dashed var(--line); box-shadow: none; align-items: center; }
.row.maybe .text { color: var(--muted); }
.mini {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 5px 12px; font-size: 14px; flex: none;
}
.mini.yes { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---- journal ---- */
.search {
  width: 100%; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 11px 14px; font: inherit; margin-top: 8px;
}
.entry {
  background: var(--card); border-radius: 14px; padding: 12px 14px 10px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.entry-when { font-size: 13.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.entry-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-text.clamp {
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.entry .pending { color: var(--muted); font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 13.5px; background: var(--chip); border-radius: 8px; padding: 3px 9px;
  overflow-wrap: anywhere;
}
.chip b { font-weight: 600; }
.chip.done { text-decoration: line-through; color: var(--muted); }
.chip.maybe { background: none; border: 1px dashed var(--line); color: var(--muted); }
.more { display: block; margin: 12px auto; }

/* ---- entry sheet ---- */
#sheet {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 85vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 12px 18px calc(env(safe-area-inset-bottom) + 24px);
}
.sheet-close { float: right; }
#sheet-body .entry { box-shadow: none; padding: 0; background: none; clear: both; }
#sheet-body .entry-text { font-size: 18px; }
.remove { color: var(--rec); margin-top: 18px; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  z-index: 30; background: var(--ink); color: var(--bg); border-radius: 14px;
  padding: 12px 16px; display: flex; align-items: center; gap: 12px; max-width: 560px; margin: 0 auto;
}
#toast span { flex: 1; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 4px; }

/* ---- login ---- */
body.login { display: grid; place-items: center; padding: 16px; }
body.login form { width: 100%; max-width: 340px; text-align: center; }
body.login img { border-radius: 16px; }
body.login h1 { margin: 10px 0 18px; font-size: 24px; }
body.login input {
  width: 100%; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 13px 14px; font: inherit; margin-bottom: 10px;
}
body.login button {
  width: 100%; border: 0; border-radius: 12px; background: var(--ink); color: var(--bg);
  padding: 13px; font-weight: 600;
}
body.login .err { color: var(--rec); min-height: 1.4em; font-size: 15px; }
