/* ============================================================
   PerfRoute — styles
   ============================================================ */

:root {
  --bg: #0b0e13;
  --panel: #141821;
  --panel-2: #1a1f2b;
  --panel-3: #212735;
  --border: #27303f;
  --border-soft: #1e2530;
  --text: #e8ecf3;
  --muted: #8b95a8;
  --faint: #5c6678;
  --accent: #f5a83c;
  --accent-soft: rgba(245, 168, 60, 0.14);
  --accent-2: #ffc86b;
  /* Surface tokens — the app chrome beyond the base palette, overridden by
     each app theme (see the theme blocks below). */
  --on-accent: #141414;             /* text on accent-filled surfaces */
  --topbar-bg: linear-gradient(180deg, #161b26, #10141d);
  --stage-bg: #0a0d11;
  --stage-dot: rgba(255, 255, 255, 0.05);
  --status-bg: linear-gradient(180deg, rgba(20, 24, 33, 0.9), rgba(16, 20, 29, 0.95));
  --float-bg: rgba(20, 24, 33, 0.86);  /* glass toolbars */
  --pop-bg: rgba(22, 27, 38, 0.97);    /* popovers / menus */
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(245, 168, 60, 0.05), transparent 70%);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- App themes ----------
   Midnight lives in :root above; the blocks below swap in a new hue family
   and surface treatment via the same variables, so every component restyles
   automatically. Set from the Settings panel (#appThemes). */

html[data-apptheme='graphite'] {
  --bg: #0d0f12;
  --panel: #14171b;
  --panel-2: #191d22;
  --panel-3: #20252b;
  --border: #2a3038;
  --border-soft: #1e2329;
  --text: #e9edf2;
  --muted: #8b95a3;
  --faint: #5d6773;
  --accent: #6ea8ff;
  --accent-soft: rgba(110, 168, 255, 0.14);
  --accent-2: #9dc3ff;
  --on-accent: #0c1220;
  --topbar-bg: linear-gradient(180deg, #171b21, #111419);
  --stage-bg: #0b0d10;
  --stage-dot: rgba(255, 255, 255, 0.05);
  --status-bg: linear-gradient(180deg, rgba(20, 24, 30, 0.9), rgba(15, 18, 23, 0.95));
  --float-bg: rgba(20, 24, 30, 0.86);
  --pop-bg: rgba(23, 27, 34, 0.97);
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(110, 168, 255, 0.06), transparent 70%);
}

html[data-apptheme='forest'] {
  --bg: #0a100e;
  --panel: #0f1815;
  --panel-2: #14201c;
  --panel-3: #1a2a24;
  --border: #24372f;
  --border-soft: #1a2823;
  --text: #e7efe9;
  --muted: #8ba193;
  --faint: #5d7266;
  --accent: #34d3a2;
  --accent-soft: rgba(52, 211, 162, 0.14);
  --accent-2: #7be8c4;
  --on-accent: #06251b;
  --topbar-bg: linear-gradient(180deg, #12201b, #0d1613);
  --stage-bg: #08100d;
  --stage-dot: rgba(255, 255, 255, 0.05);
  --status-bg: linear-gradient(180deg, rgba(15, 26, 22, 0.9), rgba(11, 19, 16, 0.95));
  --float-bg: rgba(15, 26, 22, 0.86);
  --pop-bg: rgba(17, 28, 24, 0.97);
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(52, 211, 162, 0.06), transparent 70%);
}

html[data-apptheme='amethyst'] {
  --bg: #0f0c17;
  --panel: #171227;
  --panel-2: #1d1633;
  --panel-3: #251b40;
  --border: #33285a;
  --border-soft: #231a40;
  --text: #ede9f7;
  --muted: #9b8fb8;
  --faint: #6c6285;
  --accent: #b18cff;
  --accent-soft: rgba(177, 140, 255, 0.14);
  --accent-2: #d2b9ff;
  --on-accent: #170b33;
  --topbar-bg: linear-gradient(180deg, #1a1430, #131022);
  --stage-bg: #0d0a15;
  --stage-dot: rgba(255, 255, 255, 0.05);
  --status-bg: linear-gradient(180deg, rgba(24, 18, 44, 0.9), rgba(18, 14, 33, 0.95));
  --float-bg: rgba(24, 18, 44, 0.86);
  --pop-bg: rgba(27, 20, 48, 0.97);
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(177, 140, 255, 0.07), transparent 70%);
}

html[data-apptheme='ember'] {
  --bg: #120d0a;
  --panel: #1c1511;
  --panel-2: #241b15;
  --panel-3: #2f241c;
  --border: #413227;
  --border-soft: #2e2319;
  --text: #f6ede5;
  --muted: #b09a87;
  --faint: #7c6a58;
  --accent: #ff8a5c;
  --accent-soft: rgba(255, 138, 92, 0.14);
  --accent-2: #ffb08f;
  --on-accent: #2b0f02;
  --topbar-bg: linear-gradient(180deg, #261a13, #181009);
  --stage-bg: #100b08;
  --stage-dot: rgba(255, 255, 255, 0.05);
  --status-bg: linear-gradient(180deg, rgba(30, 21, 15, 0.9), rgba(23, 15, 10, 0.95));
  --float-bg: rgba(30, 21, 15, 0.86);
  --pop-bg: rgba(33, 24, 17, 0.97);
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(255, 138, 92, 0.06), transparent 70%);
}

html[data-apptheme='paper'] {
  --bg: #f2f3f6;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --panel-3: #eceef2;
  --border: #d6dae1;
  --border-soft: #e4e7ec;
  --text: #1d232b;
  --muted: #5b6572;
  --faint: #9099a6;
  --accent: #e08a1e;
  --accent-soft: rgba(224, 138, 30, 0.13);
  --accent-2: #a86a00;
  --on-accent: #ffffff;
  --topbar-bg: linear-gradient(180deg, #ffffff, #f4f5f8);
  --stage-bg: #e9ebef;
  --stage-dot: rgba(0, 0, 0, 0.08);
  --status-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(242, 243, 246, 0.95));
  --float-bg: rgba(255, 255, 255, 0.9);
  --pop-bg: rgba(255, 255, 255, 0.98);
  --accent-glow: radial-gradient(60% 50% at 50% 42%, rgba(224, 138, 30, 0.08), transparent 70%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

::selection { background: rgba(245, 168, 60, 0.35); }

button { font-family: inherit; }

/* ---------- App shell ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 16px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
}

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

.brand svg {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  filter: drop-shadow(0 2px 5px rgba(245,168,60,.25));
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-text h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

.brand-text h1 span { color: var(--accent); }

.brand-text p {
  margin: 0;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
}

.brand-credit {
  margin-left: 2px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

.brand-credit a {
  color: var(--accent-2);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s ease;
}

.brand-credit a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.brand-credit a:focus-visible {
  outline: none;
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(245, 168, 60, 0.25);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.unit-badge {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent-2);
  border: 1px solid rgba(245, 168, 60, 0.35);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 5px;
  line-height: 1;
}

.top-stats {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  line-height: 1;
}

/* ---------- Layout ---------- */

.layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .idx {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(245, 168, 60, 0.25);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ---------- Fields ---------- */

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.field-label em {
  font-style: normal;
  font-size: 10px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.15);
}

.input-wrap input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 0;
}

.suffix {
  font-size: 10px;
  color: var(--faint);
  font-family: var(--mono);
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------- Presets ---------- */

.presets { display: flex; flex-direction: column; gap: 8px; }

.preset-label {
  font-size: 11px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  color: var(--text);
  border-color: var(--faint);
  transform: translateY(-1px);
}

.chip.active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(245, 168, 60, 0.35);
}

/* ---------- Board orientation toolbar (floating, top-right of board) ---------- */

.board-tools {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  background: var(--float-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  /* Only the buttons themselves capture pointer events, so hover
     tooltips and drag-routing pass through the toolbar's padding/gaps. */
  pointer-events: none;
}

.tbtn-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.tbtn-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 3px;
}

.tbtn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  pointer-events: auto;
}

.tbtn:hover {
  color: var(--accent-2);
  background: var(--accent-soft);
  border-color: rgba(245, 168, 60, 0.35);
  transform: translateY(-1px);
}

.tbtn:active {
  transform: translateY(0) scale(0.94);
}

.tbtn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

/* Zoom percentage readout: a clickable reset button, a touch wider than
   the icon buttons so "100%" fits without the label jumping around. */
.tbtn.zoom-pct {
  width: auto;
  min-width: 46px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

/* Undo / redo: grey out while there's nothing to step back/forward to */
.tbtn:disabled {
  color: var(--muted-dim, #5a6372);
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
  transform: none;
  box-shadow: none;
  background: transparent;
  border-color: transparent;
}

/* Bottom-right twin of the top-right orientation toolbar, anchored to the
   board stage so it floats over the board rather than the status footer. */
.board-history {
  top: auto;
  bottom: 16px;
  right: 16px;
}

/* ---------- Floating settings (bottom-left of the board stage) ---------- */

.settings-btn {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--float-bg);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: all 0.15s ease;
}

.settings-btn svg {
  width: 21px;
  height: 21px;
  display: block;
  transition: transform 0.28s ease;
}

.settings-btn:hover {
  color: var(--accent-2);
  border-color: rgba(245, 168, 60, 0.4);
  background: rgba(245, 168, 60, 0.12);
  transform: translateY(-1px);
}

.settings-btn:active { transform: scale(0.94); }

.settings-btn[aria-expanded='true'] {
  color: var(--accent-2);
  border-color: rgba(245, 168, 60, 0.45);
  background: var(--accent-soft);
}

.settings-btn[aria-expanded='true'] svg { transform: rotate(90deg); }

.settings-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

/* Popover that opens upward from the settings button. Cards inside render
   flat (no nested chrome) and are separated by hairlines. */
.settings-panel {
  position: absolute;
  left: 16px;
  bottom: 68px;
  z-index: 30;
  width: min(304px, calc(100% - 32px));
  max-height: min(560px, calc(100% - 92px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--pop-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  padding: 8px;
  animation: settingsIn 0.16s ease;
}

.settings-panel[hidden] { display: none; }

.settings-panel::-webkit-scrollbar { width: 8px; }
.settings-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid var(--pop-bg);
}
.settings-panel::-webkit-scrollbar-track { background: transparent; }

.settings-panel-head {
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.github-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-3);
  transition: all 0.15s ease;
}

.github-link svg {
  width: 13px;
  height: 13px;
  display: block;
}

.github-link:hover {
  color: var(--accent-2);
  border-color: rgba(245, 168, 60, 0.4);
  background: var(--accent-soft);
}

.github-link:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

.settings-panel .card {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  border-radius: 0;
  padding: 13px 12px;
}

.settings-panel .card:last-of-type { border-bottom: none; }

.settings-panel .reset-btn { margin-top: 6px; }

/* App-theme picker: a mini preview chip (panel + accent) per theme */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 11px;
  padding: 8px 4px 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-swatch i {
  width: 34px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--c1) 0 50%, var(--c2) 50% 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.28);
}

.theme-swatch:hover {
  color: var(--text);
  border-color: var(--faint);
  transform: translateY(-1px);
}

.theme-swatch:active { transform: scale(0.96); }

.theme-swatch.active {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.theme-swatch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 1px var(--accent);
}

@keyframes settingsIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Swatches ---------- */

.swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.swatch i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

.swatch:hover {
  color: var(--text);
  border-color: var(--faint);
  transform: translateY(-1px);
}

.swatch.active {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------- Toggle rows ---------- */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 2px 0;
}

.hint-inline {
  display: block;
  font-style: normal;
  font-size: 10px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1px;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.switch i {
  position: absolute;
  inset: 0;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.18s ease, border-color 0.18s ease;
  pointer-events: none;
}

.switch i::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2), background 0.18s ease;
}

.switch input:checked + i {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.switch input:checked + i::after {
  transform: translateX(18px);
  background: var(--accent);
}

.switch input:focus-visible + i { box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25); }

/* ---------- Tools: floating vertical rail of square icon buttons ----------
   Mirrors the top-right orientation toolbar: a glass pill anchored to the
   top-left corner of the board area. Only the buttons capture pointer
   events, so drags pass through the rail's padding/gaps. */

.tool-rail {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px;
  background: var(--float-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.tool-rail #toolSwitch {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tool-icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease,
    transform 0.1s ease;
  pointer-events: auto;
}

.tool-icon-btn svg {
  width: 21px;
  height: 21px;
  display: block;
}

.tool-icon-btn:hover {
  color: var(--text);
  background: var(--panel-2);
}

.tool-icon-btn:active { transform: scale(0.94); }

.tool-icon-btn.active {
  color: var(--on-accent);
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(245, 168, 60, 0.35);
}

.tool-icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

/* Separator + "add a board" square below the placement tools */
.tool-rail-sep {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.add-mcu-btn {
  color: var(--accent-2);
}
.add-mcu-btn:hover {
  color: var(--on-accent);
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(245, 168, 60, 0.35);
}
.add-mcu-btn[aria-expanded='true'] {
  color: var(--on-accent);
  background: var(--accent);
  box-shadow: 0 1px 6px rgba(245, 168, 60, 0.35);
}

/* Microcontroller preset picker — opens below the tool rail */
.mcu-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 30;
  width: 272px;
  max-height: min(420px, 70vh);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--pop-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  padding: 8px;
  animation: settingsIn 0.16s ease;
  pointer-events: auto;
}
.mcu-panel[hidden] { display: none; }

.mcu-panel::-webkit-scrollbar { width: 8px; }
.mcu-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid var(--pop-bg);
}
.mcu-panel::-webkit-scrollbar-track { background: transparent; }

.mcu-panel-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 6px 9px;
  border-bottom: 1px solid var(--border-soft);
}
.mcu-panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}
.mcu-panel-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}

.mcu-sex {
  display: flex;
  gap: 6px;
  padding: 8px 6px 9px;
  border-bottom: 1px solid var(--border-soft);
}
.mcu-sex button {
  flex: 1;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.mcu-sex button:hover { color: var(--text); border-color: var(--faint); }
.mcu-sex button.active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}
.mcu-sex button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

.mcu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 2px 2px;
}
.mcu-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}
.mcu-card:hover {
  border-color: var(--faint);
  background: var(--panel-3);
  transform: translateY(-1px);
}
.mcu-card:active { transform: scale(0.98); }
.mcu-card:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}
.mcu-card-icon {
  width: 44px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}
.mcu-card-icon svg {
  display: block;
  max-width: 100%;
  max-height: 100%;
}
.mcu-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.mcu-card-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}
.mcu-card-note {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}

/* Routed wires, pin headers, solder and resize handles: never intercept
   pointer events (hit-testing is manual). */
#wires, #solder, #headers, #handles, #preview { pointer-events: none; }

.wire, .header { transition: filter 0.12s ease, opacity 0.12s ease; }
.wire.hl, .header.hl { filter: brightness(1.5) drop-shadow(0 0 3px rgba(255, 255, 255, 0.4)); }

/* Resize handles on the selected wire/header: a white ring with a dark
   core so they read as grab points over pads, solder and plastic alike. */
.handle {
  animation: handleIn 0.16s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.handle circle {
  transition: r 0.12s ease, opacity 0.12s ease;
}
@keyframes handleIn {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

.wire-label {
  font-family: var(--mono);
  font-size: 1.3px;
  font-weight: 600;
  fill: #fff;
  stroke: rgba(8, 10, 14, 0.85);
  stroke-width: 0.45px;
  stroke-linejoin: round;
  paint-order: stroke;
}

#board { cursor: crosshair; touch-action: none; }

/* ---------- Reset / notes ---------- */

.reset-btn {
  display: block;
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reset-btn:hover {
  color: var(--accent-2);
  border-color: rgba(245, 168, 60, 0.4);
  background: var(--accent-soft);
}

/* ---------- Board area ---------- */

.board-area {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background-color: var(--stage-bg);
  background-image: radial-gradient(var(--stage-dot) 1px, transparent 1.4px);
  background-size: 22px 22px;
  overflow: hidden;
}

.board-area::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--accent-glow);
}

.board-stage {
  position: relative; /* anchors the bottom-right undo/redo toolbar */
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px 26px 10px;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 26px 42px rgba(0, 0, 0, 0.55));
}

/* Pads: hover micro-interaction */
.pad { cursor: pointer; }

.padcopper, .padhole {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.12s ease;
}

.pad:hover .padcopper { transform: scale(1.08); filter: brightness(1.28); }
.pad:hover .padhole { transform: scale(1.08); }

#pads.pads-in { animation: pop 0.42s cubic-bezier(0.22, 0.9, 0.3, 1.15) both; }

.labels { font-family: var(--mono); }

@keyframes pop {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- Board status bar ---------- */

.board-status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 18px;
  background: var(--status-bg);
  border-top: 1px solid var(--border-soft);
  backdrop-filter: blur(6px);
}

#statusText {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badges { display: flex; gap: 8px; flex: 0 0 auto; }

.badge {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid rgba(245, 168, 60, 0.25);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

/* ---------- Tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 50;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent-2);
  border-radius: 7px;
  padding: 4px 9px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: tipIn 0.12s ease;
}

.tooltip::after {
  content: 'HOLE';
  display: block;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.1em;
  opacity: 0.55;
  text-align: center;
}

@keyframes tipIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Wire context menu (recolor / remove) ---------- */

.wire-menu {
  position: fixed;
  z-index: 60;
  min-width: 168px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  background: var(--pop-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  animation: menuIn 0.13s ease;
}

.wire-menu[hidden] { display: none; }

/* The hidden attribute must beat the author display rules for the
   context-menu sections we toggle (recolor palette for headers). */
#wireMenuColors[hidden], .wire-menu-label[hidden], .wire-menu-sex[hidden] { display: none; }

.wire-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wire-menu-title {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-2);
  letter-spacing: 0.03em;
}

.wire-menu-delete {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.35);
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.wire-menu-delete:hover {
  color: #fff;
  background: rgba(255, 107, 107, 0.35);
  border-color: #ff6b6b;
}

.wire-menu-delete:active { transform: scale(0.96); }

.wire-menu-delete:focus-visible {
  outline: none;
  border-color: #ff6b6b;
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.3);
}

.wire-menu-sep {
  height: 1px;
  background: var(--border);
}

.wire-menu-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.wire-menu-sex {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.wire-menu-sex:hover {
  color: var(--accent-2);
  border-color: rgba(245, 168, 60, 0.4);
  background: var(--accent-soft);
}

.wire-menu-sex:active { transform: scale(0.97); }

.wire-menu-sex:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.25);
}

.wire-menu-colors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
  gap: 7px;
}

.menu-swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  background: var(--wc);
  border: 2px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.menu-swatch:hover {
  transform: scale(1.14);
  border-color: rgba(255, 255, 255, 0.5);
}

.menu-swatch:active { transform: scale(0.92); }

.menu-swatch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 168, 60, 0.45);
}

.menu-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), inset 0 -2px 4px rgba(0, 0, 0, 0.35);
}

@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .app { height: auto; min-height: 100dvh; }
  .layout { display: block; }
  .board-area { min-height: 62vh; }
  .top-stats { display: none; }
}

@media (max-width: 560px) {
  .board-status { flex-direction: column; align-items: flex-start; gap: 6px; }
  .brand-credit { display: none; }
}

@media (max-width: 440px) {
  .brand-text p { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
