:root {
  --bg: #0a0a0c;
  --panel: rgba(18, 18, 24, 0.82);
  --panel-solid: #121218;
  --panel-2: #1a1a22;
  --border: #2a2a36;
  --text: #f0f0f4;
  --muted: #8b8b9a;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.22);
  --radius: 12px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: none;
}

.back-link,
.fs-btn {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: rgba(10, 10, 12, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  font-family: var(--font);
}

.back-link {
  left: max(12px, env(safe-area-inset-left));
  text-decoration: none;
}

.fs-btn {
  right: max(12px, env(safe-area-inset-right));
}

.back-link:hover,
.fs-btn:hover {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--border);
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
}

#gl {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 20;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 420px;
  padding: 14px 16px 16px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}

.hud-head {
  margin: 0;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.hud-head h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.35;
}

.pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.picker-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.picker select,
#cat-select,
#shader-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  box-sizing: border-box;
  font-family: var(--font);
  font-size: 0.86rem;
  font-weight: 550;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 44px;
  padding: 8px 28px 8px 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b8b9a' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.picker select:hover,
#cat-select:hover,
#shader-select:hover {
  border-color: #3a3a4a;
}

.picker select:focus,
#cat-select:focus,
#shader-select:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.55);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.mouse-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.mouse-row input {
  accent-color: var(--accent);
  width: 24px;
  height: 24px;
  margin: -1px 0 -1px -1px;
  flex-shrink: 0;
  cursor: pointer;
}

.mouse-row:has(input:checked) {
  color: var(--text);
}

.params {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.param {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
}

.param label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.param .val {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text);
}

.param input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
  cursor: pointer;
}

.hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

@media (min-width: 720px) {
  .hud {
    left: max(20px, env(safe-area-inset-left));
    bottom: max(20px, env(safe-area-inset-bottom));
    right: auto;
  }
}

@media (max-width: 480px) {
  .hud {
    max-width: none;
    padding: 12px 14px 14px;
  }

  .hud-head h1 {
    font-size: 1.15rem;
  }

  .tagline {
    display: none;
  }
}

/* Fullscreen: canvas only — hide all chrome + request widget (Esc exits) */
html.is-fullscreen .hud,
html.is-fullscreen .back-link,
html.is-fullscreen .fs-btn,
html.is-fullscreen .req-fab,
html.is-fullscreen .req-scrim,
html.is-fullscreen .req-toast,
html.is-fullscreen .req-modal,
html.is-fullscreen .request-widget,
html.is-fullscreen [id^="req-"],
html.is-fullscreen [class*="request-"],
body.is-fullscreen .hud,
body.is-fullscreen .back-link,
body.is-fullscreen .fs-btn,
body.is-fullscreen .req-fab,
body.is-fullscreen .req-scrim,
body.is-fullscreen .req-toast,
body.is-fullscreen .req-modal,
body.is-fullscreen .request-widget,
body.is-fullscreen [id^="req-"],
body.is-fullscreen [class*="request-"],
body.is-fs .hud,
body.is-fs .back-link,
body.is-fs .fs-btn,
body.is-fs .req-fab,
body.is-fs .req-scrim,
body.is-fs .req-toast,
body.is-fs [id^="req-"] {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

body.no-gl .hud::after {
  content: "WebGL unavailable in this browser.";
  color: #f87171;
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* HUD stays hidden until app.js fills the pickers/params, so it doesn't grow after first paint (CLS). Fallback reveal after 2.5s. */
html:not(.sh-ready) .hud { visibility: hidden; animation: shReveal 0s 2.5s forwards; }
@keyframes shReveal { to { visibility: visible; } }
