:root {
  --bg:         #080808;
  --surface:    #0f0f0f;
  --border:     rgba(255,255,255,0.07);
  --border-mid: rgba(255,255,255,0.14);
  --border-hi:  rgba(255,255,255,0.35);
  --text-hi:    rgba(255,255,255,0.85);
  --text-mid:   rgba(255,255,255,0.45);
  --text-lo:    rgba(255,255,255,0.20);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-hi);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  pointer-events: none;
}

/* ============ LAYOUT ============ */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 260px;
  height: 100vh;
  overflow: hidden;
}

.work {
  display: flex;
  flex-direction: column;
  padding: 22px 24px;
  background: transparent;
  min-width: 0;
  min-height: 0;
}

.work-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.logo {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-hi);
}

.head-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-mid);
}
.status.busy { color: rgba(255,255,255,0.70); }
.status.error { color: #e0726a; }

/* language toggle */
.lang { display: flex; gap: 2px; }
.lang-seg {
  padding: 4px 7px;
  background: transparent;
  border: 0.5px solid rgba(255,255,255,0.10);
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-lo);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.lang-seg:first-child { border-radius: 5px 0 0 5px; }
.lang-seg:last-child { border-radius: 0 5px 5px 0; border-left: none; }
.lang-seg:hover { color: var(--text-mid); }
.lang-seg.active {
  color: var(--text-hi);
  border-color: rgba(255,255,255,0.30);
}

/* ============ STAGE ============ */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0.5px solid var(--border);
  background:
    linear-gradient(rgba(15,15,15,0.72), rgba(15,15,15,0.72)) padding-box;
  overflow: hidden;
}

.preview {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: none;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
}
.preview.ready { display: block; }

.dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone.hide { display: none; }
.dropzone.drag { background: rgba(255,255,255,0.03); }

.drop-inner { text-align: center; pointer-events: none; }
.drop-icon {
  font-size: 26px;
  font-weight: 300;
  color: var(--text-lo);
  margin-bottom: 12px;
}
.dropzone.drag .drop-icon { color: var(--text-mid); }
.drop-title {
  font-size: 12px;
  color: var(--text-mid);
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}
.drop-sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-lo);
}

/* ============ OVERLAY ============ */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,8,8,0.78);
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.overlay-box { width: 240px; text-align: center; }
.overlay-label {
  font-size: 11px;
  color: var(--text-mid);
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.overlay-sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-lo);
  margin-top: 12px;
}
[hidden] { display: none !important; }

/* ---- cosmic indeterminate loader (compositor-driven, never freezes) ---- */
.cosmic {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
}
.cosmic .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 0.5px solid rgba(255,255,255,0.10);
}
.cosmic .ring.r2 { inset: 16px; border-color: rgba(255,255,255,0.07); }
.cosmic .orbit {
  position: absolute;
  inset: 0;
  animation: cosmic-spin 2.8s linear infinite;
  will-change: transform;
}
.cosmic .orbit.o2 {
  inset: 16px;
  animation-duration: 1.8s;
  animation-direction: reverse;
}
.cosmic .planet {
  position: absolute;
  top: -2px;
  left: 50%;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: rgba(255,255,255,0.75);
  box-shadow: 0 0 6px rgba(255,255,255,0.4);
}
.cosmic .orbit.o2 .planet {
  width: 3px;
  height: 3px;
  background: rgba(255,255,255,0.5);
}
.cosmic .core {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  box-shadow: 0 0 12px rgba(255,255,255,0.5);
  animation: cosmic-pulse 1.9s ease-in-out infinite;
  will-change: transform, opacity;
}
@keyframes cosmic-spin { to { transform: rotate(360deg); } }
@keyframes cosmic-pulse {
  0%, 100% { transform: scale(0.78); opacity: 0.55; }
  50% { transform: scale(1.2); opacity: 1; }
}
.bar {
  height: 1px;
  background: rgba(255,255,255,0.10);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: rgba(255,255,255,0.70);
  transition: width 0.2s ease;
}
.overlay-pct {
  margin-top: 10px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-hi);
}

/* ============ EXPORT ROW ============ */
.export-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 9px 0;
  background: transparent;
  border: 0.5px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.50);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn:hover:not(:disabled) {
  border-color: rgba(255,255,255,0.35);
  color: rgba(255,255,255,0.85);
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ============ SIDEBAR ============ */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 22px 20px;
  background: transparent;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  min-height: 0;
}

.group { display: flex; flex-direction: column; gap: 13px; }
.group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-lo);
  margin-bottom: 2px;
}

.divider {
  height: 1px;
  margin: 18px 0;
  /* --glow set per-divider from cursor proximity (main.js) */
  background: rgba(255,255,255, calc(0.07 + var(--glow, 0) * 0.26));
  transition: background 0.12s linear;
}

.param {
  display: grid;
  grid-template-columns: 64px 1fr 38px;
  align-items: center;
  gap: 10px;
}
.param label {
  font-size: 11px;
  color: var(--text-mid);
}
.param output {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-hi);
  text-align: right;
}

/* ============ SLIDERS ============ */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: rgba(255,255,255,0.10);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.70);
  border: none;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.70);
  border: none;
  cursor: pointer;
}

/* ============ TOGGLES ============ */
.param-toggle { grid-template-columns: 64px 1fr; }
.toggle {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* shape selector — label row, then full-width button row */
.param-shape {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toggle-shape {
  justify-content: flex-start;
  gap: 5px;
}
.toggle-shape .seg {
  flex: 1;
  min-width: 0;
  padding: 7px 0;
  font-size: 12px;
  line-height: 1;
}
.seg {
  min-width: 30px;
  padding: 5px 9px;
  background: transparent;
  border: 0.5px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(255,255,255,0.50);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.seg:hover { border-color: rgba(255,255,255,0.30); color: var(--text-hi); }
.seg.active {
  border-color: rgba(255,255,255,0.35);
  color: var(--text-hi);
  background: rgba(255,255,255,0.05);
}

/* ============ COLOR ============ */
.param-color {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.swatch-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.swatch-wrap label {
  font-size: 11px;
  color: var(--text-mid);
}
.swatch {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 0.5px solid var(--border-mid);
  border-radius: 4px;
  overflow: hidden;
}
.swatch input[type="color"] {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
}
/* clip the native color-input chrome (light inner border on dark colors) */
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border: none; }
.swatch input[type="color"]::-webkit-color-swatch { border: none; }
.swatch input[type="color"]::-moz-color-swatch { border: none; }

/* curated color presets */
.palette-block {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.palette-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-lo);
}
.palette {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  width: 18px;
  height: 18px;
  border: 0.5px solid var(--border-mid);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.chip:hover {
  transform: translateY(-1px);
  border-color: var(--border-hi);
}
.chip.active {
  border-color: rgba(255,255,255,0.75);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.25);
}

/* invert button */
.invert-btn {
  align-self: flex-start;
  padding: 6px 11px;
  background: transparent;
  border: 0.5px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mid);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.invert-btn:hover { border-color: var(--border-hi); color: var(--text-hi); }

/* style presets */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset-btn {
  padding: 6px 10px;
  background: transparent;
  border: 0.5px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--text-mid);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.preset-btn:hover {
  border-color: var(--border-hi);
  color: var(--text-hi);
}
.preset-btn.active {
  border-color: rgba(255,255,255,0.35);
  color: var(--text-hi);
  background: rgba(255,255,255,0.05);
}

/* ============ PROCESS ============ */
/* spacer pushes Process to the bottom when there's room, but guarantees a
   minimum gap so the button never sticks to the threshold slider */
.sidebar-spacer {
  flex: 1 1 auto;
  min-height: 24px;
}
.process {
  padding: 12px 0;
  background: rgba(255,255,255,0.05);
  border: 0.5px solid rgba(255,255,255,0.18);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.80);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.process:hover:not(:disabled) {
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.35);
}
.process:disabled { opacity: 0.4; cursor: not-allowed; }
