/* ==========================================================================
   SHADER COSMOS — Deep-Space Architectural Glass HUD
   Typography: Syne (Display) + JetBrains Mono (Telemetry & Uniforms)
   ========================================================================== */

:root {
  --bg-void: #05060a;
  --glass-bg: rgba(9, 11, 18, 0.56);
  --glass-bg-strong: rgba(8, 10, 17, 0.78);
  --glass-border: rgba(255, 255, 255, 0.11);
  --glass-border-hover: rgba(255, 255, 255, 0.24);
  --glass-highlight: rgba(255, 255, 255, 0.05);

  --text-primary: #f4f6fb;
  --text-secondary: rgba(226, 232, 245, 0.72);
  --text-muted: rgba(182, 193, 219, 0.5);

  --accent: #7dd3fc;
  --accent-soft: rgba(125, 211, 252, 0.14);
  --accent-glow: rgba(125, 211, 252, 0.36);
  --fps-good: #6ee7b7;
  --fps-warn: #fcd34d;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --font-display: 'Syne', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-void);
  color: var(--text-primary);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* Full-Viewport WebGL Canvas */
#gl-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
  z-index: 0;
}

/* Shared Glassmorphism Material */
.glass-surface {
  background: var(--glass-bg);
  backdrop-filter: blur(22px) saturate(145%);
  -webkit-backdrop-filter: blur(22px) saturate(145%);
  border: 1px solid var(--glass-border);
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* HUD Layer Orchestration */
.hud-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: max(18px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr auto;
  gap: 16px;
  transition: opacity 0.42s var(--ease-out), transform 0.42s var(--ease-out);
}

body.hud-hidden .hud-layer {
  opacity: 0;
  transform: scale(0.99);
  pointer-events: none;
}

body.hud-hidden .hud-layer * {
  pointer-events: none !important;
}

/* Top Architectural Bar */
.hud-topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-cluster,
.telemetry-bar,
.action-cluster {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-pill);
}

.brand-cluster {
  padding: 9px 18px 9px 12px;
  gap: 12px;
}

.brand-mark {
  position: relative;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.orbit-ring {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.85;
  transform: rotate(-28deg) scaleY(0.58);
  box-shadow: 0 0 12px var(--accent-glow);
}

.orbit-core {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-primary);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.9);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.08;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Telemetry Pill */
.telemetry-bar {
  padding: 9px 18px;
  gap: 14px;
}

.telemetry-item {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
}

.t-label {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.t-value {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.accent-fps {
  color: var(--fps-good);
  min-width: 2ch;
  text-align: right;
}

.accent-fps.warn {
  color: var(--fps-warn);
}

.t-divider {
  width: 1px;
  height: 14px;
  background: var(--glass-border);
}

/* Action Buttons */
.action-cluster {
  padding: 5px;
  gap: 5px;
}

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  transition: background 0.2s var(--ease-out), color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.12);
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn.accent-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(125, 211, 252, 0.26);
}

.icon-btn.accent-btn:hover {
  background: rgba(125, 211, 252, 0.24);
  color: #e0f2fe;
  border-color: rgba(125, 211, 252, 0.5);
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-secondary);
  line-height: 1;
}

/* Right-Side Uniform Inspector */
.inspector-panel {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
  width: 312px;
  padding: 22px;
  border-radius: var(--radius-lg);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}

.inspector-panel::-webkit-scrollbar {
  width: 4px;
}

.inspector-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-top: 4px;
}

.scene-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  color: var(--accent);
  white-space: nowrap;
}

.panel-desc {
  font-size: 0.72rem;
  line-height: 1.58;
  color: var(--text-secondary);
}

/* Sliders */
.uniform-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.slider-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.slider-meta label {
  color: var(--text-secondary);
  font-weight: 500;
}

.u-var {
  color: var(--text-muted);
  font-size: 0.62rem;
  margin-left: 4px;
  letter-spacing: 0;
}

.slider-meta output {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
}

input[type='range'].hue-slider {
  background: linear-gradient(
    90deg,
    #f97316 0%,
    #eab308 18%,
    #22c55e 36%,
    #06b6d4 54%,
    #6366f1 72%,
    #ec4899 90%,
    #f97316 100%
  );
  height: 5px;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-void);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45), 0 0 12px var(--accent-glow);
  transition: transform 0.16s var(--ease-out);
}

input[type='range']::-webkit-slider-thumb:hover {
  transform: scale(1.22);
}

input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2px solid var(--bg-void);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45), 0 0 12px var(--accent-glow);
}

.panel-divider {
  height: 1px;
  background: var(--glass-border);
}

.meta-controls {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.mouse-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mono-val {
  font-size: 0.72rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

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

.chip-btn,
.subtle-btn {
  appearance: none;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.67rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
}

.chip-btn:hover,
.subtle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--glass-border-hover);
  color: var(--text-primary);
}

.chip-btn.active {
  background: var(--accent-soft);
  border-color: rgba(125, 211, 252, 0.35);
  color: var(--text-primary);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.chip-btn.active .chip-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.panel-footer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Bottom Architectural Gallery Dock */
.gallery-dock {
  grid-column: 1 / -1;
  grid-row: 3;
  justify-self: center;
  pointer-events: auto;
  padding: 6px;
  border-radius: var(--radius-lg);
  max-width: 100%;
  overflow-x: auto;
}

.shader-tabs {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.shader-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  padding: 10px 16px;
  border-radius: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  min-width: 178px;
  transition: background 0.22s var(--ease-out), border-color 0.22s ease, transform 0.18s ease, color 0.2s ease;
}

.shader-tab:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary);
}

.shader-tab.active {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.24);
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.tab-swatch {
  width: 10px;
  height: 28px;
  border-radius: 99px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.shader-tab.active .tab-swatch {
  opacity: 1;
  transform: scaleY(1.06);
}

.tab-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tab-idx {
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.tab-name {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* Restore HUD Pill */
.hud-restore-pill {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 25;
  padding: 9px 14px;
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.25s ease, transform 0.2s ease;
}

.hud-restore-pill:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.hud-restore-pill[hidden] {
  display: none;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

/* GLSL Inspector Modal */
.code-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
}

.code-modal[hidden] {
  display: none;
}

.code-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 4, 8, 0.72);
  backdrop-filter: blur(8px);
}

.code-modal-dialog {
  position: relative;
  width: min(860px, 100%);
  max-height: min(82vh, 760px);
  border-radius: var(--radius-lg);
  background: var(--glass-bg-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.code-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--glass-border);
  gap: 12px;
}

.code-modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-viewer {
  overflow: auto;
  padding: 20px 22px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.65;
  color: #dbeafe;
  user-select: text;
  white-space: pre;
  tab-size: 2;
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.73rem;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  border-color: rgba(125, 211, 252, 0.34);
  pointer-events: none;
  animation: toastIn 0.28s var(--ease-out);
}

.toast[hidden] {
  display: none;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* WebGL Fallback */
.fallback-screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 35%, #111827, #05060a 72%);
}

.fallback-screen[hidden] {
  display: none;
}

.fallback-card {
  max-width: 440px;
  padding: 32px;
  border-radius: var(--radius-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fallback-card h1 {
  font-family: var(--font-display);
  font-size: 1.7rem;
}

.fallback-card p {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.mobile-only {
  display: none;
}

/* Responsive Breakpoints */
@media (max-width: 1040px) {
  .hide-lg {
    display: none;
  }

  .shader-tab {
    min-width: 152px;
    padding: 9px 12px;
  }
}

@media (max-width: 820px) {
  .hud-layer {
    padding: 12px;
    gap: 10px;
  }

  .hide-md,
  .hide-sm {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }

  .brand-sub {
    display: none;
  }

  .inspector-panel {
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: 84px;
    width: auto;
    max-height: 58vh;
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out);
  }

  .inspector-panel.mobile-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .gallery-dock {
    width: 100%;
  }

  .shader-tabs {
    width: max-content;
  }

  .shader-tab {
    min-width: 138px;
  }
}

@media (max-width: 480px) {
  .hide-xs {
    display: none;
  }

  .brand-cluster {
    padding: 7px 13px 7px 9px;
  }

  .brand-title {
    font-size: 0.78rem;
  }

  .icon-btn {
    padding: 7px 9px;
  }
}
