/* ============================================================
   LUMEN — generative shader studio
   dark precision-instrument UI
   ============================================================ */

:root {
  --bg: #09090b;
  --bg-stage: #0c0c0f;
  --bg-rail: #101013;
  --bg-raised: #16161a;
  --bg-hover: #1c1c21;
  --line: #222228;
  --line-soft: #1a1a1f;
  --text: #ececef;
  --text-mid: #9b9ba4;
  --text-dim: #5e5e68;
  --focus: #d7d7de;
  --radius-s: 6px;
  --radius-m: 9px;
  --font-ui: "Inter", -apple-system, "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", var(--font-ui);
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;
  --topbar-h: 52px;
  --rail-w: 308px;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); }
.dim { color: var(--text-dim); }

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }

/* ---------- top bar ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
  position: relative;
  z-index: 5;
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 260px; }
.brand-mark { width: 17px; height: 17px; color: var(--text); align-self: center; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.22em;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.topbar-center { display: flex; justify-content: center; }

.topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 260px; justify-content: flex-end; }
.topbar-divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 130ms ease, border-color 130ms ease, transform 80ms ease;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; flex: none; }
.btn:hover { background: var(--bg-hover); border-color: #2e2e36; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: #0a0a0c;
}
.btn-primary:hover { background: #fff; border-color: #fff; }

.icon-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-s);
  color: var(--text-mid);
  transition: background 130ms ease, color 130ms ease;
}
.icon-btn svg { width: 13px; height: 13px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- segmented control ---------- */

.segmented {
  display: inline-flex;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 2px;
  gap: 2px;
}
.segmented button {
  height: 24px;
  padding: 0 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  transition: background 120ms ease, color 120ms ease;
}
.segmented button:hover { color: var(--text-mid); }
.segmented button.active { background: #26262d; color: var(--text); }

/* ---------- layout ---------- */

.app {
  display: flex;
  height: calc(100vh - var(--topbar-h));
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 90% 70% at 50% 42%, #101016 0%, var(--bg-stage) 70%);
  min-width: 0;
  position: relative;
}

.canvas-frame {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 34px 40px 18px;
  min-height: 0;
}

#view {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.055),
    0 24px 70px -18px rgba(0,0,0,0.85),
    0 6px 22px -8px rgba(0,0,0,0.6);
  background: #000;
}

.stage-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px 14px;
  flex: none;
}
.meta-left, .meta-right { display: flex; align-items: center; gap: 10px; }
.meta-item { font-size: 11px; letter-spacing: 0.03em; }
.meta-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--line); }

/* ---------- control rail ---------- */

.rail {
  width: var(--rail-w);
  flex: none;
  background: var(--bg-rail);
  border-left: 1px solid var(--line-soft);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #26262d transparent;
}
.rail::-webkit-scrollbar { width: 8px; }
.rail::-webkit-scrollbar-thumb { background: #26262d; border-radius: 4px; border: 2px solid var(--bg-rail); }

.rail-section { border-bottom: 1px solid var(--line-soft); padding: 14px 16px 17px; }
.rail-section:last-child { border-bottom: none; padding-bottom: 28px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.section-dice {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  color: var(--text-dim);
  transition: background 120ms ease, color 120ms ease, transform 80ms ease;
}
.section-dice svg { width: 12px; height: 12px; }
.section-dice:hover { background: var(--bg-hover); color: var(--text); }
.section-dice:active { transform: rotate(90deg); }

/* ---------- mode grid ---------- */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 2px 8px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-soft);
  background: var(--bg-raised);
  color: var(--text-dim);
  transition: border-color 130ms ease, color 130ms ease, background 130ms ease;
}
.mode-card svg { width: 26px; height: 18px; }
.mode-card span { font-size: 10px; font-weight: 500; letter-spacing: 0.02em; }
.mode-card:hover { color: var(--text-mid); border-color: #2c2c33; }
.mode-card.active {
  border-color: #4a4a55;
  background: #1d1d23;
  color: var(--text);
}

.style-lock {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--text-dim);
  font-size: 11.5px;
  user-select: none;
  cursor: pointer;
}
.style-lock input { display: none; }
.lock-box {
  width: 14px; height: 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 120ms ease, border-color 120ms ease;
}
.lock-box svg { width: 8px; height: 8px; opacity: 0; transition: opacity 120ms ease; }
.style-lock input:checked + .lock-box { background: var(--text); border-color: var(--text); }
.style-lock input:checked + .lock-box svg { opacity: 1; }

/* ---------- palette ---------- */

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.preset-chip {
  height: 22px;
  width: 46px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.08);
  overflow: hidden;
  display: flex;
  padding: 0;
  transition: transform 100ms ease, border-color 120ms ease;
}
.preset-chip i { flex: 1; display: block; }
.preset-chip:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.3); }
.preset-chip.active { border-color: #fff; box-shadow: 0 0 0 1px #fff inset; }

.swatch-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.swatch {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.10);
  overflow: hidden;
  flex: none;
  cursor: pointer;
  transition: transform 100ms ease;
}
.swatch:hover { transform: scale(1.06); }
.swatch input {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0;
}
.swatch-label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
  letter-spacing: 0.05em;
}
.swatch-wrap { display: flex; flex-direction: column; }
.swatch-gap { width: 1px; height: 30px; background: var(--line); margin: 0 3px; align-self: flex-start; margin-top: 2px; }

/* ---------- sliders ---------- */

.ctl { margin-bottom: 11px; }
.ctl:last-child { margin-bottom: 0; }

.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}
.ctl-label { font-size: 11.5px; font-weight: 500; color: var(--text-mid); }
.ctl-value {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
  display: block;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(to right, #62626e var(--fill, 0%), #232329 var(--fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #e8e8ec;
  border: none;
  margin-top: -4.5px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
  transition: transform 100ms ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.25); background: #fff; }
input[type="range"]::-moz-range-track {
  height: 3px; border-radius: 2px; background: #232329;
}
input[type="range"]::-moz-range-progress { height: 3px; border-radius: 2px; background: #62626e; }
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: #e8e8ec; border: none;
}

/* ---------- selects / small inputs ---------- */

.field-row { display: flex; gap: 8px; align-items: center; margin-bottom: 11px; }
.field-row:last-child { margin-bottom: 0; }
.field-row .ctl-label { flex: 1; }

select, .num-input {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  height: 28px;
  padding: 0 8px;
  outline: none;
}
select:focus, .num-input:focus { border-color: #3c3c46; }
select { cursor: pointer; appearance: none; padding-right: 22px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%235e5e68'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.num-input { width: 74px; text-align: right; }

.seed-row { display: flex; gap: 6px; align-items: center; }
.seed-row .num-input { flex: 1; text-align: left; }

.mini-btn {
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text-mid);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms ease, color 120ms ease;
  white-space: nowrap;
}
.mini-btn svg { width: 11px; height: 11px; }
.mini-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- toggle ---------- */

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 11px;
}
.toggle-row:last-child { margin-bottom: 0; }
.toggle {
  position: relative;
  width: 30px; height: 17px;
  border-radius: 9px;
  background: #26262d;
  transition: background 140ms ease;
  flex: none;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2.5px; left: 2.5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #9b9ba4;
  transition: transform 140ms ease, background 140ms ease;
}
.toggle.on { background: var(--text); }
.toggle.on::after { transform: translateX(13px); background: #0a0a0c; }

/* ---------- share section ---------- */

.share-row { display: flex; gap: 8px; margin-bottom: 10px; }
.share-row .mini-btn { flex: 1; justify-content: center; }
.share-input {
  width: 100%;
  text-align: left;
  color: var(--text-mid);
}
.share-input::placeholder { color: var(--text-dim); }

/* ---------- share section ---------- */

.share-row { display: flex; gap: 8px; margin-bottom: 10px; }
.share-row .mini-btn { flex: 1; justify-content: center; }
.share-input {
  width: 100%;
  text-align: left;
}
.share-input::placeholder { color: var(--text-dim); }

/* ---------- export section ---------- */

.export-grid { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.export-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 38px;
  padding: 0 13px;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 130ms ease, border-color 130ms ease;
}
.export-btn svg { width: 14px; height: 14px; color: var(--text-mid); }
.export-btn:hover { background: var(--bg-hover); border-color: #2e2e36; }
.export-btn .ext {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

/* ---------- overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,5,7,0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: 320px;
  background: var(--bg-rail);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px 22px 18px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.9);
}
.overlay-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}
.overlay-detail { font-size: 11px; color: var(--text-dim); margin-bottom: 14px; }
.progress {
  height: 4px;
  border-radius: 2px;
  background: #1d1d23;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--text);
  transition: width 160ms ease;
}
.overlay-cancel { width: 100%; justify-content: center; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 11.5px;
  padding: 9px 16px;
  border-radius: 8px;
  z-index: 60;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,0.7);
  animation: toast-in 200ms ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .brand-sub { display: none; }
  .topbar-center { display: none; }
  .brand { min-width: 0; }
  .topbar-actions { min-width: 0; }
  .btn { padding: 0 10px; }
  .btn span { display: none; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .app { flex-direction: column; height: auto; }
  .stage { height: 58vh; }
  .rail { width: 100%; border-left: none; border-top: 1px solid var(--line-soft); }
  .canvas-frame { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
