:root {
  --bg:        #080810;
  --surface:   #10101a;
  --surface2:  #18182a;
  --surface3:  #1e1e30;
  --border:    #252538;
  --accent:    #6e57ff;
  --accent-hi: #9d87ff;
  --accent-lo: #3d2dcc;
  --glow:      rgba(110,87,255,0.35);
  --text:      #d8d8f0;
  --muted:     #5a5a80;
  --danger:    #ff5e7a;
  --ok:        #4dffa0;
  --warn:      #ffc84d;
  --r:         9px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  overflow: hidden;
}

/* ── LAYOUT ──────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 80% at 50% 50%, #0e0e1e 0%, var(--bg) 100%);
  padding: 24px;
  position: relative;
}

/* grid background lines */
#main::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.25;
  pointer-events: none;
}

/* ── CANVAS ──────────────────────────────────── */
#canvas-wrap {
  position: relative;
  width: min(calc(100vw - 348px), 580px);
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 60px rgba(110,87,255,0.2),
    0 24px 80px rgba(0,0,0,0.7);
  z-index: 1;
}

#canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ── SIDEBAR HEADER ──────────────────────────── */
.s-head {
  padding: 22px 18px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 20%, var(--accent-hi) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-dot { color: var(--accent); -webkit-text-fill-color: var(--accent); }

.tagline {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* ── SECTIONS ────────────────────────────────── */
.sec {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sec-label {
  font-family: 'Syne', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.count-badge {
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--accent-hi);
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

/* ── COLOR LIST ──────────────────────────────── */
#color-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 265px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 11px;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ci {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 7px;
  transition: border-color .15s;
  user-select: none;
}

.ci:hover { border-color: var(--accent-lo); }

.ci-swatch {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.08);
  cursor: pointer;
}

.ci-swatch input[type="color"] {
  position: absolute;
  top: -30%; left: -30%;
  width: 160%; height: 160%;
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0;
}

.ci-swatch-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 4px;
}

.ci-hex {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 3px 7px;
  outline: none;
  min-width: 0;
  text-transform: uppercase;
}
.ci-hex:focus { border-color: var(--accent); }

.ci-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ib {
  width: 20px;
  height: 20px;
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  line-height: 1;
  transition: all .13s;
}
.ib:hover { background: var(--surface2); color: var(--text); border-color: var(--accent); }
.ib.del { color: var(--danger); border-color: rgba(255,94,122,.2); }
.ib.del:hover { background: rgba(255,94,122,.12); border-color: var(--danger); }

/* ── BUTTON ROW ──────────────────────────────── */
.btn-row { display: flex; gap: 7px; }

.btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface3); border-color: var(--accent-lo); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 16px rgba(110,87,255,.4);
}
.btn-accent:hover {
  background: var(--accent-hi);
  border-color: var(--accent-hi);
  box-shadow: 0 0 24px rgba(157,135,255,.5);
}

/* ── TOGGLE GROUP ────────────────────────────── */
.tog {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 4px;
}

.tog-opt {
  flex: 1;
  padding: 7px 10px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  transition: all .18s;
  color: var(--muted);
  user-select: none;
}
.tog-opt.on {
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15);
}

/* ── SLIDERS ─────────────────────────────────── */
.ctrl { margin-bottom: 13px; }
.ctrl:last-child { margin-bottom: 0; }

.ctrl-lbl {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.ctrl-val {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  background: var(--accent-hi);
  border-radius: 50%;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--accent), 0 0 8px var(--glow);
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  background: var(--accent-hi);
  border-radius: 50%;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--accent);
  cursor: pointer;
}

/* ── REC INDICATOR ───────────────────────────── */
#rec-badge {
  position: absolute;
  top: 14px; right: 14px;
  background: rgba(255,60,90,.88);
  backdrop-filter: blur(12px);
  color: #fff;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 10;
  font-family: 'Syne', sans-serif;
  letter-spacing: .05em;
}
#rec-badge.on { display: flex; }
#rec-dot {
  width: 7px; height: 7px;
  background: #fff;
  border-radius: 50%;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── TOAST ───────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 28px; right: 28px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(20px) scale(.95);
  transition: all .28s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  z-index: 9999;
  font-family: 'Syne', sans-serif;
}
#toast.show { opacity: 1; transform: translateY(0) scale(1); }

/* ── EXPORT STATUS ───────────────────────────── */
#rec-status {
  display: none;
  margin-top: 9px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── PROGRESS BAR ────────────────────────────── */
#rec-progress-bar {
  display: none;
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}
#rec-progress-fill {
  height: 100%;
  background: var(--danger);
  border-radius: 2px;
  width: 0%;
  transition: width .1s linear;
}

/* ── SCROLLBAR ───────────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 780px) {
  html, body { overflow: auto; }
  #app { flex-direction: column; height: auto; }
  #sidebar { width: 100%; min-width: 100%; max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  #main { padding: 20px 16px; min-height: auto; }
  #canvas-wrap { width: min(calc(100vw - 32px), 480px); }
  #main::before { display: none; }
}
