/* ============================================================
   Emergency Crew - Design System
   Glassmorphism dark theme
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a3e;
  --bg-panel: rgba(26, 26, 62, 0.85);
  --bg-panel-hover: rgba(42, 42, 94, 0.9);
  --border-panel: rgba(255, 217, 61, 0.15);
  --border-panel-active: rgba(255, 217, 61, 0.4);

  --text-primary: #ffffff;
  --text-secondary: #aaaaaa;
  --text-muted: #666666;
  --text-accent: #ffd93d;

  --color-red: #ff6b6b;
  --color-blue: #3498db;
  --color-green: #2ecc71;
  --color-green-hover: #27ae60;
  --color-orange: #f39c12;
  --color-gold: #ffd93d;
  --color-danger: #e74c3c;
  --color-danger-hover: #c0392b;

  --player-blue: #3498db;
  --player-red: #e74c3c;
  --player-green: #2ecc71;
  --player-orange: #f39c12;

  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-game: 'Courier New', monospace;

  --glass-blur: 12px;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --transition: 0.3s ease;
}

/* --- Reset & Base --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-ui);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* --- Animated Grid Background --- */
.grid-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 63px,
      rgba(26, 26, 62, 0.3) 63px,
      rgba(26, 26, 62, 0.3) 64px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 63px,
      rgba(26, 26, 62, 0.3) 63px,
      rgba(26, 26, 62, 0.3) 64px
    );
  animation: gridDrift 20s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes gridDrift {
  from { transform: translate(0, 0); }
  to { transform: translate(64px, 32px); }
}

/* --- Screen System --- */
.screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  z-index: 1;
}

.screen--active {
  opacity: 1;
  visibility: visible;
}

/* --- Glass Panel --- */
.glass-panel {
  background: var(--bg-panel);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-panel);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  padding: 24px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn:active { transform: scale(0.97); }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-green);
  color: #fff;
  box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-green-hover);
  box-shadow: 0 6px 20px rgba(46, 204, 113, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: var(--text-accent);
  border: 2px solid var(--text-accent);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 217, 61, 0.1);
  box-shadow: 0 0 15px rgba(255, 217, 61, 0.2);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--color-danger-hover);
  transform: translateY(-1px);
}

.btn-small {
  padding: 8px 16px;
  font-size: 13px;
}

.btn-large {
  padding: 16px 40px;
  font-size: 20px;
}

/* Pulsing glow for start button */
.btn-glow {
  animation: btnGlow 2s ease-in-out infinite;
}
@keyframes btnGlow {
  0%, 100% { box-shadow: 0 4px 15px rgba(46, 204, 113, 0.3); }
  50% { box-shadow: 0 4px 30px rgba(46, 204, 113, 0.6); }
}

/* --- Inputs --- */
.input {
  background: rgba(15, 15, 35, 0.8);
  border: 2px solid var(--border-panel);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-accent);
  font-family: var(--font-game);
  font-size: 18px;
  text-align: center;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.input:focus {
  border-color: var(--text-accent);
  box-shadow: 0 0 10px rgba(255, 217, 61, 0.2);
}
.input::placeholder {
  color: var(--text-muted);
}

/* ============================================================
   MENU SCREEN
   ============================================================ */
.menu-content {
  text-align: center;
  z-index: 1;
}

.menu-title {
  font-size: clamp(40px, 6vw, 72px);
  font-weight: 900;
  color: var(--color-red);
  text-shadow:
    0 0 20px rgba(255, 107, 107, 0.5),
    0 0 40px rgba(255, 107, 107, 0.3),
    0 0 60px rgba(255, 107, 107, 0.1);
  letter-spacing: 2px;
  margin-bottom: 8px;
  animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 0 0 20px rgba(255, 107, 107, 0.5), 0 0 40px rgba(255, 107, 107, 0.3); }
  50% { text-shadow: 0 0 30px rgba(255, 107, 107, 0.7), 0 0 60px rgba(255, 107, 107, 0.4); }
}

.menu-subtitle {
  font-size: 18px;
  color: var(--text-accent);
  font-weight: 600;
  margin-bottom: 48px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.menu-panels {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.menu-panel {
  width: 280px;
  text-align: center;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.menu-panel:hover {
  border-color: var(--border-panel-active);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.menu-panel h2 {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.menu-panel .input {
  margin-bottom: 16px;
}

.menu-version {
  position: absolute;
  bottom: 20px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Error / loading messages */
.menu-message {
  margin-top: 20px;
  font-size: 14px;
  min-height: 20px;
}
.menu-message.error { color: var(--color-red); }
.menu-message.loading {
  color: var(--text-accent);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================
   LOBBY SCREEN
   ============================================================ */
.lobby-content {
  width: 100%;
  max-width: 960px;
  z-index: 1;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 16px;
}

.lobby-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--text-accent);
  letter-spacing: 1px;
}

.lobby-room-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lobby-room-code {
  font-family: var(--font-game);
  font-size: 18px;
  color: var(--color-green);
  background: rgba(46, 204, 113, 0.1);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 204, 113, 0.3);
  letter-spacing: 2px;
}

.lobby-copy-confirm {
  font-size: 12px;
  color: var(--color-green);
  opacity: 0;
  transition: opacity var(--transition);
}
.lobby-copy-confirm.show { opacity: 1; }

/* Player Cards */
.lobby-players {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin: 32px 0;
  flex-wrap: wrap;
}

.player-card {
  width: 180px;
  min-height: 200px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  transition: all var(--transition);
  border-color: transparent;
}

.player-card.filled {
  border-color: var(--border-panel-active);
}

.player-card.filled .player-avatar {
  animation: avatarPulse 2s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.1); }
  50% { box-shadow: 0 0 15px 5px rgba(255, 255, 255, 0.1); }
}

.player-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid currentColor;
  opacity: 0.25;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.player-card.filled .player-avatar {
  opacity: 1;
}

.player-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-muted);
  transition: color var(--transition);
}

.player-card.filled .player-name {
  color: var(--text-primary);
}

.player-name.is-local {
  color: var(--color-green) !important;
}

.player-color-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* Ready indicator */
.player-ready-indicator {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-danger);
  position: absolute; top: 12px; right: 12px;
  transition: background var(--transition);
  display: none;
}
.player-card.is-ready .player-ready-indicator { background: var(--color-green); }
.player-card { position: relative; }

/* Avatar wrapper for cosmetics */
.player-avatar-wrap { position: relative; display: inline-block; }
.player-hat-icon {
  position: absolute; top: -10px; left: 50%;
  transform: translateX(-50%); font-size: 18px;
  line-height: 1;
}
.player-acc-icon {
  position: absolute; bottom: 2px; right: -8px;
  font-size: 14px; line-height: 1;
}

/* Nickname in lobby */
.player-nickname {
  font-size: 15px; font-weight: 700;
  color: var(--text-muted);
  transition: color var(--transition);
  max-width: 150px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.player-card.filled .player-nickname { color: var(--text-primary); }
.player-nickname.is-local { color: var(--color-green) !important; }

/* Customization panel */
.lobby-customize {
  max-width: 480px; margin: 0 auto 16px;
  padding: 16px 24px;
}
.lobby-customize h3 {
  font-size: 13px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 12px; text-align: center;
}
.customize-row {
  display: flex; align-items: center;
  gap: 12px; margin-bottom: 10px;
}
.customize-row label {
  font-size: 13px; color: var(--text-secondary);
  min-width: 90px; text-transform: uppercase;
  letter-spacing: 0.5px; font-weight: 600;
}
.input-small { max-width: 220px; padding: 8px 12px; font-size: 14px; }

/* Cosmetic picker */
.cosmetic-picker { display: flex; gap: 8px; }
.cosmetic-btn {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  background: rgba(15, 15, 35, 0.8);
  border: 2px solid var(--border-panel);
  color: var(--text-secondary); font-size: 18px;
  cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.cosmetic-btn:hover { border-color: var(--text-accent); }
.cosmetic-btn.active {
  border-color: var(--color-green);
  background: rgba(46, 204, 113, 0.15);
  color: var(--text-primary);
}

/* Ready button active state */
#btn-ready.is-ready {
  background: var(--color-green); color: #fff;
  border-color: var(--color-green);
}

/* Lobby bottom */
.lobby-bottom {
  text-align: center;
}

.lobby-player-count {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.lobby-waiting {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 12px;
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
#game-canvas-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas-container canvas {
  display: block;
}

/* --- HUD Overlay --- */
#game-hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10;
  pointer-events: none;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.hud-timer {
  font-family: var(--font-game);
  font-size: 28px;
  font-weight: bold;
  color: var(--text-primary);
  min-width: 80px;
  transition: color var(--transition);
}
.hud-timer.critical {
  color: var(--color-red);
  animation: pulse 0.5s ease-in-out infinite;
}

.hud-timer-label,
.hud-score-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-stability {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  max-width: 350px;
  margin: 0 24px;
}

.hud-stability-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-stability-track {
  width: 100%;
  height: 16px;
  background: rgba(51, 51, 51, 0.8);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.hud-stability-fill {
  height: 100%;
  border-radius: 8px;
  transition: width 0.3s ease, background-color 0.5s ease;
  width: 100%;
}
.hud-stability-fill.high { background: var(--color-green); }
.hud-stability-fill.mid { background: var(--color-orange); }
.hud-stability-fill.low { background: var(--color-red); }

.hud-stability-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-game);
  font-size: 11px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.hud-stability-wrap {
  position: relative;
  width: 100%;
}

.hud-score-section {
  text-align: right;
  min-width: 80px;
}

.hud-score {
  font-family: var(--font-game);
  font-size: 28px;
  font-weight: bold;
  color: var(--text-accent);
}

/* HUD Bottom */
.hud-bottom {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.hud-carried {
  font-family: var(--font-game);
  font-size: 14px;
  color: var(--text-accent);
  min-width: 180px;
}
.hud-carried.empty { color: var(--text-muted); }

.hud-emergencies {
  font-family: var(--font-game);
  font-size: 13px;
  font-weight: bold;
  color: var(--color-red);
  text-align: center;
}

.hud-controls {
  font-family: var(--font-game);
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
}

/* Emergency Toast Notifications */
.hud-toasts {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.hud-toast {
  background: rgba(255, 0, 0, 0.15);
  border: 1px solid rgba(255, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-game);
  font-size: 18px;
  font-weight: bold;
  color: var(--color-red);
  animation: toastSlide 0.3s ease-out, toastFade 0.5s ease-in 2.5s forwards;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

@keyframes toastSlide {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toastFade {
  to { opacity: 0; transform: translateY(-10px); }
}

/* Tutorial Compris overlay */
.hud-tutorial-compris {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 20;
  pointer-events: none;
}

/* Disconnect overlay */
.hud-disconnect {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: auto;
}
.hud-disconnect.show { display: flex; }
.hud-disconnect h2 {
  font-size: 32px;
  color: var(--color-red);
}
.hud-disconnect p {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ============================================================
   END SCREEN
   ============================================================ */
.end-content {
  text-align: center;
  z-index: 1;
  max-width: 900px;
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  padding: 20px;
}

.end-status {
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 900;
  margin-bottom: 4px;
}
.end-status.saved { color: var(--color-green); }
.end-status.destroyed { color: var(--color-red); }

.end-stability {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* Podium */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
  min-height: 220px;
}

.podium-card {
  width: 180px;
  text-align: center;
  padding: 20px 16px;
  transition: all var(--transition);
}

.podium-card.place-1 {
  min-height: 200px;
  order: 2;
}
.podium-card.place-2 {
  min-height: 160px;
  order: 1;
}
.podium-card.place-3 {
  min-height: 130px;
  order: 3;
}

.podium-card.place-1 {
  border-color: rgba(255, 217, 61, 0.4);
  animation: goldGlow 2s ease-in-out infinite;
}

@keyframes goldGlow {
  0%, 100% { box-shadow: 0 0 15px rgba(255, 217, 61, 0.2); }
  50% { box-shadow: 0 0 30px rgba(255, 217, 61, 0.4); }
}

.podium-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  animation: badgeFloat 2s ease-in-out infinite;
}

@keyframes badgeFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.podium-place {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.podium-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid currentColor;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.podium-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.podium-score {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-accent);
}

/* Score Table */
.end-ranking {
  margin: 0 auto 24px;
  max-width: 500px;
}

.end-ranking h3 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(51, 51, 102, 0.5);
}

.ranking-row {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
}
.ranking-row:nth-child(even) {
  background: rgba(26, 26, 62, 0.3);
}

.ranking-pos {
  width: 30px;
  font-size: 14px;
  color: var(--text-muted);
}
.ranking-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
}
.ranking-score {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-accent);
}

/* Special Badges */
.end-badges {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.end-badge {
  padding: 12px 20px;
  min-width: 180px;
}

.end-badge-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.end-badge-subtitle {
  font-size: 11px;
  color: var(--text-secondary);
}
