/* ════════════════════════════════════════════════════════════════════
   v1 Phase 1B — Dark theme (DESIGN.md §3.2)
   ────────────────────────────────────────────────────────────────────
   Activated by `<html data-theme="dark">`. Overrides the new tokens
   plus enough legacy ones (--paper / --surface / --ink / --line) so
   the un-migrated CSS visually inverts. Topbar / floating panels use
   the new --surface-2 / --ink-1 / --line-1 directly and respond
   without legacy bridging.
   ════════════════════════════════════════════════════════════════════ */

[data-theme="dark"] {
  color-scheme: dark;

  /* New tokens */
  --bg:           #0E0E10;
  --surface-1:    #0E0E10;
  --surface-2:    #16161A;
  --surface-3:    #1F1F24;

  --ink-1:        #F4F4F5;
  /* Dark ink scale brightened one notch 2026-05-29 (user: "dark text still
     hard to read"). Old ink-3 #71717A was ~3.8:1 on surface-2 — below AA.
     New values clear ≥4.5 for ink-2/ink-3; ink-4 (faint/disabled) ~3.8.
     Light theme unchanged. (DESIGN.md §3.2) */
  --ink-2-v1:     #B7B7BF;
  --ink-3-v1:     #94949E;
  --ink-4:        #74747E;

  --line-1:       #33333B;   /* v2 affordance ↑ 自 #2A2A30 — 柔分隔（仅有底色块辅助处）*/
  --line-hard:    #6E6E78;   /* v2 新增 — 唯一线索结构边界（表格行线 / 面板页眉 / dock 分组线，U11）*/
  --line-2-v1:    #3F3F46;
  --line-soft-v1: #1F1F24;   /* v2 降级：禁承担分隔职责，仅存量装饰 */

  /* Control seat layer (v2 affordance — see 00-tokens-base for spec) */
  --ctl-rest:     rgba(255, 255, 255, 0.08);
  --ctl-line:     #4C4C55;

  --overlay-1:    rgba(255, 255, 255, 0.09);   /* v2 ↑ 0.06→0.09 */
  --overlay-2:    rgba(255, 255, 255, 0.14);   /* v2 ↑ 0.10→0.14 */
  --overlay-3:    rgba(0, 0, 0, 0.60);

  /* Hover / active semantic tokens (dark variant — see 00-tokens-base for spec). */
  --hover-border: rgba(255, 255, 255, 0.22);
  --hover-bg:     rgba(255, 255, 255, 0.13);  /* v2 ↑ 0.08→0.13：明显高于 --ctl-rest(0.08) 座 */
  --active-border: var(--ink-1);
  --active-bg:    rgba(255, 255, 255, 0.18);  /* v2 ↑ 0.12→0.18：阶梯顶 */

  --sig-warn:     #D9A661;
  --sig-warn-bg:  #3A2E1C;
  --sig-error:    #D67878;
  --sig-error-bg: #3E2222;

  /* perf 工具调色板（dev-only，DESIGN.md §3.6）— dark 同族（GitHub 暗色） */
  --perf-good:      #3FB950;
  --perf-warn:      #D29922;
  --perf-bad:       #F85149;
  --perf-controls:  #8B949E;
  --perf-callbacks: #58A6FF;
  --perf-render3d:  #BC8CFF;
  --perf-css2d:     #56D4DD;
  --perf-other:     #6E7681;
  --perf-gpu:       #FFA657;   /* GPU 真实执行（"other" 拆分，暖色=耗时所在） */
  --perf-present:   #484F58;   /* 合成 + vsync 等待（"other" 余量，冷灰=空等） */
  --sig-ok:       #79B98C;
  --sig-ok-bg:    #1F3324;
  --sig-select:   #34D2E8;   /* brighter cyan for the dark canvas */

  --canvas-bg:    #38383F;   /* 3D 暗模式天空/clear 色（user 2026-06-15：原 #18181B 太黑→#2A2A30；user 2026-06-29：photoreal 整体偏暗，再抬一档 #2A2A30→#38383F，仍低于 --canvas-bg-2d #42424A 保层级）。2D 检查模式另用更亮的 --canvas-bg-2d。 */
  --canvas-bg-2d: #42424A;   /* 2D 立面检查模式抬亮的画布底（user 2026-06-15：暗模式 2D 黑底太重、侧影读不清；逐步调浅 #2A2A30→#3A3A42→#42424A）。比 3D --canvas-bg 再高一档的炭灰，仍属暗主题但不死黑；只 dark 定义，亮主题回退 --canvas-bg（theme.js canvasTargetColors）。 */
  --canvas-floor: #42424A;   /* dark ground plane, 比 --canvas-bg 高一档使其读作平面（user 2026-06-29：随 --canvas-bg 抬一档 #34343A→#42424A） */

  /* Liquid glass — dark (DESIGN.md §6.4). Slightly more opaque than light
     (0.70) so the dark Canvas + bright beam bloom don't wash out text; the
     specular rim drops to a faint 0.10 white so it reads as polished glass,
     not a hard line. */
  /* Glass v2 dark — 暗底是玻璃的主场：遮挡同降、白色高光边提亮一档、
     三层影加深；边框换白 alpha 描边。 */
  --glass-resident:  rgba(20, 20, 24, 0.88);  /* v2 affordance ↑ 自 0.78（同 light，U4/U11）*/
  --glass-transient: rgba(20, 20, 24, 0.62);   /* Bench 域 chip 不动 */
  --figure-studio-glass: rgba(20, 20, 24, 0.72);
  --float-bg:     var(--glass-resident);
  --glass-border: rgba(255, 255, 255, 0.13);
  --glass-card:       rgba(255, 255, 255, 0.05);
  --glass-card-hover: rgba(255, 255, 255, 0.10);
  --float-shadow: 0 1px 1px rgba(0, 0, 0, 0.30),
                  0 4px 12px rgba(0, 0, 0, 0.38),
                  0 16px 48px rgba(0, 0, 0, 0.60);
  --float-edge:   inset 0 1px 0 rgba(255, 255, 255, 0.22),
                  inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  --chip-shadow:  0 1px 2px rgba(0, 0, 0, 0.40),
                  0 4px 10px rgba(0, 0, 0, 0.35),
                  inset 0 1px 0 rgba(255, 255, 255, 0.18);
  --chip-shadow-hover: 0 1px 2px rgba(0, 0, 0, 0.40),
                  0 4px 10px rgba(0, 0, 0, 0.35),
                  inset 0 1px 0 rgba(255, 255, 255, 0.34);
  /* --measure-accent 不再在此覆写：它在 tokens-base 已 alias 到 var(--sig-select)，
     本主题的 --sig-select（#34D2E8）会通过惰性替换自动生效 → 测量工具与光程同青。 */

  /* Legacy bridges — keep 3500 lines of legacy v0 CSS readable in dark
     without per-rule rewrites. Phase 1C will replace these one cluster
     at a time. */
  --paper:        #0E0E10;
  --paper-soft:   #16161A;
  --paper-deep:   #1F1F24;
  --surface:      #16161A;
  --surface-2:    #1F1F24;   /* matches §3.2 surface-3 to keep layered cards visible */
  --ink:          #F4F4F5;
  --ink-2:        #B7B7BF;   /* brightened 2026-05-29, was #A1A1AA (DESIGN.md §3.2) */
  --ink-3:        #94949E;   /* brightened 2026-05-29, was #71717A — now ≥4.5 on dark */
  --line:         #33333B;   /* v2 affordance ↑ 与 --line-1 同族 */
  --line-2:       #3F3F46;
  --line-soft:    #1F1F24;

  /* 命名债清理（affordance 批⑤，2026-07-04）：dark cobalt 别名同步删除；引用已
     改为 --ink-1 / --surface-3 / --surface-2（dark 值经 tokens 覆盖自动跟随）。 */

  --warn:         var(--sig-warn);
  --warn-bg:      var(--sig-warn-bg);
  --warn-ink:     #E8C99B;
  --caution:      #E08A4A;        /* 光高中档橙（§6.4 3–10mm），暗底可读，黄↔红之间 */
  --caution-bg:   #3A2A18;
  --caution-ink:  #ECC49A;
  --bad:          var(--sig-error);
  --bad-bg:       var(--sig-error-bg);
  --bad-ink:      #EDB0B0;
  --good:         var(--sig-ok);

  /* 3D fault-sign hazard palette — vivid on the dark canvas (see :root note;
     User 2026-06-03「奶红色」). NOT the muted UI --sig-* (those stay for chrome). */
  --fault-warn:   #F59E0B;
  --fault-caution: #F97316;   /* 光高中档橙（§6.4 3–10mm），画布上鲜明，琥珀↔红之间 */
  --fault-bad:    #EF4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100vw;
  height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* UX-7 (2026-06-10, DESIGN.md §15.7): selection ENABLED by default —
     any data text (specs, SKUs, readings, BOM rows) is copyable and the
     native right-click menu works in DOM panels. Only "things that move
     when clicked" opt out via the deny-list below. (Inverts the old
     global user-select:none that made panels uncopyable.) */
}

/* ── Interaction-chrome deny-list (UX-7) ────────────────────────────
   No text selection on controls, drag surfaces and the 3D canvas — the
   stuff a pointer drags or toggles. Placed BEFORE the text allow-list
   below so explicit text leaves win on conflicts. */
button, kbd,
input[type="range"], input[type="checkbox"], select, summary,
[data-drag-handle], [data-drag-handle] *,
.resizer, .dock-edge-toggle, .panel-strip,
#stage, #css2d-layer,
.action-dock,
.lib-draggable-toggle, .lf-head, .lf-range,
.topbar-search-hint {
  user-select: none;
  -webkit-user-select: none;
}

/* ── Text selection allow-list (2026-05-27) ─────────────────────────
   Re-enable native text selection only on the *text* parts of components
   the user might want to copy from. Buttons inside the same component
   stay un-selectable so click-drag and hover-press UX is preserved.
   3D canvas / drag handles / sliders / icons all keep the body default. */
.ins-card-main, .ins-card-main *,
.ins-row, .ins-row *,
#ins-specs .ins-row, #ins-specs .ins-row *,
#ins-readings, #ins-readings *,
.datasheet-table, .datasheet-table *,
.datasheet-figure-empty,
.modal-title, .modal-meta, .modal-eyebrow,
.lib-card-name, .lib-card-sku, .lib-card-spec,
.lib-prod-name, .lib-prod-sku, .lib-prod-spec,
.lib-row-title, .lib-crumb-current,
.ins-value-input  /* number inputs already selectable but be explicit */ {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
/* But text-cursor only on actual text leaves — container chrome
   (entire row/card) shouldn't show I-beam when hovering padding. */
.ins-row, #ins-readings, .datasheet-table, .ins-card-main,
.lib-card, .lib-prod {
  cursor: default;
}

