/* ── Umbra Shaders — Global Reset & Base ─────────────────────── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden;background:#030308;color:#e2e8f0;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
canvas{display:block;position:fixed;inset:0;width:100%;height:100%;z-index:0}
#canvas-milkdrop{opacity:0;pointer-events:none;transition:opacity .8s ease}
#canvas-milkdrop.active{opacity:1}
#canvas-gl{opacity:1;transition:opacity .8s ease}
#canvas-gl.hidden{opacity:0;pointer-events:none}

/* ── Control Panel ──────────────────────────────────────────── */
#panel{position:fixed;top:1rem;right:1rem;width:22rem;max-width:calc(100vw - 2rem);max-height:calc(100vh - 2rem);overflow-y:auto;z-index:10;background:rgba(10,12,24,.78);backdrop-filter:blur(16px) saturate(1.4);border:1px solid rgba(255,255,255,.08);border-radius:1rem;padding:1.1rem 1rem;box-shadow:0 20px 60px rgba(0,0,0,.5),0 0 0 1px rgba(139,92,246,.06);transition:transform .35s cubic-bezier(.4,0,.2,1),opacity .35s ease;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.12) transparent}
/* Shift Umbra panel below ImploseLabs arcade shell header when present.
   Also move panel to the LEFT to avoid overlapping shell's right-side
   radio dropdown and chat panel (which are at z-index 10002). */
body:has(#arcade-header) #panel { top: 52px; left: 1rem; right: auto; max-height: calc(100vh - 64px); }
/* When panel is on the left, slide it out to the left instead of right */
body:has(#arcade-header) #panel.collapsed { transform: translateX(calc(-100% - 2rem)); opacity: 0; pointer-events: none; }
/* When arcade footer is also present, account for its height */
body:has(#arcade-footer) #panel { max-height: calc(100vh - 116px); }
body:has(#arcade-header):has(#arcade-footer) #panel { top: 52px; left: 1rem; right: auto; max-height: calc(100vh - 120px); }
body:has(#arcade-header):has(#arcade-footer) #panel.collapsed { transform: translateX(calc(-100% - 2rem)); opacity: 0; pointer-events: none; }
#panel::-webkit-scrollbar{width:5px}
#panel::-webkit-scrollbar-thumb{background:rgba(255,255,255,.15);border-radius:3px}
#panel.collapsed{transform:translateX(calc(100% + 2rem));opacity:0;pointer-events:none}

.panel-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:.75rem;gap:.5rem}
.panel-header h1{font-size:1.05rem;font-weight:700;letter-spacing:-.02em;background:linear-gradient(90deg,#c4b5fd,#a78bfa);-webkit-background-clip:text;-webkit-text-fill-color:transparent;flex:1;text-shadow:0 0 12px rgba(167,139,250,.25)}
.panel-header .actions{display:flex;gap:.35rem;flex-shrink:0}
.header-badges{display:flex;gap:.35rem;align-items:center}
.badge{font-size:.65rem;font-weight:700;padding:.15rem .4rem;border-radius:.3rem;background:rgba(139,92,246,.2);color:#c4b5fd;border:1px solid rgba(139,92,246,.25);line-height:1}
.badge.hidden{display:none}
.icon-btn{width:28px;height:28px;border-radius:.4rem;border:1px solid rgba(255,255,255,.2);background:rgba(10,12,24,.65);color:#e2e8f0;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:all .15s;font-size:.85rem;text-shadow:0 1px 2px rgba(0,0,0,.5);touch-action:manipulation}
.icon-btn:hover{background:rgba(139,92,246,.3);color:#fff;border-color:rgba(139,92,246,.55);box-shadow:0 0 8px rgba(139,92,246,.25)}
.icon-btn.active{background:rgba(139,92,246,.35);color:#fff;border-color:rgba(139,92,246,.6);box-shadow:0 0 10px rgba(139,92,246,.3)}

/* ── Shader Grid ────────────────────────────────────────────── */
.shader-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:.45rem;margin-bottom:.75rem}
.shader-btn{padding:.55rem .5rem;border-radius:.5rem;border:1px solid rgba(255,255,255,.08);background:rgba(255,255,255,.03);color:#cbd5e1;font-size:.78rem;font-weight:500;cursor:pointer;transition:all .15s;text-align:left;line-height:1.3;touch-action:manipulation}
.shader-btn:hover{background:rgba(255,255,255,.07);border-color:rgba(255,255,255,.14)}
.shader-btn.active{background:rgba(139,92,246,.15);border-color:rgba(139,92,246,.35);color:#ddd6fe}

/* ── Sliders ────────────────────────────────────────────────── */
.control-row{display:flex;align-items:center;justify-content:space-between;gap:.6rem;margin-bottom:.55rem;font-size:.78rem;color:#94a3b8}
.control-row label{flex-shrink:0}
.control-row input[type="range"]{flex:1;-webkit-appearance:none;appearance:none;height:4px;border-radius:2px;background:rgba(255,255,255,.1);outline:none;cursor:pointer}
.control-row input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:14px;height:14px;border-radius:50%;background:#a78bfa;box-shadow:0 0 6px rgba(167,139,250,.4);cursor:pointer;border:2px solid rgba(255,255,255,.15)}
.control-row input[type="range"]::-moz-range-thumb{width:14px;height:14px;border-radius:50%;background:#a78bfa;box-shadow:0 0 6px rgba(167,139,250,.4);cursor:pointer;border:2px solid rgba(255,255,255,.15);border:none}
.control-row .val{min-width:2.2rem;text-align:right;font-variant-numeric:tabular-nums;color:#c4b5fd;font-weight:600}
.control-row.inactive{opacity:.4}
.control-row.inactive input[type="range"]{cursor:not-allowed}

/* ── Toggles & Buttons ──────────────────────────────────────── */
.row-btns{display:flex;gap:.4rem;margin-bottom:.6rem;flex-wrap:wrap}
.btn{padding:.45rem .8rem;border-radius:.45rem;border:1px solid rgba(255,255,255,.1);background:rgba(255,255,255,.05);color:#cbd5e1;font-size:.78rem;font-weight:600;cursor:pointer;transition:all .15s;display:inline-flex;align-items:center;gap:.35rem;touch-action:manipulation}
.btn:hover{background:rgba(255,255,255,.1);border-color:rgba(255,255,255,.18)}
.btn.primary{background:rgba(139,92,246,.2);border-color:rgba(139,92,246,.35);color:#ddd6fe}
.btn.primary:hover{background:rgba(139,92,246,.3)}
.btn:disabled{opacity:.4;cursor:not-allowed}

/* ── Audio Source ───────────────────────────────────────────── */
.audio-row{display:flex;gap:.4rem;margin-bottom:.6rem;align-items:center}
.audio-row select{flex:1;padding:.4rem .5rem;border-radius:.4rem;border:1px solid rgba(255,255,255,.1);background:rgba(0,0,0,.25);color:#e2e8f0;font-size:.78rem;outline:none}
.drop-zone{border:2px dashed rgba(139,92,246,.2);border-radius:.6rem;padding:.7rem;text-align:center;color:#94a3b8;font-size:.75rem;margin-bottom:.6rem;transition:all .2s;cursor:pointer}
.drop-zone:hover,.drop-zone.dragover{border-color:rgba(139,92,246,.45);background:rgba(139,92,246,.06);color:#c4b5fd}

/* Audio visualizer */
#audio-viz{width:100%;height:36px;border-radius:.35rem;background:rgba(0,0,0,.35);margin-bottom:.6rem;display:block;border:1px solid rgba(139,92,246,.15);box-shadow:0 0 8px rgba(139,92,246,.08)}

/* ── Mini Bar ───────────────────────────────────────────────── */
#mini-bar{position:fixed;bottom:1rem;left:50%;transform:translateX(-50%) translateY(0);z-index:10;display:flex;align-items:center;gap:.5rem;background:rgba(10,12,24,.85);backdrop-filter:blur(14px);border:1px solid rgba(255,255,255,.1);border-radius:.7rem;padding:.4rem .7rem;box-shadow:0 10px 40px rgba(0,0,0,.45);transition:transform .3s cubic-bezier(.4,0,.2,1),opacity .3s ease;opacity:1}
#mini-bar.hidden{transform:translateX(-50%) translateY(120%);opacity:0;pointer-events:none}
#mini-bar .shader-name{font-size:.78rem;font-weight:600;color:#c4b5fd;max-width:10rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding:0 .2rem}
#mini-bar .sep{width:1px;height:18px;background:rgba(255,255,255,.12)}

/* ── Start Overlay ──────────────────────────────────────────── */
#start-overlay{position:fixed;inset:0;z-index:50;display:flex;align-items:center;justify-content:center;background:rgba(3,3,8,.92);backdrop-filter:blur(8px);transition:opacity .6s ease}
#start-overlay.hidden{opacity:0;pointer-events:none}
.start-card{text-align:center;max-width:26rem;padding:2rem}
.start-card h2{font-size:1.8rem;font-weight:800;margin-bottom:.4rem;background:linear-gradient(135deg,#c4b5fd,#818cf8,#c084fc);-webkit-background-clip:text;-webkit-text-fill-color:transparent;letter-spacing:-.03em}
.start-card p{color:#94a3b8;font-size:.95rem;margin-bottom:1.5rem;line-height:1.5}
.start-card .big-btn{padding:.7rem 2rem;border-radius:.6rem;border:none;background:linear-gradient(135deg,#7c3aed,#6366f1);color:#fff;font-size:1rem;font-weight:700;cursor:pointer;box-shadow:0 4px 20px rgba(124,58,237,.35);transition:all .2s}
.start-card .big-btn:hover{transform:translateY(-1px);box-shadow:0 6px 28px rgba(124,58,237,.45)}
.start-card .hint{color:#64748b;font-size:.75rem;margin-top:1rem}

/* ── Help Overlay ───────────────────────────────────────────── */
#help-overlay{position:fixed;inset:0;z-index:60;display:flex;align-items:center;justify-content:center;background:rgba(3,3,8,.85);backdrop-filter:blur(6px);transition:opacity .3s ease}
#help-overlay.hidden{opacity:0;pointer-events:none}
.help-card{max-width:26rem;width:90%;background:rgba(10,12,24,.9);backdrop-filter:blur(16px);border:1px solid rgba(255,255,255,.1);border-radius:1rem;padding:1.5rem;box-shadow:0 20px 60px rgba(0,0,0,.5)}
.help-card h3{font-size:1.1rem;font-weight:700;margin-bottom:1rem;color:#c4b5fd}
.help-grid{display:grid;grid-template-columns:1fr 1fr;gap:.5rem;margin-bottom:1rem}
.help-grid div{display:flex;align-items:center;gap:.45rem;font-size:.8rem;color:#cbd5e1;min-height:1.6rem}
.help-grid kbd{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:.7rem;padding:.12rem .3rem;border-radius:.3rem;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);color:#e2e8f0;white-space:nowrap;flex-shrink:0}
.help-grid span{color:#94a3b8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

/* ── Shader Editor ──────────────────────────────────────────── */
#editor-panel{position:fixed;top:1rem;left:1rem;width:32rem;max-width:calc(100vw - 2rem);max-height:calc(100vh - 2rem);z-index:11;background:rgba(10,12,24,.85);backdrop-filter:blur(16px) saturate(1.4);border:1px solid rgba(139,92,246,.15);border-radius:1rem;display:flex;flex-direction:column;box-shadow:0 20px 60px rgba(0,0,0,.5);transition:transform .35s cubic-bezier(.4,0,.2,1),opacity .35s ease;scrollbar-width:thin;scrollbar-color:rgba(255,255,255,.12) transparent}
#editor-panel.hidden{transform:translateX(calc(-100% - 2rem));opacity:0;pointer-events:none}
/* Shift editor below arcade shell header and move to RIGHT
   so it doesn't overlap with the panel which moves to LEFT. */
body:has(#arcade-header) #editor-panel { top: 52px; left: auto; right: 1rem; max-height: calc(100vh - 64px); }
/* When editor is on the right, slide it out to the right instead of left */
body:has(#arcade-header) #editor-panel.hidden { transform: translateX(calc(100% + 2rem)); opacity: 0; pointer-events: none; }
/* Account for footer */
body:has(#arcade-footer) #editor-panel { max-height: calc(100vh - 116px); }
body:has(#arcade-header):has(#arcade-footer) #editor-panel { top: 52px; left: auto; right: 1rem; max-height: calc(100vh - 120px); }
body:has(#arcade-header):has(#arcade-footer) #editor-panel.hidden { transform: translateX(calc(100% + 2rem)); opacity: 0; pointer-events: none; }
.editor-header{display:flex;align-items:center;justify-content:space-between;padding:.7rem .9rem;border-bottom:1px solid rgba(255,255,255,.08)}
.editor-header span{font-size:.85rem;font-weight:600;color:#c4b5fd}
.editor-actions{display:flex;gap:.35rem}
#shader-editor{flex:1;background:rgba(3,3,8,.7);color:#e2e8f0;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:.78rem;line-height:1.5;padding:.7rem .9rem;border:none;outline:none;resize:none;min-height:12rem;white-space:pre;overflow:auto}
#shader-editor::selection{background:rgba(139,92,246,.35)}
.editor-error{padding:.5rem .9rem;font-size:.75rem;color:#fca5a5;background:rgba(220,38,38,.1);border-top:1px solid rgba(220,38,38,.15);max-height:6rem;overflow-y:auto;white-space:pre-wrap}
.editor-error.hidden{display:none}
.editor-error:empty{display:none}

/* ── Toast ──────────────────────────────────────────────────── */
#toast{position:fixed;bottom:4.5rem;left:50%;transform:translateX(-50%) translateY(20px);z-index:20;background:rgba(10,12,24,.9);backdrop-filter:blur(10px);border:1px solid rgba(255,255,255,.1);border-radius:.5rem;padding:.5rem 1rem;color:#e2e8f0;font-size:.8rem;opacity:0;pointer-events:none;transition:all .3s ease}
#toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
/* Shift toast above arcade footer */
body:has(#arcade-footer) #toast { bottom: calc(56px + 1rem); }

/* ── Palette ────────────────────────────────────────────────── */
.palette-search{width:100%;padding:.45rem .6rem;border-radius:.45rem;border:1px solid rgba(255,255,255,.1);background:rgba(0,0,0,.25);color:#e2e8f0;font-size:.8rem;margin-bottom:.6rem;outline:none;-webkit-appearance:none;appearance:none}
.palette-search:focus{border-color:rgba(139,92,246,.4);box-shadow:0 0 0 2px rgba(139,92,246,.08)}
.palette-search::placeholder{color:#64748b}

#palette{max-height:20rem;overflow-y:auto;margin-bottom:.75rem;scrollbar-width:8px;scrollbar-color:rgba(255,255,255,.3) transparent;display:flex;flex-direction:column;gap:.35rem;padding-right:.25rem}
#palette::-webkit-scrollbar{width:8px}
#palette::-webkit-scrollbar-track{background:rgba(255,255,255,.05);border-radius:4px}
#palette::-webkit-scrollbar-thumb{background:rgba(139,92,246,.4);border-radius:4px}
#palette::-webkit-scrollbar-thumb:hover{background:rgba(139,92,246,.6)}

.category{display:flex;flex-direction:column;border-radius:.5rem;overflow:hidden;background:rgba(0,0,0,.15);border:1px solid rgba(255,255,255,.05)}
.category-header{display:flex;align-items:center;gap:.45rem;width:100%;padding:.4rem .55rem;border:none;background:transparent;color:#94a3b8;font-size:.8rem;font-weight:600;cursor:pointer;transition:all .15s;text-align:left;touch-action:manipulation}
.category-header:hover{color:#e2e8f0;background:rgba(255,255,255,.04)}
.category-header.active-cat{color:#e2e8f0;background:rgba(139,92,246,.1)}
.cat-icon{font-size:.9rem;width:1.1rem;text-align:center}
.cat-name{flex:1}
.cat-count{font-size:.68rem;font-weight:700;padding:.1rem .35rem;border-radius:.3rem;background:rgba(255,255,255,.08);color:#64748b;line-height:1}
.category-header.active-cat .cat-count{background:rgba(139,92,246,.2);color:#c4b5fd}
.cat-chevron{font-size:.65rem;transition:transform .2s ease;color:#64748b}
.category-header.collapsed .cat-chevron{transform:rotate(-90deg)}

.category-body{padding:.35rem .45rem .5rem;display:flex;flex-direction:column;gap:.25rem;transition:max-height .25s ease,opacity .2s ease,padding .25s ease}
.category-body.collapsed{max-height:0;opacity:0;padding:0 .45rem;overflow:hidden}
.swatch-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:.35rem}
.swatch-btn{padding:.45rem .5rem;border-radius:.4rem;border:1px solid rgba(255,255,255,.12);background:rgba(255,255,255,.06);color:#e2e8f0;font-size:.75rem;font-weight:500;cursor:pointer;transition:all .15s;text-align:left;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;position:relative;touch-action:manipulation}
.swatch-btn:hover{background:rgba(139,92,246,.12);border-color:rgba(139,92,246,.35);color:#fff}
.swatch-btn.active{background:rgba(139,92,246,.18);border-color:rgba(139,92,246,.4);color:#ddd6fe;box-shadow:0 0 8px rgba(139,92,246,.15)}
.swatch-btn .star{position:absolute;right:.3rem;top:50%;transform:translateY(-50%);font-size:.65rem;color:rgba(251,191,36,.7);opacity:0;transition:opacity .15s}
.swatch-btn:hover .star,.swatch-btn.fav .star{opacity:1}
.swatch-btn.fav .star{opacity:1}
.swatch-btn .star-btn{position:absolute;right:.2rem;top:50%;transform:translateY(-50%);font-size:.7rem;color:#94a3b8;background:none;border:none;cursor:pointer;padding:0 .15rem;line-height:1}
.swatch-btn .star-btn:hover{color:#fbbf24}
.swatch-btn.fav .star-btn{color:#fbbf24}

.palette-empty{text-align:center;color:#64748b;font-size:.78rem;padding:.6rem 0;font-style:italic}

/* ── Responsive ─────────────────────────────────────────────── */
@media(max-width:768px){
  #panel{width:calc(100vw - 1.5rem);top:.75rem;right:.75rem}
  #editor-panel{width:calc(100vw - 1.5rem);top:.75rem;left:.75rem}
  .swatch-grid{grid-template-columns:1fr}
  .help-grid{grid-template-columns:1fr}
  #mini-bar{bottom:5.5rem;max-width:calc(100vw - 2rem)}
  /* On mobile with arcade shell, keep panel/editor at edges but account for header */
  body:has(#arcade-header) #panel { top: 48px; left: .75rem; right: auto; }
  body:has(#arcade-header) #editor-panel { top: 48px; left: auto; right: .75rem; }
}

/* Shift Umbra mini-bar above ImploseLabs arcade shell footer when present */
body:has(#arcade-footer) #mini-bar {
  bottom: 56px;
}
/* Remove the old rule that moved mini-bar to top when header is present.
   The header is at the top; it doesn't interfere with a bottom-centered mini-bar. */
