:root {
  --gap: 12px;
  --bar-h: 48px;
  --pal-w: 256px;
  --props-w: 304px;
  --status-h: 32px;
  --free-l: calc(var(--gap) * 2 + var(--pal-w));
  --free-r: calc(var(--gap) * 2 + var(--props-w));
  --free-t: calc(var(--gap) * 2 + var(--bar-h));
  --free-b: calc(var(--gap) * 2 + var(--status-h));

  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--air);
  -webkit-font-smoothing: antialiased;
}

.sprite { display: none; }

svg.i {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Floating chrome over the full-window scene */

#viewport {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

#topbar,
#palette,
#props,
#status {
  position: fixed;
  border: 1px solid var(--glass-edge);
  box-shadow: var(--glass-highlight), var(--glass-shade);
}

#palette,
#props,
#status {
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

#topbar {
  top: var(--gap);
  left: var(--gap);
  right: var(--gap);
  z-index: 20;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--bar-h);
  padding: 0 7px 0 20px;
  border-radius: 999px;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
}
#topbar::-webkit-scrollbar { display: none; }

/* The glass lives on a pseudo-element: backdrop-filter on #topbar itself would
   become the containing block for the position:fixed «Ещё» panel. */
#topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}

#palette,
#props {
  top: var(--free-t);
  bottom: var(--gap);
  z-index: 10;
  overflow-y: auto;
  padding: 14px 14px 16px;
  border-radius: var(--r-window);
  background: var(--glass-strong);
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 30, 46, .2) transparent;
}
#palette { left: var(--gap); width: var(--pal-w); }
#props { right: var(--gap); width: var(--props-w); }

#status {
  bottom: var(--gap);
  left: var(--free-l);
  right: var(--free-r);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--status-h);
  padding: 0 16px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--ink-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}
#status-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#status-right { flex: none; font-variant-numeric: tabular-nums; }

/* Toolbar */

.brand {
  margin-right: 4px;
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -.02em;
}
.brand span { color: var(--supply); }

.group { display: flex; align-items: center; gap: 2px; }
.group + .group { padding-left: 12px; border-left: 1px solid var(--hairline); }
.more-menu { margin-left: auto; padding-left: 0 !important; border-left: 0 !important; }

#topbar > .group > button,
.more-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  min-height: 0;
  padding: 0 11px 0 9px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 500;
}
#topbar > .group > button.icon-only { width: 34px; padding: 0; justify-content: center; }
#topbar > .group > button:hover:not(:disabled),
.more-menu > summary:hover { background: rgba(255, 255, 255, .78); }
#topbar > .group > button:active:not(:disabled) { background: rgba(15, 30, 46, .07); }
#topbar > .group > button.active {
  color: #fff;
  background: var(--supply);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2);
}

.more-menu > summary {
  list-style: none;
  cursor: pointer;
  background: rgba(255, 255, 255, .6);
}
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu[open] > summary { color: var(--supply-ink); background: #fff; }
.more-menu:not([open]) .more-panel { display: none; }

.more-panel {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: max-content;
  max-width: min(440px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--glass-edge);
  border-radius: 16px;
  background: var(--glass-strong);
  box-shadow: var(--glass-highlight), var(--pop-shade);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  white-space: normal;
  animation: pop .14s var(--ease);
}
.more-title { margin: 6px 4px 2px; color: var(--ink-muted); font-size: 12px; font-weight: 600; }
.more-title:first-child { margin-top: 0; }
.more-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.more-row button { display: inline-flex; align-items: center; gap: 6px; padding-left: 8px; }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Controls */

button {
  font: inherit;
  min-height: 30px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--ink);
  background: rgba(255, 255, 255, .78);
  line-height: 1.2;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { border-color: #bfccd8; background: #fff; }
button:active { background: var(--air-deep); }
button.active { border-color: var(--supply); color: #fff; background: var(--supply); }
button.small { min-height: 26px; padding: 3px 8px; font-size: 12px; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: rgba(200, 50, 43, .4); }
button:disabled { opacity: .4; cursor: default; }
button:disabled:hover { border-color: var(--line); background: rgba(255, 255, 255, .78); }

:where(button, summary, input, select, a):focus-visible {
  outline: 3px solid rgba(10, 102, 216, .4);
  outline-offset: 1px;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-muted);
}
.chk input[type="checkbox"] { width: 15px; height: 15px; margin: 0; accent-color: var(--supply); }

select,
input[type="number"],
input[type="text"] {
  font: inherit;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255, 255, 255, .92);
  transition: border-color .12s, box-shadow .12s;
}
select:hover, input[type="number"]:hover, input[type="text"]:hover { border-color: #bfccd8; }
select:focus, input[type="number"]:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--supply);
  box-shadow: var(--focus);
}
input:disabled { color: var(--ink-muted); background: rgba(15, 30, 46, .04); }
input[type="number"] { width: 100%; font-variant-numeric: tabular-nums; }

/* Panels */

h2 {
  margin: 18px 2px 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}
h2:first-child { margin-top: 2px; font-size: 15px; }

#palette-buttons { display: flex; flex-direction: column; gap: 1px; }
.pal-group-title {
  margin: 12px 2px 3px;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 550;
}
.pal-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 6px 8px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}
.pal-btn:hover { border-color: var(--line); background: rgba(255, 255, 255, .9); }

.swatch,
.pal-btn .swatch,
.prop-head .swatch,
.list .item .swatch,
.oname .swatch {
  display: inline-block;
  flex: none;
  border: 0;
  border-radius: var(--r-chip);
  box-shadow: inset 0 0 0 1px rgba(15, 30, 46, .3), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.pal-btn .swatch { width: 14px; height: 14px; }
.prop-head .swatch { width: 16px; height: 16px; }
.list .item .swatch { width: 11px; height: 11px; margin-right: 4px; vertical-align: -1px; border-radius: 3px; }
.oname .swatch { width: 11px; height: 11px; border-radius: 3px; }
.swatch.group {
  width: 14px;
  height: 14px;
  background: repeating-linear-gradient(45deg, var(--steel) 0 3px, var(--air-deep) 3px 6px);
  vertical-align: -2px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { color: var(--ink-muted); font-size: 12px; }
.field small { color: var(--ink-muted); font-size: 11px; line-height: 1.35; }

.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.row3 .field { margin-bottom: 0; min-width: 0; }
.row3 .field > span { overflow: hidden; font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.row3 input[type="number"] { min-width: 0; padding: 0 4px 0 7px; }
.row3 input[type="number"]::-webkit-inner-spin-button,
.row3 input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.row3 input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.prop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; }
.prop-head .type { color: var(--ink); }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.btn-row button { flex: 1 1 calc(50% - 3px); min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.bbox,
.offer {
  border-radius: var(--r-control);
  background: rgba(15, 30, 46, .045);
  font-variant-numeric: tabular-nums;
}
.bbox { margin-top: 8px; padding: 8px 10px; color: var(--ink-muted); font-size: 12px; }
.bbox b { color: var(--ink); }

.muted { color: var(--ink-muted); }

.list { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.list .item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 28px;
  padding: 3px 4px 3px 9px;
  border-radius: 8px;
  background: rgba(15, 30, 46, .045);
  font-size: 12px;
}
.list .item b { font-variant-numeric: tabular-nums; }
.list .item button { min-height: 22px; padding: 1px 7px; font-size: 12px; }

.hints-box { margin-top: 18px; }
.hints-box summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.hints-box summary::-webkit-details-marker { display: none; }
.hints-box summary svg.i { width: 16px; height: 16px; color: var(--ink-muted); }
.hints { margin: 8px 0 0; padding-left: 16px; color: var(--ink-muted); font-size: 12px; line-height: 1.55; }
.hints li + li { margin-top: 4px; }
.hints b {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink);
  background: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
}

.hint { margin: 4px 0; font-size: 11px; }
.badge {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  color: var(--supply-ink);
  background: var(--supply-tint);
  font-size: 11px;
  font-weight: 600;
}
button.link {
  min-height: 0;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--supply-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Scene outline */

.outline { display: flex; flex-direction: column; gap: 1px; }
.orow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.orow:hover { background: rgba(15, 30, 46, .05); }
.orow.selected { background: var(--supply-tint); box-shadow: inset 2px 0 0 var(--supply); }
.orow.frozen .oname { opacity: .5; }
.oname { display: flex; flex: 1; align-items: center; gap: 7px; min-width: 0; }
.oname > span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.olock { min-height: 22px; padding: 0 5px; border: 0; background: none; font-size: 12px; line-height: 1; }
.olock:hover { background: rgba(15, 30, 46, .07); }
.oprice { flex: none; color: var(--ink); font-size: 11px; font-variant-numeric: tabular-nums; }

.offer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 2px 8px;
  margin-bottom: 10px;
  padding: 8px 10px;
}
.offer .store { color: var(--ink-muted); font-size: 12px; }
.offer a, .offer .material { grid-column: 1 / -1; font-size: 12px; }
.offer a { color: var(--supply-ink); }
.offer .material { color: var(--ink); }

/* Viewport overlays */

#viewport canvas { display: block; width: 100%; height: 100%; outline: none; }
#viewport.measure canvas { cursor: crosshair; }
#viewport.fly canvas { cursor: grab; }
#viewport.fly.looking canvas { cursor: grabbing; }

#empty-guide {
  position: absolute;
  left: calc(var(--free-l) + (100% - var(--free-l) - var(--free-r)) / 2);
  top: calc(var(--free-t) + (100% - var(--free-t) - var(--free-b)) / 2);
  z-index: 4;
  width: min(360px, calc(100% - var(--free-l) - var(--free-r) - 32px));
  padding: 20px 22px;
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-window);
  background: var(--glass-strong);
  box-shadow: var(--glass-highlight), var(--pop-shade);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  transform: translate(-50%, -50%);
}
#empty-guide p { margin: 0 0 12px; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
#empty-guide ol { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; counter-reset: step; }
#empty-guide li {
  display: flex;
  align-items: center;
  gap: 10px;
  counter-increment: step;
}
#empty-guide li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--supply-ink);
  background: var(--supply-tint);
  font-size: 12px;
  font-weight: 700;
}
.empty-actions { display: flex; gap: 8px; margin-top: 16px; }
.empty-actions button { min-height: 34px; padding-inline: 16px; }
#btn-empty-sample { border-color: var(--supply); color: #fff; background: var(--supply); }
#btn-empty-sample:hover { background: var(--supply-hover); }

#center-hud {
  position: absolute;
  top: var(--free-t);
  left: var(--free-l);
  z-index: 5;
  width: 268px;
  max-height: calc(100% - var(--free-t) - var(--free-b));
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-card);
  background: var(--glass-strong);
  box-shadow: var(--glass-highlight), var(--glass-shade);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
.center-hud-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.center-hud-head strong { flex: 1; font-size: 13px; font-weight: 650; }
#center-hud .list { max-height: 240px; overflow-y: auto; }
#center-hud .center-switch { margin-bottom: 10px; }
#center-hud .center-switch select { width: 100%; }
#center-hud .hint { margin: 8px 0 0; }

.center-item { gap: 6px; cursor: pointer; }
.center-item.active { background: var(--supply-tint); }
.center-item .cnum {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  color: var(--ink);
  background: rgba(15, 30, 46, .08);
  font-size: 11px;
  font-weight: 700;
}
.center-item.active .cnum { color: #fff; background: var(--supply); }
.center-item input[type="text"] { flex: 1; min-width: 0; height: 26px; padding: 0 7px; border-radius: 7px; }

#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.label {
  position: absolute;
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--ink);
  background: var(--extract);
  box-shadow: 0 1px 2px rgba(15, 30, 46, .25);
  font-size: 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.label small { display: block; font-size: 10px; font-weight: 500; opacity: .85; }
.label.pending { color: #fff; background: var(--supply); }

/* Product picker */

#product-picker {
  width: min(480px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 48px));
  padding: 0;
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-window);
  color: var(--ink);
  background: var(--glass-strong);
  box-shadow: var(--glass-highlight), var(--pop-shade);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
#product-picker::backdrop {
  background: rgba(16, 42, 67, .35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
#product-picker form { display: flex; flex-direction: column; max-height: min(640px, calc(100vh - 48px)); }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.picker-head h2 { margin: 0; font-size: 17px; }
#product-picker .hint { margin: 8px 18px 0; }
#picker-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; padding: 12px 18px 18px; }
.picker-store { margin: 8px 2px 0; color: var(--ink-muted); font-size: 12px; font-weight: 600; }
.picker-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name price" "meta price";
  gap: 1px 12px;
  padding: 9px 12px;
  border-radius: 12px;
  text-align: left;
}
.picker-name { grid-area: name; font-weight: 600; }
.picker-meta { grid-area: meta; color: var(--ink-muted); font-size: 12px; }
.picker-card b { grid-area: price; align-self: center; font-variant-numeric: tabular-nums; }

/* Breakpoints: panels narrow, the editor stays a desktop tool */

@media (max-width: 1279px) {
  :root { --pal-w: 224px; --props-w: 264px; }
  #topbar .files .lbl { display: none; }
  #topbar > .files > button { width: 34px; padding: 0; justify-content: center; }
}

@media (max-width: 1099px) {
  :root { --pal-w: 184px; --props-w: 216px; font-size: 12px; }
  .brand { display: none; }
  #topbar > .group > .view .lbl { display: none; }
  #topbar > .group > .view { width: 34px; padding: 0; justify-content: center; }
  .hints { display: none; }
}
