:root {
  color-scheme: dark light;
  --bg: #0c0d10;
  --surface: #14161b;
  --surface-2: #1c1f26;
  --line: #292d36;
  --text: #eceef2;
  --muted: #8b92a0;
  --accent: #c6f24e;
  --accent-ink: #151a05;
  --warn: #f3b755;
  --danger: #ff7a70;
  --dot: #2b2f39;
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --line: #dfe2e8;
    --text: #15171c;
    --muted: #666e7c;
    --accent: #1f6feb;
    --accent-ink: #ffffff;
    --warn: #9a6400;
    --danger: #c9362b;
    --dot: #cfd3da;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 品牌 */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark {
  width: 15px; height: 15px; border-radius: 4px;
  background: var(--accent);
  box-shadow: 4px 4px 0 -1px color-mix(in srgb, var(--accent) 35%, transparent);
}

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 8px;
  background: none; cursor: pointer; font-weight: 600;
  text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { opacity: .88; }
.btn.primary:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.btn.ghost { border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.wide { width: 100%; }
.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; }
.link-btn { border: 0; background: none; padding: 4px; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.link-btn:hover { color: var(--text); }
.link-btn.danger:hover { color: var(--danger); }

/* 登录 */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 18px; padding: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.login-card h1 { font-size: 22px; letter-spacing: -.02em; }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.field input {
  height: 40px; padding: 0 12px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; }

/* 布局 */
.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 372px;
}
.rail {
  display: flex; flex-direction: column; gap: 18px; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--line); min-height: 0;
}
.rail > .brand { padding: 4px 6px; }
.rail > .link-btn { align-self: flex-start; }

.sub-list { flex: 1; overflow: auto; display: grid; gap: 2px; align-content: start; min-height: 0; }
.sub-item {
  width: 100%; display: grid; gap: 1px; padding: 9px 10px;
  border: 0; border-radius: 8px; background: none; text-align: left; cursor: pointer;
}
.sub-item:hover { background: var(--surface-2); }
.sub-item.active { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }
.sub-item b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-item small { color: var(--muted); font-size: 12px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.name-input {
  flex: 1; min-width: 0; height: 36px; padding: 0 8px; margin-left: -8px;
  border: 0; border-radius: 6px; background: none;
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
}
.name-input::placeholder { color: var(--muted); font-weight: 450; }
.dirty { color: var(--warn); font-size: 12.5px; white-space: nowrap; }

/* 画布 */
.canvas {
  position: relative; flex: 1; min-height: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  background-size: 20px 20px;
  transition: box-shadow .15s;
}
.canvas:focus-within { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.canvas.flash { box-shadow: inset 0 0 0 2px var(--accent); }
.canvas textarea {
  position: absolute; inset: 0; width: 100%; height: 100%;
  padding: 22px 24px; border: 0; outline: 0; resize: none;
  background: transparent; tab-size: 2; white-space: pre; overflow: auto;
  font: 13px/1.65 var(--mono);
}
.canvas.has-content textarea { background: color-mix(in srgb, var(--bg) 80%, transparent); }
.canvas-hint {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 6px; text-align: center; pointer-events: none; color: var(--muted);
}
.canvas-hint p { margin-top: 14px; font-size: 18px; font-weight: 600; color: var(--text); letter-spacing: -.01em; }
.canvas-hint kbd {
  display: inline-block; margin: 0 3px; padding: 7px 12px;
  font: 600 14px var(--mono); color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 8px;
}

.statusbar {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 7px 16px; border-top: 1px solid var(--line);
  color: var(--muted); font: 12px var(--mono);
}
.statusbar .ok { color: var(--accent); }
.statusbar .err { color: var(--danger); }
#status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lines { white-space: nowrap; }

/* 右栏 */
.inspector {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line);
}
.panel { padding: 16px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: 0; }
.panel h2 { margin-bottom: 12px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }
.muted { color: var(--muted); font-size: 13px; }

.links { display: grid; gap: 8px; }
.link-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px;
  padding: 8px 8px 8px 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.link-row b { font-size: 12.5px; font-weight: 600; }
.link-row code {
  grid-column: 1; font: 11.5px var(--mono); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-row button { grid-column: 2; grid-row: 1 / span 2; }
.panel-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.panel-actions .btn { margin-right: auto; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats:empty { display: none; }
.stat { padding: 9px 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.stat b { display: block; font: 600 20px/1.2 var(--mono); letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; }

.warnings { display: grid; gap: 6px; margin-bottom: 10px; }
.warnings:empty { display: none; }
.warnings li { color: var(--warn); font-size: 12.5px; }

.nodes { flex: 1; min-height: 0; overflow: auto; margin: 0 -8px; }
.nodes:empty { display: none; }
.node { padding: 9px 8px; border-top: 1px solid var(--line); }
.node:first-child { border-top: 0; }
.node-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.node-name { flex: 1; min-width: 0; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proto {
  flex: none; padding: 1px 6px; border-radius: 5px;
  font: 600 11px/1.5 var(--mono); background: var(--surface-2); color: var(--muted);
}
.node-meta { margin-top: 2px; color: var(--muted); font: 11.5px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-note { margin-top: 3px; color: var(--warn); font-size: 12px; }
.targets { display: flex; gap: 4px; flex: none; }
.target { padding: 0 5px; border-radius: 4px; font: 600 10.5px/1.6 var(--mono); border: 1px solid var(--line); color: var(--muted); }
.target.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.target:not(.on) { text-decoration: line-through; opacity: .6; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  max-width: min(90vw, 480px); padding: 9px 16px;
  background: var(--text); color: var(--bg); border-radius: 8px; font-weight: 550; font-size: 13px;
}

@media (max-width: 1080px) {
  html, body { height: auto; }
  .shell { height: auto; grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .sub-list { max-height: 180px; }
  .stage { height: 70vh; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); }
  .nodes { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
