:root {
  color-scheme: dark;
  --bg: #0f0e0d;
  --surface: #161514;
  --fg: #e6e2db;
  --strong: #f4f1ec;
  --muted: hsl(36 10% 86% / .66);
  --border: hsl(36 12% 70% / .12);
  --accent: #c9b48c;
  --accent-fg: #17140f;
  --accent-hover: #d9c7a3;
  --stroke: #7d776d;
  --stroke-mid: #57524c;
  --stroke-low: #3a3733;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.7 var(--sans);
  --hairline-plate: var(--bg);
  --hairline-hi: var(--accent);
  --hairline-edge: var(--stroke);
  --hairline-mid: var(--stroke-mid);
  --hairline-lo: var(--stroke-low);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .35; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }
main:focus { outline: none; }
::selection { background: var(--accent); color: var(--accent-fg); }
header, main, #result, footer { width: min(840px, calc(100% - 48px)); margin-inline: auto; }
header { height: 96px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.brand { text-decoration: none; font-size: 15px; letter-spacing: .1em; font-weight: 550; }
.brand span { border-left: 1px solid var(--border); padding-left: 16px; margin-left: 12px; font-size: 13px; font-weight: 400; }
.quiet { background: none; color: var(--muted); border: 0; padding: 8px; font-size: 12px; }
.quiet:hover { color: var(--strong); }
.welcome { min-height: 480px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px; }
h1 { font-size: 36px; font-weight: 500; line-height: 1.3; letter-spacing: -.025em; color: var(--strong); margin: 0; }
.welcome h1 { font-size: 88px; letter-spacing: -.06em; }
.welcome h1 span { color: var(--muted); }
.primary { min-height: 44px; padding: 10px 28px; border: 1px solid transparent; border-radius: 5px; background: var(--accent); color: var(--accent-fg); font-weight: 550; }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary { background: none; color: var(--fg); border: 1px solid var(--stroke); padding: 9px 20px; border-radius: 5px; }
.secondary:hover { background: var(--bg); }
.chapter { margin: 36px auto; padding: 112px 14% 90px; }
.chapter-number { font: 12px/1.7 var(--mono); color: var(--muted); margin: 0; }
.panel { position: relative; max-width: 780px; transform: translate(var(--device-shift, 0px), var(--device-drop, 0px)); }
.device-face { position: relative; padding: 28px; background: var(--surface); border: 1px solid var(--stroke-mid); border-radius: 12px; }
.device-face::before { content: ""; position: absolute; inset: 6px; border: 1px solid var(--border); border-radius: 7px; pointer-events: none; }
.device-face::after { content: ""; position: absolute; inset: 0; border: 1px solid var(--strong); border-radius: inherit; opacity: var(--failure-flash, 0); pointer-events: none; }
.fasteners { position: absolute; inset: 12px; pointer-events: none; }
.fasteners i { position: absolute; width: 8px; height: 8px; border: 1px solid var(--stroke-mid); border-radius: 50%; }
.fasteners i::after { content: ""; position: absolute; top: 2px; left: 0; width: 6px; border-top: 1px solid var(--stroke-mid); transform: rotate(-45deg); }
.fasteners i:nth-child(1) { top: 0; left: 0; }
.fasteners i:nth-child(2) { top: 0; right: 0; }
.fasteners i:nth-child(3) { bottom: 0; left: 0; }
.fasteners i:nth-child(4) { bottom: 0; right: 0; }
.panel-heading, .panel-body, .panel-footer { position: relative; }
.panel-heading { display: flex; align-items: center; justify-content: flex-end; padding: 0 8px 16px; border-bottom: 1px solid var(--border); }
.outcome-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 10; }
.panel-body { padding: 24px 8px; }
.panel-body::after { content: ""; position: absolute; left: 0; right: 0; top: calc(var(--success-progress, 0) * 100%); height: 1px; background: var(--stroke); opacity: var(--success-sweep, 0); pointer-events: none; }
.panel .bomb-stage { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; --hairline-plate: var(--surface); }
.bomb-stage svg { width: 100%; height: 100%; display: block; }
.controls { min-width: 0; }
.control-well { min-height: 228px; display: flex; align-items: center; justify-content: center; }
.controls .primary { width: 80px; min-height: 80px; padding: 0; border-radius: 50%; outline: 1px solid var(--stroke-mid); outline-offset: 6px; }
.controls .primary:focus-visible { outline: 2px solid var(--accent); }
.readout { padding: 16px; background: var(--bg); border: 1px solid var(--stroke); border-radius: 6px; }
.readout label { margin: 0; color: var(--muted); font-size: 12px; }
.readout input { min-height: 64px; padding: 8px 0; background: none; border: 0; border-radius: 0; font-size: 14px; }
.control-actions { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 32px; padding-inline: 8px; }
.control-actions button { margin-top: 0; }
.sample-control { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sample-control output { min-height: 20px; }
.panel-footer:has(#result[hidden]) { display: none; }
.panel-footer #result { width: 100%; margin: 0; padding: 24px 8px 0; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
[data-state]:empty { display: none; }
[data-state], #sample-state { color: var(--muted); font-size: 12px; }
form { width: 100%; }
label { display: block; font-size: 13px; margin-bottom: 10px; }
input { width: 100%; min-height: 46px; padding: 10px 12px; background: var(--bg); color: var(--fg); border: 1px solid var(--stroke); border-radius: 5px; font: 12px/1.8 var(--mono); }
form button { margin-top: 20px; }
#result { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 20px 0; border-top: 1px solid var(--border); margin-bottom: 24px; }
#result p { margin: 0; font-size: 13px; }
#result p:empty { display: none; }
#result-text { color: var(--muted); }
#next { flex-shrink: 0; }
.complete { min-height: calc(100svh - 96px); padding: 32px 0 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
.complete h1 { font-size: 52px; }
.complete .primary { margin-top: 8px; }
.trophy-stage { --hairline-edge: var(--muted); --hairline-mid: var(--stroke); --hairline-lo: var(--stroke-mid); position: relative; width: min(440px, 100%, max(280px, calc(100svh - 360px))); aspect-ratio: 5 / 4; }
.trophy-stage[data-reveal="pending"] { visibility: hidden; }
.trophy-stage:not([data-reveal="ready"]) { pointer-events: none; }
.trophy-stage > svg { position: absolute; inset: 0; width: 25%; height: 25%; overflow: visible; }
@media (prefers-reduced-motion: reduce) { .trophy-stage { pointer-events: none; } }
footer { padding: 22px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
@media (max-width: 720px) {
  header { height: 76px; }
  .chapter { margin: 24px auto; }
  .device-face { padding: 24px; }
  .panel-heading, .panel-body, .panel-footer #result { padding-inline: 0; }
}
@media (max-width: 420px) {
  .chapter { padding-inline: 12%; }
  .device-face { padding: 20px; }
  .control-actions { padding-inline: 0; }
  #result { align-items: flex-start; flex-direction: column; gap: 16px; }
}
