:root {
  --bg-dark: #0a1324;
  --panel-bg: rgba(14, 26, 48, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text-main: #f0f4f8;
  --text-muted: #94a3b8;
  --accent-cyan: #38bdf8;
  --accent-gold: #fbbf24;
  --btn-active: #0284c7;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  height: 100dvh;
  background-color: var(--bg-dark);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-main);
}

#app-container {
  position: relative;
  width: 100%;
  height: 100%;
}

canvas {
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#webgpu-canvas {
  z-index: 1;
}

#overlay-canvas {
  z-index: 2;
  pointer-events: auto;
  cursor: grab;
}

#overlay-canvas:active {
  cursor: grabbing;
}

/* Loading Overlay */
#loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: radial-gradient(circle at center, #112240 0%, #0a1324 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(56, 189, 248, 0.2);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-main);
}

.loading-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* HUD Top Header */
#hud-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  padding: 10px 16px;
  border-radius: 12px;
  pointer-events: auto;
}

.app-brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #ffffff 0%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-cyan);
  border-radius: 99px;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

#stats-display {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-gold);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  min-width: 270px;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.stat-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.stat-value {
  display: inline-block;
  min-width: 4.5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  color: #ffffff;
}

.stat-divider {
  color: rgba(255, 255, 255, 0.2);
  font-weight: 400;
}

/* HUD Bottom Footer Controls */
#hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(92vw, 780px);
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.time-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.control-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.clock-wrap {
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-cyan);
  min-width: 110px;
  text-align: right;
}

.slider-wrap {
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
}

#time-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: 2px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.6);
  transition: transform 0.15s ease;
}

#time-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.speed-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 4px;
}

.speed-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.speed-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-main);
}

.speed-btn.active {
  background: var(--btn-active);
  color: #ffffff;
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 12px rgba(2, 132, 199, 0.5);
}

/* Intro Dialog */
#intro-dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 10, 20, 0.62);
  backdrop-filter: blur(2px);
  animation: intro-fade-in 0.3s ease;
  transition: opacity 0.25s ease;
}

#intro-dialog[hidden] {
  display: none;
}

#intro-dialog.closing {
  opacity: 0;
  pointer-events: none;
}

@keyframes intro-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.intro-panel {
  max-width: 460px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 24px 26px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.intro-panel h2 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent-cyan);
  margin-bottom: 12px;
}

.intro-panel p {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-muted);
  margin-bottom: 20px;
}

@media (width < 675px) {
  .app-brand {
    display: none;
  }

  .intro-panel {
    padding: 20px;
  }

  .intro-panel p {
    font-size: 0.86rem;
  }

  #hud-top {
    justify-content: center;
    top: 12px;
    left: 12px;
    right: 12px;
  }

  #stats-display {
    padding: 8px 14px;
    font-size: 0.84rem;
    min-width: 240px;
  }

  #hud-bottom {
    bottom: 12px;
    width: calc(100vw - 24px);
    padding: 10px 14px;
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
  }

  .time-controls {
    justify-content: space-between;
    width: 100%;
  }

  .slider-wrap {
    width: 100%;
    min-width: 0;
  }

  .speed-controls {
    justify-content: space-between;
    width: 100%;
  }
}

@media (height < 450px) {
  .app-brand, #stats-display {
    padding: 2px 10px;
  }
  #hud-bottom {
    bottom: 6px;
    padding: 8px 14px;
    gap: 2px;
  }
  .time-controls {
    gap: 0px;
  }
  .clock-wrap {
    font-size: 0.8rem;
  }
  .speed-btn, .control-btn {
    padding: 2px 10px;
  }
  .intro-panel {
    padding: 14px 18px;
  }
  .intro-panel h2 {
    font-size: 1rem;
    margin-bottom: 8px;
  }
  .intro-panel p {
    font-size: 0.82rem;
    line-height: 1.4;
    margin-bottom: 12px;
  }
}
