:root {
  --bg: #111417;
  --topbar: #15191d;
  --panel: #1a1f24;
  --card: #20262d;
  --item: #1c2228;
  --input: #14181c;
  --btn: #2a323a;
  --line: #2e363e;
  --text: #e8ecef;
  --muted: #9aa4ad;
  --accent: #f59e0b;
  --accent-ink: #1a1206;
  --overlay: rgba(20,24,28,.85);
  --veil: rgba(0,0,0,.35);
}
/* Light theme: high contrast for viewing 3D metal models */
[data-theme="light"] {
  --bg: #eef1f4;
  --topbar: #ffffff;
  --panel: #f6f8fa;
  --card: #ffffff;
  --item: #ffffff;
  --input: #ffffff;
  --btn: #e3e8ed;
  --line: #d5dbe1;
  --text: #1b2127;
  --muted: #5c6a75;
  --accent: #b45309;
  --accent-ink: #ffffff;
  --overlay: rgba(255,255,255,.92);
  --veil: rgba(255,255,255,.6);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--topbar); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; border-radius: 8px;
}
.brand small { display: block; color: var(--muted); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.wa-badge {
  font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); padding: 6px 10px; border-radius: 999px;
}
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100dvh - 57px); }
.panel {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.card h2 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
input {
  width: 100%; margin-top: 4px; padding: 9px 10px;
  background: var(--input); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
.items { display: flex; flex-direction: column; gap: 8px; }
.item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  display: flex; flex-direction: column; gap: 6px; background: var(--item);
}
.item.active { border-color: var(--accent); }
.item-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-head strong { font-size: 14px; }
.price { color: var(--accent); font-weight: 700; font-size: 13px; white-space: nowrap; }
.item p { margin: 0; color: var(--muted); font-size: 13px; }
.item-foot { display: flex; gap: 8px; align-items: center; }
.item-foot label { display: flex; gap: 6px; align-items: center; margin: 0; }
.btn {
  border: 1px solid var(--line); background: var(--btn); color: var(--text);
  padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { filter: brightness(1.1); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 12px; padding: 6px 9px; background: var(--overlay); }
/* .btn.small would otherwise override .btn.primary's background (same specificity, later rule) */
.btn.primary.small { background: var(--accent); color: var(--accent-ink); }
.row { display: flex; gap: 8px; margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.total { font-weight: 800; margin-top: 6px; }
.visor { position: relative; min-width: 0; }
.canvas-wrap { position: absolute; inset: 0; }
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.toolbar {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 6;
}
.btn.rail {
  position: relative; width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center;
  background: var(--overlay); border: 1px solid var(--line); border-radius: 10px;
}
.btn.rail:hover { border-color: var(--accent); }
.btn.rail svg { display: block; }
/* hover tooltip with the label */
.btn.rail::after {
  content: attr(data-label);
  position: absolute; right: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  background: var(--overlay); border: 1px solid var(--line); color: var(--text);
  font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 8px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s;
}
.btn.rail:hover::after { opacity: 1; }
.btn.rail.active { border-color: var(--accent); color: var(--accent); }
.btn.active { border-color: var(--accent); color: var(--accent); }
.rail-wrap { position: relative; }
/* brightness popover: vertical slider opening upwards */
.bright-pop {
  position: absolute; bottom: calc(100% + 10px); right: 4px; /* (42-34)/2: centered on the rail button */
  width: 34px; height: 152px;
  background: var(--overlay); border: 1px solid var(--line); border-radius: 10px;
  display: grid; place-items: center; overflow: hidden;
}
.bright-pop[hidden] { display: none; }
.bright-pop input[type="range"] {
  width: 132px; transform: rotate(-90deg); accent-color: var(--accent); margin: 0;
}
/* custom vertical slider (native rotated inputs render inconsistently) */
.bright-track {
  position: relative; width: 10px; height: 126px;
  background: var(--input); border: 1px solid var(--line);
  border-radius: 999px; cursor: pointer; touch-action: none; outline: none;
}
.bright-track:focus-visible { border-color: var(--accent); }
.bright-fill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 40%;
  background: var(--accent); border-radius: 999px; pointer-events: none;
}
.bright-thumb {
  position: absolute; left: 50%; bottom: 40%; transform: translate(-50%, 50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); pointer-events: none;
}
/* collapsible card */
details.card summary {
  font-size: 14px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 6px;
}
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
details.card[open] summary::before { transform: rotate(90deg); }
details.card summary + * { margin-top: 10px; }
.item-info {
  position: absolute; left: 10px; top: 10px;
  background: var(--overlay); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 10px; max-width: min(420px, 70vw);
}
.item-info span { display: block; font-size: 12px; }
.hint {
  position: absolute; bottom: 8px; width: 100%; text-align: center;
  color: var(--muted); font-size: 12px; margin: 0; pointer-events: none;
}
.loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--veil); z-index: 5;
}
/* author display:grid beats UA [hidden]{display:none} — restore it */
.loading[hidden] { display: none; }
.measure-info {
  position: absolute; left: 10px; top: 76px;
  background: var(--overlay); border: 1px solid var(--accent);
  padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 700;
  max-width: min(420px, 70vw); z-index: 6;
}
.measure-info[hidden] { display: none; }
.measure-info small { display: block; font-weight: 400; color: var(--muted); }
.ruler-label {
  position: absolute; z-index: 6; pointer-events: none;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px;
  white-space: nowrap;
}
.anno-pop {
  position: absolute; z-index: 10; width: 240px;
  background: var(--overlay); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px;
  backdrop-filter: blur(4px);
}
.anno-pop[hidden] { display: none; }
.anno-pop strong { font-size: 13px; }
.anno-pop textarea {
  width: 100%; margin: 6px 0; padding: 8px;
  background: var(--input); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 13px; resize: vertical;
}
.anno-list { display: flex; flex-direction: column; gap: 6px; }
.anno {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  font-size: 13px; background: var(--item);
}
.anno-head { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.anno-num {
  min-width: 20px; height: 20px; display: inline-grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 800; border-radius: 50%;
}
.anno-head .muted { font-size: 11px; }
.anno p { margin: 2px 0 6px; }
.anno-foot { display: flex; gap: 6px; }
.only-mobile { display: none; }
.scrim { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .panel {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 72dvh; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; transform: translateY(100%); transition: transform .25s ease;
  }
  body.panel-open .panel { transform: none; }
  body.panel-open .scrim {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25;
  }
}
