:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --ink: #1f2a24;
  --muted: #6b726c;
  --line: #e2ddd1;
  --accent: #2f6b4f;
  --accent-ink: #f4efe3;
  --l0: #d9d4c7;
  --l1: #e7b75f;
  --l2: #7fb08f;
  --l3: #2f6b4f;
  --gap: #b5452f;
  --skipped: #5b6fa8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 42, 36, 0.06), 0 4px 16px rgba(31, 42, 36, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a17;
    --surface: #1d2420;
    --ink: #e8e6df;
    --muted: #9aa39c;
    --line: #2f3833;
    --accent: #6fb38f;
    --accent-ink: #10150f;
    --l0: #39423d;
    --l1: #c99a45;
    --l2: #5f9a75;
    --l3: #8fd1ab;
    --gap: #e07a62;
    --skipped: #8ea0d6;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button { font: inherit; cursor: pointer; color: inherit; }
input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; letter-spacing: 0.02em; }
.brand svg { width: 28px; height: 28px; }
.brand rect { fill: var(--accent); }
.brand path { stroke: var(--accent-ink); stroke-width: 2.2; fill: none; stroke-linecap: round; }
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav button { background: none; border: 0; padding: 6px 12px; border-radius: 8px; color: var(--muted); }
#nav button:hover { color: var(--ink); background: var(--bg); }
#nav button.active { color: var(--ink); background: var(--bg); font-weight: 600; }
.who { display: flex; gap: 12px; align-items: center; color: var(--muted); font-size: 14px; margin-left: auto; }
.link { background: none; border: 0; color: var(--accent); padding: 0; }

main { max-width: 1180px; margin: 0 auto; padding: 32px 24px 64px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted, .sub { color: var(--muted); }
.sub { margin: 4px 0 0; font-size: 14px; }

/* auth */
.auth { display: grid; grid-template-columns: 1.2fr 1fr; gap: 56px; align-items: center; min-height: 70vh; }
.auth-intro h1 { font-size: 44px; letter-spacing: -0.01em; margin-bottom: 20px; }
.auth-intro p { font-size: 17px; color: var(--muted); max-width: 34em; }
.points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; }
.points li { padding-left: 18px; position: relative; }
.points li::before { content: ""; position: absolute; left: 0; top: 0.6em; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.points b { margin-right: 8px; }
.auth-card { padding: 28px; display: grid; gap: 16px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input[type="email"], input[type="password"], input[type="text"], input[type="search"], select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 10px 12px; width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.error { margin: 0; min-height: 1.2em; color: var(--gap); font-size: 14px; }
.primary { white-space: nowrap; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.6; cursor: wait; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--ink); }
.ghost:hover { border-color: var(--accent); }

/* views */
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h2 { font-size: 26px; }
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.controls input[type="search"] { width: 220px; }
.toggle { display: flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 16px; align-items: center; }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.l0 { background: var(--l0); } .dot.l1 { background: var(--l1); } .dot.l2 { background: var(--l2); } .dot.l3 { background: var(--l3); }
.flag { font-style: normal; font-size: 12px; padding: 0 6px; border-radius: 4px; border: 1px solid currentColor; line-height: 18px; }
.flag.gap { color: var(--gap); } .flag.skipped { color: var(--skipped); }
.flag.frontier { color: var(--accent); border-style: dashed; }
.seg { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--line); padding: 3px; border-radius: 9px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.pick { font-size: 12px; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); background: none; white-space: nowrap; }
.pick:hover { background: var(--accent); color: var(--accent-ink); }
.intree { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row.not-in-tree .title { color: var(--muted); }
.empty-tree { padding: 28px 20px; text-align: center; color: var(--muted); }
.empty-tree p { margin: 6px 0; }

.tree-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.tree { padding: 12px 8px; }
.node { list-style: none; }
.tree ul { margin: 0; padding-left: 18px; border-left: 1px dashed var(--line); margin-left: 10px; }
.tree > ul { border: 0; padding: 0; margin: 0; }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; cursor: pointer; }
.row:hover { background: var(--bg); }
.row.selected { background: var(--bg); outline: 1px solid var(--line); }
.caret { width: 16px; color: var(--muted); flex: none; text-align: center; font-size: 11px; transition: transform 0.15s; }
.node.collapsed > .row .caret { transform: rotate(-90deg); }
.node.collapsed > ul { display: none; }
.row .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .group-title { font-weight: 600; }
.row .meta { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.bar { width: 64px; height: 6px; border-radius: 3px; background: var(--l0); overflow: hidden; flex: none; }
.bar i { display: block; height: 100%; border-radius: 3px; }
.proposed { font-size: 11px; color: var(--muted); border: 1px dashed var(--line); border-radius: 4px; padding: 0 4px; }

.detail { padding: 20px; position: sticky; top: 84px; }
.detail h3 { font-size: 18px; margin-bottom: 4px; }
.detail .path { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
.detail .desc { margin: 12px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.chip { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; color: var(--muted); }
.big-level { display: flex; align-items: baseline; gap: 10px; margin: 12px 0; }
.big-level b { font-size: 28px; font-family: var(--mono); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.two-col h3 { font-size: 16px; margin-bottom: 12px; color: var(--muted); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.timeline .when { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.timeline .what { margin-top: 4px; }
.badge { font-size: 12px; border-radius: 4px; padding: 0 6px; background: var(--bg); border: 1px solid var(--line); }
.delta-pos { color: var(--l3); font-family: var(--mono); }
.delta-neg { color: var(--gap); font-family: var(--mono); }
.empty { color: var(--muted); padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; list-style: none; }

.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 24px; }
.project { padding: 16px; }
.project h3 { font-size: 16px; }
.project ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.suggest { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; counter-reset: s; }
.suggest li { counter-increment: s; display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.suggest li::before { content: counter(s); font-family: var(--mono); color: var(--muted); font-size: 18px; }
.suggest .reason { font-size: 13px; color: var(--muted); }

.step { padding: 20px 24px; margin-bottom: 16px; }
.step h3 { font-size: 17px; margin-bottom: 8px; }
.step p { margin: 12px 0 8px; }
.copybox { display: flex; gap: 8px; align-items: flex-start; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.copybox code { flex: 1; font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-all; }
.steps { margin: 8px 0 12px; padding-left: 22px; display: grid; gap: 6px; }
.steps code, .step p code { font-family: var(--mono); font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.inline { display: flex; gap: 8px; max-width: 520px; }
.warn { color: var(--gap); font-size: 14px; }
.tokens { width: 100%; border-collapse: collapse; font-size: 14px; }
.tokens th, .tokens td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.tokens th { color: var(--muted); font-weight: 500; }
.tokens code { font-family: var(--mono); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; gap: 28px; min-height: 0; }
  .auth-intro h1 { font-size: 34px; }
  .tree-layout, .two-col { grid-template-columns: 1fr; }
  .detail { position: static; }
  main { padding: 20px 16px 48px; }
  .topbar { padding: 10px 16px; gap: 8px 12px; }
  #nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; margin: 0 -8px; }
  #nav button { white-space: nowrap; }
  .bar { width: 40px; }
  .controls input[type="search"] { width: 100%; }
  .inline { flex-direction: column; }
}

/* OAuth authorize / consent pages */
.oauth { max-width: 440px; margin: 0 auto; padding: 48px 16px; display: grid; gap: 20px; }
.oauth .brand { justify-self: center; }
.oauth .auth-card h2 { font-size: 22px; }
.oauth .auth-card p { margin: 0; }
.oauth-form { display: grid; gap: 14px; }
.oauth-form .link { justify-self: center; font-size: 14px; }
.perm { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.oauth code { font-family: var(--mono); font-size: 13px; }
