:root {
  --bg: #0b0714;
  --panel: #150c22;
  --panel2: #1e1230;
  --ink: #f2e9ff;
  --dim: #a58cc9;
  --accent: #ff2d95;
  --accent2: #00e5ff;
  --accent3: #ffd166;
  --line: #3a2158;
  --radius: 12px;
  --tabbar-h: 46px;
  --panel-h: 34vh;
  --topbar-h: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
#app { display: flex; flex-direction: column; height: 100%; }

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 8px; padding-top: env(safe-area-inset-top, 0px);
  background: linear-gradient(180deg, #1a0f2e, #120a20);
  border-bottom: 1px solid var(--line); flex: none; z-index: 20;
}
#brand { font-weight: 800; letter-spacing: 2px; font-size: 12px;
  background: linear-gradient(90deg, var(--accent), var(--accent3), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent; white-space: nowrap; }
#topbar-actions { display: flex; gap: 6px; align-items: center; }
.iconbtn {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; min-width: 34px; height: 32px; font-size: 15px; padding: 0 8px;
}
.iconbtn:disabled { opacity: 0.35; }
.surprise {
  background: linear-gradient(90deg, #ff2d95, #ff6b35, #ffd166);
  color: #1a0010; border: none; border-radius: 16px; font-weight: 800;
  font-size: 10px; letter-spacing: 0.5px; padding: 8px 10px; white-space: nowrap;
}
.surprise:active { transform: scale(0.96); }

/* ---- stage ---- */
#stage { flex: 1; min-height: 0; position: relative; }
#canvas-wrap { position: absolute; inset: 0; }
#gl { width: 100%; height: 100%; display: block; touch-action: none; }
#status-toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(20,10,34,0.92); border: 1px solid var(--line);
  color: var(--ink); font-size: 12px; padding: 8px 14px; border-radius: 20px;
  max-width: 90%; text-align: center; pointer-events: none; z-index: 15;
}
#depth-thumb-wrap {
  position: absolute; right: 8px; top: 8px; background: rgba(10,6,18,0.8);
  border: 1px solid var(--line); border-radius: 8px; padding: 3px; z-index: 10;
}
#depth-thumb { display: block; width: 88px; height: auto; image-rendering: pixelated; border-radius: 4px; }
#depth-thumb-label { font-size: 9px; color: var(--dim); display: block; text-align: center; }
.hidden { display: none !important; }

/* large-art mode */
#app.bigart #panel, #app.bigart #tabbar { display: none; }

/* ---- tab bar ---- */
#tabbar {
  flex: none; display: flex; height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: #120a20; border-top: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
#tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-width: 52px; background: none; border: none; color: var(--dim);
  font-size: 10px; font-weight: 700; letter-spacing: 1px; padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab .tab-ico { font-size: 15px; }
.tab.active { color: var(--accent3); }

/* ---- panel ---- */
#panel {
  flex: none; height: var(--panel-h); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px 18px;
}
#app.bigart #panel { display: none; }
.panel-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.panel-sec { margin-bottom: 14px; }
.panel-sec > h4 {
  margin: 0 0 6px; font-size: 10px; letter-spacing: 1.5px; color: var(--dim);
  text-transform: uppercase; display: flex; justify-content: space-between; align-items: center;
}
button.ctl {
  background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 9px; padding: 8px 10px; font-size: 12px; font-weight: 600;
}
button.ctl.active { border-color: var(--accent); color: var(--accent3); background: #2a1440; }
button.ctl.small { padding: 5px 8px; font-size: 11px; }
select.ctl, input.ctl-text {
  background: var(--panel2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 9px; padding: 8px; font-size: 13px; max-width: 100%;
}

/* slider rows */
.slider-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.slider-row label { flex: 0 0 118px; font-size: 11px; color: var(--ink); }
.slider-row .val { flex: 0 0 44px; font-size: 10px; color: var(--dim); text-align: right;
  font-variant-numeric: tabular-nums; }
.slider-row input[type=range] {
  flex: 1; min-width: 60px; -webkit-appearance: none; appearance: none; height: 26px; background: transparent;
}
.slider-row input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); margin-top: -9px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 5px 0; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.swatch.locked { border-color: #fff; }
.swatch.selected { border-color: var(--accent3); box-shadow: 0 0 6px var(--accent3); }
.palette-strip { height: 14px; border-radius: 7px; margin: 4px 0; }

/* collapsible */
details.adv summary { font-size: 11px; color: var(--dim); cursor: pointer; padding: 4px 0; }
details.adv { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 4px; }

/* modal */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,2,10,0.7); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#modal {
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; max-width: 420px; width: 100%;
}
#modal-text { font-size: 14px; line-height: 1.45; margin-bottom: 14px; white-space: pre-wrap; }
#modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* progress bar inside toast/modal */
.prog { height: 6px; border-radius: 3px; background: #2a1440; overflow: hidden; margin-top: 6px; }
.prog > div { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* desktop widening */
@media (min-width: 768px) {
  :root { --panel-h: 38vh; }
  #panel { max-width: 560px; margin-left: auto; border-left: 1px solid var(--line); }
  .slider-row label { flex-basis: 150px; }
}
