:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --panel-bg: rgba(18, 22, 31, 0.92);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text-primary: #f6f7fb;
  --text-secondary: #b7bfce;
  --accent: #76d5ff;
  --danger: #ff8686;
  --control-bg: rgba(255, 255, 255, 0.08);
  --control-bg-strong: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #090b10; color: var(--text-primary); }
button, input, select { font: inherit; }
button { cursor: pointer; }
canvas { display: block; touch-action: none; }

#app {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.viewport {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 35% 15%, #2c3240 0%, #111621 36%, #05070a 100%);
}

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #080b11;
  transition: opacity 240ms ease;
}

.loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-title { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 1rem; }
.progress-track { width: min(420px, 70vw); height: 8px; background: rgba(255,255,255,0.12); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #75d4ff, #d7a5ff); transition: width 180ms ease; }
.progress-label { margin-top: 0.8rem; color: var(--text-secondary); font-size: 0.875rem; }

.control-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 5;
  width: 378px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: var(--panel-bg);
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
  backdrop-filter: blur(18px);
}

.panel-title {
  margin: 0 0 2px;
  font-size: 1.1rem;
  font-weight: 700;
}

.panel-subtitle {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.35;
}

.panel-section {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 14px;
  margin-top: 14px;
}

.panel-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.section-title {
  margin: 0 0 10px;
  font-weight: 650;
  color: #ffffff;
  font-size: 0.92rem;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 6px 0;
}

.control-row.stack {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.control-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text-primary);
  font-size: 0.88rem;
  line-height: 1.25;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.35);
  flex: 0 0 auto;
}

.toggle {
  position: relative;
  width: 46px;
  height: 28px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.slider-toggle {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.16);
  border-radius: 999px;
  transition: background 140ms ease;
}
.slider-toggle::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  top: 3px;
  left: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 140ms ease;
}
.toggle input:checked + .slider-toggle { background: #4fbaec; }
.toggle input:checked + .slider-toggle::before { transform: translateX(18px); }

select, input[type='range'], .button {
  width: 100%;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--text-primary);
  background: var(--control-bg);
  padding: 0 10px;
}

input[type='range'] {
  padding: 0;
  accent-color: var(--accent);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--control-bg-strong);
}
.button.active { background: rgba(118, 213, 255, 0.28); border-color: rgba(118, 213, 255, 0.65); }
.button.warn { color: var(--danger); }

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.value-line {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 0.76rem;
  margin-top: -3px;
}

.info-panel {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 4;
  width: min(440px, calc(100vw - 32px));
  padding: 14px 16px;
  background: rgba(14, 18, 27, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 18px 42px rgba(0,0,0,0.34);
  backdrop-filter: blur(16px);
}
.info-panel h2 { margin: 0 0 6px; font-size: 1rem; }
.info-panel p { margin: 0; color: var(--text-secondary); font-size: 0.84rem; line-height: 1.42; }
.info-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; font-size: 0.8rem; }
.info-panel dt { color: var(--text-secondary); }
.info-panel dd { margin: 0; color: var(--text-primary); }

.hud {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hud-card {
  width: max-content;
  max-width: 380px;
  padding: 9px 11px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(13, 17, 25, 0.76);
  color: var(--text-secondary);
  font-size: 0.78rem;
  backdrop-filter: blur(12px);
}
.hud-card strong { color: var(--text-primary); }

.mobile-sheet-toggle { display: none; }

@media (max-width: 720px) {
  .control-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: min(72vh, 640px);
    border-radius: 22px 22px 0 0;
    transform: translateY(calc(100% - 64px));
    transition: transform 220ms ease;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .control-panel.open { transform: translateY(0); }
  .mobile-sheet-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 36px;
    margin-bottom: 8px;
    border: 0;
    color: var(--text-secondary);
    background: transparent;
  }
  .mobile-sheet-toggle::before {
    content: '';
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255,255,255,0.35);
  }
  .info-panel { bottom: 74px; }
  .hud-card { max-width: calc(100vw - 32px); }
}
