:root {
  --bg: #050508;
  --panel: rgba(14, 14, 20, 0.88);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #818cf8;
  --accent-2: #fbbf24;
  --ok: #34d399;
  --danger: #f87171;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --side-w: min(300px, 92vw);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: relative; width: 100%; height: 100%; height: 100dvh; }
#c {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Boot */
.boot {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: #050508;
  transition: opacity 0.4s, visibility 0.4s;
}
.boot.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-card { text-align: center; width: min(280px, 80vw); }
.boot-brand {
  font-weight: 800;
  letter-spacing: 0.22em;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  color: #e4e4e7;
}
.boot-bar {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
#boot-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #fbbf24);
  transition: width 0.2s;
}
#boot-text { margin: 0.75rem 0 0; font-size: 0.8rem; color: var(--muted); }

/* Top */
.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand-block { display: flex; align-items: baseline; gap: 0.45rem; }
.brand {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 0.9rem;
}
.brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.top-actions { display: flex; gap: 0.4rem; }
.app-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  padding: 0.22rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(16px);
}
.app-switch .mode-btn { padding: 0.38rem 0.85rem; min-width: 6.2rem; }

#workshop-pane {
  position: absolute;
  z-index: 6;
  left: 0.55rem;
  top: 3.45rem;
  bottom: 2.15rem;
  width: var(--sheet-w, min(640px, 46vw));
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.38);
  background: #13161e;
  display: flex;
  flex-direction: column;
}

#workshop-pane iframe {
  width: 100%;
  flex: 1;
  min-height: 0;
  height: auto;
  border: 0;
  background: #13161e;
}
#sheet-grip {
  position: absolute;
  z-index: 3;
  top: 2.55rem;
  right: 0;
  bottom: 0;
  width: 14px;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
}
#sheet-grip::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 3px;
  width: 5px;
  height: 52px;
  margin-top: -26px;
  border-radius: 4px;
  background: #1c2130;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9), 0 1px 4px rgba(0, 0, 0, 0.45);
}
#sheet-grip:hover,
#workshop-pane.is-resizing #sheet-grip {
  background: linear-gradient(90deg, transparent, rgba(28, 33, 48, 0.08));
}
#sheet-grip:hover::after,
#workshop-pane.is-resizing #sheet-grip::after,
#workshop-pane.is-wide #sheet-grip::after {
  background: #3b5bdb;
  box-shadow: 0 0 0 1px #fff, 0 1px 6px rgba(0, 0, 0, 0.45);
}
#workshop-pane.is-min #sheet-grip { display: none; }
body.sheet-drag, body.sheet-drag * { cursor: ew-resize !important; }
body.sheet-drag { user-select: none; }
.mode-row.levels { grid-template-columns: repeat(3, 1fr); }
#lift-block { display: flex; flex-direction: column; gap: 0.45rem; }
#lift-block[hidden] { display: none; }

/* Sides */
.side {
  position: absolute;
  top: 3.5rem;
  bottom: 2.4rem;
  z-index: 5;
  width: var(--side-w);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.side.left { left: 0.75rem; }
.side.right { right: 0.75rem; }
.side h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}
.hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.hint strong { color: #e4e4e7; }

.section-h {
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.scene-list { display: flex; flex-direction: column; gap: 0.32rem; }
.scn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  border-radius: 12px;
  padding: 0.35rem 0.45rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.scn:hover { border-color: rgba(129,140,248,0.45); }
.scn.selected {
  border-color: var(--scn-accent, var(--accent));
  background: rgba(99,102,241,0.16);
  box-shadow: inset 3px 0 0 var(--scn-accent, var(--accent));
}
.scn-thumb {
  width: 54px;
  height: 32px;
  border-radius: 7px;
  object-fit: cover;
  flex-shrink: 0;
  background: #111;
  display: block;
}
.scn-thumb-void {
  background: radial-gradient(circle at 42% 38%, #2a2a36 0%, #050508 68%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}
.scn-thumb-void-white {
  background: radial-gradient(circle at 42% 38%, #ffffff 0%, #e4e4e7 70%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
}
.scn-copy { min-width: 0; }
.scn-title {
  display: block;
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1.2;
}
.scn-meta {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.65rem;
  color: var(--muted);
  font-family: var(--mono);
}

.config-list { display: flex; flex-direction: column; gap: 0.4rem; }
.cfg {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.12s, background 0.12s;
}
.cfg:hover { border-color: rgba(129,140,248,0.45); }
.cfg.selected {
  border-color: var(--accent);
  background: rgba(99,102,241,0.16);
}
.cfg-title { display: block; font-weight: 700; font-size: 0.9rem; }
.cfg-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
}

.detail-empty {
  margin: auto 0;
  text-align: center;
  color: var(--muted);
}
.detail-empty h2 { color: var(--text); margin-bottom: 0.4rem; }
.detail-empty p { font-size: 0.85rem; line-height: 1.4; }

.d-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.bom {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.bom-item {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.3rem;
  text-align: center;
}
.bom-n {
  display: block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent-2);
}
.bom-l {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.1rem;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.mode-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.mode-btn.selected {
  background: rgba(99,102,241,0.22);
  border-color: var(--accent);
}

.build-panel {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.65rem;
  border-radius: 12px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
}
.build-panel[hidden] { display: none; }
.step-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}
.pill {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(251,191,36,0.15);
  color: var(--accent-2);
  text-transform: uppercase;
}
.pill.bridge {
  background: rgba(96,165,250,0.15);
  color: #93c5fd;
}
.step-help {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.step-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.4rem;
}

.color-block { display: flex; flex-direction: column; gap: 0.4rem; }
.color-label { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}
.swatch {
  appearance: none;
  border: 2px solid transparent;
  border-radius: 8px;
  height: 32px;
  cursor: pointer;
  padding: 0;
}
.swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(129,140,248,0.5);
}
.swatch.black { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2); }

#c.paint-indiv { cursor: crosshair; }

#group-target-row[hidden] { display: none; }
#paint-help { margin: 0; }

.toggles {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.toggles label { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }

.legal-note {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  line-height: 1.4;
  opacity: 0.9;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover { background: rgba(255,255,255,0.1); }
.btn.primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-color: transparent;
  color: #fff;
}
.btn.ghost {
  background: transparent;
}
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  pointer-events: none;
}
.status-bar .sep { opacity: 0.4; }
#status { color: #c7d2fe; font-weight: 600; }

@media (max-width: 900px) {
  #workshop-pane {
    left: 0.4rem;
    right: 0.4rem;
    width: auto;
    top: 3.35rem;
    height: 40vh;
    bottom: auto;
  }
  #sheet-grip { display: none; }
  .app-switch .mode-btn { min-width: 0; padding: 0.38rem 0.55rem; }
  .side.left {
    top: auto;
    bottom: 2.2rem;
    left: 0.4rem;
    right: 50%;
    width: auto;
    max-height: 34vh;
    margin-right: 0.2rem;
  }
  .side.right {
    top: auto;
    bottom: 2.2rem;
    right: 0.4rem;
    left: 50%;
    width: auto;
    max-height: 34vh;
    margin-left: 0.2rem;
  }
}

@media (max-width: 560px) {
  .side.left, .side.right {
    left: 0.4rem;
    right: 0.4rem;
    width: auto;
    margin: 0;
  }
  .side.left { bottom: calc(2.2rem + 36vh); max-height: 28vh; }
  .side.right { max-height: 34vh; }
}

.pane-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 8, 12, 0.55);
  flex-shrink: 0;
}
.pane-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e4e4e7;
}
.pane-min {
  appearance: none;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.pane-min:hover { background: rgba(255, 255, 255, 0.12); }
.pane-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem 0.95rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.side.is-min,
#workshop-pane.is-min {
  width: 2.7rem;
  bottom: auto;
  height: auto;
}
.side.is-min { padding: 0; }
.side.is-min .pane-body,
#workshop-pane.is-min iframe { display: none; }
.is-min .pane-bar {
  flex-direction: column-reverse;
  border-bottom: 0;
  padding: 0.55rem 0.2rem 0.7rem;
  gap: 0.55rem;
  cursor: pointer;
}
.is-min .pane-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.export-wrap { position: relative; }
.export-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 250px;
  padding: 0.35rem;
  background: rgba(14, 14, 20, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
.export-pop[hidden] { display: none; }
.export-pop button {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 0;
  text-align: left;
  font: inherit;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}
.export-pop button span {
  display: block;
  margin-top: 0.12rem;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}
.export-pop button:hover { background: rgba(255, 255, 255, 0.06); }

@media (max-width: 900px) {
  #workshop-pane.is-min {
    width: auto;
    left: 0.4rem;
    right: 0.4rem;
    height: auto;
    bottom: auto;
    top: 3.35rem;
  }
  .side.is-min {
    height: auto;
    max-height: none;
    top: auto;
  }
  .is-min .pane-bar { flex-direction: row; cursor: pointer; }
  .is-min .pane-title {
    writing-mode: horizontal-tb;
    transform: none;
  }
}
