/* PixelRealm — CSS principal */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Inter:wght@400;600&display=swap');

:root {
  --bg: #0d0d1a;
  --bg2: #141428;
  --panel: #1a1a35;
  --panel2: #22224a;
  --border: #3a3a7a;
  --accent: #7c5cbf;
  --accent2: #a678ff;
  --gold: #f5c842;
  --green: #4ecb71;
  --red: #e05c5c;
  --blue: #4ea8de;
  --orange: #f5883c;
  --text: #e8e8ff;
  --text-dim: #9090c0;
  --pixel: 'Press Start 2P', monospace;
  --body: 'Inter', sans-serif;
  --r: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Stars background */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 70%, #aaa 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 25%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 75% 85%, #bbb 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 40%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 20% 90%, #aaa 0%, transparent 100%),
    radial-gradient(1px 1px at 65% 55%, #fff 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 10%, #ccc 0%, transparent 100%),
    radial-gradient(1px 1px at 80% 65%, #fff 0%, transparent 100%);
  pointer-events: none; z-index: 0;
}

/* ===================== LOBBY ===================== */
#screen-lobby {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh;
  padding: 20px; position: relative; z-index: 1;
}

.game-title {
  font-family: var(--pixel);
  font-size: clamp(18px, 4vw, 36px);
  color: var(--accent2);
  text-shadow: 0 0 20px var(--accent), 4px 4px 0 #3a1a7a;
  margin-bottom: 8px;
  animation: glow 2s ease-in-out infinite alternate;
  text-align: center;
}
.game-subtitle {
  font-family: var(--pixel); font-size: 9px;
  color: var(--gold); letter-spacing: 2px; margin-bottom: 40px;
  text-align: center;
}
@keyframes glow {
  from { text-shadow: 0 0 10px var(--accent), 4px 4px 0 #3a1a7a; }
  to   { text-shadow: 0 0 30px var(--accent2), 0 0 60px var(--accent), 4px 4px 0 #3a1a7a; }
}

.lobby-card {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 30px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(124,92,191,0.2);
}

.lobby-tabs {
  display: flex; gap: 4px; margin-bottom: 24px;
  background: var(--bg); border-radius: var(--r); padding: 4px;
}
.tab-btn {
  flex: 1; padding: 10px; border: none; border-radius: 4px;
  background: transparent; color: var(--text-dim); cursor: pointer;
  font-family: var(--pixel); font-size: 8px; transition: all 0.2s;
}
.tab-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(124,92,191,0.4);
}

.form-group { margin-bottom: 16px; }
label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
input[type=text], select {
  width: 100%; padding: 12px 14px;
  background: var(--bg2); border: 2px solid var(--border);
  border-radius: var(--r); color: var(--text);
  font-family: var(--body); font-size: 14px;
  transition: border-color 0.2s;
}
input[type=text]:focus, select:focus { outline: none; border-color: var(--accent2); }

.hero-grid {
  display: grid; grid-template-columns: repeat(2,1fr); gap: 8px;
}
.hero-card {
  padding: 14px 10px; border: 2px solid var(--border);
  border-radius: var(--r); cursor: pointer; text-align: center;
  background: var(--bg2); transition: all 0.15s;
}
.hero-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.hero-card.selected { border-color: var(--accent2); background: rgba(124,92,191,0.2); }
.hero-emoji { font-size: 28px; display: block; margin-bottom: 6px; }
.hero-name { font-family: var(--pixel); font-size: 7px; color: var(--accent2); }
.hero-desc { font-size: 10px; color: var(--text-dim); margin-top: 4px; line-height: 1.4; }

.btn {
  width: 100%; padding: 14px; border: none; border-radius: var(--r);
  cursor: pointer; font-family: var(--pixel); font-size: 10px;
  transition: all 0.15s; position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%); color: #fff; box-shadow: 0 4px 15px rgba(124,92,191,0.4); }
.btn-primary:hover { box-shadow: 0 6px 20px rgba(124,92,191,0.6); transform: translateY(-1px); }
.btn-secondary { background: var(--panel2); color: var(--text); border: 2px solid var(--border); }
.btn-danger { background: linear-gradient(135deg, #c0392b, var(--red)); color: #fff; }
.btn-gold { background: linear-gradient(135deg, #b8860b, var(--gold)); color: #111; }
.btn-green { background: linear-gradient(135deg, #27ae60, var(--green)); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 8px; width: auto; }

.error-msg { color: var(--red); font-size: 12px; padding: 10px; background: rgba(224,92,92,0.1); border-radius: var(--r); border-left: 3px solid var(--red); margin-top: 10px; }
.success-msg { color: var(--green); font-size: 12px; padding: 10px; background: rgba(78,203,113,0.1); border-radius: var(--r); border-left: 3px solid var(--green); margin-top: 10px; }

/* ===================== WAITING ROOM ===================== */
#screen-waiting {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; padding: 20px; z-index: 1; position: relative;
}
.room-code-display {
  font-family: var(--pixel); font-size: clamp(28px,6vw,52px);
  color: var(--gold); letter-spacing: 8px;
  text-shadow: 0 0 20px var(--gold);
  padding: 20px 30px; background: var(--panel);
  border: 3px solid var(--gold); border-radius: 12px;
  margin: 20px 0; cursor: pointer; position: relative;
}
.copy-hint { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--text-dim); white-space: nowrap; }

.players-waiting {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px; width: 100%; max-width: 600px; margin: 20px 0;
}
.player-slot {
  background: var(--panel); border: 2px solid var(--border);
  border-radius: 10px; padding: 16px; text-align: center; min-height: 100px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: all 0.3s;
}
.player-slot.filled { border-color: var(--green); }
.player-slot.ready { border-color: var(--gold); background: rgba(245,200,66,0.05); }
.player-slot-icon { font-size: 32px; margin-bottom: 8px; }
.player-slot-name { font-family: var(--pixel); font-size: 7px; margin-bottom: 4px; }
.player-slot-status { font-size: 10px; color: var(--text-dim); }

/* ===================== GAME ===================== */
#screen-game {
  display: none; flex-direction: column;
  min-height: 100vh; position: relative; z-index: 1;
}

.game-header {
  background: var(--panel); border-bottom: 2px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.game-header-title { font-family: var(--pixel); font-size: 10px; color: var(--accent2); flex: 1; }

.game-layout {
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  gap: 0; flex: 1;
  height: calc(100vh - 60px);
}

.panel-left, .panel-right {
  background: var(--panel); border-right: 2px solid var(--border);
  overflow-y: auto; padding: 14px 12px;
  display: flex; flex-direction: column; gap: 12px;
}
.panel-right { border-right: none; border-left: 2px solid var(--border); }

.panel-center {
  display: flex; flex-direction: column; background: var(--bg);
  position: relative; overflow: hidden;
}

/* Map */
#game-map {
  flex: 1; position: relative; overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(34,180,80,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 60%, rgba(44,120,220,0.06) 0%, transparent 60%),
    var(--bg);
}

/* Grid overlay */
#game-map::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(60,60,120,0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(60,60,120,0.1) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* Hero sprite on map */
.map-hero {
  position: absolute; width: 40px; height: 48px;
  transform: translate(-50%, -50%);
  transition: left 0.5s ease, top 0.5s ease;
  cursor: pointer; z-index: 10;
}
.hero-sprite {
  width: 40px; height: 40px;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
  animation: hero-idle 1s steps(2) infinite;
}
@keyframes hero-idle {
  0%  { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.hero-name-tag {
  font-family: var(--pixel); font-size: 6px;
  text-align: center; white-space: nowrap;
  text-shadow: 0 1px 3px #000, 0 -1px 3px #000;
  margin-top: 2px;
}
.hero-hp-bar {
  width: 40px; height: 4px; background: rgba(0,0,0,0.5);
  border-radius: 2px; margin-top: 2px; overflow: hidden;
}
.hero-hp-fill { height: 100%; background: var(--green); border-radius: 2px; transition: width 0.3s; }
.hero-hp-fill.low { background: var(--red); }
.hero-hp-fill.mid { background: var(--orange); }

/* Map resources decoration */
.map-resource {
  position: absolute; font-size: 20px;
  opacity: 0.5; user-select: none; pointer-events: none;
  animation: sway 3s ease-in-out infinite;
}
@keyframes sway { 0%,100%{transform:rotate(-5deg)} 50%{transform:rotate(5deg)} }

/* ===================== PANELS ===================== */
.panel-section { }
.panel-title {
  font-family: var(--pixel); font-size: 8px; color: var(--accent2);
  margin-bottom: 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* My resources */
.resource-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 4px; margin-bottom: 4px;
  background: var(--bg2);
}
.resource-label { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.resource-value { font-family: var(--pixel); font-size: 9px; color: var(--gold); }

/* Action buttons */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.action-btn {
  padding: 10px 6px; border: 2px solid var(--border);
  border-radius: var(--r); background: var(--bg2);
  color: var(--text); cursor: pointer; font-size: 11px;
  text-align: center; transition: all 0.15s; display: flex;
  flex-direction: column; align-items: center; gap: 4px;
}
.action-btn:hover { border-color: var(--accent); background: rgba(124,92,191,0.15); transform: translateY(-1px); }
.action-btn:active { transform: scale(0.95); }
.action-btn .action-icon { font-size: 20px; }
.action-btn .action-label { font-size: 9px; font-family: var(--pixel); }
.action-btn .action-cost { font-size: 9px; color: var(--text-dim); }

/* HP bar in panel */
.hp-bar-wrap { background: var(--bg); border-radius: 4px; overflow: hidden; height: 14px; position: relative; }
.hp-bar-fill { height: 100%; background: var(--green); border-radius: 4px; transition: width 0.3s; }
.hp-bar-fill.low { background: var(--red); }
.hp-bar-fill.mid { background: var(--orange); }
.hp-bar-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; font-family: var(--pixel); }

/* Players list */
.player-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 10px; margin-bottom: 6px;
  transition: all 0.2s;
}
.player-card.me { border-color: var(--accent); }
.player-card.dead { opacity: 0.4; }
.player-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.player-class-icon { font-size: 20px; }
.player-card-name { font-family: var(--pixel); font-size: 7px; flex: 1; }
.player-card-level { font-family: var(--pixel); font-size: 7px; color: var(--gold); }
.attack-btn {
  padding: 4px 8px; background: var(--red); border: none;
  border-radius: 4px; color: #fff; cursor: pointer;
  font-family: var(--pixel); font-size: 7px; transition: all 0.15s;
}
.attack-btn:hover { background: #c0392b; transform: scale(1.05); }

/* Building grid */
.building-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; }
.building-tile {
  aspect-ratio: 1; background: var(--bg2); border: 2px solid var(--border);
  border-radius: var(--r); display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: pointer;
  transition: all 0.15s; padding: 6px;
}
.building-tile:hover { border-color: var(--accent); transform: scale(1.03); }
.building-tile.built { border-color: var(--green); background: rgba(78,203,113,0.1); }
.building-tile .b-icon { font-size: 22px; }
.building-tile .b-name { font-family: var(--pixel); font-size: 6px; text-align: center; margin-top: 3px; }
.building-tile .b-cost { font-size: 9px; color: var(--text-dim); text-align: center; }

/* Chat */
#chat-log {
  flex: 1; overflow-y: auto; font-size: 12px;
  background: var(--bg2); border-radius: var(--r);
  padding: 8px; max-height: 200px; min-height: 80px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-msg { padding: 3px 0; }
.chat-name { font-weight: 700; }
.chat-input-row { display: flex; gap: 6px; margin-top: 6px; }
.chat-input-row input { flex: 1; }

/* Event log */
#event-log {
  max-height: 160px; overflow-y: auto;
  font-size: 11px; background: var(--bg2);
  border-radius: var(--r); padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.event-item { padding: 3px 6px; border-radius: 4px; border-left: 3px solid var(--border); }
.event-item.attack { border-left-color: var(--red); }
.event-item.collect { border-left-color: var(--green); }
.event-item.build { border-left-color: var(--blue); }
.event-item.kill { border-left-color: var(--gold); background: rgba(245,200,66,0.05); }
.event-item.level_up { border-left-color: var(--accent2); }
.event-item.heal { border-left-color: #4ecdc4; }

/* XP bar */
.xp-bar-wrap { background: var(--bg); border-radius: 4px; overflow: hidden; height: 6px; margin-top: 4px; }
.xp-bar-fill { height: 100%; background: var(--accent2); transition: width 0.3s; }

/* Toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 2px solid var(--accent);
  border-radius: 8px; padding: 12px 20px; font-size: 13px;
  z-index: 9999; max-width: 90vw; text-align: center;
  box-shadow: var(--shadow); transition: opacity 0.3s;
  pointer-events: none; opacity: 0;
}
#toast.show { opacity: 1; }

/* Bottom action bar on mobile */
.game-bottom-bar {
  display: none; background: var(--panel); border-top: 2px solid var(--border);
  padding: 10px; gap: 8px;
}

/* ===================== COOLDOWN ===================== */
.cooldown-bar-wrap {
  width: 100%; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px; overflow: hidden;
  margin-top: 5px;
}
.cooldown-bar {
  height: 100%; width: 0%;
  background: var(--accent2);
  border-radius: 2px;
  transition: width 0.1s linear;
}
.cooldown-timer {
  font-family: var(--pixel); font-size: 7px;
  color: var(--gold); margin-top: 2px;
  min-height: 10px; display: block;
  letter-spacing: 0;
}
.action-btn.on-cooldown {
  opacity: 0.55; cursor: not-allowed;
  pointer-events: none;
}
.action-btn.on-cooldown .action-icon {
  filter: grayscale(0.6);
}

/* Floating combat text */
.dmg-float {
  position: absolute; font-family: var(--pixel); font-size: 14px;
  font-weight: bold; pointer-events: none; z-index: 100;
  animation: float-up 1.5s ease forwards;
}
.dmg-float.dmg { color: var(--red); }
.dmg-float.heal { color: var(--green); }
.dmg-float.gold { color: var(--gold); }
@keyframes float-up {
  0%  { opacity: 1; transform: translateY(0) scale(1.2); }
  100%{ opacity: 0; transform: translateY(-60px) scale(0.8); }
}

/* Game Over */
#screen-gameover {
  display: none; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; padding: 20px;
  z-index: 1; position: relative; text-align: center;
}

/* Responsive */
@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .panel-left { order: 2; max-height: 250px; border-right: none; border-top: 2px solid var(--border); }
  .panel-right { order: 3; max-height: 300px; border-left: none; border-top: 2px solid var(--border); }
  .panel-center { order: 1; min-height: 300px; }
  #game-map { min-height: 300px; }
}
