:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-2: #f0ebe3;
  --border: #e2dbd0;
  --text: #1f2623;
  --muted: #5e6862;
  --brand: #2f5d50;
  --brand-strong: #244a40;
  --brand-soft: #e3eee9;
  --accent: #b97d10;
  --accent-soft: #fbf0d9;
  --danger: #a3372b;
  --danger-soft: #f9e4e0;
  --added: #e2f2e6;
  --added-text: #1f5c2e;
  --removed: #fbe5e2;
  --removed-text: #8a2b20;
  --shadow: 0 1px 2px rgb(31 38 35 / 0.05), 0 6px 20px rgb(31 38 35 / 0.05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --surface: #1c211f;
    --surface-2: #242a27;
    --border: #323a36;
    --text: #e9ece9;
    --muted: #a2aca6;
    --brand: #7cc0a8;
    --brand-strong: #9ad3bf;
    --brand-soft: #22342e;
    --accent: #e9b44c;
    --accent-soft: #3a2f18;
    --danger: #f08a7c;
    --danger-soft: #3d2420;
    --added: #1d3324;
    --added-text: #9fdcae;
    --removed: #3b2220;
    --removed-text: #f2aca2;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--brand); }
code, pre, .mono { font-family: var(--mono); font-size: 0.88em; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.7rem; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  font-weight: 600;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent);
  outline-offset: 2px;
}
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .primary { color: #10201b; } }
.danger { color: var(--danger); }
.danger:hover { border-color: var(--danger); }
.small-button { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.link-button { border: none; background: none; color: var(--muted); padding: 0.3rem; font-weight: 500; }
.link-button:hover { color: var(--text); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}
textarea { resize: vertical; min-height: 5rem; }
label { font-weight: 600; display: block; margin-bottom: 0.3rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 750; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.9rem; }
.local-pill { background: var(--brand-soft); color: var(--brand-strong); border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.78rem; font-weight: 650; }

.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 55px); }
.sidebar { border-right: 1px solid var(--border); padding: 1.1rem 0.9rem; }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; padding: 0 0.4rem; }
.sidebar-heading h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.project-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.project-list a { display: block; padding: 0.55rem 0.6rem; border-radius: 10px; color: var(--text); text-decoration: none; }
.project-list a:hover { background: var(--surface-2); }
.project-list a[aria-current="page"] { background: var(--brand-soft); }
.project-list .name { font-weight: 650; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-list .meta { font-size: 0.8rem; color: var(--muted); }
.project-list .waiting { color: var(--accent); font-weight: 650; }

main { padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1040px; width: 100%; }
main:focus { outline: none; }
.loading { color: var(--muted); }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .sub { color: var(--muted); margin-top: 0.3rem; }
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.4rem; overflow-x: auto; }
.tabs a { padding: 0.6rem 0.85rem; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--brand); }
.count { display: inline-block; min-width: 1.4em; padding: 0 0.4em; margin-left: 0.3rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.78rem; text-align: center; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; }
.kicker { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.big-text { font-size: 1.05rem; white-space: pre-wrap; }
.empty-text { color: var(--muted); }
.byline { color: var(--muted); font-size: 0.85rem; margin-top: 0.45rem; }
.card.attention { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }

.welcome { max-width: 720px; }
.welcome h1 { font-size: 2.1rem; margin-bottom: 0.6rem; }
.welcome .lede { font-size: 1.1rem; color: var(--muted); margin-bottom: 1.6rem; }
.steps { list-style: none; padding: 0; margin: 0 0 1.75rem; display: grid; gap: 0.75rem; }
.steps li { display: grid; grid-template-columns: 2.2rem 1fr; gap: 0.75rem; align-items: start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.steps .num { width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); display: grid; place-items: center; font-weight: 750; }
.steps strong { display: block; }
.steps span { color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.timeline li { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 1rem; }
.timeline .line { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; flex-wrap: wrap; }
.timeline .title { font-weight: 650; }
.timeline .who-when { color: var(--muted); font-size: 0.85rem; }
.timeline .tag { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; border-radius: 6px; padding: 0.1rem 0.4rem; margin-right: 0.45rem; background: var(--surface-2); color: var(--muted); }
.tag.current { background: var(--brand-soft); color: var(--brand-strong); }
.tag.restore { background: var(--accent-soft); color: var(--accent); }
.tag.goal, .tag.next { background: var(--brand-soft); color: var(--brand-strong); }
.tag.decision { background: var(--accent-soft); color: var(--accent); }
.note-text { white-space: pre-wrap; margin-top: 0.35rem; }

.changes { margin-top: 0.8rem; display: grid; gap: 0.5rem; }
.changes .summary { color: var(--muted); font-size: 0.9rem; }
.file-change { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.file-change summary { cursor: pointer; padding: 0.5rem 0.75rem; background: var(--surface-2); font-family: var(--mono); font-size: 0.85rem; display: flex; gap: 0.5rem; align-items: center; }
.badge { font-family: system-ui, sans-serif; font-size: 0.7rem; font-weight: 750; text-transform: uppercase; border-radius: 6px; padding: 0.05rem 0.4rem; }
.badge.added { background: var(--added); color: var(--added-text); }
.badge.removed { background: var(--removed); color: var(--removed-text); }
.badge.changed { background: var(--accent-soft); color: var(--accent); }
.diff { margin: 0; padding: 0.4rem 0; overflow-x: auto; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5; background: var(--surface); }
.diff div { padding: 0 0.75rem; white-space: pre; min-height: 1.2em; }
.diff .add { background: var(--added); color: var(--added-text); }
.diff .del { background: var(--removed); color: var(--removed-text); }
.diff .skip { color: var(--muted); font-style: italic; }

.files { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.files li + li { border-top: 1px solid var(--border); }
.files button { width: 100%; text-align: left; border: none; border-radius: 0; background: none; padding: 0.6rem 1rem; font-family: var(--mono); font-weight: 500; font-size: 0.88rem; }
.files button:hover, .files button[aria-pressed="true"] { background: var(--surface-2); }
.viewer { margin-top: 1rem; }
.viewer pre { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; overflow: auto; max-height: 60vh; white-space: pre; }

.form-grid { display: grid; gap: 0.9rem; }
.choice-list { display: grid; gap: 0.5rem; }
.choice { display: grid; grid-template-columns: auto 1fr; gap: 0.7rem; align-items: start; border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem 0.9rem; cursor: pointer; font-weight: 400; margin: 0; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice input { width: auto; margin-top: 0.3rem; }
.choice strong { display: block; }
.choice span { color: var(--muted); font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.88rem; }

.access-list { display: grid; gap: 0.6rem; }
.access-item { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.status-chip { font-size: 0.75rem; font-weight: 700; border-radius: 999px; padding: 0.1rem 0.55rem; background: var(--brand-soft); color: var(--brand-strong); }
.status-chip.off { background: var(--surface-2); color: var(--muted); }

.copy-block { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 5.5rem 0.75rem 0.85rem; font-family: var(--mono); font-size: 0.82rem; white-space: pre-wrap; word-break: break-word; }
.copy-block button { position: absolute; top: 0.45rem; right: 0.45rem; }
.step-label { font-weight: 700; margin: 1rem 0 0.4rem; }
.warning-box { background: var(--accent-soft); border-radius: 10px; padding: 0.7rem 0.9rem; color: var(--text); }

dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25); }
dialog::backdrop { background: rgb(20 24 22 / 0.45); }
#dialog-body { padding: 1.4rem 1.5rem 1.3rem; display: grid; gap: 1rem; max-height: 85vh; overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.65rem 1.1rem; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 30px rgb(0 0 0 / 0.2); z-index: 20; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

.honest { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.7rem; }
.honest span { font-size: 0.78rem; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 0.1rem 0.55rem; }

.link-card { max-width: 560px; margin: 2rem auto; display: grid; gap: 1rem; }
.link-card h1 { font-size: 1.5rem; }
.big-button { padding: 0.75rem 1.6rem; font-size: 1.05rem; }
.done-mark { font-size: 2.5rem; line-height: 1; color: var(--brand); }
.link-banner { margin-bottom: 1.25rem; display: grid; gap: 0.6rem; }
.code-row { display: flex; gap: 0.5rem; max-width: 22rem; }
.code-row input { text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--mono); }

.signed-out { max-width: 520px; margin: 4rem auto; text-align: center; display: grid; gap: 0.9rem; }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { min-width: 0; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); padding: 0.8rem 16px; }
  .project-list { grid-auto-flow: column; grid-auto-columns: minmax(160px, 1fr); overflow-x: auto; }
  main { padding: 1.25rem 16px 3rem; }
  .grid { grid-template-columns: 1fr; }
  .local-pill { display: none; }
  .topbar { padding: 0.6rem 16px; }
}
