/* style.css — Block Racers 3D */

:root {
  color-scheme: dark;
  --bg-dark: #0f0f1a;
  --bg-panel: #1a1a2e;
  --bg-surface: #252540;
  --bg-hover: #2f2f50;
  --text-primary: #e8e8f0;
  --text-secondary: #9999aa;
  --text-muted: #666677;
  --accent: #3498db;
  --accent-glow: rgba(52, 152, 219, 0.3);
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --border: #333355;
  --radius: 8px;
  --radius-lg: 12px;
  --font-display: ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Consolas, 'Liberation Mono', Menlo, monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg-dark: #f0f0f5;
    --bg-panel: #ffffff;
    --bg-surface: #e8e8f0;
    --bg-hover: #d8d8e8;
    --text-primary: #1a1a2e;
    --text-secondary: #555566;
    --text-muted: #888899;
    --accent: #2980b9;
    --accent-glow: rgba(41, 128, 185, 0.2);
    --border: #ccccdd;
  }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-dark: #0f0f1a;
  --bg-panel: #1a1a2e;
  --bg-surface: #252540;
  --bg-hover: #2f2f50;
  --text-primary: #e8e8f0;
  --text-secondary: #9999aa;
  --text-muted: #666677;
  --accent: #3498db;
  --accent-glow: rgba(52, 152, 219, 0.3);
  --border: #333355;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-dark: #f0f0f5;
  --bg-panel: #ffffff;
  --bg-surface: #e8e8f0;
  --bg-hover: #d8d8e8;
  --text-primary: #1a1a2e;
  --text-secondary: #555566;
  --text-muted: #888899;
  --accent: #2980b9;
  --accent-glow: rgba(41, 128, 185, 0.2);
  --border: #ccccdd;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text-primary);
  touch-action: manipulation;
}

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

.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ── Menu Screen ── */
#screen-menu {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a3e 50%, #0f0f1a 100%);
}

html[data-theme="light"] #screen-menu {
  background: linear-gradient(135deg, #f0f0f5 0%, #e0e0f0 50%, #f0f0f5 100%);
}

.menu-content {
  text-align: center;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
}

.title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 7vw, 3.5rem);
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 30px var(--accent-glow);
  text-transform: uppercase;
}

.title .accent {
  color: var(--accent);
}

.badge {
  font-size: 0.4em;
  vertical-align: super;
  background: var(--accent);
  color: #fff;
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  letter-spacing: 0.05em;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.btn {
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.03em;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { box-shadow: 0 0 20px var(--accent-glow); filter: brightness(1.1); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-race {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  font-size: 1.2rem;
  padding: 1rem 2rem;
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}
.btn-race:hover { box-shadow: 0 0 25px rgba(231, 76, 60, 0.4); filter: brightness(1.1); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.1); }

.btn-back {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-family: var(--font-body);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-back:hover { color: var(--text-primary); background: var(--bg-surface); }

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
}

.btn-small.btn-danger {
  margin-left: 0.4rem;
  background: var(--danger);
}

.saved-list {
  margin-top: 1rem;
}

.no-saves {
  color: var(--text-muted);
  font-style: italic;
}

.save-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.save-item > span {
  font-weight: 600;
}

.save-buttons {
  display: flex;
  align-items: center;
}

/* ── Builder Screen ── */
#screen-builder {
  background: var(--bg-dark);
}

.builder-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.builder-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.builder-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.builder-stats {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.builder-stats span {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-surface);
  border-radius: 4px;
  color: var(--text-secondary);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-family: var(--font-display);
}

.builder-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.block-palette {
  width: 180px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.palette-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-body);
  font-size: 0.85rem;
}

.palette-btn:hover { background: var(--bg-hover); }
.palette-btn.active { border-color: var(--accent); background: var(--accent-glow); }

.palette-preview {
  width: 24px;
  height: 24px;
  border-radius: 3px;
  flex-shrink: 0;
}

.color-palette {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.color-palette h4 {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-display);
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: inline-block;
  margin: 2px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s ease;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.3); }

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  position: relative;
}

.canvas-area canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.canvas-area canvas:active {
  cursor: grabbing;
}

.block-info {
  width: 220px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  padding: 0.75rem;
  overflow-y: auto;
  font-size: 0.85rem;
}

.block-info h3 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.block-info p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  line-height: 1.4;
}

/* ── Layer / Height Controls ── */
.layer-control {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.layer-control h4 {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-display);
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.layer-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.layer-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.layer-btn:active { transform: scale(0.92); }

.layer-display {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  padding: 0.25rem 0;
}

.layer-hint {
  font-size: 0.72rem !important;
  color: var(--text-muted) !important;
  margin: 0.5rem 0 0 0 !important;
  line-height: 1.35;
}

#block-details {
  margin-bottom: 1rem;
}

.builder-footer {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  justify-content: center;
}

/* ── Race Screen ── */
#screen-race {
  background: #000;
}

#race-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.race-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  pointer-events: none;
  z-index: 10;
}

.hud-left, .hud-right {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hud-center {
  text-align: center;
}

.hud-speed {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 10px rgba(52,152,219,0.5);
  letter-spacing: 0.08em;
}

.hud-lap, .hud-position, .hud-distance {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.08em;
}

.hud-position {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--warning);
}

.hud-weapon, .hud-weapon-count {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.08em;
}

/* ── HP Bar ── */
.hud-hp-bar {
  width: 160px;
  height: 18px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 9px;
  overflow: hidden;
  position: relative;
  margin-top: 0.25rem;
}

.hud-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  border-radius: 9px;
  transition: width 0.3s ease, background 0.3s ease;
}

.hud-hp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  letter-spacing: 0.05em;
}

/* ── Damage Flash ── */
.damage-flash {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at center, rgba(255,0,0,0.4) 0%, rgba(255,0,0,0.1) 60%, transparent 100%);
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.race-start-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.5);
  z-index: 20;
}

.countdown {
  font-family: var(--font-display);
  font-size: 6rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 40px var(--accent-glow);
  animation: pulse 1s ease-in-out infinite;
  letter-spacing: 0.1em;
}

.go-text {
  font-family: var(--font-display);
  font-size: 5rem;
  font-weight: 700;
  color: var(--success);
  text-shadow: 0 0 40px rgba(46,204,113,0.5);
  animation: pulse 0.5s ease-in-out infinite;
  letter-spacing: 0.15em;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* ── Results Screen ── */
#screen-results {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a3e 50%, #0f0f1a 100%);
}

html[data-theme="light"] #screen-results {
  background: linear-gradient(135deg, #f0f0f5 0%, #e0e0f0 50%, #f0f0f5 100%);
}

.results-content {
  text-align: center;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
}

.results-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.results-podium {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.podium-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 200px;
}

.podium-item.player {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.podium-pos {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  min-width: 30px;
}

.podium-name {
  flex: 1;
  text-align: left;
  font-weight: 600;
}

.podium-time {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: var(--font-display);
}

.results-stats {
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
  line-height: 1.8;
  font-family: var(--font-display);
  font-size: 0.85rem;
}

.results-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .builder-main {
    flex-direction: column;
  }

  .block-palette {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 120px;
    overflow-y: auto;
  }

  .palette-btn {
    flex: 1;
    min-width: 80px;
    justify-content: center;
    padding: 0.4rem;
    font-size: 0.75rem;
  }

  .palette-preview {
    width: 18px;
    height: 18px;
  }

  .color-palette {
    border-top: none;
    border-left: 1px solid var(--border);
    padding-left: 0.5rem;
    margin-top: 0;
    flex-direction: row;
    flex-wrap: wrap;
    display: flex;
    align-items: center;
  }

  .color-palette h4 {
    margin-right: 0.5rem;
    margin-bottom: 0;
  }

  .block-info {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 180px;
  }

  .hud-speed {
    font-size: 1.3rem;
  }

  .countdown {
    font-size: 4rem;
  }

  .go-text {
    font-size: 3rem;
  }

  .builder-stats span {
    font-size: 0.65rem;
    padding: 0.15rem 0.35rem;
  }

  .layer-btn {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }

  .layer-display {
    font-size: 0.85rem;
  }

  .hud-hp-bar {
    width: 120px;
    height: 14px;
  }

  .hud-hp-text {
    font-size: 0.6rem;
  }
}

@media (max-width: 360px) {
  .menu-buttons {
    gap: 0.5rem;
  }

  .btn {
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
  }

  .btn-race {
    font-size: 1rem;
    padding: 0.8rem 1.5rem;
  }
}


