/* ═══ DOPPELGANGER — STYLES ═══ */
:root {
  --bg-dark: #0a0a0f;
  --bg-panel: #12121a;
  --bg-input: #1a1a2e;
  --border: #2a2a3e;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --danger: #ff4757;
  --warning: #ffa502;
  --success: #2ed573;
  --human-color: #3498db;
  --ai-color: #e74c3c;
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-pixel: 'Press Start 2P', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ═══ SCREENS ═══ */
.screen { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
.screen.active { display: flex; }

/* ═══ AUTH SCREEN ═══ */
#auth-screen {
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
  justify-content: center;
  align-items: center;
}

.logo { text-align: center; margin-bottom: 30px; }
.logo-icon { font-size: 64px; margin-bottom: 10px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.logo h1 {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--accent);
  letter-spacing: 4px;
  text-shadow: 0 0 20px var(--accent-glow);
}

.tagline { color: var(--text-dim); font-size: 14px; margin-top: 8px; }

.auth-intro {
  margin-bottom: 18px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.16), rgba(52, 152, 219, 0.1));
  border: 1px solid rgba(108, 92, 231, 0.25);
  border-radius: 12px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-input);
  border-radius: 8px;
  padding: 4px;
}

.auth-tabs .tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 6px;
  font-weight: 600;
  transition: all 0.2s;
}

.auth-tabs .tab.active {
  background: var(--accent);
  color: white;
}

.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }

#auth-screen.onboarding-active .auth-tabs,
#auth-screen.onboarding-active .auth-form {
  display: none;
}

.auth-form input {
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ═══ NEEDS PANEL ═══ */
#needs-panel {
  position: fixed;
  top: 60px;
  left: 16px;
  width: 280px;
  background: rgba(18, 18, 26, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  font-size: 13px;
  backdrop-filter: blur(10px);
  z-index: 150;
}

.needs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(108, 92, 231, 0.1);
  border-bottom: 1px solid var(--border);
}

.needs-title {
  font-weight: 600;
  color: var(--accent);
}

.needs-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.needs-content {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.need-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.need-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
}

.need-icon {
  font-size: 14px;
}

.need-bar {
  position: relative;
  height: 18px;
  background: rgba(42, 42, 62, 0.6);
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.need-fill {
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 8px;
}

.need-fill.hunger {
  background: linear-gradient(90deg, #ff4757 0%, #ffa502 50%, #2ed573 100%);
}

.need-fill.energy {
  background: linear-gradient(90deg, #ff4757 0%, #ffa502 50%, #3498db 100%);
}

.need-fill.bladder {
  background: linear-gradient(90deg, #ff4757 0%, #ffa502 50%, #9b59b6 100%);
}

.need-fill.health {
  background: linear-gradient(90deg, #e74c3c 0%, #f39c12 40%, #e74c3c 100%);
}

.need-percent {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  color: white;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

.inventory-section {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.inventory-header {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 600;
}

.inventory-slots {
  display: flex;
  gap: 6px;
}

.inventory-slot {
  flex: 1;
  height: 40px;
  background: rgba(42, 42, 62, 0.4);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: border-color 0.2s;
}

.inventory-slot:hover {
  border-color: var(--accent);
}

.slot-empty {
  font-size: 10px;
  color: var(--text-dim);
}

.slot-item {
  font-size: 10px;
  text-align: center;
  color: var(--text);
  line-height: 1.2;
}

.slot-item-icon {
  font-size: 16px;
  display: block;
  margin-bottom: 2px;
}

/* Needs panel collapsed state */
#needs-panel.collapsed .needs-content {
  display: none;
}

#needs-panel.collapsed {
  width: auto;
}

/* Critical need warnings */
.need-fill[style*="width: 0%"], .need-fill[style*="width: 1%"], .need-fill[style*="width: 2%"] {
  animation: criticalPulse 1s infinite;
}

@keyframes criticalPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.btn-primary {
  padding: 14px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: #7c6cf7;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-secondary {
  padding: 14px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.12);
}

.error-msg {
  color: var(--danger);
  text-align: center;
  font-size: 13px;
  min-height: 20px;
  margin-top: 8px;
}

.error-msg.success {
  color: var(--success);
}

.online-count {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 20px;
}

.online-count .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ═══ GAME RULES (Login Screen) ═══ */
.game-rules {
  margin-top: 20px;
  padding: 16px;
  background: rgba(108, 92, 231, 0.08);
  border: 1px solid rgba(108, 92, 231, 0.2);
  border-radius: 10px;
  max-height: 250px;
  overflow-y: auto;
}

.game-rules h3 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 10px;
  text-align: center;
}

.game-rules ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.game-rules li {
  font-size: 12px;
  color: var(--text-dim);
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  line-height: 1.5;
}

.game-rules li:last-child { border-bottom: none; }

.game-rules li strong { color: var(--text); }

.auth-container {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 420px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 80px var(--accent-glow);
}

.onboarding-flow.hidden,
.onboarding-panel.hidden {
  display: none;
}

.onboarding-flow {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.onboarding-steps {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.onboarding-step {
  padding: 10px 8px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
}

.onboarding-step.active {
  color: white;
  border-color: rgba(108, 92, 231, 0.4);
  background: rgba(108, 92, 231, 0.16);
}

.onboarding-step.done {
  color: #b8ffd6;
  border-color: rgba(46, 213, 115, 0.35);
  background: rgba(46, 213, 115, 0.12);
}

.onboarding-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(22, 22, 36, 0.98), rgba(14, 14, 24, 0.98));
  border: 1px solid rgba(108, 92, 231, 0.18);
  border-radius: 14px;
}

.onboarding-panel h2 {
  font-size: 18px;
  color: var(--text);
}

.onboarding-panel p {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

.pending-email {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(52, 152, 219, 0.08);
  border: 1px solid rgba(52, 152, 219, 0.24);
  color: #8fd3ff;
  font-weight: 600;
  word-break: break-word;
}

.verification-hint {
  margin-top: -4px;
}

.onboarding-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.question-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}

.question-card span:first-child {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.question-card input[type="range"] {
  width: 100%;
}

.question-scale {
  color: var(--text-dim);
  font-size: 12px;
}

.agent-profile-preview {
  padding: 14px;
  border-radius: 12px;
  background: rgba(255, 165, 2, 0.08);
  border: 1px solid rgba(255, 165, 2, 0.2);
  color: #ffe3a6;
  font-size: 13px;
  line-height: 1.5;
}

/* ═══ REVEAL BUTTON ═══ */
.reveal-btn {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, #f39c12, #e67e22);
  border: none;
  border-radius: 6px;
  color: white;
  font-weight: 700;
  cursor: pointer;
  margin: 8px 0;
  transition: all 0.2s;
}

.reveal-btn:hover {
  background: linear-gradient(135deg, #e67e22, #d35400);
  transform: translateY(-1px);
}

.reveal-result {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  margin: 8px 0;
}

.reveal-result.ai { background: rgba(231, 76, 60, 0.2); color: var(--ai-color); }
.reveal-result.human { background: rgba(52, 152, 219, 0.2); color: var(--human-color); }

/* ═══ GAME SCREEN ═══ */
#game-screen { flex-direction: column; }

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

/* ═══ HUD TOP BAR ═══ */
#hud-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.hud-center { display: flex; align-items: center; gap: 12px; }

.game-title {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 2px;
}

.separator { color: var(--border); }

#hud-coords {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.stat-pill.danger { border: 1px solid rgba(231, 76, 60, 0.3); }
.stat-pill.warning { border: 1px solid rgba(255, 165, 2, 0.3); }
.stat-pill.eco { border: 1px solid rgba(46, 204, 113, 0.3); color: #2ecc71; }

.hud-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.hud-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* ═══ CHAT PANEL ═══ */
#chat-panel {
  position: fixed;
  bottom: 16px;
  left: 16px;
  width: 360px;
  max-height: 300px;
  background: rgba(18, 18, 26, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  z-index: 90;
  overflow: hidden;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  max-height: 240px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 0;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; } }

.chat-msg .sender {
  font-weight: 700;
  cursor: pointer;
}

.chat-msg .sender:hover { text-decoration: underline; }

.chat-msg.system {
  color: var(--warning);
  font-style: italic;
  font-size: 12px;
}

.chat-msg.elimination {
  color: var(--danger);
  font-weight: 700;
  padding: 8px;
  background: rgba(255, 71, 87, 0.1);
  border-radius: 6px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

#chat-input:focus { border-color: var(--accent); }

.btn-sm {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-sm:hover { background: #7c6cf7; }

/* ═══ PANELS ═══ */
.panel {
  position: fixed;
  background: rgba(18, 18, 26, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  z-index: 95;
  min-width: 280px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.panel.hidden { display: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
}

.panel-close {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg-input);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
}

.panel-close:hover { background: var(--danger); color: white; }

.panel-body { padding: 16px; }

/* Player Info Panel */
#player-info {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.avatar-preview {
  width: 80px;
  height: 80px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 3px solid var(--accent);
}

.pi-stats {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.vote-section { text-align: center; }
.vote-section p { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }

.vote-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.vote-btn {
  padding: 10px 20px;
  border: 2px solid;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
  color: var(--text);
}

.vote-btn.human { border-color: var(--human-color); }
.vote-btn.human:hover { background: var(--human-color); color: white; }
.vote-btn.ai { border-color: var(--ai-color); }
.vote-btn.ai:hover { background: var(--ai-color); color: white; }

.reputation-bar {
  width: 100%;
  padding: 4px 0;
}

.reputation-track {
  position: relative;
  width: 100%;
  height: 20px;
  background: var(--bg-input);
  border-radius: 10px;
  overflow: hidden;
}

.reputation-zone {
  position: absolute;
  top: 0;
  height: 100%;
}

.reputation-zone.negative {
  left: 0;
  width: 50%;
  background: linear-gradient(90deg, rgba(231, 76, 60, 0.15), transparent);
}

.reputation-zone.positive {
  right: 0;
  width: 50%;
  background: linear-gradient(270deg, rgba(46, 204, 113, 0.15), transparent);
}

.reputation-marker {
  position: absolute;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #f39c12;
  border: 2px solid #fff;
  left: 50%;
  transform: translateX(-50%);
  transition: left 0.5s ease;
  z-index: 2;
  box-shadow: 0 0 6px rgba(243, 156, 18, 0.6);
}

.reputation-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  margin-top: 2px;
  opacity: 0.7;
}

.rep-label-val {
  font-weight: 700;
  font-size: 12px;
  opacity: 1;
}

.eco-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 16px;
  z-index: 9999;
  animation: ecoToastIn 0.4s ease, ecoToastOut 0.4s ease 2.6s;
  box-shadow: 0 4px 20px rgba(46, 204, 113, 0.4);
  pointer-events: none;
}

@keyframes ecoToastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes ecoToastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

/* Leaderboard */
#leaderboard-panel {
  top: 60px;
  right: 16px;
  width: 350px;
}

#leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#leaderboard-table th {
  color: var(--text-dim);
  font-weight: 600;
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

#leaderboard-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(42, 42, 62, 0.3);
}

#leaderboard-table tr:hover td { background: rgba(108, 92, 231, 0.1); }

/* ═══ MINIMAP ═══ */
#minimap {
  display: block;
}

/* ═══ PHONE BUTTON ═══ */
#phone-btn {
  position: fixed;
  bottom: 16px;
  right: 204px;
  width: 48px;
  height: 48px;
  background: rgba(18, 18, 26, 0.9);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 24px;
  cursor: pointer;
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#phone-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 12px var(--accent-glow);
  border-color: var(--accent);
}

/* ═══ PHONE OVERLAY ═══ */
#phone-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
#phone-overlay.hidden { display: none; }

#phone-frame {
  width: 320px;
  max-height: 560px;
  background: linear-gradient(145deg, #1a1a2e 0%, #12121a 100%);
  border: 2px solid var(--border);
  border-radius: 28px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 4px rgba(108,92,231,0.15);
}

.phone-notch {
  width: 100px;
  height: 20px;
  background: #0a0a0f;
  border-radius: 0 0 16px 16px;
  margin: 0 auto;
}

.phone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.phone-time {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-ui);
}
.phone-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.phone-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.phone-close-btn:hover { color: var(--danger); background: rgba(255,71,87,0.1); }

.phone-status {
  padding: 6px 16px;
  font-size: 11px;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(42,42,62,0.3);
}
.status-online { color: var(--success); font-weight: 600; }
.status-offline { color: var(--text-dim); }

/* App Grid */
.phone-apps-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-content: start;
}

.phone-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}
.phone-app:hover { transform: scale(1.08); }
.phone-app:active { transform: scale(0.95); }

.app-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  position: relative;
}
.app-icon.installed::after {
  content: '✓';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: var(--success);
  border-radius: 50%;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.app-name {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.phone-home-bar {
  width: 80px;
  height: 4px;
  background: var(--text-dim);
  border-radius: 2px;
  margin: 8px auto 12px;
  opacity: 0.4;
}

/* ═══ APP INSTALL MODAL ═══ */
#app-install-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 210;
}
#app-install-modal.hidden { display: none; }

.app-modal-content {
  width: 300px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
}
.app-modal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 18px;
  font-weight: 700;
}
.app-modal-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.4;
}
#app-modal-url {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 12px;
}
#app-modal-url:focus {
  outline: none;
  border-color: var(--accent);
}
.app-modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.app-modal-buttons button {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border) !important; }
.btn-secondary:hover { color: var(--text); }

/* ═══ NEARBY PLAYERS ═══ */
#nearby-panel {
  position: fixed;
  top: 60px;
  left: 316px;
  width: 200px;
  background: rgba(18, 18, 26, 0.8);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 90;
  max-height: 300px;
  overflow-y: auto;
}

.nearby-header {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
}

.nearby-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
}

.nearby-player:hover { background: rgba(108, 92, 231, 0.15); }

.nearby-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.nearby-dot.eliminated { background: var(--danger); }

/* ═══ TOAST NOTIFICATIONS ═══ */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  padding: 16px 24px;
  background: rgba(18, 18, 26, 0.95);
  border: 2px solid var(--danger);
  border-radius: 12px;
  z-index: 200;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  animation: toastIn 0.5s ease;
  box-shadow: 0 10px 40px rgba(255, 71, 87, 0.3);
}

.toast.hidden { display: none; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ═══ FRIEND BUTTON (PLAYER INFO) ═══ */
.friend-section { padding: 8px 12px; border-top: 1px solid var(--border); }
.add-friend-btn {
  width: 100%;
  padding: 8px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.add-friend-btn:hover { opacity: 0.85; }
.add-friend-btn:disabled { opacity: 0.5; cursor: default; }
.friend-status-msg {
  display: block;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}
.friend-status-msg.hidden { display: none; }

/* ═══ PHONE CONTACTS SCREEN ═══ */
.phone-contacts-screen {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
}
.phone-contacts-screen.hidden { display: none; }

.contacts-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 1;
}
.contacts-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.contacts-back-btn:hover { background: rgba(108, 92, 231, 0.15); }
.contacts-badge {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.contacts-section { padding: 4px 0; }
.contacts-section.hidden { display: none; }
.contacts-section-title {
  padding: 6px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.12s;
}
.contact-item:hover { background: rgba(108, 92, 231, 0.1); }
.contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.contact-info { flex: 1; min-width: 0; }
.contact-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contact-meta {
  font-size: 10px;
  color: var(--text-dim);
}
.contact-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.contact-status-dot.online { background: var(--success); }
.contact-status-dot.offline { background: var(--text-dim); }
.contact-actions {
  display: flex;
  gap: 4px;
}
.contact-actions button {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.btn-accept { background: var(--success); color: #fff; }
.btn-reject { background: var(--danger); color: #fff; }
.btn-remove { background: var(--bg-input); color: var(--text-dim); border: 1px solid var(--border) !important; font-size: 10px; }
.contacts-empty {
  padding: 20px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Phone badge for pending requests */
#phone-btn .phone-notif {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
#phone-btn .phone-notif.hidden { display: none; }

/* ═══ MESSAGING SCREENS ═══ */
.phone-messages-screen,
.phone-chat-thread,
.phone-friend-profile {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
}
.phone-messages-screen.hidden,
.phone-chat-thread.hidden,
.phone-friend-profile.hidden { display: none; }

.messages-conv-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid rgba(42,42,62,0.4);
}
.conv-item:hover { background: rgba(108, 92, 231, 0.1); }
.conv-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0;
  position: relative;
}
.conv-online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--bg-panel);
}
.conv-online-dot.online { background: var(--success); }
.conv-online-dot.offline { background: var(--text-dim); }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 13px; font-weight: 600; }
.conv-preview {
  font-size: 11px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 160px;
}
.conv-meta { text-align: right; flex-shrink: 0; }
.conv-time { font-size: 9px; color: var(--text-dim); display: block; }
.conv-unread {
  background: var(--accent);
  color: #fff; font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px; margin-top: 2px;
}
.conv-unread.hidden { display: none; }

/* Chat thread */
.chat-thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dm-bubble {
  max-width: 80%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.dm-bubble.mine {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.dm-bubble.theirs {
  background: var(--bg-input);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.dm-bubble .dm-clone-tag {
  font-size: 9px;
  opacity: 0.6;
  display: block;
  margin-top: 2px;
}
.dm-bubble .dm-time {
  font-size: 9px;
  opacity: 0.5;
  display: block;
  text-align: right;
  margin-top: 2px;
}
.chat-thread-input-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
.chat-thread-input-bar input {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.chat-thread-input-bar input:focus { border-color: var(--accent); }
.chat-thread-input-bar button {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-thread-input-bar button:hover { opacity: 0.9; }

/* Friend profile */
.friend-profile-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.friend-profile-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 700;
  border: 2px solid var(--border);
}
.friend-profile-status {
  font-size: 12px;
  color: var(--text-dim);
}
.friend-profile-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  width: 100%;
  margin-top: 12px;
  padding: 0 4px;
}
.friend-profile-apps {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.friend-app-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.friend-app-item:hover { background: rgba(108, 92, 231, 0.15); }
.friend-app-icon {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.friend-app-name { font-size: 12px; font-weight: 600; flex: 1; }
.friend-app-link { font-size: 10px; color: var(--accent); }

/* ═══ SCROLLBARS ═══ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  /* Auth screen */
  .auth-container {
    padding: 20px 16px;
    width: 100%;
    max-width: 100vw;
    border-radius: 0;
    max-height: 100vh;
    border: none;
  }
  .logo-icon { font-size: 48px; }
  .logo h1 { font-size: 16px; letter-spacing: 2px; }
  .tagline { font-size: 12px; }
  .game-rules { max-height: 180px; padding: 12px; }
  .game-rules li { font-size: 11px; }
  .auth-form input { padding: 12px 14px; font-size: 16px; /* prevent iOS zoom */ }
  .btn-primary { padding: 12px; font-size: 14px; }
  .btn-secondary { padding: 12px; font-size: 13px; }
  .onboarding-steps { grid-template-columns: 1fr; }
  .onboarding-panel { padding: 16px; }
  .question-card { padding: 12px; }

  /* HUD top bar */
  #hud-top { height: 40px; padding: 0 8px; }
  .game-title { font-size: 8px; letter-spacing: 1px; }
  .separator { display: none; }
  #hud-coords { font-size: 10px; }
  .stat-pill { padding: 4px 8px; font-size: 11px; gap: 4px; }
  .stat-icon { font-size: 12px; }
  .hud-btn { width: 32px; height: 32px; font-size: 14px; }

  /* Chat panel */
  #chat-panel {
    width: calc(100% - 16px);
    left: 8px;
    bottom: 8px;
    max-height: 200px;
    border-radius: 10px;
  }
  #chat-messages { max-height: 140px; padding: 8px; }
  .chat-msg { font-size: 12px; }
  .chat-input-row { padding: 6px 8px; gap: 6px; }
  #chat-input { padding: 10px; font-size: 16px; /* prevent iOS zoom */ }
  .btn-sm { padding: 10px 14px; font-size: 12px; }

  /* Nearby panel — position to right of needs panel */
  #nearby-panel {
    top: 44px;
    left: 296px;
    width: auto;
    max-width: 160px;
    max-height: 200px;
    border-radius: 8px;
  }
  .nearby-header { padding: 6px 10px; font-size: 9px; }
  .nearby-player { padding: 5px 10px; font-size: 12px; }

  /* Minimap */
  #minimap {
    width: 100px;
    height: 100px;
    bottom: 8px;
    right: 8px;
    border-radius: 6px;
  }
  #phone-btn { right: 116px; bottom: 8px; width: 40px; height: 40px; font-size: 20px; }
  #phone-frame { width: 280px; max-height: 480px; }

  /* Panels (player info, leaderboard) */
  .panel {
    min-width: unset;
    width: calc(100% - 32px) !important;
    max-width: 360px;
    left: 50% !important;
    right: auto !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
  }
  #leaderboard-panel { width: calc(100% - 32px) !important; }
  .panel-body { padding: 12px; }
  .panel-header { padding: 10px 14px; font-size: 13px; }

  /* Vote buttons */
  .vote-btn { padding: 10px 16px; font-size: 13px; }

  /* Toast */
  .toast {
    left: 8px;
    right: 8px;
    transform: none;
    font-size: 14px;
    padding: 12px 16px;
  }
  @keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* Very small phones */
@media (max-width: 400px) {
  .auth-container { padding: 16px 12px; }
  .logo-icon { font-size: 36px; }
  .logo h1 { font-size: 14px; }
  .game-rules { max-height: 150px; }
  #chat-panel { max-height: 160px; }
  #chat-messages { max-height: 110px; }
  .stat-pill { padding: 3px 6px; font-size: 10px; }
  #nearby-panel { display: none; }
  #minimap { width: 80px; height: 80px; }
  #phone-btn { right: 96px; width: 36px; height: 36px; font-size: 18px; }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #chat-panel {
    width: 280px;
    max-height: 160px;
    bottom: 4px;
    left: 4px;
  }
  #hud-top { height: 36px; }
  #nearby-panel { display: none; }
  #minimap { width: 80px; height: 80px; bottom: 4px; right: 4px; }
  #phone-btn { right: 88px; bottom: 4px; width: 36px; height: 36px; }
}

/* Touch device: prevent text selection on game canvas */
#game-canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

/* ─── Mobile Horizontal Optimization ─────────── */
@media screen and (max-height: 500px) and (min-width: 600px) {
  /* Landscape mobile mode */
  
  #hud-top {
    padding: 4px 8px !important;
    height: 36px !important;
    font-size: 11px !important;
  }
  
  #hud-top .hud-center {
    gap: 8px !important;
  }
  
  .stat-pill {
    padding: 2px 6px !important;
    font-size: 10px !important;
  }
  
  .hud-ecos-pill {
    padding: 2px 8px !important;
    font-size: 11px !important;
  }
  
  .hud-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 14px !important;
  }
  
  #needs-panel {
    width: 180px !important;
    max-height: 60vh !important;
    bottom: 8px !important;
    left: 8px !important;
  }
  
  .needs-header {
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  
  #needs-panel .need-item {
    margin-bottom: 4px !important;
  }
  
  .need-label {
    font-size: 10px !important;
  }
  
  .need-bar {
    height: 12px !important;
  }
  
  .need-percent {
    font-size: 9px !important;
  }
  
  #chat-panel {
    width: 240px !important;
    max-height: 140px !important;
    bottom: 8px !important;
    right: 8px !important;
  }
  
  #chat-messages {
    max-height: 100px !important;
    font-size: 11px !important;
  }
  
  .chat-input-row {
    padding: 4px !important;
  }
  
  #chat-input {
    font-size: 11px !important;
    padding: 4px 6px !important;
  }
  
  .btn-sm {
    padding: 4px 8px !important;
    font-size: 10px !important;
  }
  
  .inventory-section {
    margin-top: 6px !important;
  }
  
  .inventory-slot {
    width: 28px !important;
    height: 28px !important;
    font-size: 10px !important;
  }
  
  #admin-panel {
    width: 260px !important;
    top: 40px !important;
    right: 8px !important;
    max-height: calc(100vh - 50px) !important;
    font-size: 10px !important;
  }
  
  .admin-btn {
    padding: 4px 6px !important;
    font-size: 9px !important;
    min-width: 50px !important;
  }
  
  .admin-input {
    padding: 2px 4px !important;
    font-size: 10px !important;
    width: 40px !important;
  }
  
  #phone-panel {
    width: 240px !important;
    bottom: 160px !important;
    right: 8px !important;
    max-height: 50vh !important;
  }
}

/* ─── Admin Panel ─────────────────────────── */
#admin-panel {
  position: fixed;
  top: 56px;
  right: 10px;
  width: 320px;
  max-height: calc(100vh - 70px);
  background: rgba(10, 10, 30, 0.95);
  border: 1px solid rgba(255, 215, 0, 0.4);
  border-radius: 8px;
  z-index: 200;
  font-size: 12px;
  color: #e0e0e0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 215, 0, 0.15);
  border-bottom: 1px solid rgba(255, 215, 0, 0.3);
  font-weight: bold;
  color: #ffd700;
  font-size: 13px;
}

.admin-status {
  font-size: 11px;
  color: #4ecdc4;
}

.admin-toggle {
  background: none;
  border: 1px solid rgba(255, 215, 0, 0.3);
  color: #ffd700;
  width: 24px;
  height: 24px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}

.admin-content {
  overflow-y: auto;
  max-height: calc(100vh - 130px);
}

.admin-section {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.admin-btn-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}

.admin-btn {
  flex: 1;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e0e0e0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.15s;
}
.admin-btn:hover {
  background: rgba(255, 215, 0, 0.2);
  color: #fff;
}

.admin-input {
  width: 60px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e0e0e0;
  border-radius: 4px;
  font-size: 11px;
  text-align: center;
}

.admin-player-list {
  max-height: 50vh;
  overflow-y: auto;
}

.admin-player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.1s;
}
.admin-player-row:hover {
  background: rgba(255, 255, 255, 0.05);
}
.admin-player-row.ai {
  border-left: 3px solid #e74c3c;
}
.admin-player-row.human {
  border-left: 3px solid #2ecc71;
}

.ap-info {
  font-size: 11px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ap-info b {
  color: #fff;
}

.ap-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.ap-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ccc;
  padding: 2px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}
.ap-btn:hover {
  background: rgba(255, 215, 0, 0.2);
  color: #fff;
}

.admin-stats-panel {
  padding: 10px;
}

.admin-stat {
  margin: 4px 0;
  font-size: 12px;
}
.admin-stat b {
  color: #ffd700;
}

/* Admin mode: hide player-specific UI */
body.admin-mode #needs-panel,
body.admin-mode #phone-panel,
body.admin-mode #chat-input,
body.admin-mode #chat-send,
body.admin-mode .vote-section,
body.admin-mode .reveal-section {
  display: none !important;
}

