/* NoKeyOut 装机模拟器 — 全屏场景 + HUD（token 见 DESIGN.md） */
:root {
  --bg: #0b0e13;
  --surface: #12161d;
  --surface-2: #171d25;
  --border: #232b36;
  --fg: #e8eef5;
  --muted: #8d99a6;
  --accent: #4f8ff7;
  --success: #35c76d;
  --warning: #f0a83c;
  --error: #f0574f;
  --c1: #f0574f; --c2: #f0a83c; --c3: #35c76d; --c4: #4f8ff7; --c5: #bc8cff; --c6: #39c5cf;
  --sans: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  --r-card: 14px; --r-ctl: 10px; --r-pill: 999px;
  --glass: rgba(11, 14, 19, .86);
  --ease: cubic-bezier(.2, .7, .3, 1);
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- 全屏场景 ---------- */
#scene { position: fixed; inset: 0; overflow: hidden; background: #0b0e13; }
#bench3d { position: absolute; inset: 0; }
#fx-canvas { position: absolute; inset: 0; z-index: 70; pointer-events: none; }
#scene.fx-celebrate::after {
  content: ''; position: absolute; inset: 0; z-index: 55; pointer-events: none;
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 62%);
  animation: fx-celebrate 2200ms ease-out;
}
@keyframes fx-celebrate {
  0% { opacity: 0; }
  18% { opacity: .9; }
  100% { opacity: 0; }
}
#sfx-toggle { min-width: 34px; font-size: 14px; line-height: 1; }
#step-card.fx-pop { animation: fx-pop 500ms var(--ease); }
#step-card.fx-shake { animation: fx-shake 380ms var(--ease); }
#progress-fill.fx-glow { box-shadow: 0 0 14px color-mix(in srgb, var(--success) 75%, transparent); filter: brightness(1.35); }
@keyframes fx-pop {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
  35% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 28px color-mix(in srgb, var(--accent) 30%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes fx-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}
#bench3d canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#bench3d-tip {
  position: fixed; left: 0; top: 0; z-index: 60; max-width: 300px; padding: 7px 10px;
  border-radius: 8px; background: rgba(11, 14, 19, .96); border: 1px solid var(--border);
  color: var(--fg); font: 12px/1.5 var(--sans); pointer-events: none; will-change: transform;
}
#bench3d-tip b { font-family: var(--mono); font-weight: 600; }

/* ---------- HUD 通用 ---------- */
.hud { position: fixed; z-index: 20; }
.panel {
  background: var(--glass);
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: var(--r-card);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .45);
  backdrop-filter: blur(14px) saturate(1.1);
}
#hud-top {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(8, 11, 15, .92), rgba(8, 11, 15, .55) 70%, transparent);
  pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#hud-top .brand {
  font: 700 14px/1.2 var(--mono); letter-spacing: -.02em; white-space: nowrap;
}
.github-link {
  font: 600 11.5px/1.2 var(--mono); color: var(--muted); white-space: nowrap;
  padding: 5px 9px; border: 1px solid var(--border); border-radius: 8px;
  background: rgba(11, 14, 19, .55); text-decoration: none;
  max-width: 34vw; overflow: hidden; text-overflow: ellipsis;
}
.github-link:hover { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); text-decoration: none; }
#hud-progress { flex: 1; max-width: 460px; display: flex; align-items: center; gap: 10px; }
#hud-count { font: 600 12px var(--mono); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress-track { flex: 1; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .12); overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--success)); transition: width var(--t-panel, 180ms) var(--ease); }
.hud-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#hud-switch { font-family: var(--mono); }
#hud-switch.on { border-color: color-mix(in srgb, var(--error) 60%, var(--border)); color: var(--error); }

/* ---------- 当前步骤卡 ---------- */
#step-card {
  left: 20px; bottom: 20px; width: min(430px, calc(100vw - 40px));
  max-height: min(62vh, 620px); overflow: auto;
  padding: 16px 18px 18px;
}
#step-card .kicker {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  color: var(--muted); font: 600 11px/1.4 var(--mono); letter-spacing: .06em; text-transform: uppercase;
  margin-bottom: 6px;
}
#step-source { font-weight: 400; letter-spacing: 0; text-transform: none; opacity: .75; text-align: right; }
#step-card h1 { font-size: 20px; line-height: 1.35; margin: 0 0 10px; letter-spacing: -.01em; }
#step-body { color: #c7d2de; font-size: 13.5px; }
#step-body p { margin: 6px 0; }
#step-body .target { color: var(--accent); font-family: var(--mono); font-weight: 700; }
#step-body .warn { color: var(--warning); }
.model-hint { color: var(--warning); font: 12px/1.5 var(--mono); margin-top: 8px; }
#step-feedback { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.55; }
#step-feedback.bad { background: color-mix(in srgb, var(--error) 14%, transparent); border: 1px solid color-mix(in srgb, var(--error) 45%, var(--border)); color: #ffb1ab; }
#step-feedback.good { background: color-mix(in srgb, var(--success) 12%, transparent); border: 1px solid color-mix(in srgb, var(--success) 40%, var(--border)); color: #9be8b6; }
#step-nav { display: flex; justify-content: flex-start; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
#step-nav .btn { opacity: .8; }

/* ---------- 控件 ---------- */
.btn {
  font: 500 14px var(--sans); color: var(--fg); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-ctl); padding: 8px 14px;
  cursor: pointer; transition: border-color var(--t-micro, 120ms), transform var(--t-micro, 120ms), background var(--t-micro, 120ms);
}
.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08111f; font-weight: 600; }
.btn.small { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #08111f; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="number"], select {
  background: #0d1117; color: var(--fg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font: 14px var(--mono); min-width: 120px;
}
select { font-family: var(--sans); }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.choices { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

/* ---------- 万用表 ---------- */
.meter {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .035); border: 1px solid var(--border);
}
.meter .probe-info { font: 12px/1.5 var(--mono); color: var(--muted); margin-top: 8px; }
.dmm-top { display: flex; gap: 10px; align-items: stretch; }
.dmm-screen {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 8px; background: #0a2416; border: 1px solid #1f5a37;
}
.dmm-mode {
  padding: 2px 6px; border-radius: 4px; border: 1px solid #1f5a37;
  font: 600 11px var(--mono); color: #3fb950;
}
.dmm-jacks { display: flex; gap: 8px; }
.jack { width: 52px; text-align: center; font: 600 10px var(--mono); color: var(--muted); }
.jack-hole {
  display: block; width: 22px; height: 22px; margin: 0 auto 3px; border-radius: 50%;
  background: #080b0f; border: 2px solid #4b5563; box-shadow: inset 0 0 0 3px #161b22;
}
.jack.black .jack-hole { border-color: #8d99a6; }
.jack.red .jack-hole { border-color: #c8382f; }
.jack b { display: block; color: var(--fg); font-size: 10px; }
.jack small { display: block; font-size: 9px; color: var(--muted); }
.dmm-dial {
  position: relative; width: 150px; height: 150px; margin: 12px auto 6px; border-radius: 50%;
  border: 2px solid #2b3138; background: radial-gradient(circle at 40% 30%, #1b222c, #0b0e13 70%);
}
.dmm-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%;
  background: #2b3138; border: 2px solid #4b5563; transform: translate(-50%, -50%) rotate(0deg);
  transition: transform .18s var(--ease); box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.dmm-knob::after {
  content: ''; position: absolute; left: 50%; top: 3px; width: 3px; height: 20px;
  border-radius: 2px; background: var(--accent); transform: translateX(-50%);
}
.dmm-range {
  position: absolute; padding: 2px 4px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font: 600 11px var(--mono);
}
.dmm-range[data-range=off] { left: 50%; top: 6px; transform: translateX(-50%); }
.dmm-range[data-range=ohm] { right: 6px; top: 50%; transform: translateY(-50%); }
.dmm-range[data-range=volt] { left: 50%; bottom: 6px; transform: translateX(-50%); }
.dmm-range[data-range=cont] {
  left: 5px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.dmm-ico { width: 18px; height: 12px; fill: currentColor; vertical-align: -2px; }
.dmm-beep { display: flex; align-items: center; gap: 3px; font: 600 10px var(--mono); color: var(--muted); }
.dmm-beep.open { color: var(--success); }
.dmm-beep.short { color: var(--error); }
.dmm-range.on { color: var(--accent); text-shadow: 0 0 8px rgba(79, 143, 247, .55); }
.dmm-help { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.dmm-help i {
  display: inline-block; width: 15px; height: 15px; line-height: 15px; text-align: center;
  margin-right: 4px; border-radius: 50%; background: var(--surface-2); color: var(--fg);
  font: 600 9px var(--mono); font-style: normal;
}
.dmm-help b { color: var(--accent); font-family: var(--mono); }
.probe-tag {
  display: inline-block; min-width: 16px; margin: 0 4px 0 0; padding: 1px 4px;
  border-radius: 4px; text-align: center; font: 600 10px var(--mono); color: #fff;
}
.probe-tag.a { background: #c8382f; }
.probe-tag.b { background: #1b1e24; border: 1px solid #4b5563; color: #cbd5e1; }
.dmm-readout {
  font: 600 22px var(--mono); letter-spacing: 1px; min-width: 72px;
  color: #7ef0a0; text-align: right; font-variant-numeric: tabular-nums;
}

/* ---------- 场景提示 / 镜头 ---------- */
#scene-hint {
  right: 20px; bottom: 20px; max-width: 430px; text-align: right;
  color: var(--muted); font-size: 12px; line-height: 1.5;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}
.scene-buttons { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.scene-buttons .btn { background: rgba(11, 14, 19, .8); }
#btn-reset { right: 20px; bottom: 96px; z-index: 25; opacity: .8; }

/* ---------- 采购清单 ---------- */
#procurement {
  right: 20px; top: 68px; width: min(440px, calc(100vw - 40px));
  max-height: calc(100vh - 110px); overflow: auto; padding: 14px 16px; z-index: 36;
}
#proc-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; }
#proc-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
}
#proc-list li:last-child { border-bottom: 0; }
#proc-list b { font-size: 13px; }
#proc-list .qty { color: var(--accent); font: 600 11.5px var(--mono); }
#proc-list .spec { grid-column: 1 / -1; color: var(--muted); font-size: 11.5px; line-height: 1.45; }

/* ---------- 步骤抽屉 ---------- */
#step-drawer {
  right: 20px; top: 68px; width: min(340px, calc(100vw - 40px));
  max-height: calc(100vh - 110px); overflow: auto; padding: 14px 16px;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.drawer-head h3 { margin: 0; font-size: 14px; font-family: var(--mono); }
#step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
#step-list li {
  display: flex; gap: 8px; align-items: baseline; padding: 5px 6px; border-radius: 7px;
  color: var(--muted); font-size: 12.5px; line-height: 1.45;
}
#step-list li .no { font: 600 10.5px var(--mono); min-width: 24px; text-align: right; opacity: .7; }
#step-list li.done { color: #9ddcb2; }
#step-list li.done .no { color: var(--success); opacity: 1; }
#step-list li.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--fg); }
#step-list li.on .no { color: var(--accent); opacity: 1; }
/* ---------- Toast ---------- */
#toast {
  left: 50%; top: 68px; transform: translateX(-50%);
  max-width: min(640px, calc(100vw - 32px));
  padding: 9px 15px; border-radius: var(--r-pill);
  background: rgba(11, 14, 19, .94); border: 1px solid var(--border);
  font-size: 13px; color: var(--fg); z-index: 40; pointer-events: none;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  transition: opacity .2s ease, transform .2s ease;
}
#toast.ok { border-color: color-mix(in srgb, var(--success) 55%, var(--border)); }
#toast.bad { border-color: color-mix(in srgb, var(--error) 55%, var(--border)); color: #ffc2bd; }

/* ---------- 完成 ---------- */
#complete {
  inset: 0; z-index: 50; background: rgba(5, 8, 12, .62);
  display: grid; place-items: center; padding: 24px; overflow: auto;
}
#complete[hidden] { display: none; }
.complete-card { width: min(720px, 100%); padding: 22px 24px; max-height: 94vh; overflow: auto; }
.complete-card .kicker { color: var(--success); font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.complete-card h2 { margin: 6px 0 10px; font-size: 26px; letter-spacing: -.02em; }
.complete-card p { color: #c7d2de; font-size: 14px; }

/* ---------- 常驻注记（最后一步完成后） ---------- */
#anno-layer { position: fixed; inset: 0; z-index: 18; pointer-events: none; }
#anno-layer[hidden] { display: none; }
.anno-dot {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 35%, transparent);
  transform: translate(-50%, -50%); box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 55%, transparent);
}
.anno-line {
  position: absolute; height: 0; border-top: 1px dashed color-mix(in srgb, var(--accent) 75%, transparent);
  transform-origin: 0 0; opacity: .9;
}
.anno-box {
  position: absolute; padding: 6px 9px; border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: rgba(11, 14, 19, .93); color: var(--fg);
  font: 12px/1.35 var(--sans); white-space: nowrap;
  transform: translate(-50%, -50%); box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
.anno-box b { color: var(--accent); font-family: var(--mono); font-weight: 600; }

/* ---------- TF 烧录伪终端 ---------- */
#tf-term {
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  right: auto; bottom: auto; z-index: 40; padding: 0; overflow: hidden;
  width: min(1180px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; font-family: var(--mono);
}
#tf-term[hidden] { display: none; }
.term-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.term-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 8px var(--success); flex: none;
}
#tf-term[data-state=running] .term-dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); animation: term-pulse 1s infinite; }
#tf-term[data-state=ready] .term-dot { background: var(--success); }
.term-name { font: 600 12px var(--mono); letter-spacing: .04em; }
.term-path { font-size: 11.5px; color: var(--muted); }
.term-head .btn { margin-left: auto; }
.term-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; }
.term-pane { display: flex; flex-direction: column; min-width: 0; background: #07090c; }
.term-out {
  height: 320px; overflow: auto; padding: 10px 12px;
  font: 12px/1.55 var(--mono); color: #c9d6e2; white-space: pre-wrap; word-break: break-word;
}
.term-line { min-height: 1.2em; }
.term-line.sys { color: var(--accent); }
.term-line.cmd { color: var(--fg); }
.term-line.dim { color: var(--muted); }
.term-line.hint { color: var(--warning); }
.term-line.bad { color: #ff8b84; }
.term-line.ok { color: #7ee2a8; }
.term-input-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border-top: 1px solid var(--border); background: #0a0d12;
}
.term-input-row[hidden] { display: none; }
.term-prompt { color: var(--success); font-size: 12px; white-space: nowrap; }
#tf-term-input {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--fg);
  font: 12px var(--mono); padding: 6px 2px; caret-color: var(--accent);
}
#tf-term-input:focus { outline: none; }
.term-side {
  padding: 12px 14px; border-left: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow: auto;
}
.term-side .kicker { font: 600 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.term-cmd {
  display: block; padding: 8px 9px; border-radius: 8px; user-select: all; min-width: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: #cfe0ff; font: 11px/1.55 var(--mono); word-break: break-all;
}
.term-params { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.term-params li { display: flex; flex-direction: column; gap: 1px; font: 11px/1.45 var(--mono); color: #c9d6e2; cursor: help; }
.term-params b { color: var(--accent); font-weight: 600; }
.term-params span { color: var(--muted); font-family: var(--sans); font-size: 11px; }
.term-hint { margin: 0; color: var(--muted); font: 11.5px/1.5 var(--sans); }
.term-hint.ok { color: #7ee2a8; }
.term-doc { font: 11.5px var(--sans); color: var(--accent); }
.term-copy { align-self: flex-start; }
@keyframes term-pulse { 50% { opacity: .35; } }

/* ---------- 载入 ---------- */
#loading {
  left: 50%; top: 52%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 10px; padding: 12px 18px;
  color: var(--muted); font-size: 13px; z-index: 35;
}
#loading[hidden] { display: none; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading.error { color: #ffb1ab; max-width: min(520px, calc(100vw - 40px)); text-align: left; }
#loading.error .spinner { display: none; }

@media (max-width: 760px) {
  #hud-top { gap: 8px; padding: 10px 12px; }
  #hud-top .brand { display: none; }
  .github-link { font-size: 10px; max-width: 44vw; padding: 4px 7px; }
  #hud-progress { max-width: none; }
  #hud-count { font-size: 11px; }
  #hud-steps-toggle { display: none; }
  #step-card { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 48vh; padding: 14px; }
  #step-card h1 { font-size: 17px; }
  #scene-hint { display: none; }
  #btn-reset { right: 10px; bottom: auto; top: 66px; }
  #step-drawer { left: 10px; right: 10px; width: auto; top: 56px; max-height: 52vh; }
  #procurement { left: 10px; right: 10px; width: auto; top: 56px; max-height: 58vh; }
  .complete-card { padding: 16px; }
  #tf-term { left: 10px; right: 10px; top: 10px; bottom: 10px; transform: none; width: auto; max-height: none; }
  .term-grid { grid-template-columns: 1fr; }
  .term-side { border-left: 0; border-top: 1px solid var(--border); }
  .term-out { height: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
