:root {
  --ink: #18222d;
  --steel: #5b6875;
  --rule: #cfd6dd;
  --blue: #1f5c99;
  --orange: #e8630a;
  --paper-top: #f6f7f9;
  --paper-bot: #c5ced6;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --tag: rgba(255, 255, 255, 0.96);
  --shadow: 0 1px 1px rgba(24, 34, 45, 0.06), 0 10px 28px rgba(24, 34, 45, 0.1);
  --sans: "Barlow", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", "Segoe UI", sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6ebf0; --steel: #9aa7b4; --rule: #34404c;
    --paper-top: #26303a; --paper-bot: #161d24;
    --panel: rgba(30, 38, 47, 0.94); --panel-solid: #1e262f; --tag: #1e262f;
    --blue: #6aa3dc;
  }
}
:root[data-theme="dark"] {
  --ink: #e6ebf0; --steel: #9aa7b4; --rule: #34404c;
  --paper-top: #26303a; --paper-bot: #161d24;
  --panel: rgba(30, 38, 47, 0.94); --panel-solid: #1e262f; --tag: #1e262f;
  --blue: #6aa3dc;
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body {
  font-family: var(--sans); color: var(--ink);
  background: linear-gradient(180deg, var(--paper-top), var(--paper-bot));
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
#app { position: relative; height: 100%; width: 100%; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#vignette {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(ellipse at 58% 46%, transparent 46%, rgba(20, 32, 44, 0.08) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 18%, transparent 72%, rgba(24, 34, 45, 0.06));
}
#leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

button {
  font: 500 14px/1 var(--sans); color: var(--ink); background: transparent;
  border: 0; padding: 9px 12px; border-radius: 6px; cursor: pointer;
}
button:hover { background: rgba(31, 92, 153, 0.09); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
button[aria-pressed="true"],
button[aria-pressed="true"]:hover { background: var(--blue); color: #fff; }

/* Nameplate — styled like an engraved equipment plate */
.plate {
  position: absolute; top: 16px; left: 16px; z-index: 3;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px 10px 16px; background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.72); border-left: 5px solid var(--orange);
  border-radius: 14px; box-shadow: var(--shadow);
  max-width: calc(100% - 320px); backdrop-filter: blur(16px);
}
.plate h1 {
  margin: 0; font: 700 clamp(18px, 2vw, 30px)/1 var(--cond); letter-spacing: 0.01em; color: var(--ink);
}
.plate p { margin: 5px 0 0; font-size: clamp(12px, 1.1vw, 14px); color: var(--steel); }
.model-pick { display: block; margin-bottom: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.model-pick select {
  max-width: 100%; padding: 6px 28px 6px 10px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--panel-solid); color: var(--ink); font: 600 14px/1 var(--cond);
}
.brand { height: clamp(40px, 7vh, 72px); width: auto; display: block; }

.panel {
  position: absolute; z-index: 3; background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 14px; box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

/* Assembly dashboard: stays a side column, sized from the screen */
#parts {
  top: clamp(96px, 14vh, 128px); left: 16px;
  width: clamp(248px, 22vw, 280px);
  height: clamp(220px, 46vh, 520px);
  max-width: min(320px, 30vw);
  max-height: min(50vh, calc(100% - 200px));
  display: flex; flex-direction: column;
}
#parts.collapsed {
  width: auto !important; height: auto !important; max-width: none; max-height: none; padding: 0 !important;
}
#parts.collapsed .dash-tabs,
#parts.collapsed #partsBody,
#parts.collapsed #bomBody,
#parts.collapsed .dash-size { display: none !important; }
#parts.collapsed .dash-head { border: 0; }
.panel-toggle {
  display: inline-flex; align-items: center; margin: 8px 8px 8px 0; padding: 0 10px; border-radius: 8px;
  font: 600 14px/1 var(--cond); color: var(--ink); background: transparent;
}
#parts.collapsed .panel-toggle { margin: 0; padding: 10px 14px; border-radius: 14px; font-size: 16px; }
.dash-size {
  position: absolute; right: 3px; bottom: 3px; z-index: 2;
  width: 14px; height: 14px; padding: 0; border-radius: 3px; cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 46%, var(--steel) 46% 54%, transparent 54% 62%, var(--steel) 62% 70%, transparent 70%);
}
.dash-size:hover {
  background:
    linear-gradient(135deg, transparent 46%, var(--blue) 46% 54%, transparent 54% 62%, var(--blue) 62% 70%, transparent 70%);
}
.dash-head { display: flex; align-items: stretch; border-bottom: 1px solid var(--rule); }
.dash-tabs { display: flex; flex: 1; gap: 4px; padding: 6px; }
.dash-tabs button {
  flex: 1; padding: 6px 8px; border-radius: 8px;
  font: 600 14px/1.1 var(--cond); color: var(--ink); background: transparent; text-align: center;
}
.dash-tabs button[aria-selected="true"],
.dash-tabs button[aria-selected="true"]:hover { background: var(--blue); color: #fff; }
.dash-tabs .count { font: 500 12px/1 var(--sans); opacity: 0.8; }
#partsBody, #bomBody { overflow: auto; min-height: 0; flex: 1; }
#partsBody { padding: 4px 6px 10px; }
#partsBody h3 {
  margin: 12px 8px 4px; font: 600 13px/1.2 var(--sans); color: var(--blue);
}
.part {
  display: grid; grid-template-columns: 26px 12px 1fr auto; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 7px 8px; font-size: 14px; line-height: 1.25; border-radius: 8px;
}
.swatch {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid rgba(24, 34, 45, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}
.part .q { color: var(--steel); font-size: 13px; font-variant-numeric: tabular-nums; }
.part.on { background: rgba(232, 99, 10, 0.14); }
.part.on .balloon { border-color: var(--orange); background: var(--orange); color: #fff; }

#bomBody { display: flex; flex-direction: column; }
#bomBody[hidden] { display: none; }
.bom-scroll { flex: 1; min-height: 0; overflow: auto; padding: 4px 6px 8px; }
.bom-scroll h3 { margin: 10px 8px 2px; font: 600 13px/1.2 var(--sans); color: var(--blue); }
.bom-line {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  width: 100%; text-align: left; padding: 6px 8px; border-radius: 8px;
}
.bom-copy { min-width: 0; display: flex; flex-direction: column; gap: 1px; padding: 0; background: transparent; text-align: left; }
.bom-copy:hover { background: transparent; }
.bom-name { display: block; font: 500 13px/1.25 var(--sans); color: var(--ink); }
.bom-meta, .bom-note { color: var(--steel); font-size: 12px; line-height: 1.3; }
.bom-price { display: flex; align-items: center; gap: 2px; color: var(--steel); font-size: 12px; }
.bom-price input {
  width: 74px; padding: 4px 6px; border: 1px solid var(--rule); border-radius: 6px;
  background: var(--panel-solid); color: var(--ink); font: 500 12px/1.2 var(--sans);
  text-align: right; font-variant-numeric: tabular-nums;
}
.bom-price input::placeholder { color: var(--steel); }
.bom-line.on { background: rgba(232, 99, 10, 0.14); }
.bom-line.on .balloon { border-color: var(--orange); background: var(--orange); color: #fff; }
.bom-note { margin: 0; padding: 8px 12px 10px; border-top: 1px solid var(--rule); }

.balloon {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid var(--ink); background: var(--tag); color: var(--ink);
  font: 600 13px/1 var(--cond); font-variant-numeric: tabular-nums; flex: none;
}

/* Detail card */
#detail { top: 68px; right: 16px; width: clamp(220px, 22vw, 300px); padding: 16px 16px 14px; border-radius: 14px; }

#downloads {
  position: absolute; z-index: 6; top: 16px; right: 16px;
  display: flex; align-items: flex-start; gap: 8px;
}
a.tool, button.tool {
  display: inline-flex; align-items: center; text-decoration: none;
  font: 500 14px/1 var(--sans); color: var(--ink);
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.72); border-radius: 999px;
  box-shadow: var(--shadow); white-space: nowrap; backdrop-filter: blur(16px); padding: 10px 14px;
}
.tool .short { display: none; }
a.tool:hover, button.tool:hover { background: var(--panel-solid); }
.menu { position: relative; }
.menu-pop[hidden] { display: none; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 148px;
  display: flex; flex-direction: column; gap: 2px; padding: 4px;
  background: var(--panel-solid); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-pop button { width: 100%; text-align: left; }
.detail-head { display: flex; gap: 10px; align-items: flex-start; }
.detail-head .balloon { width: 30px; height: 30px; font-size: 16px; border-color: var(--orange); background: var(--orange); color: #fff; }
.detail-head > div { flex: 1; min-width: 0; }
#detail h2 { margin: 2px 0 0; font: 600 21px/1.1 var(--cond); }
#detail .meta { margin: 3px 0 0; font-size: 13px; color: var(--steel); }
#detail #dDesc { margin: 10px 0 12px; font-size: 15px; line-height: 1.45; }
.icon { padding: 6px 8px; font-size: 14px; color: var(--steel); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-actions button { border: 1px solid var(--rule); border-radius: 999px; background: var(--panel-solid); color: var(--ink); }
.detail-actions button:hover { background: rgba(31, 92, 153, 0.09); color: var(--ink); }
.detail-actions button[aria-pressed="true"],
.detail-actions button[aria-pressed="true"]:hover {
  background: var(--blue); border-color: var(--blue); color: #fff;
}

/* Toolbar */
#toolbar {
  position: absolute; z-index: 4; left: 0; right: 0; margin: 0 auto; width: max-content;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 24px); padding: 6px; background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.72); border-radius: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
#toolbar button { border-radius: 10px; padding: 8px 11px; }
#bExploded[aria-pressed="true"],
#bExploded[aria-pressed="true"]:hover { background: var(--orange); color: #fff; }
#toolbar .seg, #toolbar .grp { display: flex; gap: 2px; padding-right: 6px; border-right: 1px solid var(--rule); }
#toolbar .grp:last-child { border-right: 0; padding-right: 0; }
#bQuote { background: var(--orange); color: #fff; border-color: var(--orange); }
#bQuote:hover { background: #cf5608; }
#quoteDlg {
  border: 0; border-radius: 12px; padding: 22px 22px 18px; max-width: 380px; width: calc(100% - 32px);
  background: #fff; color: var(--ink); box-shadow: var(--shadow);
}
#quoteDlg::backdrop { background: rgba(24, 34, 45, 0.48); }
#quoteDlg h2 { margin: 0 28px 8px 0; font: 600 26px/1 var(--cond); }
#quoteDlg p { margin: 0 0 14px; color: var(--steel); font-size: 15px; line-height: 1.45; }
#quoteDlg .icon { position: absolute; top: 10px; right: 10px; }
#qr {
  display: grid; place-items: center; margin: 0 auto 14px; width: 212px; height: 212px;
  background: #fff; border: 1px solid var(--rule); border-radius: 8px;
}
#qr svg { width: 196px; height: 196px; display: block; }
.quote-open {
  display: block; text-align: center; text-decoration: none; font-weight: 600;
  color: #fff; background: var(--blue); border-radius: 8px; padding: 11px 14px;
}
.quote-open:hover { background: #184a7c; }
#bZoomOut, #bZoomIn { width: 36px; font-size: 18px; padding: 7px 0; }
.spread { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 4px; border-right: 1px solid var(--rule); font-size: 14px; color: var(--steel); }
.spread input { width: 130px; accent-color: var(--orange); height: 18px; cursor: pointer; }

#hint {
  position: absolute; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom, 0px)); margin: 0;
  font-size: 13px; color: var(--steel); text-align: center; max-width: 90%;
  transition: opacity 0.6s;
}
#hint.gone { opacity: 0; }

/* Callouts */
.callout {
  position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 3px; border-radius: 999px; background: var(--tag);
  border: 1px solid rgba(24, 34, 45, 0.12); box-shadow: 0 4px 14px rgba(24, 34, 45, 0.12);
  font: 500 13px/1 var(--sans); white-space: nowrap; pointer-events: auto; cursor: pointer;
  will-change: transform; backdrop-filter: blur(10px);
}
.has-sel .callout:not(.on) { opacity: 0.5; }
.callout.on { border-color: var(--orange); }
.callout.on .balloon { background: var(--orange); border-color: var(--orange); color: #fff; }
.callout.compact { padding-right: 3px; }
.callout.compact .nm { display: none; }
#leaders polyline, #leaders line {
  fill: none; stroke: var(--ink); stroke-width: 1.25; opacity: 0.72;
  stroke-linejoin: round; stroke-linecap: round;
}
#leaders polyline.on, #leaders line.on { stroke: var(--orange); opacity: 1; stroke-width: 1.7; }
#leaders circle { fill: var(--ink); stroke: #fff; stroke-width: 1; opacity: 0.9; }
#leaders circle.on { fill: var(--orange); opacity: 1; }

#tip {
  position: absolute; z-index: 5; pointer-events: none; padding: 5px 9px; border-radius: 5px;
  background: var(--ink); color: var(--panel-solid); font-size: 13px; white-space: nowrap;
}

#loading {
  position: absolute; inset: 0; z-index: 10; display: grid; place-content: center; gap: 10px; justify-items: center;
  background: linear-gradient(180deg, var(--paper-top), var(--paper-bot)); transition: opacity 0.4s;
  font-size: 14px; color: var(--steel);
}
#loading .bar { width: 220px; height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--orange); transition: width 0.2s; }
#loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 820px) {
  #downloads {
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: auto; right: 8px; gap: 6px;
    justify-content: flex-end; flex-wrap: nowrap;
  }
  .plate {
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 8px; right: auto;
    width: calc(100% - 210px); max-width: 210px;
    padding: 6px 8px 6px 10px; gap: 8px; overflow: hidden;
  }
  .plate > div { min-width: 0; flex: 1; }
  .plate h1 { font-size: clamp(13px, 3.7vw, 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .plate p { display: none; }
  .model-pick { margin-bottom: 3px; }
  .model-pick select { max-width: 100%; font-size: clamp(11px, 3vw, 12px); padding: 4px 18px 4px 8px; }
  .brand { display: block; height: clamp(24px, 7.5vw, 32px); width: auto; flex: none; }
  #downloads .tool { padding: clamp(6px, 1.6vw, 8px) clamp(8px, 2.4vw, 10px); font-size: clamp(11px, 3.1vw, 13px); }
  .tool .full { display: none; }
  .tool .short { display: inline; }
  #parts {
    top: auto; left: 10px; right: 10px; width: auto; max-width: none;
    bottom: calc(104px + env(safe-area-inset-bottom, 0px));
    height: auto; max-height: 34vh; padding-top: 8px;
  }
  .dash-size, .dash-size:hover {
    left: 50%; right: auto; top: 6px; bottom: auto; width: 36px; height: 4px;
    transform: translateX(-50%); border-radius: 999px; cursor: ns-resize;
    background: var(--rule);
  }
  .panel-toggle { display: inline-flex; align-items: center; }
  #parts.collapsed #partsBody, #parts.collapsed #bomBody { display: none; }
  #detail { top: auto; left: 10px; right: 10px; width: auto; bottom: calc(104px + env(safe-area-inset-bottom, 0px)); }
  #toolbar { bottom: calc(8px + env(safe-area-inset-bottom, 0px)); gap: 2px; width: calc(100% - 16px); }
  #toolbar button { font-size: clamp(11px, 3.2vw, 14px); padding: 7px clamp(6px, 2vw, 10px); }
  #bZoomOut, #bZoomIn { width: 32px; font-size: clamp(15px, 4.2vw, 18px); }
  .spread { position: relative; font-size: clamp(11px, 3vw, 13px); gap: 6px; }
  .spread span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #toolbar .spread input { width: clamp(52px, 16vw, 80px); }
  #parts.collapsed .panel-toggle { font-size: clamp(13px, 3.8vw, 15px); }
  .dash-tabs button { font-size: clamp(12px, 3.4vw, 14px); }
  .dash-tabs .count { font-size: clamp(10px, 2.8vw, 12px); }
  #partsBody h3, .bom-scroll h3 { font-size: clamp(11px, 3.1vw, 13px); }
  .part { font-size: clamp(12px, 3.4vw, 14px); }
  .part .q { font-size: clamp(11px, 3vw, 12px); }
  .bom-name { font-size: clamp(12px, 3.2vw, 13px); }
  .bom-meta, .bom-note, .bom-price, .bom-price input { font-size: clamp(11px, 2.9vw, 12px); }
  .balloon { width: clamp(20px, 5.5vw, 24px); height: clamp(20px, 5.5vw, 24px); font-size: clamp(11px, 3vw, 13px); }
  #detail h2 { font-size: clamp(17px, 4.6vw, 20px); }
  #detail .meta { font-size: clamp(12px, 3.2vw, 13px); }
  #detail #dDesc { font-size: clamp(13px, 3.6vw, 15px); }
  .detail-actions button { font-size: clamp(12px, 3.3vw, 14px); }
  #quoteDlg h2 { font-size: clamp(20px, 5.5vw, 24px); }
  #quoteDlg p, .quote-open { font-size: clamp(13px, 3.6vw, 15px); }
  .callout { font-size: clamp(11px, 3.1vw, 13px); }
  .menu-pop button { font-size: clamp(12px, 3.4vw, 14px); }
  #hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
