/* ═══════════════════════════════════════════════════════════════
   GARGANTUA — Schwarzschild Black Hole Raytracer
   UI styling: deep-space glass panels, monospace telemetry.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #000000;
  --ink: #dbe7ff;
  --ink-dim: #7f8fae;
  --accent: #ffb347;
  --accent-2: #6fc3ff;
  --panel: rgba(7, 10, 16, 0.74);
  --line: rgba(120, 175, 255, 0.16);
  --line-hot: rgba(255, 179, 71, 0.55);
  --mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
  --sans: "Inter", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  touch-action: none;
  cursor: grab;
}
#gl:active { cursor: grabbing; }

/* ─────────────── boot overlay ─────────────── */
#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, #0a0f1a 0%, #000 70%);
  transition: opacity 0.8s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-inner h1 {
  margin: 22px 0 6px;
  font-size: 26px;
  letter-spacing: 0.55em;
  font-weight: 500;
  text-indent: 0.55em;
  color: #fff;
  text-shadow: 0 0 28px rgba(111, 195, 255, 0.55);
}
#loading-msg {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--ink-dim);
}
.ring {
  width: 74px;
  height: 74px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(111, 195, 255, 0.18);
  border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
  box-shadow: 0 0 34px rgba(255, 179, 71, 0.28), inset 0 0 24px rgba(111, 195, 255, 0.2);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────── fatal overlay ─────────────── */
#fatal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.92);
}
#fatal[hidden] { display: none; }
.fatal-inner {
  max-width: 640px;
  width: 100%;
  border: 1px solid rgba(255, 90, 90, 0.4);
  background: rgba(18, 6, 8, 0.85);
  padding: 28px 30px;
  border-radius: 10px;
  box-shadow: 0 0 60px rgba(255, 60, 60, 0.12);
}
.fatal-inner h1 { margin: 0 0 12px; font-size: 16px; letter-spacing: 0.3em; color: #ff8b8b; }
.fatal-inner p { margin: 0 0 14px; font-size: 12px; line-height: 1.7; color: var(--ink); font-family: var(--sans); }
.fatal-inner pre {
  margin: 0 0 18px;
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  font-size: 10px;
  line-height: 1.5;
  color: #ffb4b4;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 90, 90, 0.2);
  white-space: pre-wrap;
}
.fatal-inner button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #000;
  background: #ff8b8b;
  border: 0;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
}
.fatal-inner button:hover { background: #ffb4b4; }

/* ─────────────── HUD shell ─────────────── */
#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0.35s;
  font-size: 11px;
  letter-spacing: 0.06em;
}
#hud.hidden { opacity: 0; visibility: hidden; }
#hud button { pointer-events: auto; font-family: var(--mono); }

/* ── brand + telemetry ── */
#brand {
  position: absolute;
  top: 18px;
  left: 18px;
  padding: 14px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 10px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  min-width: 216px;
}
.brand-title {
  font-size: 15px;
  letter-spacing: 0.34em;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 179, 71, 0.35);
}
.brand-title .dot { color: var(--accent); font-size: 9px; margin-left: 7px; vertical-align: 2px; }
.brand-sub {
  margin-top: 3px;
  font-size: 8.5px;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
}
#stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
  margin: 11px 0 0;
  padding: 9px 0 0;
  border-top: 1px solid var(--line);
}
#stats > div { display: flex; justify-content: space-between; gap: 8px; }
#stats dt { color: var(--ink-dim); font-size: 8.5px; letter-spacing: 0.16em; }
#stats dd { margin: 0; color: var(--accent-2); font-size: 9.5px; }

/* ── debug badge ── */
#debug-badge {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 100px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 9px;
  letter-spacing: 0.26em;
  color: var(--ink-dim);
  opacity: 0.55;
  transition: opacity 0.3s, border-color 0.3s;
}
#debug-badge.active { opacity: 1; border-color: var(--line-hot); color: var(--accent); }
#debug-badge b {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-size: 9px;
}

/* ── control deck ── */
#panel {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 306px;
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
}
#panel.collapsed { transform: translateX(calc(100% + 26px)); opacity: 0; pointer-events: none; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--accent);
}
.panel-head button {
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.panel-head button:hover { color: #fff; }
.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 0 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 175, 255, 0.25) transparent;
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(120, 175, 255, 0.22); border-radius: 3px; }
.panel-foot { padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.panel-foot button {
  width: 100%;
  padding: 9px;
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--ink-dim);
  background: rgba(120, 175, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.panel-foot button:hover { color: #fff; border-color: var(--line-hot); background: rgba(255, 179, 71, 0.1); }

.quality-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.quality-row label { font-size: 9px; letter-spacing: 0.22em; color: var(--ink-dim); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  padding: 6px 10px;
  font-size: 9px;
  letter-spacing: 0.12em;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--ink-dim);
  cursor: pointer;
  transition: all 0.2s;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: #fff; }
.seg button.on { background: var(--accent); color: #000; font-weight: 700; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 6px;
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--accent-2);
}
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.param { padding: 6px 14px 8px; }
.param-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.param-name { font-size: 9px; color: var(--ink-dim); letter-spacing: 0.1em; }
.param-val { font-size: 9.5px; color: var(--ink); font-variant-numeric: tabular-nums; }
.param-val.modified { color: var(--accent); }
.param input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  margin: 5px 0 0;
  background: transparent;
  cursor: pointer;
}
.param input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, rgba(255, 179, 71, 0.75), rgba(111, 195, 255, 0.5));
  border-radius: 2px;
}
.param input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(255, 179, 71, 0.9);
  box-shadow: 0 0 10px rgba(255, 179, 71, 0.6);
}
.param input[type="range"]::-moz-range-track {
  height: 2px;
  background: linear-gradient(90deg, rgba(255, 179, 71, 0.75), rgba(111, 195, 255, 0.5));
  border-radius: 2px;
}
.param input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(255, 179, 71, 0.9);
}

/* ── floating panel toggle (mobile-first, shown when panel closed) ── */
#panel-toggle {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: #000;
  background: var(--accent);
  border: 0;
  border-radius: 100px;
  box-shadow: 0 10px 30px rgba(255, 179, 71, 0.3);
  cursor: pointer;
}
#panel-toggle span { font-size: 9px; }
#hud.panel-open #panel-toggle { display: none; }

/* ── bottom bars ── */
#presets {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(92vw, 900px);
}
#presets button {
  padding: 9px 12px;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
#presets button b { color: var(--accent); font-weight: 500; margin-right: 3px; }
#presets button:hover { color: #fff; border-color: var(--line-hot); }
#presets button.on { color: #000; background: var(--accent); border-color: var(--accent); }
#presets button.on b { color: #000; }

#shortcuts {
  position: absolute;
  left: 18px;
  bottom: 18px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  max-width: 300px;
}
.sc-head {
  display: flex;
  justify-content: space-between;
  font-size: 8.5px;
  letter-spacing: 0.26em;
  color: var(--accent);
  margin-bottom: 8px;
}
.sc-head span {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 5px;
  color: var(--ink-dim);
}
.sc-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 4px 7px;
  align-items: center;
  font-size: 8.5px;
  color: var(--ink-dim);
}
.sc-grid kbd {
  font-family: var(--mono);
  font-size: 8px;
  color: var(--ink);
  background: rgba(120, 175, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 4px;
  text-align: center;
}
.sc-grid i { font-style: normal; }

/* ── toast ── */
#toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 16px);
  padding: 10px 18px;
  background: rgba(8, 10, 16, 0.9);
  border: 1px solid var(--line-hot);
  border-radius: 100px;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ─────────────── responsive / mobile ─────────────── */
@media (max-width: 860px), (pointer: coarse) {
  #brand { top: 10px; left: 10px; padding: 10px 12px 9px; min-width: 0; }
  .brand-sub { display: none; }
  #stats { margin-top: 8px; gap: 1px 12px; }
  #stats > div:nth-child(n + 5) { display: none; }

  #debug-badge { top: 10px; padding: 5px 10px; font-size: 8px; letter-spacing: 0.16em; }

  #panel {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: 58vh;
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }
  #panel.open { transform: none; opacity: 1; pointer-events: auto; }
  #panel.collapsed { transform: translateY(calc(100% + 24px)); }

  #panel-toggle { display: flex; }
  #hud.panel-open #panel-toggle { display: none; }

  #shortcuts { display: none; }

  #presets {
    left: 10px;
    right: 10px;
    bottom: 74px;
    transform: none;
    max-width: none;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  #presets::-webkit-scrollbar { display: none; }
  #presets button { flex: 0 0 auto; padding: 10px 12px; }

  #toast { bottom: 128px; }
}

@media (max-height: 520px) {
  #shortcuts { display: none; }
  #brand #stats { display: none; }
}
