:root {
  --bg: #f6f4f1;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a64;
  --border: rgba(29, 27, 25, 0.12);
  --accent: #e8743b;
  --accent-soft: #f4a26f;
  --topbar: #161514;
  --topbar-text: #f3f1ee;
  --shadow: 0 8px 28px rgba(20, 16, 12, 0.12);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --panel: rgba(30, 28, 27, 0.82);
    --panel-solid: #1e1c1b;
    --text: #f1eeea;
    --muted: #a39d96;
    --border: rgba(255, 255, 255, 0.12);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Top bar */
.topbar {
  height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--topbar);
  color: var(--topbar-text);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; letter-spacing: 0.01em; }
.brand svg { width: 22px; height: 22px; }
.brand b { font-weight: 600; }
.model-pick select {
  max-width: 52vw;
  background: #262422;
  color: var(--topbar-text);
  border: 1px solid #3a3734;
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
}

/* Stage */
.stage { position: relative; flex: 1; min-height: 0; transition: background 0.3s; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }

.info {
  position: absolute;
  top: 16px;
  left: 16px;
  max-width: min(360px, calc(100% - 32px));
  padding: 14px 16px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.info h1 { margin: 0; font-size: 18px; font-weight: 650; }
.info p { margin: 4px 0 0; color: var(--muted); }
.info p:empty { display: none; }
.stats { display: flex; gap: 18px; margin: 12px 0 0; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.parts { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.parts h2 { margin: 0 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.parts ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.parts button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.parts button:hover { background: var(--border); }
.parts button.on { background: color-mix(in srgb, var(--accent) 16%, transparent); font-weight: 600; }
.parts button span, .spot {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* Hotspots (positioned every frame from JS) */
.hotspots { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.spot {
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  pointer-events: auto;
  font: 700 13px/1 system-ui, sans-serif;
}
.spot::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: pulse 2.4s ease-out infinite;
}
.spot.on { background: #fff; color: var(--accent); border-color: var(--accent); }
@keyframes pulse { 0% { transform: scale(0.7); opacity: 0.8; } 100% { transform: scale(1.5); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .spot::after { animation: none; } }

.card {
  position: absolute;
  top: 16px;
  right: 76px;
  width: min(300px, calc(100% - 32px));
  padding: 14px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 24px 4px 0; font-size: 16px; }
.card p { margin: 0; color: var(--muted); }
.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}
.card-close:hover { background: var(--border); color: var(--text); }

.explode-box {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 600;
}
.explode-box input { width: 160px; accent-color: var(--accent); }

/* Loader */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  transition: opacity 0.4s;
}
.loader.done { opacity: 0; pointer-events: none; }
.ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { display: grid; justify-items: center; }
.loader-text span { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.loader-text small { color: var(--muted); }
.bar { width: 200px; height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

.error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  padding: 16px 20px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-left: 4px solid #d64545;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.drop {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  font-size: 16px;
  font-weight: 600;
  pointer-events: none;
}

/* Toolbar */
.toolbar {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toolbar button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.toolbar button:hover { background: var(--border); }
.toolbar button.on { background: var(--accent); color: #fff; }
.toolbar button:focus-visible, .bgs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar .sep { height: 1px; margin: 2px 6px; background: var(--border); }

/* Background chips */
.bgs {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.bgs button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
}
.bgs button.on { box-shadow: 0 0 0 2px var(--panel-solid), 0 0 0 4px var(--accent); }

.hint {
  position: absolute;
  right: 16px;
  bottom: 16px;
  margin: 0;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-radius: 999px;
  pointer-events: none;
}

@media (max-width: 640px) {
  .brand span { display: none; }
  .info { padding: 10px 12px; }
  .info h1 { font-size: 16px; }
  .stats { gap: 12px; }
  .toolbar { top: auto; bottom: 64px; right: 12px; transform: none; }
  .bgs { left: 12px; bottom: 12px; }
  .hint { display: none; }
  .parts { display: none; }
  .card { top: auto; right: 12px; left: 12px; bottom: 60px; width: auto; }
  .explode-box { bottom: 60px; }
  .card:not([hidden]) ~ .explode-box { display: none; }
}
