:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --panel: #1c2029;
  --panel-2: #232833;
  --line: #2e3440;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #5eead4;
  --accent-2: #7c9cff;
  --danger: #ff6b6b;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a2030 0%, var(--bg) 60%);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: rgba(15,17,21,.6); backdrop-filter: blur(8px); flex-wrap: wrap;
}
.header-actions { display: flex; gap: 6px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 30px; color: var(--accent);
  text-shadow: 0 0 18px rgba(94,234,212,.5);
}
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: .3px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.asset-name { display: flex; flex-direction: column; gap: 4px; }
.asset-name label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.asset-name input {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-family: 'JetBrains Mono', monospace; font-size: 13px;
  width: 180px;
}

/* ---------- Steps ---------- */
.steps { display: flex; gap: 8px; padding: 14px 22px 0; flex-wrap: wrap; }
.step {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: .15s;
}
.step b {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--panel-2); font-size: 12px;
}
.step:hover:not(:disabled) { border-color: var(--accent-2); color: var(--text); }
.step.active { color: #06131a; background: var(--accent); border-color: var(--accent); }
.step.active b { background: rgba(0,0,0,.2); color: #06131a; }
.step:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout { flex: 1; padding: 14px 18px 28px; }
.panel { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.controls { position: sticky; top: 8px; max-height: calc(100vh - 120px); overflow-y: auto; }
.editor-viewport, .sheet-viewport {
  max-width: 100%; max-height: min(70vh, 560px); overflow: auto;
  border: 1px solid var(--line); border-radius: 6px; background: #141820;
}
.editor-card { flex: 1; min-width: 280px; }
.zoom-hint { font-size: 11px; margin: 6px 0 0; }
.project-library { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.lib-asset {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: grab; font-size: 12px;
}
.lib-asset canvas { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; }
.split-suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; max-height: 200px; overflow-y: auto; }
.split-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 12px;
}
.split-row canvas { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; }
.split-meta { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.split-meta span { color: var(--muted); font-size: 11px; }
.split-row .btn { padding: 6px 8px; font-size: 11px; flex: 0; }
.lib-tint { width: 28px; height: 28px; padding: 0; border: none; background: transparent; cursor: pointer; flex-shrink: 0; }
.tint-field { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
.tint-field input[type="color"] { width: 44px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.modal {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; max-width: 360px; width: 90%; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; font-size: 16px; }
.modal-card canvas { margin: 12px auto; display: block; }
.steps { padding: 10px 18px 0; }
.steps .step { padding: 6px 12px; font-size: 12px; }
.control-group, .dropzone {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.control-group h3 { margin: 0 0 14px; font-size: 14px; letter-spacing: .3px; }
.control-group + .control-group, .dropzone + .control-group, .control-group + .dropzone { margin-top: 12px; }

/* ---------- Dropzone ---------- */
.dropzone { cursor: pointer; text-align: center; border-style: dashed; transition: .15s; }
.dropzone.drag { border-color: var(--accent); background: var(--panel-2); }
.dz-inner { padding: 28px 10px; }
.dz-icon { font-size: 34px; color: var(--accent); }
.dropzone p { margin: 8px 0 0; font-size: 14px; }
.dropzone .hint { color: var(--muted); font-size: 12px; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; }
.field span { color: var(--muted); display: flex; justify-content: space-between; }
.field em { color: var(--accent); font-style: normal; font-family: 'JetBrains Mono', monospace; }
select, input[type="range"] { width: 100%; }
select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font-size: 13px;
}
input[type="range"] { accent-color: var(--accent); }
.checkbox { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; font-size: 13px; color: var(--text); cursor: pointer; }
.checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 8px; padding: 9px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: .15s;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); color: #06131a; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 6px; }
.btn.tool.active { background: var(--accent-2); color: #06131a; border-color: var(--accent-2); }
.tool-row, .crop-row { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tool-row .btn, .crop-row .btn { flex: 1; }

/* ---------- Stage ---------- */
.stage { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.center-stage { justify-content: center; }
.stage-empty {
  width: 100%; min-height: 320px; border: 1px dashed var(--line); border-radius: var(--radius);
  display: grid; place-items: center; color: var(--muted); font-size: 14px;
}
.preview-wrap { display: flex; gap: 18px; flex-wrap: wrap; }
.canvas-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.canvas-card.wide { flex: 1 1 480px; }
.canvas-head { font-size: 12px; color: var(--muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .5px; }
.canvas-head em { color: var(--accent); font-style: normal; }
canvas { display: block; max-width: 100%; border-radius: 6px; }
.pixelated { image-rendering: pixelated; image-rendering: crisp-edges; }
.checker {
  background-image:
    linear-gradient(45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #20242e;
}
#sourceCanvas { max-height: 420px; }

/* ---------- Crop ---------- */
.source-holder { position: relative; display: inline-block; }
.crop-overlay {
  position: absolute; border: 2px dashed var(--accent); background: rgba(94,234,212,.12);
  cursor: move;
}

/* ---------- Animate ---------- */
.playbar { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.frame-count { color: var(--muted); font-size: 12px; font-family: 'JetBrains Mono', monospace; }
.frame-strip { display: flex; gap: 6px; flex-wrap: wrap; max-width: 340px; }
.frame-strip canvas { width: 48px; height: 48px; border: 1px solid var(--line); }
.note { color: var(--muted); font-size: 12px; margin: 10px 0 4px; line-height: 1.5; }

/* ---------- Export ---------- */
.export-list { margin: 8px 0 14px; }
.meta {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--accent);
  max-height: 360px; overflow: auto; white-space: pre-wrap; margin: 0;
}
#sheetCanvas { max-width: 100%; }

/* ---------- Segmented control ---------- */
.seg { display: flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; }
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.seg-btn.active { background: var(--accent); color: #06131a; }
.mode-group .note { margin-bottom: 0; }

/* ---------- Frame thumbnails (import) ---------- */
.frame-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.frame-thumb { position: relative; }
.frame-thumb canvas {
  width: 56px; height: 56px; border: 1px solid var(--line); border-radius: 6px;
  image-rendering: pixelated; background: #20242e;
}
.frame-thumb .idx {
  position: absolute; top: 2px; left: 4px; font-size: 10px; color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
}
.frame-thumb .del {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none; cursor: pointer; font-size: 11px; line-height: 1;
}

/* ---------- Parts list (rig) ---------- */
.parts-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.part-chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; font-size: 13px;
}
.part-chip.active { border-color: var(--accent); }
.part-chip .swatch { width: 12px; height: 12px; border-radius: 3px; }
.part-chip .pmeta { margin-left: auto; color: var(--muted); font-size: 11px; font-family: 'JetBrains Mono', monospace; }
.sep { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.text-input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
#rigCanvas { max-width: 100%; }

/* ---------- Block face net (cube unwrap) ---------- */
.face-net {
  display: grid;
  grid-template-columns: repeat(4, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
  justify-content: center;
}
.face-slot {
  width: 52px; height: 52px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); cursor: pointer; position: relative; overflow: hidden;
  image-rendering: pixelated;
}
.face-slot.empty { background-image:
  linear-gradient(45deg, #2a2f3a 25%, transparent 25%),
  linear-gradient(-45deg, #2a2f3a 25%, transparent 25%),
  linear-gradient(45deg, transparent 75%, #2a2f3a 75%),
  linear-gradient(-45deg, transparent 75%, #2a2f3a 75%);
  background-size: 10px 10px; background-color: #20242e;
}
.face-slot.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(94,234,212,.3); }
.face-slot .lbl {
  position: absolute; bottom: 1px; left: 0; right: 0; text-align: center;
  font-size: 8px; color: var(--muted); background: rgba(0,0,0,.45); padding: 1px 0;
}
.face-slot[data-pos="top"] { grid-column: 2; grid-row: 1; }
.face-slot[data-pos="left"] { grid-column: 1; grid-row: 2; }
.face-slot[data-pos="front"] { grid-column: 2; grid-row: 2; }
.face-slot[data-pos="right"] { grid-column: 3; grid-row: 2; }
.face-slot[data-pos="back"] { grid-column: 4; grid-row: 2; }
.face-slot[data-pos="bottom"] { grid-column: 2; grid-row: 3; }
.block-faces { max-width: 400px; }

/* ---------- Shade picker ---------- */
.shade-picker { margin-bottom: 12px; }
.shade-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch-btn {
  width: 30px; height: 30px; border-radius: 6px; border: 2px solid var(--line); cursor: pointer;
  background-image:
    linear-gradient(45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f3a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f3a 75%);
  background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; position: relative;
}
.swatch-btn span { position: absolute; inset: 0; border-radius: 3px; }
.swatch-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(94,234,212,.35); }

/* Inline checkbox (playbar) */
.checkbox.inline { margin: 0; font-size: 12px; gap: 5px; }
.checkbox.inline input { width: 14px; height: 14px; }

/* Draggable frame thumbs */
.frame-thumb { cursor: grab; }
.frame-thumb.dragging { opacity: .4; }
.frame-thumb.drop-target canvas { outline: 2px solid var(--accent); }
.frame-thumb .hold {
  position: absolute; bottom: 2px; right: 3px; font-size: 9px; color: var(--accent-2);
  font-family: 'JetBrains Mono', monospace; background: rgba(0,0,0,.5); padding: 0 3px; border-radius: 3px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent-2); color: var(--text);
  padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; z-index: 50;
}
.toast.error { border-color: var(--danger); }

@media (max-width: 860px) {
  .panel { grid-template-columns: 1fr; }
  .controls { position: static; }
}
