:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d2126;
  --muted: #5f6670;
  --line: #dedbd2;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --accent-soft: #e2ece8;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #a3322b;
  --danger-soft: #f8e4e2;
  --ok: #2f6b3a;
  --rec: #c2412d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .06), 0 4px 16px rgba(20, 20, 20, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --surface-2: #272b30;
    --text: #e9e7e2;
    --muted: #a2a8b0;
    --line: #353a41;
    --accent: #7fb8a5;
    --accent-text: #0f1a16;
    --accent-soft: #23332e;
    --warn: #e8b04a;
    --warn-soft: #3a3020;
    --danger: #f08a80;
    --danger-soft: #3b2424;
    --ok: #8fcf98;
    --rec: #ff7b66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.boot { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---- Buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: .45rem .9rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { min-height: 32px; padding: .2rem .6rem; font-size: .875rem; }
.btn.block { width: 100%; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], textarea, select {
  width: 100%; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
  min-height: 42px;
}
textarea { resize: vertical; min-height: 5rem; line-height: 1.5; }
input:focus, textarea:focus, select:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: .25rem; }
.field { margin-bottom: .9rem; }
.field-inline { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 420px) { .field-inline { grid-template-columns: 1fr; } }

/* ---- Shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.nav { display: flex; gap: .25rem; }
.nav a {
  padding: .35rem .7rem; border-radius: 8px; color: var(--muted); text-decoration: none;
}
.nav a.active { background: var(--surface-2); color: var(--text); }
.save-state { font-size: .8rem; color: var(--muted); margin-left: auto; }
.save-state.error { color: var(--danger); font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }
.tabbar { display: none; }

@media (max-width: 760px) {
  .topbar .nav, .topbar .capture-top { display: none; }
  .topbar { padding: .5rem 1rem; padding-top: max(.5rem, env(safe-area-inset-top)); }
  main { padding: 1rem 1rem calc(var(--tabbar-h) + 2.5rem + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    height: var(--tabbar-h); font-size: .72rem; color: var(--muted); text-decoration: none;
  }
  .tabbar a.active { color: var(--accent); font-weight: 600; }
  .tabbar svg { width: 22px; height: 22px; }
  .fab {
    justify-self: center; align-self: center;
    width: 64px; height: 64px; margin-top: -26px; border-radius: 50%;
    border: 4px solid var(--bg);
    background: var(--accent); color: var(--accent-text);
    display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
    cursor: pointer;
  }
  .fab svg { width: 28px; height: 28px; }
}

/* ---- Cards & lists ---- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.section { margin-bottom: 1.25rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.idea-card { display: block; text-decoration: none; color: inherit; cursor: pointer; }
.idea-card:hover { border-color: var(--muted); }
.idea-card .title { font-weight: 600; margin-bottom: .2rem; }
.idea-card .snippet {
  color: var(--muted); font-size: .92rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; font-size: .8rem; color: var(--muted); align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .1rem .5rem; border-radius: 999px; font-size: .78rem;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.busy::before {
  content: ""; width: .6rem; height: .6rem; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button, .segmented a {
  border: 0; background: transparent; padding: .35rem .8rem; border-radius: 8px; cursor: pointer; color: var(--muted);
  text-decoration: none; font-size: .9rem;
}
.segmented .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.notice { padding: .7rem .9rem; border-radius: 10px; background: var(--surface-2); font-size: .92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--accent-soft); color: var(--accent); }

/* ---- Capture sheet ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 761px) { .overlay { align-items: center; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}
@media (min-width: 761px) { .sheet { border-radius: 18px; } }
.record-area { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 1rem 0 1.25rem; }
.record-btn {
  width: 96px; height: 96px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--rec); color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(194, 65, 45, .35);
}
.record-btn svg { width: 38px; height: 38px; }
.record-btn.recording { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(194, 65, 45, .15); } }
.timer { font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 600; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: .5rem 0 1rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---- Board ---- */
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr);
  gap: .75rem; overflow-x: auto; padding-bottom: .75rem; scroll-snap-type: x mandatory;
}
.column { scroll-snap-align: start; background: var(--surface-2); border-radius: var(--radius); padding: .6rem; min-height: 8rem; }
.column h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; padding: .2rem .3rem .5rem; }
.post-card { padding: .75rem; margin-bottom: .5rem; }
.post-card .title { font-weight: 600; text-decoration: none; color: var(--text); display: block; margin-bottom: .25rem; }
.post-card .next { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.post-card select { min-height: 34px; padding: .2rem .4rem; font-size: .85rem; margin-top: .4rem; }
@media (max-width: 760px) { .board { grid-auto-columns: 82vw; margin: 0 -1rem; padding: 0 1rem .75rem; } }

/* ---- Post detail ---- */
.post-head { display: flex; gap: .75rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.post-head .title-input {
  font-size: 1.3rem; font-weight: 700; border-color: transparent; background: transparent; padding-left: 0;
}
.post-head .title-input:hover, .post-head .title-input:focus { border-color: var(--line); background: var(--surface); padding-left: .7rem; }
.post-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.post-tabs { display: none; margin-bottom: 1rem; }
@media (max-width: 900px) {
  .post-grid { grid-template-columns: 1fr; }
  .post-tabs { display: inline-flex; }
  .post-grid > [data-pane]:not(.pane-active) { display: none; }
}
.conversation { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.msg { max-width: 92%; padding: .65rem .85rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .who { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; text-transform: uppercase; letter-spacing: .04em; }
.composer { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { min-height: 3rem; }
.original { font-size: .92rem; }
.original summary { cursor: pointer; color: var(--muted); }
.original blockquote { margin: .5rem 0 0; padding: .6rem .8rem; border-left: 3px solid var(--line); white-space: pre-wrap; background: var(--surface); border-radius: 0 8px 8px 0; }

.skeleton { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: .9rem; }
.skeleton.approved { border-color: var(--accent); }
.skeleton .field { margin-bottom: .6rem; }
.skeleton textarea { min-height: 2.6rem; }
.beat { display: flex; gap: .4rem; align-items: flex-start; margin-bottom: .4rem; }
.beat .n { width: 1.4rem; padding-top: .6rem; color: var(--muted); font-size: .85rem; text-align: right; }
.claim { display: flex; gap: .4rem; align-items: center; margin-bottom: .4rem; font-size: .92rem; }

.research-item { padding: .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.research-item.done { opacity: .7; }
.research-item .text { font-weight: 500; }
.brief textarea { min-height: 12rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

.lookup-pop { position: relative; }
.lookup-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 15; width: min(360px, 90vw);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; box-shadow: var(--shadow);
}

/* ---- Toast ---- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 1.5rem + env(safe-area-inset-bottom)); z-index: 60; display: grid; gap: .4rem; width: min(92vw, 420px); }
@media (min-width: 761px) { .toasts { bottom: 1.5rem; } }
.toast { background: var(--text); color: var(--bg); padding: .65rem .9rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .92rem; display: flex; gap: .75rem; align-items: center; justify-content: space-between; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 8px; padding: .15rem .5rem; cursor: pointer; }

/* ---- Auth ---- */
.auth { max-width: 380px; margin: 12vh auto; }
.auth h1 { margin-bottom: 1rem; }

/* ---- Next ---- */
.next-item { display: grid; grid-template-columns: 1fr auto; gap: .5rem .75rem; align-items: center; }
.next-item .title { font-weight: 600; color: var(--text); text-decoration: none; }
.next-item .reasons { font-size: .88rem; color: var(--muted); }
.next-item .date-edit { width: 11rem; }
@media (max-width: 520px) { .next-item { grid-template-columns: 1fr; } }

audio { width: 100%; height: 40px; }
.post-grid > [data-pane=editor] { grid-row: span 2; }
@media (max-width: 900px) { .post-grid > [data-pane=editor] { grid-row: auto; } }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.meta select, .row select, .post-head select { width: auto; min-height: 34px; padding: .2rem .5rem; }
.post-head .row { flex-wrap: nowrap; }
.research-item .meta { margin-top: 0; margin-bottom: .5rem; }
.research-item .field { margin-bottom: .5rem; }
@media (min-width: 901px) {
  .post-grid > [data-pane=editor] { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow-y: auto; padding-right: .25rem; }
}
.post-head > .grow { flex: 1 1 320px; }
main.wide { max-width: none; }
@media (min-width: 761px) { .board { grid-auto-columns: minmax(150px, 1fr); } }
.post-card .chip { white-space: normal; text-align: left; }

/* ---- Editor rounds ---- */
.editor-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .5rem; margin-bottom: .9rem; }
.editor-option {
  display: flex; flex-direction: column; gap: .2rem; text-align: left; cursor: pointer;
  padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.editor-option:hover { border-color: var(--muted); }
.editor-option.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.editor-option .name { font-weight: 600; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.editor-option .desc { font-size: .85rem; color: var(--muted); }
.round-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: .6rem; margin-top: .4rem;
}
.round-head:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.round-log summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.round-log .conversation { margin-top: .6rem; }
.handoff-note textarea { font-size: .92rem; min-height: 9rem; }
.handoff-panel h3 { margin-top: .5rem; }
.skeleton h3 .muted { font-weight: 400; }
