:root {
  --bg: #0f1216;
  --panel: #171c23;
  --panel-2: #1e242d;
  --line: #2a323d;
  --text: #e6eaf0;
  --muted: #8b97a7;
  --accent: #4f8cff;
  --accent-2: #6aa0ff;
  --success: #21b573;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1b2230 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(20,25,32,.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 26px; color: var(--accent);
  background: var(--panel-2); border: 1px solid var(--line);
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.tagline { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.pill {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2);
}
.pill-muted { color: var(--muted); }
.pill-ok { color: var(--success); border-color: rgba(33,181,115,.4); }
.pill-warn { color: #f0b03a; border-color: rgba(240,176,58,.4); }

/* Layout */
.app {
  display: grid; grid-template-columns: 360px 1fr; gap: 18px;
  padding: 18px; max-width: 1400px; margin: 0 auto; align-items: start;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.controls { padding: 6px 16px 16px; max-height: calc(100vh - 110px); overflow-y: auto; }
.controls::-webkit-scrollbar { width: 10px; }
.controls::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 10px; }

.group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: none; }
.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 0 0 12px; }

/* Presets */
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.preset {
  font-size: 12px; padding: 6px 9px; border-radius: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.preset:hover { border-color: var(--accent); }
.preset.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.preset .cat { display:block; font-size:10px; color: var(--muted); }
.preset.active .cat { color: rgba(255,255,255,.8); }

.size-custom { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
.field-inline { display:flex; align-items:center; gap:12px; margin: 8px 0; }
.field-inline > label { font-size: 12px; color: var(--muted); }
input[type=number], select, input[type=color] {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px; font-size: 14px; width: 100%;
}
input[type=color] { padding: 2px; height: 34px; width: 40px; cursor: pointer; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.row-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); font-size: 12px; }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 20px;
  cursor: pointer; transition: border-color .15s, background .15s; text-align: center;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--panel-2); }
.dz-big { font-size: 15px; font-weight: 600; color: var(--accent-2); }

.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .rm {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border: none; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff;
  cursor: pointer; font-size: 13px; line-height: 1; display:grid; place-items:center;
}
.thumb .badge {
  position:absolute; bottom:3px; left:3px; font-size:10px; padding:1px 5px;
  border-radius: 5px; background: rgba(33,181,115,.85); color:#fff;
}
.thumb .star {
  position:absolute; top:3px; left:3px; width:20px; height:20px;
  border:none; border-radius:6px; background: rgba(0,0,0,.55); color:#fff;
  cursor:pointer; font-size:12px; line-height:1; display:grid; place-items:center;
}
.thumb .star.on { background: rgba(255,193,7,.95); color:#3a2c00; }
.thumb .rot {
  position:absolute; bottom:3px; right:3px; width:20px; height:20px;
  border:none; border-radius:6px; background: rgba(0,0,0,.55); color:#fff;
  cursor:pointer; font-size:13px; line-height:1; display:grid; place-items:center;
}
.thumb .rot:hover { background: rgba(79,140,255,.9); }
.thumb.hero { outline: 2px solid #ffc107; outline-offset: -2px; }

/* Segmented control */
.seg {
  display:flex; gap:4px; background: var(--panel-2); padding:4px;
  border-radius:10px; border:1px solid var(--line); margin-bottom:12px;
}
.seg-btn {
  flex:1; padding:9px; border:none; background:transparent; color:var(--muted);
  border-radius:7px; cursor:pointer; font-weight:600; font-size:13px;
}
.seg-btn.active { background: var(--accent); color:#fff; }

/* Swatches */
.swatches { display: flex; align-items: center; gap: 6px; }
.sw { width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--line); cursor: pointer; }
.sw.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,140,255,.3); }

.load-status { margin: 10px 0 0; font-size: 12px; }
.load-status.warn-text { color: #f0b03a; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; margin-top: 6px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Buttons */
.actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

/* Preview */
.preview { padding: 16px; position: sticky; top: 90px; display: flex; flex-direction: column; }
.preview-head { display:flex; justify-content: space-between; align-items:center; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.canvas-wrap {
  position: relative; flex: 1; min-height: 420px;
  background:
    linear-gradient(45deg, #11151a 25%, transparent 25%, transparent 75%, #11151a 75%),
    linear-gradient(45deg, #11151a 25%, #0c0f13 25%, #0c0f13 75%, #11151a 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  display: grid; place-items: center; overflow: hidden; padding: 16px;
}
#preview { max-width: 100%; max-height: calc(100vh - 220px); box-shadow: var(--shadow); display: none; cursor: grab; }
#preview.ready { display: block; }
#preview.dragging { cursor: grabbing; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.empty-inner { text-align: center; color: var(--muted); }
.empty-icon { font-size: 54px; opacity: .35; }

.progress { margin-top: 12px; display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .preview { position: static; }
}
