:root {
  --paper: #F5F6F2;
  --paper-2: #ECEEE7;
  --ink: #18211E;
  --muted: #5D6A65;
  --line: #D6DBD2;
  --mat: #1F4A41;
  --mat-ink: #DCE7E0;
  --filament: #F2C230;
  --filament-deep: #D9A916;
  --filament-ink: #261F00;
  --alert: #A4281F;
  --focus: #2F7DE1;
  --radius-s: 6px;
  --radius-m: 10px;
  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-ui: "Figtree", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151A18;
    --paper-2: #1C2320;
    --ink: #E9EEE9;
    --muted: #9AA8A1;
    --line: #2C3531;
    --mat: #183A33;
    --alert: #FF8A80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }

/* ---------- top bar */
.topbar {
  height: 56px;
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
}
.wordmark { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.wordmark svg { width: 30px; height: 22px; }
.wordmark svg rect:nth-child(1) { fill: var(--mat); }
.wordmark svg rect:nth-child(2) { fill: var(--filament); }
.wordmark svg rect:nth-child(3) { fill: var(--ink); opacity: .85; }
.wordmark span { font: 700 21px/1 var(--font-display); font-variation-settings: "opsz" 40; letter-spacing: -0.02em; }
.picture-chip { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.picture-chip img { width: 38px; height: 38px; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--paper-2); }
.pic-count { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.link-btn { background: none; border: 0; padding: 4px 2px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 500; }

/* ---------- three columns */
.workspace {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 340px;
  height: calc(100vh - 56px);
}
.modes { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 0; }
.stage { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.panel { border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }

/* ---------- mode rail */
.mode {
  display: grid; grid-template-columns: 28px 1fr; gap: 2px 12px;
  width: 100%; text-align: left;
  padding: 11px 18px 11px 16px;
  background: none; border: 0; border-left: 4px solid transparent;
  cursor: pointer; color: var(--ink);
}
.mode:hover { background: var(--paper-2); }
.mode svg { grid-row: span 2; width: 28px; height: 28px; margin-top: 2px; fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.mode .t { font: 600 15.5px/1.25 var(--font-display); }
.mode .b { font-size: 13px; line-height: 1.4; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mode[aria-pressed="true"] { border-left-color: var(--filament); background: var(--paper-2); }
.mode[aria-pressed="true"] svg { stroke: var(--ink); }
.mode[aria-pressed="true"] .t { font-weight: 700; }

/* ---------- viewer */
.viewer { position: relative; flex: 1 0 auto; min-height: 420px; height: 62vh; background: var(--mat); --mat: #1F4A41; }
@media (prefers-color-scheme: dark) { .viewer { --mat: #183A33; } }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; --mat: inherit; }
.viewer canvas:active { cursor: grabbing; }

.dropzone {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
  background:
    linear-gradient(rgba(220,231,224,.07) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(220,231,224,.07) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(rgba(220,231,224,.16) 1px, transparent 1px) 0 0 / 100px 100px,
    linear-gradient(90deg, rgba(220,231,224,.16) 1px, transparent 1px) 0 0 / 100px 100px,
    var(--mat);
  color: var(--mat-ink);
}
.dropzone[hidden] { display: none; }
.dropzone-inner { max-width: 34rem; }
.dropzone h1 { font-size: clamp(30px, 4vw, 46px); line-height: 1.05; font-weight: 700; font-variation-settings: "opsz" 96; color: #fff; letter-spacing: -0.025em; }
.dropzone p { margin: 14px 0 0; max-width: 31rem; color: var(--mat-ink); }
.dz-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.dz-small { font-size: 13px; opacity: .75; }

.readout {
  position: absolute; left: 16px; bottom: 14px;
  color: #fff; font: 600 15px/1 var(--font-display); font-variant-numeric: tabular-nums;
  padding: 8px 10px; border-radius: var(--radius-s); background: rgba(10, 30, 26, .45);
}
.readout small { display: block; font: 500 12px/1.3 var(--font-ui); opacity: .8; margin-top: 4px; }
.readout small:empty { display: none; }
.view-tools { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px; }
.chip {
  border: 1px solid rgba(220,231,224,.35); background: rgba(10,30,26,.4); color: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.chip:hover { background: rgba(10,30,26,.65); }
.busy {
  position: absolute; top: 14px; right: 14px; display: flex; align-items: center; gap: 8px;
  color: var(--filament-ink); background: var(--filament); padding: 6px 12px 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.error {
  position: absolute; top: 14px; left: 14px; right: 14px; max-width: 36rem;
  background: #FFF4F2; color: var(--alert); border: 1px solid #F0C4BE; border-radius: var(--radius-s); padding: 10px 12px; font-size: 14px;
}
.partlist {
  position: absolute; top: 14px; left: 14px; max-width: min(46%, 300px); max-height: calc(100% - 80px); overflow: auto;
  display: flex; flex-direction: column; gap: 2px; padding: 6px; border-radius: var(--radius-s); background: rgba(10,30,26,.45);
}
.partlist label { display: flex; align-items: center; gap: 8px; color: #fff; font-size: 13px; padding: 2px 6px; cursor: pointer; }
.partlist input { accent-color: var(--filament); margin: 0; }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }

/* ---------- details below viewer */
.details { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 28px; padding: 24px; border-top: 1px solid var(--line); }
.figures { display: flex; flex-direction: column; gap: 18px; }
.figures figure { margin: 0; }
.figures img { display: block; max-width: 100%; max-height: 560px; border-radius: var(--radius-s); border: 1px solid var(--line); background: #fff; image-rendering: auto; }
.figures figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; }
.facts h3, .downloads h3, .tips h3 { font-size: 17px; font-weight: 650; margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0 0 20px; font-size: 14px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.tips ul { margin: 0; padding-left: 18px; font-size: 14px; }
.tips li { margin-bottom: 6px; max-width: 62ch; }
table.parts { border-collapse: collapse; width: 100%; font-size: 14px; margin-bottom: 20px; font-variant-numeric: tabular-nums; }
table.parts th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 4px 8px 6px 0; }
table.parts td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }

/* ---------- settings panel */
.panel-head { padding: 18px 20px 6px; }
.panel-head h2 { font-size: 23px; font-weight: 700; font-variation-settings: "opsz" 48; }
.panel-head p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.settings { padding: 4px 20px 16px; }
.group { border-top: 1px solid var(--line); }
.group:first-child { border-top: 0; }
.group > summary {
  list-style: none; cursor: pointer; padding: 12px 0; font: 600 15px/1.2 var(--font-display);
  display: flex; justify-content: space-between; align-items: center;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-3px); transition: transform .15s; }
.group[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.group-body { display: flex; flex-direction: column; gap: 14px; padding-bottom: 16px; }
.field[hidden] { display: none; }
.field label.lbl { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.field output { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.field select, .field input[type="text"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--paper);
}
.field input[type="range"] { width: 100%; accent-color: var(--mat); margin: 2px 0 0; }
@media (prefers-color-scheme: dark) { .field input[type="range"] { accent-color: var(--filament); } }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--mat); flex: none; }
.color-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.color-chips .swatch { width: 20px; height: 20px; border-radius: 4px; }

/* ---------- downloads */
.downloads { margin-top: auto; padding: 16px 20px 22px; border-top: 1px solid var(--line); background: var(--paper-2); position: sticky; bottom: 0; }
.downloads ul { list-style: none; margin: 10px 0 0; padding: 0; max-height: 260px; overflow: auto; }
.downloads .more { font-size: 14px; margin-top: 8px; }
.downloads li a {
  display: flex; justify-content: space-between; gap: 12px; padding: 7px 2px; font-size: 14px; color: var(--ink);
  text-decoration: none; border-bottom: 1px solid var(--line);
}
.downloads li a:hover span:first-child { text-decoration: underline; text-underline-offset: 3px; }
.downloads li a span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-s); padding: 10px 16px; font-weight: 600; border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--filament); color: var(--filament-ink); border-color: var(--filament-deep); }
.btn-primary:hover { background: #F6CF52; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(220,231,224,.5); }
.btn-ghost:hover { background: rgba(255,255,255,.08); }
.btn-block { width: 100%; flex-direction: column; gap: 0; }
.btn-block small { font-weight: 500; opacity: .75; font-size: 12.5px; }

.drag-veil { position: fixed; inset: 0; background: rgba(31,74,65,.85); display: grid; place-items: center; z-index: 10; }
.drag-veil p { color: #fff; font: 700 32px/1 var(--font-display); border: 2px dashed rgba(255,255,255,.7); padding: 40px 56px; border-radius: var(--radius-m); }

/* ---------- narrow screens */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 310px; }
  .details { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .workspace { display: flex; flex-direction: column; height: auto; }
  .modes { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; gap: 4px; scroll-snap-type: x proximity; }
  .mode { width: auto; flex: none; grid-template-columns: 22px auto; padding: 8px 12px; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-s) var(--radius-s) 0 0; scroll-snap-align: start; }
  .mode svg { width: 22px; height: 22px; grid-row: auto; margin: 0; }
  .mode .b { display: none; }
  .mode[aria-pressed="true"] { border-bottom-color: var(--filament); }
  .viewer { height: 58vh; min-height: 340px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .downloads { position: static; }
  .details { padding: 18px 16px; }
  .topbar { padding: 0 16px; }
  .panel-head, .settings, .downloads { padding-left: 16px; padding-right: 16px; }
}
