/* ═══════════════════════════════════════════════════════════════════
   EcoCity AR — Design System & HUD Styles
   Aesthetic: Dark Eco-Futurism | Glassmorphism | Neon Accents
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;800&family=Rajdhani:wght@300;400;500;600&display=swap');

/* ── CSS Variables ───────────────────────────────────────────────── */
:root {
  --eco-green:    #00FF87;
  --eco-cyan:     #00E5FF;
  --eco-yellow:   #FFD700;
  --eco-orange:   #FF8C00;
  --eco-red:      #FF4757;
  --eco-purple:   #CE93D8;

  --bg-dark:      #030d08;
  --bg-card:      rgba(0, 30, 15, 0.75);
  --bg-glass:     rgba(0, 255, 135, 0.04);
  --border-glass: rgba(0, 255, 135, 0.18);
  --border-cyan:  rgba(0, 229, 255, 0.25);

  --text-primary: #E8F5E9;
  --text-dim:     rgba(200, 230, 210, 0.55);

  --font-display: 'Orbitron', 'Courier New', monospace;
  --font-body:    'Rajdhani', 'Segoe UI', sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --shadow-neon: 0 0 12px rgba(0, 255, 135, 0.4), 0 0 32px rgba(0, 255, 135, 0.15);
  --shadow-cyan: 0 0 12px rgba(0, 229, 255, 0.4), 0 0 32px rgba(0, 229, 255, 0.15);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  font-family: var(--font-body);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ── A-Frame Scene ───────────────────────────────────────────────── */
a-scene {
  position: fixed !important;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

/* ── HUD Root ────────────────────────────────────────────────────── */
#hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  pointer-events: none; /* Pass clicks through to AR scene */
}
#hud > * { pointer-events: all; }

/* ── Glassmorphism Panel ─────────────────────────────────────────── */
.glass-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  backdrop-filter: blur(16px) saturate(1.5);
  -webkit-backdrop-filter: blur(16px) saturate(1.5);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
}

/* ── Top Bar ─────────────────────────────────────────────────────── */
#top-bar {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px;
  min-width: 340px;
  max-width: 96vw;
  border-radius: 50px;
  background: rgba(0, 15, 8, 0.85);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-neon);
}

.top-logo {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  color: var(--eco-green);
  letter-spacing: 2px;
  text-shadow: var(--shadow-neon);
  white-space: nowrap;
}

.top-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.top-stat-label { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.top-stat-value { font-family: var(--font-display); font-size: 13px; color: var(--eco-yellow); }

#connection-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--eco-green);
  box-shadow: 0 0 6px var(--eco-green);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.room-chip {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--eco-cyan);
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid var(--border-cyan);
  border-radius: 20px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background 0.2s;
}
.room-chip:hover { background: rgba(0, 229, 255, 0.2); }

/* ── Left Panel — Energy Stats ───────────────────────────────────── */
#left-panel {
  position: absolute;
  left: 12px;
  top: 72px;
  width: 200px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-group { display: flex; flex-direction: column; gap: 4px; }
.stat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}
.stat-value {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--eco-green);
  line-height: 1.1;
}
.stat-sub { font-size: 11px; color: var(--text-dim); }

.panel-divider {
  height: 1px;
  background: var(--border-glass);
  margin: 2px 0;
}

/* Energy bar */
.energy-bar-wrap {
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}
.energy-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease, background 0.5s ease;
}

/* ── Right Panel — Weather ───────────────────────────────────────── */
#right-panel {
  position: absolute;
  right: 12px;
  top: 72px;
  width: 180px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.weather-icon { font-size: 32px; text-align: center; }
.weather-row  { display: flex; justify-content: space-between; align-items: center; }
.weather-val  { font-family: var(--font-display); font-size: 13px; color: var(--eco-cyan); }

#hud-climate-event {
  display: none;
  font-size: 11px;
  text-align: center;
  color: var(--eco-orange);
  background: rgba(255, 140, 0, 0.1);
  border: 1px solid rgba(255, 140, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  animation: climate-flash 2s ease-in-out infinite;
}
@keyframes climate-flash {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ── Bottom Bar — Quick Actions ──────────────────────────────────── */
#bottom-bar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 50px;
  background: rgba(0, 15, 8, 0.88);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(20px);
  box-shadow: 0 -2px 20px rgba(0,0,0,0.4);
}

.build-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 12px;
}
.build-btn:hover, .build-btn:active {
  background: rgba(0, 255, 135, 0.12);
  border-color: var(--eco-green);
  box-shadow: var(--shadow-neon);
  transform: translateY(-2px);
}
.build-btn-icon { font-size: 20px; }
.build-btn-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.build-btn-count {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--eco-green);
}

/* ── Storage Action Indicator ────────────────────────────────────── */
#storage-action {
  font-family: var(--font-display);
  font-size: 11px;
  text-align: center;
  padding: 4px 0;
  transition: color 0.5s;
}

/* ── Player List Panel ───────────────────────────────────────────── */
#players-panel {
  position: absolute;
  right: 12px;
  bottom: 80px;
  width: 180px;
  max-height: 200px;
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}
#players-panel.open { display: flex; }

.player-chip {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-sm);
}
.player-chip small { margin-left: auto; color: var(--eco-yellow); font-family: var(--font-display); font-size: 10px; }

/* ── Chat Panel ──────────────────────────────────────────────────── */
#chat-panel {
  position: absolute;
  left: 12px;
  bottom: 80px;
  width: 240px;
  display: none;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}
#chat-panel.open { display: flex; }

#chat-messages {
  height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-glass) transparent;
}
.chat-msg { line-height: 1.4; }
.chat-name { color: var(--eco-cyan); font-weight: 600; margin-right: 4px; }

#chat-form { display: flex; gap: 6px; }
#chat-input {
  flex: 1;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
}
#chat-input:focus { border-color: var(--eco-green); }
#chat-send {
  background: var(--eco-green);
  border: none;
  border-radius: var(--radius-sm);
  color: #000;
  cursor: pointer;
  font-size: 14px;
  padding: 0 10px;
  font-weight: 700;
  transition: opacity 0.2s;
}
#chat-send:hover { opacity: 0.85; }

/* ── Blackout Overlay ────────────────────────────────────────────── */
#blackout-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(180, 0, 0, 0.08);
  align-items: center;
  justify-content: center;
  animation: blackout-flicker 0.5s ease-in-out infinite alternate;
  pointer-events: none !important;
  user-select: none !important;
}

@keyframes blackout-flicker {
  0%   { background: rgba(180, 0, 0, 0.1); }
  100% { background: rgba(180, 0, 0, 0.2); }
}
#blackout-msg {
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(18px, 5vw, 32px);
  color: var(--eco-red);
  text-shadow: 0 0 20px var(--eco-red);
  letter-spacing: 4px;
  animation: blackout-text 1s ease-in-out infinite alternate;
}
@keyframes blackout-text {
  0%   { opacity: 0.7; transform: scale(0.98); }
  100% { opacity: 1.0; transform: scale(1.00); }
}

/* ── Toast Container ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 50px;
  background: rgba(0, 20, 10, 0.9);
  border: 1px solid var(--border-glass);
  backdrop-filter: blur(16px);
  color: var(--text-primary);
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  max-width: 90vw;
  text-overflow: ellipsis;
  overflow: hidden;
}
.toast.toast-visible { opacity: 1; transform: translateY(0) scale(1); }
.toast.toast-hiding  { opacity: 0; transform: translateY(-8px) scale(0.95); transition-timing-function: ease-in; transition-duration: 0.25s; }

.toast-success     { border-color: rgba(0, 255, 135, 0.4); color: var(--eco-green); }
.toast-error       { border-color: rgba(255, 71, 87, 0.4);  color: var(--eco-red); }
.toast-info        { border-color: rgba(0, 229, 255, 0.3);  color: var(--eco-cyan); }
.toast-achievement { border-color: rgba(255, 215, 0, 0.4);  color: var(--eco-yellow); background: rgba(20, 15, 0, 0.9); }
.toast-climate     { border-color: rgba(255, 140, 0, 0.4);  color: var(--eco-orange); }

/* ── Lobby / Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 5, 2, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: rgba(0, 20, 12, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-neon), 0 20px 60px rgba(0,0,0,0.8);
  animation: modal-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-in {
  from { transform: scale(0.85) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0);       opacity: 1; }
}

.modal-logo {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  color: var(--eco-green);
  text-shadow: var(--shadow-neon);
  letter-spacing: 3px;
  text-align: center;
  margin-bottom: 4px;
}
.modal-tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 28px;
  letter-spacing: 1px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-dim); }
.form-input, .form-select {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}
.form-input:focus, .form-select:focus { border-color: var(--eco-green); box-shadow: 0 0 0 2px rgba(0,255,135,0.1); }
.form-select option { background: #030d08; }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--eco-green);
  border: none;
  border-radius: var(--radius-sm);
  color: #000;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
  text-transform: uppercase;
}
.btn-primary:hover {
  background: #00ff9d;
  box-shadow: var(--shadow-neon);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

/* ── Build Menu ──────────────────────────────────────────────────── */
#build-menu {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 80px;
}

#build-menu-inner {
  background: rgba(0, 18, 10, 0.96);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px;
  width: 100%;
  max-width: 480px;
  animation: slide-up 0.3s ease;
}
@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.build-menu-title {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 16px;
}

.build-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.build-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.2s;
}
.build-option:hover {
  background: rgba(0, 255, 135, 0.1);
  border-color: var(--eco-green);
  box-shadow: var(--shadow-neon);
  transform: scale(1.04);
}
.build-option-icon  { font-size: 28px; }
.build-option-name  { font-size: 11px; font-weight: 600; text-align: center; }
.build-option-bonus { font-size: 9px; color: var(--eco-green); font-family: var(--font-display); }

#build-menu-close {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-body);
  transition: background 0.2s;
}
#build-menu-close:hover { background: rgba(255,255,255,0.05); }

/* ── Demo Grid (visible in desktop/no-AR mode) ───────────────────── */
#demo-grid {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #0a1f10 0%, #030d08 70%);
}
#demo-grid.visible { display: flex; }

.city-grid-demo {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px;
}
.lot-btn {
  width: 70px; height: 70px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  background: rgba(0, 30, 15, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  transition: all 0.2s;
  color: transparent;
}
.lot-btn:empty::before { content: '+'; color: var(--text-dim); font-size: 22px; font-family: var(--font-display); }
.lot-btn:hover { border-color: var(--eco-green); background: rgba(0, 255, 135, 0.08); box-shadow: var(--shadow-neon); }
.lot-btn.occupied { color: initial; }

/* ── AR instruction overlay ──────────────────────────────────────── */
#ar-instructions {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.5px;
  z-index: 50;
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-glass); border-radius: 2px; }

/* ── Mobile optimizations ────────────────────────────────────────── */
@media (max-width: 480px) {
  #left-panel  { width: 160px; font-size: 0.9em; }
  #right-panel { width: 150px; font-size: 0.9em; }
  .stat-value  { font-size: 13px; }

  .build-options { grid-template-columns: repeat(2, 1fr); }
  .build-option  { padding: 12px; }

  .build-btn { padding: 6px 10px; }
  .build-btn-icon { font-size: 18px; }

  #top-bar { min-width: auto; gap: 10px; padding: 6px 14px; }
  .top-logo { font-size: 12px; }
}

@media (max-width: 360px) {
  #left-panel, #right-panel { display: none; }
  #ar-instructions { display: none; }
}

/* ── Scan animation for AR marker UI ─────────────────────────────── */
.scan-line {
  position: fixed;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--eco-green), transparent);
  z-index: 15;
  animation: scan 3s linear infinite;
  opacity: 0.6;
}
@keyframes scan {
  0%   { top: 10%; opacity: 0; }
  5%   { opacity: 0.7; }
  95%  { opacity: 0.7; }
  100% { top: 90%; opacity: 0; }
}
