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

body {
  font-family: 'Segoe UI', sans-serif;
  background: #0a0a1a;
  color: #eee;
  height: 100vh;
  overflow: hidden;
}

.screen { display: none; width: 100vw; height: 100vh; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }

/* === USERNAME === */
#screen-username {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
}
.username-box {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 48px 40px;
  width: 380px;
  text-align: center;
}
.logo { font-size: 2.4rem; margin-bottom: 6px; }
.subtitle { color: #888; margin-bottom: 28px; font-size: 0.95rem; }
#username-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1rem;
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.2s;
}
#username-input:focus { border-color: #5580ff; }
.error-msg { color: #ff6060; font-size: 0.85rem; min-height: 20px; margin-bottom: 6px; }
.username-rules {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  margin-bottom: 16px;
}
.username-rules span {
  background: rgba(255,255,255,0.06);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: #aaa;
}
.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #5580ff, #8040ff);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }

/* === MENU === */
#screen-menu {
  background: #0e0e22;
  overflow-y: auto;
  display: block;
}
.menu-header {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  background: rgba(0,0,0,0.4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  gap: 12px;
  position: sticky; top: 0; z-index: 10;
}
.logo-sm { font-size: 1.4rem; flex: none; }
.back-to-index {
  text-decoration: none;
  color: #888;
  font-size: 0.85rem;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  transition: all 0.2s;
}
.back-to-index:hover { color: #fff; border-color: rgba(255,255,255,0.3); }
.player-info { display: flex; flex-direction: column; flex: 1; }
.player-name { font-weight: 600; font-size: 1rem; }
.player-title { font-size: 0.8rem; color: #ffd700; }
.menu-header .btn-primary { width: auto; padding: 10px 20px; }
.menu-content { padding: 24px; max-width: 1200px; margin: 0 auto; }
.section-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; color: #ccc; }
.games-section { margin-bottom: 40px; }
.games-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.game-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.game-card:hover { border-color: rgba(85,128,255,0.4); background: rgba(255,255,255,0.08); }
.game-card.featured { border-color: rgba(255,215,0,0.2); }
.game-thumb {
  font-size: 3rem;
  text-align: center;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.race-thumb { background: linear-gradient(135deg, #1a2a1a, #2a4a2a); }
.parkour-thumb { background: linear-gradient(135deg, #2a1a1a, #4a2a1a); }
.game-info h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.game-info p { font-size: 0.82rem; color: #999; line-height: 1.4; }
.game-badge {
  display: inline-block;
  background: rgba(85,128,255,0.2);
  color: #88aaff;
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.btn-play {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, #5580ff, #8040ff);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  align-self: flex-end;
}
.btn-play:hover { opacity: 0.85; }
.no-builds { color: #555; font-size: 0.9rem; padding: 20px; text-align: center; }
.game-card .game-meta { font-size: 0.78rem; color: #666; }

/* === BUILD MODE === */
#screen-build {
  position: relative;
  background: #111;
}
#build-canvas-3d, #play-canvas-3d {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
}
#build-canvas-3d canvas, #play-canvas-3d canvas {
  width: 100% !important; height: 100% !important;
}
#build-canvas-2d, #play-canvas-2d {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: crosshair;
}
#build-ui, #play-ui {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
}
#build-ui > *, #play-ui > * { pointer-events: all; }

.build-exit {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(220,50,50,0.8);
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.build-exit:hover { background: rgba(220,50,50,1); }

.mode-toggle {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  background: rgba(0,0,0,0.6);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
  border: 1px solid rgba(255,255,255,0.1);
}
.mode-btn {
  padding: 6px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  background: transparent;
  color: #aaa;
  transition: all 0.2s;
}
.mode-btn.active { background: #5580ff; color: #fff; }

.build-toolbar {
  position: absolute;
  bottom: 70px; left: 50%; transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  gap: 16px;
  background: rgba(0,0,0,0.88);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 12px 18px;
  backdrop-filter: blur(10px);
  align-items: flex-start;
  max-width: 90vw;
  flex-wrap: wrap;
}
.toolbar-section {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 64px;
}
.toolbar-section .tool-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.toolbar-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #666;
  white-space: nowrap;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #ccc;
  cursor: pointer;
  font-size: 0.72rem;
  min-width: 58px;
  transition: all 0.15s;
}
.tool-btn:hover { background: rgba(85,128,255,0.2); border-color: rgba(85,128,255,0.4); }
.tool-btn.active { background: rgba(85,128,255,0.3); border-color: #5580ff; color: #fff; }
.tool-btn.danger:hover { background: rgba(220,50,50,0.3); border-color: #dc3232; }
.tool-icon { font-size: 1.2rem; }

.save-panel {
  position: absolute;
  bottom: 16px;
  left: 50%; transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
}
.save-panel input {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 0.9rem;
  outline: none;
  width: 220px;
}
.save-panel input:focus { border-color: #5580ff; }
.save-panel .btn-primary { width: auto; padding: 10px 18px; white-space: nowrap; }

.build-hint {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: #aaa;
  pointer-events: none;
}

/* === RACE === */
#screen-race, #screen-parkour, #screen-play-build {
  position: relative;
  background: #111;
}
#race-canvas-container, #parkour-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
}
#race-canvas-container canvas {
  width: 100% !important; height: 100% !important;
}
#parkour-canvas {
  display: block;
}
#race-ui, #parkour-ui, #play-ui {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 5;
}
#race-ui > *, #parkour-ui > * { pointer-events: all; }
.back-btn {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  color: #ccc;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

.game-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  min-width: 340px;
  backdrop-filter: blur(10px);
}
.game-overlay h2 { font-size: 1.6rem; margin-bottom: 10px; }
.game-overlay p { color: #aaa; margin-bottom: 20px; font-size: 0.9rem; line-height: 1.5; }
.small-overlay { min-width: 280px; padding: 24px 28px; }
.small-overlay h3 { font-size: 1.1rem; margin-bottom: 8px; }
.small-overlay .btn-primary { width: auto; padding: 10px 24px; }

.lobby-info {
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 14px 20px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: #ccc;
}
#race-player-count { font-weight: 700; font-size: 1.1rem; color: #fff; }
.player-list {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.player-list .player-tag {
  background: rgba(85,128,255,0.2);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.82rem;
  color: #88aaff;
}
.countdown {
  font-size: 3rem;
  font-weight: 800;
  color: #ff6;
  margin: 10px 0;
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.05)} }

.winner-msg {
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffd700;
  padding: 16px;
  background: rgba(255,215,0,0.1);
  border-radius: 10px;
  margin-top: 10px;
}

.controls-hint {
  font-size: 0.8rem;
  color: #555;
  margin-top: 16px;
}

.race-hud {
  position: absolute;
  bottom: 20px;
  left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  border-radius: 10px;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 280px;
}
#race-progress-bar {
  width: 240px;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 5px;
  overflow: hidden;
}
#race-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #5580ff, #8040ff);
  width: 0%;
  transition: width 0.3s;
}
#race-pos-label { font-size: 0.8rem; color: #aaa; }

.parkour-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.7);
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: #ccc;
}
#parkour-finish-msg {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  background: rgba(0,0,0,0.9);
  border-radius: 12px;
  padding: 24px 36px;
  font-size: 1.5rem;
}

.play-title {
  position: absolute;
  top: 12px;
  left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  border-radius: 8px;
  padding: 8px 20px;
  font-weight: 700;
  font-size: 1rem;
}
#play-controls-hint {
  position: absolute;
  bottom: 16px;
  left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.78rem;
  color: #aaa;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
