:root {
  --color-void: #000000;
  --color-bone: #ffffff;
  --color-smoke: #9a9a9a;
  --color-plum-voltage: #8052ff;
  --color-amber-spark: #ffb829;
  --color-lichen: #15846e;
  --font-stack: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: var(--color-void); }
body { font-family: var(--font-stack); color: var(--color-bone); }
#stage { position: fixed; inset: 0; }
canvas { display: block; }

/* Full-page drag overlay — shows while a file is dragged over the window */
#dropOverlay {
  position: fixed; inset: 0; z-index: 60; display: flex;
  align-items: center; justify-content: center; padding: 28px;
  background: rgba(0,0,0,0.78); backdrop-filter: blur(10px);
  opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
#dropOverlay.active { opacity: 1; }
.drop-frame {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  width: 100%; height: 100%; border: 2px dashed rgba(128,82,255,0.5);
  border-radius: 20px; align-content: center; justify-content: center;
  color: var(--color-plum-voltage);
}
.drop-title { font-weight: 200; font-size: 32px; letter-spacing: -0.02em; color: var(--color-bone); }
.drop-sub { font-size: 13px; letter-spacing: 0.04em; color: var(--color-smoke); text-transform: uppercase; }

/* Drop zone overlay */
#dropzone {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 24px; text-align: center; z-index: 10;
  transition: background .2s ease, opacity .4s ease;
}
#dropzone.hidden { opacity: 0; pointer-events: none; }
.eyebrow {
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-plum-voltage);
}
.dz-headline {
  font-weight: 200; font-size: 48px; line-height: 1.1; letter-spacing: -0.02em; color: var(--color-bone);
}
.dz-body { font-weight: 400; font-size: 15px; line-height: 1.5; letter-spacing: 0.025em; color: var(--color-smoke); max-width: 42ch; }
.dz-pill {
  margin-top: 8px; border: 1px solid rgba(255,255,255,0.15); border-radius: 24px;
  padding: 14px 22px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 600; color: var(--color-bone); cursor: pointer; background: transparent;
  transition: border-color .2s ease, background .2s ease;
}
.dz-pill:hover { border-color: var(--color-plum-voltage); background: rgba(128,82,255,0.08); }
.dz-actions { display: flex; gap: 12px; margin-top: 8px; }
.dz-actions .dz-pill { margin-top: 0; }
.dz-pill-ghost { color: var(--color-smoke); }
.dz-pill-ghost:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.04); }

/* Controls panel */
#panel {
  position: fixed; top: 24px; right: 24px; z-index: 20; width: 240px;
  border: 1px solid rgba(255,255,255,0.1); border-radius: 24px; padding: 24px;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .4s ease;
}
#panel.visible { opacity: 1; pointer-events: auto; }
#panel h2 { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-smoke); margin-bottom: 18px; }
.panel-header { display: contents; }
.panel-toggle {
  display: none; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  border: 1px solid rgba(255,255,255,0.15); background: transparent; color: var(--color-smoke);
  cursor: pointer; transition: transform .25s ease, border-color .2s ease, color .2s ease;
}
.panel-toggle:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.3); }
.row { margin-bottom: 18px; }
.row label { display: flex; justify-content: space-between; font-size: 12px; letter-spacing: 0.021em; color: var(--color-bone); margin-bottom: 8px; }
.row label span { color: var(--color-plum-voltage); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 1px; background: rgba(255,255,255,0.2); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--color-plum-voltage); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border: none; border-radius: 50%; background: var(--color-plum-voltage); cursor: pointer; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  position: relative; width: 28px; height: 28px; padding: 0; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; overflow: hidden; transition: border-color .15s ease, transform .12s ease;
}
.swatch:hover { transform: scale(1.08); }
/* Pencil overlay reveals on hover -> color is editable */
.swatch-edit {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.4); opacity: 0; transition: opacity .15s ease;
}
.swatch:hover .swatch-edit { opacity: 1; }
.swatch-edit svg { width: 12px; height: 12px; stroke: #fff; }
.swatch-add {
  display: flex; align-items: center; justify-content: center; overflow: visible;
  border: 1px dashed rgba(255,255,255,0.35); background: transparent; color: var(--color-smoke);
}
.swatch-add svg { width: 14px; height: 14px; }
.swatch-add:hover { border-color: var(--color-plum-voltage); color: var(--color-bone); transform: none; }

/* Hover-effect picker */
.fx-group { display: flex; flex-wrap: wrap; gap: 6px; }
.fx-btn {
  flex: 1 1 calc(50% - 3px); font-family: inherit; font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em; color: var(--color-smoke); background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 7px 6px; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.fx-btn:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.25); }
.fx-btn.active { color: var(--color-bone); border-color: var(--color-plum-voltage); background: rgba(128,82,255,0.12); }

/* Color edit popover (anchored near the swatch being edited) */
#colorPop {
  position: fixed; z-index: 50; width: 180px; padding: 12px; border-radius: 14px;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.12);
  display: none; flex-direction: column; gap: 10px;
}
#colorPop.visible { display: flex; }
#colorPop input[type=color] {
  width: 100%; height: 40px; border: 1px solid rgba(255,255,255,0.12); border-radius: 8px;
  background: none; cursor: pointer; padding: 2px;
}
#colorPop input[type=text] {
  width: 100%; font-family: inherit; font-size: 12px; letter-spacing: 0.04em; color: var(--color-bone);
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); border-radius: 8px; padding: 7px 9px;
}
.pop-actions { display: flex; gap: 8px; }
.pop-actions button {
  flex: 1; font-family: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border-radius: 8px; padding: 8px; cursor: pointer; border: 1px solid rgba(255,255,255,0.15);
  background: transparent; color: var(--color-bone); transition: opacity .15s ease, background .15s ease;
}
#popSave { background: var(--color-plum-voltage); border-color: var(--color-plum-voltage); }
#popDelete { color: #ff6b6b; }
#popDelete:disabled { opacity: 0.35; cursor: not-allowed; }

/* Panel buttons (copy / download) */
.pbtn {
  margin-top: 6px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 24px;
  padding: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
  color: var(--color-smoke); background: transparent; cursor: pointer; font-family: inherit;
  transition: border-color .2s ease, color .2s ease;
}
.pbtn svg { flex: none; }
.pbtn:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.3); }

/* Standalone "load another model" pill, bottom-right */
.reload-pill {
  position: fixed; bottom: 24px; right: 24px; z-index: 20;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 24px;
  padding: 12px 22px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
  color: var(--color-smoke); background: rgba(0,0,0,0.4); backdrop-filter: blur(8px);
  cursor: pointer; font-family: inherit;
  opacity: 0; pointer-events: none; transition: opacity .4s ease, border-color .2s ease, color .2s ease;
}
.reload-pill.visible { opacity: 1; pointer-events: auto; }
.reload-pill:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.3); }

/* History pill + library panel */
.history-pill {
  position: fixed; top: 24px; left: 24px; z-index: 30;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 24px;
  padding: 12px 22px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
  color: var(--color-smoke); background: rgba(0,0,0,0.4); backdrop-filter: blur(8px);
  cursor: pointer; font-family: inherit;
  transition: border-color .2s ease, color .2s ease;
}
.history-pill:hover { color: var(--color-bone); border-color: rgba(255,255,255,0.3); }
#historyPanel {
  position: fixed; top: 84px; left: 24px; bottom: 64px; z-index: 25; width: 280px;
  border: 1px solid rgba(255,255,255,0.1); border-radius: 24px; padding: 24px;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(12px); overflow-y: auto;
  opacity: 0; pointer-events: none; transform: translateX(-12px);
  transition: opacity .3s ease, transform .3s ease;
}
#historyPanel.visible { opacity: 1; pointer-events: auto; transform: none; }
#historyPanel h2 { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-smoke); margin-bottom: 18px; }
.hcard {
  position: relative; margin-bottom: 14px; border: 1px solid rgba(255,255,255,0.08); border-radius: 16px;
  overflow: hidden; cursor: pointer; background: rgba(255,255,255,0.03); transition: border-color .2s ease;
}
.hcard:hover { border-color: var(--color-plum-voltage); }
.hcard img, .hthumb-empty { display: block; width: 100%; aspect-ratio: 16/10; object-fit: cover; background: #000; }
.hthumb-empty { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--color-smoke); }
.hmeta { padding: 10px 12px; }
.hname { font-size: 12px; color: var(--color-bone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hsub { font-size: 11px; color: var(--color-smoke); margin-top: 2px; }
.hdel {
  position: absolute; top: 8px; right: 8px; border: none; border-radius: 12px; padding: 4px 9px;
  font-size: 12px; line-height: 1; font-family: inherit; color: var(--color-bone);
  background: rgba(0,0,0,0.55); cursor: pointer; opacity: 0;
  transition: opacity .15s ease, background .15s ease;
}
.hcard:hover .hdel { opacity: 1; }
.hdel.confirm { background: #b3261e; }
.hempty { font-size: 12px; color: var(--color-smoke); line-height: 1.5; }

/* Recent strip on the dropzone */
.dz-recent { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; color: var(--color-smoke); margin: 24px 0 12px; }
#dzHistory { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: 620px; }
#dzHistory .hcard { width: 136px; margin-bottom: 0; }
#dzHistory .hname { font-size: 11px; }
#dzHistory .hmeta { padding: 8px 10px; }

#status { position: fixed; bottom: 24px; left: 24px; z-index: 20; font-size: 12px; letter-spacing: 0.021em; color: var(--color-smoke); }

/* Error toast (bottom-left, above status) */
#toast {
  position: fixed; bottom: 56px; left: 24px; z-index: 40; max-width: 320px;
  border: 1px solid rgba(255,255,255,0.12); border-left: 2px solid var(--color-amber-spark);
  border-radius: 12px; padding: 12px 16px; font-size: 12px; line-height: 1.4;
  letter-spacing: 0.021em; color: var(--color-bone); background: rgba(0,0,0,0.72);
  backdrop-filter: blur(8px); cursor: pointer;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#toast.visible { opacity: 1; transform: none; pointer-events: auto; }

input[type=file] { display: none; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  /* Dropzone copy shrinks to fit small screens */
  .dz-headline { font-size: 28px; max-width: 100%; }
  .dz-body { font-size: 13px; max-width: 32ch; }
  #dropzone { padding: 0 20px; gap: 16px; }
  .dz-actions { flex-direction: column; width: 100%; max-width: 280px; }
  .dz-actions .dz-pill { width: 100%; }
  #dzHistory { max-width: 100%; }
  #dzHistory .hcard { width: 120px; }

  /* Controls panel: COLLAPSED = compact pill top-right (hugs header so the
     history-pill keeps the top-left corner). EXPANDED = full-width drawer that
     overlays everything (raised z-index) — no pill bleed-through. */
  #panel {
    top: 12px; right: 12px; left: auto; width: auto;
    padding: 10px 14px; max-height: none; overflow: visible;
  }
  #panel.expanded {
    left: 12px; right: 12px; width: auto; z-index: 35;
    padding: 14px 16px; max-height: calc(100vh - 24px); overflow-y: auto;
  }
  .panel-header {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    cursor: pointer; user-select: none;
  }
  #panel h2 { margin-bottom: 0; }
  .panel-toggle { display: flex; }
  #panel:not(.expanded) .panel-toggle { transform: rotate(0deg); }
  #panel.expanded .panel-toggle { transform: rotate(180deg); }
  .panel-body {
    overflow: hidden; max-height: 0; opacity: 0;
    transition: max-height .3s ease, opacity .2s ease;
  }
  #panel.expanded .panel-body {
    max-height: calc(100vh - 90px); opacity: 1; margin-top: 16px;
  }

  /* Reload pill + history pill: smaller, won't collide with panel */
  .reload-pill, .history-pill { padding: 10px 18px; font-size: 10px; }
  /* History pill matches the collapsed Tune pill's height (48px: 10px padding + 28px toggle) */
  .history-pill { top: 12px; left: 12px; padding: 18px 18px; display: flex; align-items: center; }
  .reload-pill { bottom: 16px; right: 16px; }

  /* Library panel fits the viewport */
  #historyPanel {
    top: 64px; left: 12px; right: 12px; bottom: 56px; width: auto;
  }
  #dzHistory .hcard, .hcard { width: auto; }

  /* Color popover: cap width, keep on-screen */
  #colorPop { width: min(180px, calc(100vw - 24px)); }

  /* Toast fits narrow viewports, sits above the reload pill */
  #toast { left: 12px; right: 12px; max-width: none; bottom: 64px; }

  #status { left: 12px; bottom: 12px; }
}
