:root {
  color-scheme: dark;
  --bg: #090c0b;
  --panel: #111715;
  --panel-2: #171e1b;
  --line: #2a3530;
  --line-strong: #47564f;
  --text: #f4f1e8;
  --muted: #aab5ae;
  --gold: #d7ac58;
  --gold-2: #f0ce83;
  --green: #7bb99a;
  --danger: #d98b7a;
  --focus: #8bc9ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 65% -20%, rgba(93, 115, 99, .22), transparent 38rem),
    linear-gradient(180deg, #0c110f 0%, var(--bg) 38rem);
}
button, input, select { font: inherit; }
button, input, select {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #18201d;
}
button {
  min-height: 40px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}
button:hover { border-color: var(--gold); background: #222c28; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
button[aria-pressed="true"], button.primary {
  color: #10130f;
  border-color: var(--gold-2);
  background: var(--gold-2);
}
input, select { width: 100%; min-height: 42px; padding: 8px 10px; }
select { padding: 5px; }
select option { padding: 5px 7px; }
label { display: block; margin: 10px 0 5px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .04em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(24px, 3vw, 42px); letter-spacing: -.035em; }
h2 { margin-bottom: 8px; font-size: 16px; }
code { color: var(--gold-2); }
.skip-link { position: fixed; left: 10px; top: -60px; z-index: 100; padding: 12px; color: #10130f; background: var(--focus); }
.skip-link:focus { top: 10px; }
.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 22px;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--line);
}
.subtitle { max-width: 820px; margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.eyebrow, .panel-kicker { margin-bottom: 5px; color: var(--gold-2); font-size: 10px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.topbar-badges { display: flex; flex-wrap: wrap; justify-content: end; gap: 7px; }
.topbar-badges span, .count-badge { padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 800; white-space: nowrap; }
.app-shell {
  display: grid;
  grid-template-columns: minmax(245px, 305px) minmax(0, 1fr) minmax(235px, 285px);
  gap: 12px;
  padding: 12px;
}
.sidebar, .workspace { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 12px; }
.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(25, 33, 29, .96), rgba(14, 20, 17, .96));
  box-shadow: 0 16px 40px rgba(0, 0, 0, .18);
}
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin-bottom: 0; }
.selected-card { border-color: #4d4934; background: linear-gradient(145deg, rgba(61, 52, 31, .55), rgba(18, 23, 20, .96)); }
.muted, .fine-print { color: var(--muted); }
.fine-print { margin: 8px 0 0; font-size: 11px; line-height: 1.45; }
.selected-finish { display: grid; grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: 10px; }
.selected-finish span:last-child { display: grid; }
.selected-finish small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.large-swatch { width: 42px; height: 42px; border: 2px solid rgba(255, 255, 255, .5); border-radius: 9px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .5); }
.parts-list { display: grid; gap: 5px; max-height: min(50vh, 560px); overflow: auto; padding: 3px; }
.part-button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 6px 8px;
  text-align: left;
  font-size: 11px;
}
.part-button .visibility-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.part-button[data-visible="false"] .visibility-dot { background: #727b76; }
.part-button small { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.workspace { display: flex; flex-direction: column; gap: 10px; }
.workspace-toolbar, .workspace-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(15, 21, 18, .92);
}
.segmented, .view-tools { display: flex; align-items: center; gap: 6px; }
.segmented button { min-width: 100px; }
.view-tools output { min-width: 50px; color: var(--muted); text-align: center; font-size: 12px; font-weight: 800; }
.workspace-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 10px 12px;
  border: 1px solid #4d4934;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(61, 52, 31, .48), rgba(18, 23, 20, .96));
}
.workspace-selection h2, .workspace-selection p { margin-bottom: 0; }
.workspace-current-finish {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-width: 210px;
}
.workspace-current-finish > span:last-child { display: grid; }
.workspace-current-finish small { color: var(--muted); }
.finish-rail-panel {
  min-width: 0;
  min-height: 170px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(25, 33, 29, .97), rgba(14, 20, 17, .97));
}
.finish-rail-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}
.finish-rail-heading h2, .finish-rail-heading p { margin-bottom: 0; }
.finish-search-label {
  display: grid;
  grid-template-columns: auto minmax(190px, 330px);
  align-items: center;
  gap: 9px;
  margin: 0;
}
.finish-search-label input { min-height: 44px; }
.finish-rail-shell {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: stretch;
  gap: 7px;
  margin-top: 8px;
}
.rail-step { min-width: 44px; min-height: 76px; padding: 0; font-size: 30px; line-height: 1; }
.finish-rail {
  display: flex;
  gap: 7px;
  min-width: 0;
  min-height: 92px;
  padding: 2px 2px 10px;
  overflow-x: scroll;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: auto;
  scrollbar-color: var(--gold) #202923;
  overscroll-behavior-inline: contain;
  touch-action: pan-x pan-y;
  cursor: grab;
}
.finish-rail[data-dragging="true"] { cursor: grabbing; scroll-behavior: auto; }
.finish-rail::-webkit-scrollbar { height: 12px; }
.finish-rail::-webkit-scrollbar-track { border-radius: 999px; background: #202923; }
.finish-rail::-webkit-scrollbar-thumb { border: 2px solid #202923; border-radius: 999px; background: var(--gold); }
.finish-chip {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  flex: 0 0 164px;
  gap: 8px;
  min-height: 76px;
  padding: 7px;
  text-align: left;
}
.finish-chip-swatch {
  width: 34px;
  height: 52px;
  border: 2px solid rgba(255, 255, 255, .55);
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .5);
}
.finish-chip-text { display: grid; min-width: 0; gap: 2px; }
.finish-chip-text strong { font: 800 12px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; }
.finish-chip-text small {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.finish-chip[aria-selected="true"] {
  color: #10130f;
  border-color: var(--gold-2);
  background: var(--gold-2);
}
.finish-chip[aria-selected="true"] small { color: #343229; }
.finish-rail-empty {
  display: grid;
  place-items: center;
  flex: 1 0 100%;
  min-height: 76px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}
.finish-rail-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}
.finish-rail-footer p { margin: 0; }
.finish-rail-footer output { flex: none; font-weight: 800; }
.canvas-viewport {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background:
    linear-gradient(45deg, #d9ddda 25%, transparent 25%),
    linear-gradient(-45deg, #d9ddda 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9ddda 75%),
    linear-gradient(-45deg, transparent 75%, #d9ddda 75%),
    #eef0ee;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}
.canvas-stage {
  width: 100%;
  transform-origin: center;
  transition: transform 160ms ease-out;
  will-change: transform;
}
#replicaCanvas { display: block; width: 100%; height: auto; touch-action: manipulation; cursor: crosshair; }
.part-tooltip {
  position: absolute;
  z-index: 5;
  max-width: 260px;
  padding: 7px 9px;
  pointer-events: none;
  border: 1px solid #cba95f;
  border-radius: 7px;
  color: #131813;
  background: rgba(249, 235, 194, .97);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
  font-size: 12px;
  font-weight: 800;
}
.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: #17201b;
  background: rgba(238, 240, 238, .92);
  font-weight: 900;
}
.loading-overlay span { width: 30px; height: 30px; border: 4px solid #87928b; border-top-color: #181e1b; border-radius: 50%; animation: spin .8s linear infinite; }
body[data-ready="true"] .loading-overlay { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.workspace-status { align-items: start; color: var(--muted); font-size: 11px; line-height: 1.45; }
.workspace-status p { margin: 0; }
.workspace-status p:first-child { display: grid; gap: 3px; }
.workspace-status strong { color: var(--text); }
.source-note { text-align: right; }
.summary-panel { padding-block: 11px; }
.configuration-summary { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 2px; }
.summary-chip {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 16px auto;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 10px;
}
.summary-chip i { width: 14px; height: 14px; border: 1px solid rgba(255,255,255,.45); border-radius: 4px; }
.danger-subtle { color: #ffd8d0; border-color: #795047; background: #291b18; }
.save-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.saved-configurations { display: grid; gap: 7px; margin-top: 12px; }
.saved-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 5px; align-items: center; padding: 7px; border: 1px solid var(--line); border-radius: 8px; }
.saved-row span { min-width: 0; }
.saved-row strong, .saved-row small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-row small { color: var(--muted); font-size: 9px; }
.saved-row button { min-height: 32px; padding: 5px 7px; font-size: 10px; }
.action-stack { display: grid; gap: 7px; }
.portable-sharing-panel { border-color: #4d4934; }
.portable-sharing-actions { margin-top: 10px; }
.portable-sharing-explanation { margin-top: 10px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.portable-sharing-explanation p { margin-bottom: 6px; }
.portable-sharing-status { min-height: 1.5em; overflow-wrap: anywhere; }
.portable-sharing-status[data-tone="success"] { color: var(--green); }
.portable-sharing-status[data-tone="warning"] { color: var(--gold-2); }
.portable-sharing-status[data-tone="error"] { color: var(--danger); }
.portable-import-review {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: rgba(6, 10, 8, .7);
  overflow-wrap: anywhere;
}
.portable-import-review[hidden] { display: none; }
.portable-import-review h3 { margin: 0 0 10px; font-size: 16px; }
.portable-import-review h4 { margin: 10px 0 5px; color: var(--gold-2); font-size: 12px; }
.portable-review-facts { display: grid; gap: 5px; margin: 0; }
.portable-review-facts div { display: grid; grid-template-columns: minmax(105px, .8fr) minmax(0, 1.2fr); gap: 10px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.portable-review-facts dt { color: var(--muted); font-size: 11px; }
.portable-review-facts dd { margin: 0; font-size: 11px; font-weight: 750; text-align: right; overflow-wrap: anywhere; }
.portable-review-section ul { display: grid; gap: 4px; margin: 0; padding-left: 19px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.portable-review-errors ul { color: var(--danger); }
.portable-review-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.portable-review-actions button { min-height: 44px; }
.facts-panel dl { display: grid; gap: 6px; margin: 0; }
.facts-panel dl div { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.facts-panel dt { color: var(--muted); }
.facts-panel dd { margin: 0; text-align: right; font-weight: 800; }
footer { padding: 12px 24px 20px; color: var(--muted); font-size: 11px; text-align: center; }
footer p { margin: 0; }

@media (min-width: 1600px) and (min-height: 820px) {
  .canvas-viewport { min-height: 520px; }
}
@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 250px minmax(0, 1fr); }
  .right-panel { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 780px) {
  .topbar { align-items: start; flex-direction: column; padding: 16px; }
  .topbar-badges { justify-content: start; }
  .app-shell { grid-template-columns: 1fr; padding: 8px; }
  .left-panel { display: grid; grid-template-columns: 1fr; }
  .parts-list { max-height: 310px; }
  .workspace { grid-row: 1; }
  .left-panel { grid-row: 2; }
  .right-panel { grid-row: 3; grid-column: 1; grid-template-columns: 1fr; }
  .workspace-toolbar, .workspace-status { align-items: stretch; flex-direction: column; }
  .segmented, .view-tools { width: 100%; }
  .segmented button { flex: 1; min-width: 0; }
  .view-tools { justify-content: center; flex-wrap: wrap; }
  .workspace-selection { align-items: start; flex-direction: column; gap: 8px; }
  .workspace-current-finish { width: 100%; }
  .finish-rail-heading { align-items: stretch; flex-direction: column; gap: 8px; }
  .finish-search-label { grid-template-columns: 1fr; gap: 4px; }
  .finish-search-label input { min-height: 44px; }
  .rail-step { min-height: 76px; }
  .finish-chip { flex-basis: 154px; min-height: 76px; }
  .canvas-viewport { min-height: 240px; }
  .source-note { text-align: left; }
  .summary-panel .panel-heading { align-items: stretch; flex-direction: column; }
}
@media (max-width: 420px) {
  h1 { font-size: 25px; }
  .subtitle { font-size: 12px; }
  .topbar-badges span { font-size: 9px; }
  .panel { padding: 12px; }
  .finish-rail-panel { min-height: 176px; padding: 9px; }
  .finish-rail-shell { grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 5px; }
  .finish-chip { flex-basis: 146px; }
  .canvas-viewport { min-height: 210px; }
  .view-tools button { padding-inline: 9px; }
  .save-row { grid-template-columns: 1fr; }
  .portable-sharing-panel button,
  .portable-sharing-panel input { min-height: 44px; }
  .portable-review-facts div { grid-template-columns: 1fr; gap: 2px; }
  .portable-review-facts dd { text-align: left; }
  .portable-review-actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
