/* Slot Concept Builder — темна тема в дусі macOS.
   Ґрунт справді чорний, бо полотно теж чорне: артборд не має читатись як
   наклеєний прямокутник. Розділення несуть матеріал, волосяні лінії і тінь. */

:root {
  --bg: #000000;
  --stage: #2c2c2e;
  --material: rgba(22, 22, 24, 0.72);
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --hairline: rgba(255, 255, 255, 0.09);
  --label: #f5f5f7;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --accent: #bf5af2;
  --danger: #ff453a;

  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --r-group: 10px;
  --r-field: 6px;
  --panel-w: 300px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  background: var(--bg);
  color: var(--label);
  font: 13px/1.4 var(--ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Панель ─────────────────────────────────────────────────────────────── */

#panel {
  width: var(--panel-w);
  flex: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px 0 0;
  background: var(--material);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--hairline);
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

/* Скролиться лише середина: шапка і смуга дій лишаються на місці. */
.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 14px 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.panel-scroll::-webkit-scrollbar { width: 9px; }
.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 9px;
}

#brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 16px 16px;
}

#brand svg { flex: none; }

#brand h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 590;
  letter-spacing: -0.01em;
}

#brand .dims {
  margin-left: auto;
  font: 11px/1 var(--mono);
  color: var(--label-3);
  font-variant-numeric: tabular-nums;
}

/* ── Інспектор виділеного ───────────────────────────────────────────────── */

#inspector:not(:empty) {
  margin-bottom: 4px;
  border-radius: var(--r-group);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}

#inspector .row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 5px 10px;
  background: var(--surface-2);
}

#inspector .row > label { flex: 0 0 auto; color: var(--label-2); white-space: nowrap; }
#inspector .row input { flex: 1 1 auto; min-width: 0; background: var(--surface); }

#inspector .hint {
  padding: 8px 10px;
  background: var(--surface);
  color: var(--label-3);
  font-size: 11px;
}

/* ── Групи налаштувань ──────────────────────────────────────────────────── */

/* Кожна група — інсет-список: підпис ліворуч, контрол праворуч,
   волосяна лінія між рядками, як у системних налаштуваннях. */

#controls .group-title {
  padding: 18px 4px 6px;
  font-size: 11px;
  font-weight: 590;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--label-3);
}

#controls .group-title:first-child { padding-top: 2px; }

#controls .row,
#controls .blocks-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 5px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

#controls .row > label {
  flex: 0 0 auto;
  white-space: nowrap;
  color: var(--label-2);
}

#controls .row > :not(label),
#controls .blocks-row > * { flex: none; }

/* Текст тягнеться на всю решту рядка — заголовок не мусить обрізатись. */
#controls .row input[type="text"] { flex: 1 1 auto; width: auto; min-width: 0; margin-left: auto; }
#controls .row input[type="number"] { width: 92px; margin-left: auto; }
#controls .row select { width: 104px; margin-left: auto; }
#controls .row input[type="color"] { margin-left: auto; }

/* Перший і останній рядок групи заокруглюються — межі групи видно без рамки. */
#controls .group-title + .row,
#controls .group-title + .blocks-row {
  border-radius: var(--r-group) var(--r-group) 0 0;
}

#controls .row:has(+ .group-title),
#controls .blocks-row:has(+ .group-title),
#controls > :last-child {
  border-bottom: none;
  border-radius: 0 0 var(--r-group) var(--r-group);
}

/* ── Контроли ───────────────────────────────────────────────────────────── */

input, select, textarea, button {
  font: 13px var(--ui);
  color: var(--label);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-field);
  padding: 4px 7px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

/* Кожне точне значення — моноширинним: це те, що поїде в генератор. */
input[type="number"], input[type="text"], select, #json {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

input:hover, select:hover, textarea:hover { background: var(--surface-3); }

/* Поля показують фокус завжди, кнопки — лише з клавіатури. */
input:focus, select:focus, textarea:focus,
input:focus-visible, select:focus-visible,
textarea:focus-visible, button:focus-visible {
  outline: none;
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16);
}

input[type="color"] {
  width: 34px;
  height: 22px;
  padding: 0;
  background: none;
  border: 1px solid var(--hairline);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

select {
  appearance: none;
  padding-right: 22px;
  background-image: linear-gradient(45deg, transparent 50%, var(--label-2) 50%),
                    linear-gradient(135deg, var(--label-2) 50%, transparent 50%);
  background-position: calc(100% - 12px) 12px, calc(100% - 8px) 12px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}

button {
  cursor: pointer;
  font-weight: 510;
  padding: 5px 12px;
}

button:hover { background: var(--surface-3); }
button:active { background: var(--surface-2); transform: translateY(0.5px); }

#panel .actions {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--hairline);
  background: rgba(0, 0, 0, 0.25);
}

#panel .actions button { flex: 1 1 auto; }
#reset-layout { flex-basis: 100%; background: none; border: 1px solid var(--hairline); color: var(--label-2); }
#reset-layout:hover { background: var(--surface); color: var(--label); }

/* Головна дія — біле на чорному; решта кнопок обведені. */
#export-frames, #export-blocks {
  background: var(--label);
  color: #000;
  font-weight: 590;
}
#export-frames:hover, #export-blocks:hover { background: #ffffff; }
#export-frames:active, #export-blocks:active { background: #d8d8dc; }

/* Рядок блока: ратіо ширше за кількість рамок, «×» тримається краю. */
#controls .blocks-row input[type="text"] { flex: 1 1 auto; width: auto; min-width: 0; }
#controls .blocks-row input[type="number"] { width: 54px; }
#controls .blocks-row button {
  padding: 2px 8px;
  background: none;
  color: var(--label-3);
  font-size: 15px;
  line-height: 1;
}
#controls .blocks-row button:hover { color: var(--danger); background: none; }

#controls > button:last-child {
  margin-top: 8px;
  width: 100%;
  background: none;
  border: 1px solid var(--hairline);
  color: var(--label-2);
}
#controls > button:last-child:hover { background: var(--surface); color: var(--label); }

/* ── Пресети ────────────────────────────────────────────────────────────── */

/* Клік додає блок у сітку, перетягування — у точку, куди кинув. */
.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.presets .preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-field);
  text-align: left;
  cursor: grab;
}

.presets .preset:hover { background: var(--surface-2); border-color: rgba(255, 255, 255, 0.22); }
.presets .preset:active { cursor: grabbing; }

.presets .preset span {
  font: 10px/1 var(--mono);
  color: var(--label-3);
  letter-spacing: 0.04em;
}

#controls .row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-left: auto;
  accent-color: var(--label);
}

/* ── Конфіг ─────────────────────────────────────────────────────────────── */

.config { margin-top: 20px; }

.config > summary {
  padding: 4px 4px 8px;
  font-size: 11px;
  font-weight: 590;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--label-3);
  cursor: pointer;
  list-style: none;
}

.config > summary::-webkit-details-marker { display: none; }
.config > summary::before {
  content: "›";
  display: inline-block;
  width: 12px;
  font-size: 13px;
  transition: transform 0.15s ease;
}
.config[open] > summary::before { transform: rotate(90deg); }
.config > summary:hover { color: var(--label-2); }

#json {
  width: 100%;
  height: 220px;
  resize: vertical;
  background: var(--surface);
  line-height: 1.5;
  tab-size: 2;
}

#json-error {
  flex: 1;
  min-width: 0;
  color: var(--danger);
  font-size: 11px;
}

#panel .apply-row { display: flex; align-items: center; gap: 10px; padding-top: 8px; }

/* ── Роздільник ─────────────────────────────────────────────────────────── */

#splitter {
  flex: none;
  width: 5px;
  margin-left: -1px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.12s ease;
}

#splitter:hover,
#splitter:focus-visible,
body.resizing #splitter { background: rgba(255, 255, 255, 0.18); outline: none; }

/* Поки тягнемо роздільник, курсор не має перескакувати на текст. */
body.resizing { cursor: col-resize; user-select: none; }

/* ── Сцена ──────────────────────────────────────────────────────────────── */

#stage {
  flex: 1;
  background: var(--stage);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  overflow: auto;
}

/* width/height з атрибутів SVG інакше лишають коробку вищою за сам аркуш,
   і зверху-знизу з'являються порожні поля — на чорному тлі їх просто не було видно. */
#stage svg {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 2px;
  box-shadow: 0 18px 48px -14px rgba(0, 0, 0, 0.75);
}

.hit { cursor: move; }

/* ── Лоадер ─────────────────────────────────────────────────────────────── */

/* Знак малює три ратіо, під ним системний спінер. Екран тримається 1.5 с. */

#loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  background: var(--bg);
  animation: loader-out 0.6s ease 2.8s forwards;
}

#loader .mark rect {
  fill: none;
  stroke: var(--label);
  stroke-width: 1.25;
  /* pathLength="1" нормалізує периметр: обведення закривається на будь-якому ратіо. */
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw 0.42s cubic-bezier(0.33, 0, 0.15, 1) forwards;
}

#loader .mark rect:nth-child(1) { animation-delay: 0.02s; }
#loader .mark rect:nth-child(2) { animation-delay: 0.16s; stroke: var(--label-2); }
#loader .mark rect:nth-child(3) { animation-delay: 0.3s; stroke: var(--accent); }

/* Спиці, а не дуга: так крутиться системний індикатор, покроково. */
#loader .spinner {
  opacity: 0;
  animation: fade-in 0.3s ease 0.55s forwards;
}

#loader .spinner g {
  transform-origin: 50% 50%;
  animation: spin 0.8s steps(8, end) infinite;
}

#loader .spinner rect { fill: var(--label); }
#loader .spinner rect:nth-child(1) { opacity: 1; }
#loader .spinner rect:nth-child(2) { opacity: 0.85; }
#loader .spinner rect:nth-child(3) { opacity: 0.7; }
#loader .spinner rect:nth-child(4) { opacity: 0.55; }
#loader .spinner rect:nth-child(5) { opacity: 0.45; }
#loader .spinner rect:nth-child(6) { opacity: 0.35; }
#loader .spinner rect:nth-child(7) { opacity: 0.25; }
#loader .spinner rect:nth-child(8) { opacity: 0.15; }

/* Екран тримається повні 1.5 с, але щойно застосунок готовий — уже не ловить кліки. */
body.ready #loader { pointer-events: none; }

/* 2.8 с — це стеля на випадок, якщо застосунок не встиг. Зазвичай JS вішає .out
   на другій секунді, і екран іде плавним згасанням. */
#loader.out { animation: loader-out 0.6s ease forwards; }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes loader-out { to { opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
  #loader { animation: loader-out 0.01s linear 0.4s forwards; }
  #loader .mark rect { stroke-dashoffset: 0; animation: none; }
  #loader .spinner { opacity: 1; animation: none; }
  #loader .spinner g { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ── Контекстне меню ────────────────────────────────────────────────────── */

#menu {
  position: fixed;
  z-index: 20;
  min-width: 190px;
  padding: 5px;
  background: rgba(38, 38, 40, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

#menu button {
  display: block;
  width: 100%;
  padding: 5px 10px;
  background: none;
  border: none;
  border-radius: 5px;
  text-align: left;
  font-weight: 400;
  color: var(--label);
}

#menu button:hover { background: var(--accent); color: #fff; }
#menu button.danger:hover { background: var(--danger); }
#menu .sep { height: 1px; margin: 5px 6px; background: var(--hairline); }
#menu .title {
  padding: 4px 10px 6px;
  font: 11px/1 var(--mono);
  color: var(--label-3);
}

/* ── Вузький екран ──────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  body { flex-direction: column; overflow: auto; }
  #splitter { display: none; }
  #panel {
    width: 100%;
    height: auto;
    max-height: 52vh;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
  }
  #stage { padding: 20px; }
}
