:root {
  --wood: #c9a66a;
  --wood-dark: #8b5e3c;
  --wood-deep: #5c3d24;
  --acrylic: rgba(180, 220, 255, 0.25);
  --metal: #a8b0b8;
  --bg: #0d1117;
  --panel: rgba(18, 24, 32, 0.92);
  --border: rgba(255, 200, 120, 0.22);
  --text: #f0e6d8;
  --muted: #9a8f82;
  --accent: #f0b429;
  --green: #3dd68c;
  --blue: #4db8ff;
  --red: #ff6b6b;
  --glow: 0 0 24px rgba(240, 180, 41, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #1a2433 0%, var(--bg) 70%);
  color: var(--text);
  user-select: none;
}

#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#c.dragging { cursor: grabbing; }
#c.hover-interact { cursor: pointer; }

/* HUD */
#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(180deg, rgba(0,0,0,0.65), transparent);
  pointer-events: none;
  z-index: 10;
}
#hud-top > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 15px;
}
.brand .bolt { color: var(--accent); filter: drop-shadow(0 0 6px var(--accent)); }
.brand .sub { font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: 0; }

#charge-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  min-width: 220px;
}
.charge-label { font-size: 10px; letter-spacing: 0.12em; color: var(--muted); }
.charge-track {
  flex: 1;
  height: 8px;
  background: #1e2836;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #2a3545;
}
#charge-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4db8ff, #3dd68c);
  border-radius: 4px;
  transition: width 0.15s linear, background 0.3s;
}
#charge-fill.full { background: linear-gradient(90deg, #3dd68c, #7dffb3); box-shadow: 0 0 12px var(--green); }
#charge-fill.flashing { animation: pulse 0.6s ease-in-out infinite; }
#charge-status { font-size: 11px; min-width: 48px; text-align: right; color: var(--muted); }
#charge-status.green { color: var(--green); font-weight: 600; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.hud-actions { display: flex; gap: 8px; }

.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: #1c2736; border-color: var(--accent); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(180deg, #e8a820, #c48410);
  border-color: #f0c050;
  color: #1a1206;
  font-weight: 700;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.large { padding: 12px 28px; font-size: 16px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Inventory */
#inventory {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  z-index: 10;
  backdrop-filter: blur(10px);
}
.inv-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}
#inv-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 40px;
}
.inv-item {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #151c28;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.inv-item:hover, .inv-item.selected {
  border-color: var(--accent);
  box-shadow: var(--glow);
}
.inv-item .tag {
  font-size: 8px;
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.04em;
}
.inv-item.weight .mass-dot {
  position: absolute;
  bottom: 3px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
}
#inv-hint { font-size: 11px; margin-top: 6px; }

/* Face nav */
#face-nav {
  position: absolute;
  left: 50%;
  bottom: 56px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 10;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px;
  backdrop-filter: blur(8px);
}
#face-nav button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #151c28;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
#face-nav button:hover, #face-nav button.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow);
}

/* Side badge */
#side-badge {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 12px;
  color: var(--muted);
  z-index: 10;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  backdrop-filter: blur(8px);
}

/* Focus / panels */
#focus-panel, .panel-card {
  position: absolute;
  top: 70px;
  right: 14px;
  width: min(380px, calc(100vw - 28px));
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  z-index: 20;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}
.hidden { display: none !important; }

.focus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}
.focus-header h2, #focus-title { font-size: 16px; font-weight: 700; }

.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.45; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.check { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* Interactive widgets inside focus */
.widget-grid {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.widget-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.hole, .slider-btn, .pin-btn, .pcb-btn, .chip {
  border: 1px solid var(--border);
  background: #151c28;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  min-width: 44px;
  text-align: center;
  transition: all 0.15s;
}
.hole:hover, .slider-btn:hover, .pin-btn:hover, .pcb-btn:hover {
  border-color: var(--accent);
}
.hole.filled { background: #2a2218; border-color: var(--wood); }
.hole.correct { box-shadow: 0 0 0 1px var(--green); }
.slider-btn.active, .pin-btn.active {
  background: #2a3a20;
  border-color: var(--green);
  color: var(--green);
}
.slider-btn.pressed {
  background: #1a3048;
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 0 12px rgba(77, 184, 255, 0.4);
}
.pcb-btn {
  width: 48px;
  height: 36px;
  font-family: monospace;
}
.pcb-btn.on {
  background: #3a2010;
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(240, 180, 41, 0.5);
}
.pcb-btn.lock-key {
  outline: 1px dashed rgba(61, 214, 140, 0.35);
}
.compare-lights {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin: 12px 0;
  font-size: 28px;
}
.compare-lights .lit {
  color: var(--blue);
  text-shadow: 0 0 16px var(--blue);
  animation: pulse 1s infinite;
}
.compare-lights .dim { opacity: 0.2; }

.clock-face-ui {
  width: 220px;
  height: 220px;
  margin: 12px auto;
  border-radius: 50%;
  border: 3px solid var(--wood);
  background: radial-gradient(circle at 40% 35%, #d4a574, #8b5e3c 70%, #5c3d24);
  position: relative;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.35);
}
.clock-num {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: #2a1a0a;
  transform: translate(-50%, -50%);
}
.clock-hand {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 78px;
  background: #2a1a0a;
  transform-origin: 50% 100%;
  border-radius: 2px;
  margin-left: -2px;
  margin-top: -78px;
  transition: transform 0.35s ease;
}
.clock-hub {
  position: absolute;
  left: 50%; top: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: #2a1a0a;
}
.seq-pills {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}
.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: #151c28;
  border: 1px solid var(--border);
  font-size: 12px;
}
.pill.ok { border-color: var(--green); color: var(--green); }

/* Scale viz */
#scale-viz {
  position: relative;
  height: 140px;
  margin: 16px 0;
  background: #0f1520;
  border-radius: 10px;
  border: 1px solid #243044;
  overflow: hidden;
}
.scale-fulcrum {
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: 10px;
  height: 40px;
  margin-left: -5px;
  background: var(--metal);
  border-radius: 2px;
}
#scale-beam {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 48px;
  height: 14px;
  background: linear-gradient(180deg, #c0c8d0, #6a727a);
  border-radius: 3px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transform-origin: center center;
  transition: transform 0.45s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.scale-end {
  width: 70px;
  text-align: center;
  margin-top: -36px;
}
.magnet-slot {
  background: #1a2433;
  border: 1px dashed var(--metal);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 12px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  gap: 2px;
}
.magnet-slot.has-weight {
  border-style: solid;
  border-color: var(--accent);
  background: #2a2218;
}
.magnet-slot .w-name { font-size: 10px; color: var(--accent); }
.attach-label { font-size: 9px; color: var(--muted); margin-top: 4px; }
.scale-pivot { font-size: 10px; color: #333; margin-top: -2px; }
#scale-result {
  position: absolute;
  bottom: 6px;
  left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Weight chips for placement */
.weight-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #2a2218;
  border: 1px solid var(--wood);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  margin: 2px;
}
.weight-chip.selected { border-color: var(--accent); box-shadow: var(--glow); }

/* Toast */
#toast {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--glow);
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#event-log {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 240px;
  max-height: 120px;
  overflow: hidden;
  font-size: 11px;
  color: var(--muted);
  z-index: 10;
  pointer-events: none;
  text-align: right;
  line-height: 1.5;
  mask-image: linear-gradient(to bottom, transparent, black 30%);
}

/* Modals */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 12, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(6px);
}
.modal-card {
  background: linear-gradient(160deg, #1a2433, #121820);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.55);
}
.modal-card.wide { max-width: 560px; max-height: 80vh; overflow-y: auto; }
.modal-card.win { text-align: center; }
.modal-card h1 {
  font-size: 28px;
  margin-bottom: 10px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(240, 180, 41, 0.4);
}
.modal-card .lead { margin-bottom: 14px; color: var(--text); line-height: 1.5; }
.modal-card ul {
  margin: 0 0 16px 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
.prize-viz { font-size: 42px; margin: 16px 0; letter-spacing: 8px; }

.hint-section {
  border-top: 1px solid #243044;
  padding: 12px 0;
}
.hint-section h3 { font-size: 14px; color: var(--accent); margin-bottom: 6px; }
.hint-section p { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 4px; }
.hint-section .spoiler {
  background: #0a0e14;
  color: #0a0e14;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  transition: color 0.2s;
  user-select: none;
}
.hint-section .spoiler:hover, .hint-section .spoiler.revealed {
  color: var(--text);
}

/* Progress dots */
#progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 0;
}
.prog-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2a3545;
  border: 1px solid #3a4555;
}
.prog-dot.done { background: var(--green); border-color: var(--green); box-shadow: 0 0 8px var(--green); }
.prog-dot.current { background: var(--accent); border-color: var(--accent); }

/* Coil path UI */
.coil-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 10px 0;
}
.coil-pin {
  background: #151c28;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 4px;
  text-align: center;
  font-size: 12px;
}
.coil-pin .val {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stepper {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 6px;
}
.stepper button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1a2433;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.stepper button:hover { border-color: var(--accent); }

.path-trace {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: #0f1520;
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  line-height: 1.6;
  margin: 8px 0;
}

/* Disc aligner for clock */
.disc-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
}
.disc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.disc-row input[type="range"] { flex: 1; }

@media (max-width: 720px) {
  #inventory {
    width: auto;
    max-width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
    bottom: 100px;
  }
  #event-log { display: none; }
  #charge-meter { min-width: 0; flex: 1; }
  .brand .sub { display: none; }
  #face-nav { bottom: 48px; }
  #face-nav button { width: 32px; height: 32px; font-size: 12px; }
  #side-badge { bottom: 8px; font-size: 11px; }
  #focus-panel, .panel-card {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 55vh;
    border-radius: 16px 16px 0 0;
  }
}
