:root {
  --bg0: #0c1410;
  --bg1: #152018;
  --panel: rgba(12, 18, 14, 0.88);
  --copper: #c9853a;
  --copper-dim: #8a5a28;
  --cyan: #2ee6d6;
  --cyan-dim: #1a9e94;
  --text: #f2e8d8;
  --muted: #a8b0a4;
  --line: rgba(46, 230, 214, 0.25);
  --danger: #e07040;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #1a2a1c 0%, #0c1410 55%, #070b08 100%);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#c {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Top bar */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(8,12,10,0.6), rgba(8,12,10,0.18) 70%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.brand .wordmark {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
  font-weight: 700;
}
.brand h1 {
  font-size: clamp(14px, 3.4vw, 20px);
  font-weight: 650;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand { text-shadow: 0 1px 3px rgba(0,0,0,0.65); }
.brand a {
  color: #f2e8d8;
  font-size: 12px;
  text-decoration: none;
}
.brand a:hover { color: var(--cyan); }

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Bottom controls */
.controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row label.explode-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 56px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#explodeRange {
  flex: 1;
  min-width: 120px;
  accent-color: var(--cyan);
  height: 28px;
  cursor: pointer;
}

#explodePct {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--cyan);
  min-width: 40px;
  text-align: right;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(46, 230, 214, 0.08);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: rgba(46, 230, 214, 0.18); border-color: var(--cyan-dim); }
.btn:active { transform: scale(0.97); }
.btn.active {
  background: rgba(46, 230, 214, 0.28);
  border-color: var(--cyan);
  color: #fff;
}
.btn.primary {
  background: linear-gradient(135deg, #b87333, #d4a05a);
  border-color: #e0b070;
  color: #1a1008;
}
.btn.primary:hover { filter: brightness(1.08); }

/* Side panel */
.side {
  position: absolute;
  top: 72px;
  right: 12px;
  bottom: 140px;
  width: min(300px, calc(100vw - 24px));
  z-index: 18;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.side > * { pointer-events: auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.card h2 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 6px;
}
.card .part-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--copper);
  margin-bottom: 4px;
}
.card .part-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.card .hint {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
}

.parts-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.parts-list ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.parts-list button {
  width: 100%;
  text-align: left;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.parts-list button:hover { background: rgba(46, 230, 214, 0.1); }
.parts-list button.selected {
  background: rgba(201, 133, 58, 0.22);
  color: #ffd9a0;
}

.hint-bar {
  position: absolute;
  left: 12px;
  top: 72px;
  z-index: 15;
  max-width: min(280px, calc(100vw - 340px));
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c1410;
  transition: opacity 0.4s;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loading span {
  color: var(--cyan);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Mobile: stack UI */
@media (max-width: 720px) {
  .side {
    top: auto;
    bottom: auto;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: none;
    position: absolute;
    /* keep info card near top-right when space; collapse list under controls on very small */
    top: 68px;
    bottom: unset;
    width: min(260px, 48vw);
  }
  .parts-list { display: none; }
  .hint-bar { display: none; }
  .controls { bottom: 8px; left: 8px; right: 8px; padding: 10px; }
  .brand h1 { font-size: 13px; }
  .btn { padding: 8px 10px; font-size: 12px; }
}

@media (max-width: 420px) {
  .side { width: calc(100vw - 24px); left: 12px; right: 12px; }
  .card .part-name { font-size: 16px; }
  .row .btn.extra { display: none; }
}

/* v2: labels with SVG leader lines */
.label-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 12; display: none; }
.label-layer.on { display: block; }
.leader-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.leader { fill: none; stroke: rgba(20, 40, 34, 0.85); stroke-width: 1.4; }
.leader-dot { fill: #2ee6d6; stroke: #0c1410; stroke-width: 1; }
.part-label {
  position: absolute; white-space: nowrap;
  font: 600 11px/1.2 var(--font); color: #eafffb;
  background: rgba(10, 22, 18, 0.82); border: 1px solid rgba(46, 230, 214, 0.5);
  padding: 2px 7px; border-radius: 6px;
}
