:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1d1f;
  --muted: #6b6a66;
  --border: #dedbd3;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7dc;
  --claude: #2563eb;
  --claude-soft: #dbe7fd;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16171a; --surface: #1f2024; --surface-2: #2a2b30; --text: #ececea; --muted: #a09f9a;
    --border: #34353b; --accent: #f97316; --accent-ink: #1a0d05; --accent-soft: #3b2214;
    --claude: #7aa5ff; --claude-soft: #1d2a45; --ok: #4ade80; --ok-soft: #173123; --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16171a; --surface: #1f2024; --surface-2: #2a2b30; --text: #ececea; --muted: #a09f9a;
  --border: #34353b; --accent: #f97316; --accent-ink: #1a0d05; --accent-soft: #3b2214;
  --claude: #7aa5ff; --claude-soft: #1d2a45; --ok: #4ade80; --ok-soft: #173123; --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
code { font: .88em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 16px calc(32px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; min-width: 0; padding: 0 4px; }
.topbar h1 { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.spin .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .94rem; text-decoration: none; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row.end { justify-content: flex-end; }
.link { background: none; border: 0; padding: 4px 0; font: inherit; font-size: .88rem; font-weight: 600; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--danger); }
input[type="password"], input[type="text"], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
.field { display: grid; gap: 6px; margin: 10px 0 6px; font-size: .88rem; font-weight: 600; }

/* ---------- cards ---------- */
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: inherit; text-decoration: none; }
.card h3 { font-size: 1.02rem; }
.card p { margin: 6px 0; }
.card.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.project:active { transform: scale(.99); }
.project .summary { font-size: .93rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.draft-note { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: .82rem; color: var(--accent); font-weight: 600; }
.draft-note .icon { width: 15px; height: 15px; }
.list { display: grid; gap: 12px; }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }
.help { margin-top: 12px; font-size: .9rem; }
.help summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.help ol { padding-left: 20px; }

.chip { flex: none; display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.chip-turn { background: var(--accent-soft); color: var(--accent); }
.chip-claude { background: var(--claude-soft); color: var(--claude); }
.chip-done { background: var(--ok-soft); color: var(--ok); }
.chip-muted { background: var(--surface-2); color: var(--muted); }

.progress { position: relative; height: 8px; margin-top: 10px; margin-right: 44px; border-radius: 999px; background: var(--surface-2); }
.progress-fill { height: 100%; border-radius: inherit; background: var(--accent); }
.progress-label { position: absolute; right: -44px; top: -6px; width: 38px; text-align: right; font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- viewer ---------- */
body.viewer-mode #app { height: 100dvh; overflow: hidden; }
.banner-slot:empty { display: none; }
.banner { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: var(--accent-soft); font-size: .85rem; }
.banner > span { flex: 1; }
.stage { flex: 1; min-height: 0; position: relative; background: #fff; }
.stage > .card { margin: 16px; }
.overview-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.toolbar { border-top: 1px solid var(--border); background: var(--surface); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
.toolbar-row { display: flex; align-items: center; gap: 6px; }
.mode-hint { font-size: .8rem; color: var(--muted); text-align: center; padding: 0 4px 6px; }
.segmented { flex: 1; display: flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--surface-2); min-width: 0; }
.segmented button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; height: 36px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer;
}
.segmented button .icon { width: 17px; height: 17px; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.btn.send { min-height: 42px; padding: 0 12px; }
.with-badge .badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 700; line-height: 18px; }
@media (max-width: 380px) { .segmented button span, .btn.send span { display: none; } }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); animation: fade .15s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto; background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .2);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 4px 18px; }
.sheet-head h2 { font-size: 1.05rem; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 10px; align-content: start; }
.sheet blockquote { margin: 4px 0; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; font-size: .9rem; max-height: 9em; overflow: auto; white-space: pre-wrap; }
.sheet blockquote.clamp { max-height: 4.6em; overflow: hidden; }
.comment-item { border-bottom: 1px solid var(--border); padding: 8px 0; }
.comment-item p { margin: 4px 0; white-space: pre-wrap; }
.comment-item .btn-row { margin-top: 0; gap: 16px; }
.label { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 6px; }
.decisions { display: grid; gap: 8px; }
.decision { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.decision:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.decision input { margin-top: 4px; accent-color: var(--accent); }
.decision span { display: grid; }
.decision small { color: var(--muted); }
.summary-line { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.summary-line span { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: .82rem; font-weight: 600; }
.preview { white-space: pre-wrap; word-break: break-word; font: .78rem/1.45 ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 40dvh; overflow: auto; }
.prompt-box { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: .92rem; }
.prompt-box span { flex: 1; }
.error-text { color: var(--danger); font-size: .9rem; }
.menu { display: grid; }
.menu-item { display: block; padding: 14px 4px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item.danger { color: var(--danger); }
.existing { display: grid; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: .88rem; font-weight: 600;
  box-shadow: var(--shadow); animation: fade .15s; max-width: calc(100% - 32px);
}

/* ---------- sign-in & account ---------- */
.signin { min-height: 100dvh; align-content: center; }
.signin-card { display: grid; justify-items: center; gap: 14px; text-align: center; padding: 32px 8px; }
.signin-card img { border-radius: 16px; box-shadow: var(--shadow); }
.signin-card h1 { font-size: 1.6rem; }
.signin-card p { margin: 0; max-width: 340px; }
.signin-card .card { text-align: left; width: 100%; }
.btn.google { min-height: 48px; padding: 0 22px; background: var(--surface); border-color: var(--border); font-size: 1rem; box-shadow: var(--shadow); }
.btn.google .icon { width: 20px; height: 20px; }
.avatar {
  flex: none; width: 34px; height: 34px; margin: 0 4px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: 700 .95rem/34px system-ui, sans-serif; text-align: center;
}
