:root {
  --bg-0: #05080f;
  --bg-1: #0b1220;
  --bg-2: #111a2e;
  --line: #1d2944;
  --text: #e6edf7;
  --text-soft: #9aa7c2;
  --accent: #6fa8ff;
  --accent-2: #8be9c4;
  --danger: #ff6b6b;
  --warn: #ffd166;
  --code-bg: #0a1226;
  --shadow: 0 12px 40px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 20% -10%, #1a2745 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #102031 0%, transparent 50%),
    var(--bg-0);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  height: 100vh;
  gap: 0;
}

/* ───────────── SIDEBAR ───────────── */
#sidebar {
  background: linear-gradient(180deg, rgba(11,18,32,.95) 0%, rgba(8,12,22,.92) 100%);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 18px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font-size: 16px; letter-spacing: .3px; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--text-soft); }
.logo-dot {
  width: 28px; height: 28px; border-radius: 9px;
  background: conic-gradient(from 0deg, #6fa8ff, #8be9c4, #ffd166, #6fa8ff);
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 8px 24px -10px #6fa8ff;
}

.boards { display: grid; gap: 10px; margin-bottom: 22px; }
.board-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border-radius: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
}
.board-card strong { font-size: 13px; }
.board-card small { display: block; color: var(--text-soft); font-size: 11px; margin-top: 4px; line-height: 1.4; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: none; }
.dot.esp { background: #2563eb; box-shadow: 0 0 14px #2563eb88; }
.dot.pca { background: #16a34a; box-shadow: 0 0 14px #16a34a88; }

.section-title {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--text-soft);
  margin: 0 0 10px;
}

.bom-list {
  list-style: none; padding: 0; margin: 0 0 22px;
  display: grid; gap: 6px;
}
.bom-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}
.bom-list .bom-qty {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px;
  background: rgba(111,168,255,0.18); color: var(--accent);
  border-radius: 6px;
  font-weight: 700; font-size: 11px;
  flex: none;
}
.bom-list .bom-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex: none;
}
.bom-list .bom-dot.esp   { background: #2563eb; box-shadow: 0 0 8px #2563eb88; }
.bom-list .bom-dot.exp   { background: #d62828; box-shadow: 0 0 8px #d6282888; }
.bom-list .bom-dot.pca   { background: #16a34a; box-shadow: 0 0 8px #16a34a88; }
.bom-list .bom-dot.servo { background: #1565c0; box-shadow: 0 0 8px #1565c088; }
.bom-list .bom-dot.wire  { background: linear-gradient(90deg,#d62828,#f1c40f,#0077ff); }
.bom-list .bom-dot.usb   { background: #b0b0b0; }
.bom-list strong { display: block; font-size: 12px; }
.bom-list small  { display: block; color: var(--text-soft); font-size: 10px; margin-top: 2px; }

.step-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.step-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg-1); border: 1px solid var(--line);
  font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.step-list li:hover { background: #14213d; border-color: #2d3f6d; }
.step-list li.active {
  background: linear-gradient(90deg, #15315b 0%, #0d1b35 100%);
  border-color: #4a7ed6;
  box-shadow: 0 0 0 1px #4a7ed644;
}
.step-list li.done::after {
  content: '✓';
  margin-left: auto;
  color: #2eb481;
  font-weight: 800;
  font-size: 14px;
}
.step-list li.done .step-name { color: var(--text-soft); }
.step-list .chip { width: 12px; height: 12px; border-radius: 4px; flex: none; box-shadow: 0 0 8px currentColor; }
.step-list .step-name { flex: 1; }
.step-list .opt {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: rgba(255,209,102,.12); color: var(--warn);
}

.hints {
  margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line);
  color: var(--text-soft); font-size: 11px; line-height: 1.8;
}
kbd {
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 4px; font-family: monospace; font-size: 10px;
}

/* ───────────── STAGE ───────────── */
#stage { position: relative; }
#webgl { display: block; width: 100%; height: 100%; cursor: grab; }
#webgl:active { cursor: grabbing; }

.floating-controls {
  position: absolute; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px; padding: 8px;
  background: rgba(11,18,32,.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.floating-controls button {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.floating-controls button:hover { background: #1a2747; }
.floating-controls button:active { transform: scale(.96); }
.floating-controls button.toggle.on  { background: #173968; border-color: #4a7ed6; color: #cfe3ff; }
.floating-controls button.toggle.off { opacity: .65; }

/* ───────────── PIN LABEL OVERLAY ───────────── */
#leader-lines, #pin-labels-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
#leader-lines { z-index: 1; }
#pin-labels-overlay { z-index: 2; }

.leader {
  stroke: rgba(111,168,255,0.45);
  stroke-width: 1;
  fill: none;
  stroke-linecap: round;
}
.leader.aux {
  stroke: rgba(154,167,194,0.22);
  stroke-dasharray: 2 3;
}
.leader[data-type="GND"]   { stroke: rgba(180,180,180,0.55); }
.leader[data-type="VCC"],
.leader[data-type="POWER"] { stroke: rgba(214,40,40,0.7); }
.leader[data-type="VPLUS"] { stroke: rgba(183,28,28,0.75); }
.leader[data-type="SDA"]   { stroke: rgba(0,119,255,0.7); }
.leader[data-type="SCL"]   { stroke: rgba(241,196,15,0.75); }
.leader[data-type="ADC"]   { stroke: rgba(26,188,156,0.65); }
.leader[data-type="UART"]  { stroke: rgba(142,68,173,0.65); }

.pin-label {
  position: absolute;
  top: 0; left: 0;
  background: rgba(11,18,32,0.94);
  border: 1px solid rgba(29,41,68,0.95);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  white-space: nowrap;
  pointer-events: auto;
  cursor: default;
  user-select: none;
  transition: border-color .12s, background .12s, transform .1s, box-shadow .12s;
  will-change: transform;
  backdrop-filter: blur(2px);
}
.pin-label.aux { opacity: .65; font-size: 10px; padding: 2px 6px; }
.pin-label .pl-sub {
  color: var(--text-soft);
  font-size: 9px;
  font-weight: 400;
  margin-left: 5px;
  letter-spacing: .3px;
}
.pin-label.hi {
  border-color: var(--accent);
  background: rgba(23,57,104,0.96);
  box-shadow: 0 0 0 2px rgba(111,168,255,0.25), 0 8px 20px -8px rgba(111,168,255,0.5);
  transform: scale(1.08) translate3d(0,0,0);
  opacity: 1 !important;
}

/* Color por tipo: borde izquierdo */
.pin-label[data-type="GND"]   { border-left: 3px solid #888; }
.pin-label[data-type="VCC"],
.pin-label[data-type="POWER"] { border-left: 3px solid #d62828; }
.pin-label[data-type="VPLUS"] { border-left: 3px solid #b71c1c; }
.pin-label[data-type="SDA"]   { border-left: 3px solid #0077ff; }
.pin-label[data-type="SCL"]   { border-left: 3px solid #f1c40f; }
.pin-label[data-type="ADC"]   { border-left: 3px solid #1abc9c; }
.pin-label[data-type="UART"]  { border-left: 3px solid #8e44ad; }
.pin-label[data-type="EN"]    { border-left: 3px solid #c2185b; }
.pin-label[data-type="OE"]    { border-left: 3px solid #aaa; }
.pin-label[data-type="IN"]    { border-left: 3px solid #5a6f99; }
.pin-label[data-type="IO"]    { border-left: 3px solid #3a4a6e; }
.pin-label[data-type="CH"]    { border-left: 3px solid #2d3f6d; }

/* Loader */
#loader {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--bg-0);
  z-index: 10;
}
#loader span {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── PIN DETAIL CARD ───────────── */
.pin-detail {
  position: fixed;
  right: 380px;
  bottom: 80px;
  width: 280px;
  background: linear-gradient(180deg, rgba(17,26,46,.98), rgba(11,18,32,.98));
  border: 1px solid rgba(111,168,255,0.3);
  border-radius: 12px;
  padding: 16px 18px 14px;
  box-shadow: 0 20px 50px -16px rgba(0,0,0,0.7);
  color: var(--text);
  z-index: 80;
  transform: translateY(10px); opacity: 0; pointer-events: none;
  transition: transform .18s, opacity .18s;
}
.pin-detail.visible { transform: translateY(0); opacity: 1; pointer-events: auto; }
.pd-close {
  position: absolute; top: 8px; right: 10px;
  background: transparent; border: 0; color: var(--text-soft);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.pd-close:hover { color: var(--text); }
.pd-header { margin-bottom: 12px; }
.pd-type {
  display: inline-block;
  font-size: 10px; letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(111,168,255,0.18);
  color: var(--accent);
}
.pd-name { margin: 8px 0 2px; font-size: 22px; font-weight: 700; }
.pd-sub  { font-size: 11px; color: var(--text-soft); font-family: monospace; }
.pd-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-top: 1px solid var(--line);
  font-size: 12px;
}
.pd-row span { color: var(--text-soft); }
.pd-row strong { color: var(--text); font-weight: 600; }
.pd-desc { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--text-soft); }

/* ───────────── WELCOME MODAL ───────────── */
.welcome-overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(2,4,8,0.78);
  backdrop-filter: blur(6px);
  z-index: 1000;
  opacity: 0;
  transition: opacity .2s;
}
.welcome-overlay.visible {
  display: flex;
  opacity: 1;
  animation: fade-in .25s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: scale(.985); }
  to   { opacity: 1; transform: scale(1); }
}
.welcome-card {
  position: relative;
  width: min(560px, 92vw);
  background: linear-gradient(180deg, rgba(17,26,46,.98) 0%, rgba(11,18,32,.98) 100%);
  border: 1px solid rgba(111,168,255,0.25);
  border-radius: 18px;
  padding: 30px 32px 22px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.6), 0 0 0 1px rgba(111,168,255,0.08);
  color: var(--text);
}
.welcome-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px;
  background: transparent; border: 0;
  color: var(--text-soft);
  font-size: 22px; cursor: pointer;
  border-radius: 8px;
}
.welcome-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }

.welcome-icon { font-size: 40px; margin-bottom: 6px; line-height: 1; }
.welcome-title {
  margin: 0 0 14px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.welcome-body { font-size: 14px; line-height: 1.6; color: var(--text); }
.welcome-body p { margin: 0 0 14px; }
.welcome-body ul { margin: 8px 0 4px; padding-left: 22px; color: var(--text-soft); }
.welcome-body ul li { margin-bottom: 4px; }
.welcome-body strong { color: var(--accent); }
.welcome-body code, .welcome-body kbd {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}

.welcome-table {
  width: 100%; border-collapse: collapse; margin: 6px 0 4px;
  font-size: 13px;
}
.welcome-table th {
  text-align: left; padding: 8px 12px 8px 0;
  width: 44%; font-weight: 600; color: var(--accent);
  vertical-align: top;
}
.welcome-table td {
  padding: 8px 0; color: var(--text-soft);
  vertical-align: top;
}
.welcome-table tr + tr th, .welcome-table tr + tr td {
  border-top: 1px solid var(--line);
}

.welcome-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-top: 22px;
}
.welcome-dots { display: flex; gap: 8px; }
.welcome-dots .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--bg-2); transition: background .2s;
}
.welcome-dots .dot.active {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(111,168,255,0.7);
}
.welcome-actions { display: flex; gap: 8px; }
.welcome-btn {
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.welcome-btn:hover:not(:disabled) { background: #1a2747; }
.welcome-btn:active:not(:disabled) { transform: scale(.97); }
.welcome-btn:disabled { opacity: .35; cursor: not-allowed; }
.welcome-btn.primary {
  background: linear-gradient(180deg, #2d6ad8, #1e5bc9);
  border-color: #4a7ed6;
  color: white;
}
.welcome-btn.primary:hover { background: #357ce8; }
.welcome-btn.cta {
  background: linear-gradient(180deg, #2d9d6f, #1f8a5f);
  border-color: #2eb481;
  font-weight: 700;
  padding: 8px 22px;
  box-shadow: 0 0 0 1px #2eb481, 0 6px 24px -8px #2eb481;
}
.welcome-btn.cta:hover { background: #34b27d; }

.welcome-skip {
  display: flex; align-items: center; gap: 8px;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--text-soft);
}
.welcome-skip input { cursor: pointer; }

/* Botón "?" en la barra flotante */
.floating-controls button.help-btn {
  width: 36px; padding: 10px 0;
  font-weight: 700; color: var(--accent);
}
.floating-controls button.help-btn:hover { color: var(--text); }

/* Fly HUD */
.fly-hud {
  position: absolute;
  top: 18px; left: 18px;
  padding: 12px 16px;
  background: rgba(11,18,32,0.92);
  border: 1px solid rgba(111,168,255,0.4);
  border-radius: 10px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 8px 28px -10px rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  pointer-events: none;
  display: none;
  z-index: 50;
}
.fly-hud.visible { display: block; }
.fly-hud .fh-title {
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 10px;
  margin-bottom: 8px;
}
.fly-hud .fh-row { margin-top: 4px; color: var(--text-soft); }
.fly-hud kbd {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 10px;
  color: var(--text);
}

/* Tooltip */
.tooltip {
  position: fixed; pointer-events: none;
  background: rgba(11,18,32,.95); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
  font-size: 12px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .12s; z-index: 100;
  min-width: 110px;
}
.tooltip.visible { opacity: 1; }
.tooltip .tt-title { font-weight: 600; }
.tooltip .tt-type { font-size: 10px; color: var(--accent); margin-top: 2px; text-transform: uppercase; letter-spacing: 1px; }

/* ───────────── PANEL ───────────── */
#panel {
  background: linear-gradient(180deg, rgba(11,18,32,.95) 0%, rgba(8,12,22,.92) 100%);
  border-left: 1px solid var(--line);
  padding: 22px 18px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px;
  padding: 4px 10px; border-radius: 999px;
}
.badge-required { background: rgba(255,107,107,.15); color: var(--danger); }
.badge-optional { background: rgba(255,209,102,.15); color: var(--warn); }
.badge-overview { background: rgba(111,168,255,.18); color: var(--accent); }
.counter { font-size: 11px; color: var(--text-soft); font-family: monospace; }

.color-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 11px; color: var(--text-soft); }
.color-chip { width: 28px; height: 12px; border-radius: 4px; box-shadow: 0 0 12px currentColor; }

#panel h2 { font-size: 18px; margin: 0 0 10px; line-height: 1.3; }
#panel p  { color: var(--text-soft); line-height: 1.6; font-size: 13.5px; }

#panel pre {
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px;
  font-size: 12px; overflow-x: auto;
  color: #d6e3ff;
}

.more { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--bg-1); }
.more summary { cursor: pointer; font-size: 13px; font-weight: 500; }
.more[open] summary { margin-bottom: 10px; }
.more pre { margin: 8px 0 0; }
.hint { font-size: 11px; color: var(--text-soft); margin: 8px 0 0; }
.hint code { background: var(--bg-2); padding: 1px 5px; border-radius: 3px; }

/* ───────────── RESPONSIVE ───────────── */
@media (max-width: 1100px) {
  #app { grid-template-columns: 260px 1fr 300px; }
}
@media (max-width: 880px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 200px 1fr 280px; }
  #sidebar, #panel { overflow-y: auto; }
}
