/* ============================================
   MOLTDEFENSE - Zelda HUD Style
   8-bit pixel window panels with stone borders
   ============================================ */

/* ========== GOOGLE FONTS ========== */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* ========== CSS VARIABLES ========== */
:root {
  /* ===== BASE GRID (8px system) ===== */
  --tile: 8px;
  --tile-2x: 16px;
  --tile-3x: 24px;
  --tile-4x: 32px;
  --tile-5x: 40px;
  --tile-6x: 48px;

  /* ===== BACKGROUNDS ===== */
  --bg-base: #070A0F;
  --panel-fill: #0B1018;
  --panel-border: #1E2A3A;
  --panel-border-light: #2A3A4E;
  --panel-border-dark: #0D1520;
  --panel-highlight: rgba(255, 255, 255, 0.08);
  --panel-shadow: rgba(0, 0, 0, 0.6);

  /* ===== TEXT ===== */
  --text-primary: #EAF0FF;
  --text-muted: #93A0B4;
  --text-dim: #5D6A7E;

  /* ===== STRICT ACCENT PALETTE (4 colors only) ===== */
  --rune-green: #2EE59D;
  --rune-red: #FF4D5E;
  --rune-cyan: #3AE6FF;
  --rune-gold: #FFCC4D;

  /* ===== TEAM COLORS ===== */
  --attacker-color: var(--rune-red);
  --attacker-bg: rgba(255, 77, 94, 0.08);
  --defender-color: var(--rune-cyan);
  --defender-bg: rgba(58, 230, 255, 0.08);

  /* ===== TYPOGRAPHY ===== */
  --font-pixel: 'Press Start 2P', monospace;
  --font-body: 'Inter', 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Type scale */
  --text-pixel: 10px;     /* Pixel labels only */
  --text-hero: 28px;      /* Big numbers */
  --text-title: 16px;     /* Agent names */
  --text-body: 14px;      /* Body text */
  --text-meta: 12px;      /* Meta/small */

  /* ===== LAYOUT ===== */
  --header-height: 24px;  /* Panel header strip */
  --rail-width: 260px;    /* Narrower sidebars to emphasize game */
  --page-padding: var(--tile-2x);
  --panel-padding: var(--tile-2x);
  --gap: var(--tile-2x);

  /* ===== ANIMATION ===== */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 150ms;
}

/* ========== RESET ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  image-rendering: pixelated;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Dither texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='1' height='1' fill='%23ffffff' opacity='0.03'/%3E%3Crect x='2' y='2' width='1' height='1' fill='%23ffffff' opacity='0.03'/%3E%3C/svg%3E");
  background-size: 4px 4px;
  pointer-events: none;
  z-index: 9999;
}

/* ========== 9-SLICE PIXEL PANEL SYSTEM ========== */
/* Stone window look: dark border, bevel highlight (top/left), shadow (bottom/right), dithered center */
.panel,
.card,
#info-bar,
#game-container,
#events-panel,
#controls {
  position: relative;
  background: var(--panel-fill);
  padding: var(--panel-padding);

  /* 9-slice border effect using box-shadow */
  border: 2px solid var(--panel-border);
  box-shadow:
    /* Inner bevel highlight (top/left) */
    inset 2px 2px 0 0 var(--panel-border-light),
    /* Inner shadow (bottom/right) */
    inset -2px -2px 0 0 var(--panel-border-dark),
    /* Outer shadow */
    4px 4px 0 0 rgba(0, 0, 0, 0.4);

  /* Dithered fill pattern */
  background-image: url("data:image/svg+xml,%3Csvg width='4' height='4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='4' height='4' fill='%230B1018'/%3E%3Crect x='0' y='0' width='1' height='1' fill='%23101820' opacity='0.5'/%3E%3Crect x='2' y='2' width='1' height='1' fill='%23101820' opacity='0.5'/%3E%3C/svg%3E");
  background-size: 4px 4px;
}

/* Panel variants with rune trim */
.panel--attacker,
.agent-info.attacker {
  border-color: var(--rune-red);
  box-shadow:
    inset 2px 2px 0 0 rgba(255, 77, 94, 0.3),
    inset -2px -2px 0 0 rgba(255, 77, 94, 0.1),
    4px 4px 0 0 rgba(0, 0, 0, 0.4),
    0 0 12px rgba(255, 77, 94, 0.15);
}

.panel--defender,
.agent-info.defender {
  border-color: var(--rune-cyan);
  box-shadow:
    inset 2px 2px 0 0 rgba(58, 230, 255, 0.3),
    inset -2px -2px 0 0 rgba(58, 230, 255, 0.1),
    4px 4px 0 0 rgba(0, 0, 0, 0.4),
    0 0 12px rgba(58, 230, 255, 0.15);
}

.panel--active,
.live-match-entry {
  border-color: var(--rune-green);
  box-shadow:
    inset 2px 2px 0 0 rgba(46, 229, 157, 0.3),
    inset -2px -2px 0 0 rgba(46, 229, 157, 0.1),
    4px 4px 0 0 rgba(0, 0, 0, 0.4),
    0 0 16px rgba(46, 229, 157, 0.2);
}

/* ========== PIXEL HEADER STRIP ========== */
/* 24px height, 16x16 icon left, pixel label, status chip right */
.panel > h3,
.panel-header {
  display: flex;
  align-items: center;
  gap: var(--tile);
  height: var(--header-height);
  margin: calc(-1 * var(--panel-padding));
  margin-bottom: var(--panel-padding);
  padding: 0 var(--panel-padding);
  background: linear-gradient(180deg, rgba(255,255,255,0.04) 0%, transparent 100%);
  border-bottom: 2px solid var(--panel-border-dark);
}

/* Panel icon (16x16 sprite placeholder) */
.panel > h3::before,
.panel-header::before {
  content: '';
  width: 16px;
  height: 16px;
  background: var(--rune-cyan);
  opacity: 0.6;
  flex-shrink: 0;
}

/* Leaderboard icon = crown */
#leaderboard-panel > h3::before { background: var(--rune-gold); }
/* Stats icon = scroll */
#stats-panel > h3::before { background: var(--rune-green); }
/* Queue icon = bolt */
#queue-panel > h3::before { background: var(--rune-cyan); }
/* Battles icon = sword */
#battles-panel > h3::before { background: var(--rune-red); }
/* Events icon = scroll */
#events-panel > h3::before { background: var(--rune-green); }

/* Panel title - pixel font, all caps */
.panel > h3,
.panel-title {
  font-family: var(--font-pixel);
  font-size: var(--text-pixel);
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex: 1;
}

/* ========== STATUS CHIPS (9-slice mini) ========== */
.status-chip,
.queue-header.live,
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px;
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid;
  background: var(--panel-fill);
}

/* LIVE chip = green rune + pulsing dot */
.chip--live,
.queue-header.live {
  border-color: var(--rune-green);
  color: var(--rune-green);
  background: rgba(46, 229, 157, 0.1);
}

.chip--live::before,
.queue-header.live::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--rune-green);
  animation: runePulse 1.5s ease-in-out infinite;
}

@keyframes runePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--rune-green); }
  50% { opacity: 0.5; box-shadow: 0 0 8px var(--rune-green); }
}

/* WAITING chip = gray */
.chip--waiting {
  border-color: var(--text-dim);
  color: var(--text-dim);
}

/* IN PROGRESS chip = cyan */
.chip--progress {
  border-color: var(--rune-cyan);
  color: var(--rune-cyan);
  background: rgba(58, 230, 255, 0.1);
}

/* ========== APP BAR (Zelda top bar) ========== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--tile) var(--page-padding);
  background: var(--panel-fill);
  border-bottom: 2px solid var(--panel-border);
  box-shadow: 0 4px 0 0 rgba(0, 0, 0, 0.3);
}

header h1 {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--rune-cyan);
  letter-spacing: 0.15em;
  text-shadow:
    2px 2px 0 var(--panel-border-dark),
    0 0 10px rgba(58, 230, 255, 0.5);
}

header .subtitle {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
  margin-left: var(--tile);
}

/* ========== DASHBOARD LAYOUT ========== */
main.dashboard {
  flex: 1;
  display: grid;
  grid-template-columns: var(--rail-width) 1fr var(--rail-width);
  gap: var(--gap);
  padding: var(--page-padding);
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ========== INFO BAR (BATTLEFIELD HEADER) ========== */
#info-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--tile-3x);
  padding: var(--tile-2x);
}

/* Player panels with rune trim */
.agent-info {
  padding: var(--tile-2x);
}

.agent-info.attacker { text-align: left; }
.agent-info.defender { text-align: right; }

/* Agent label - pixel font */
.agent-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.agent-info.attacker .agent-label { color: var(--rune-red); }
.agent-info.defender .agent-label { color: var(--rune-cyan); }

/* Agent name - Inter semibold */
#attacker-name,
#defender-name,
.agent-name {
  font-family: var(--font-body);
  font-size: var(--text-title);
  font-weight: 600;
  color: var(--text-primary);
}

/* Agent stat */
#attacker-leaked,
#defender-kills,
.agent-stat {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-muted);
  margin-top: 4px;
}

/* Match info center */
#match-info {
  text-align: center;
}

#match-id {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
}

/* Wave number - big Inter bold */
#wave-info {
  font-family: var(--font-body);
  font-size: var(--text-hero);
  font-weight: 700;
  color: var(--text-primary);
}

#match-status {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-muted);
}

/* ========== HEARTS ROW (Defender Lives) ========== */
.hearts-row {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* Heart sprites: 16x16 */
.heart {
  width: 16px;
  height: 16px;
  background: var(--rune-red);
  clip-path: polygon(50% 100%, 0% 35%, 25% 0%, 50% 15%, 75% 0%, 100% 35%);
}

.heart--empty {
  background: var(--panel-border);
}

.heart--half {
  background: linear-gradient(90deg, var(--rune-red) 50%, var(--panel-border) 50%);
}

/* ========== RUPEE INDICATORS ========== */
.rupee {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.rupee::before {
  content: '';
  width: 12px;
  height: 16px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.rupee--green::before { background: var(--rune-green); }
.rupee--blue::before { background: var(--rune-cyan); }
.rupee--red::before { background: var(--rune-red); }
.rupee--gold::before { background: var(--rune-gold); }

/* ========== ARENA (BATTLEFIELD) ========== */
#game-container {
  position: relative;
  overflow: hidden;
  /* Make the arena the visual focus */
  border-width: 3px;
  border-color: var(--rune-cyan);
  box-shadow:
    /* Inner bevel */
    inset 3px 3px 0 0 rgba(58, 230, 255, 0.25),
    inset -3px -3px 0 0 rgba(58, 230, 255, 0.08),
    /* Outer shadow */
    6px 6px 0 0 rgba(0, 0, 0, 0.6),
    /* Prominent glow */
    0 0 40px rgba(58, 230, 255, 0.2),
    0 0 80px rgba(58, 230, 255, 0.1);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: 280px;
  background: var(--bg-base);
  image-rendering: pixelated;
  /* Subtle inner shadow for depth */
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Tower pad nodes (A-E indicators below canvas) */
.lane-nodes {
  display: flex;
  justify-content: space-around;
  padding: var(--tile) 0;
  margin-top: var(--tile);
}

.lane-node {
  width: var(--tile-4x);
  height: var(--tile-4x);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--text-dim);
  border: 2px solid var(--panel-border);
  background: var(--panel-fill);
}

.lane-node:hover,
.lane-node.active {
  border-color: var(--rune-green);
  color: var(--rune-green);
  box-shadow: 0 0 8px rgba(46, 229, 157, 0.3);
}

/* ========== LEADERBOARD (Adventurer Rankings) ========== */
#leaderboard-list {
  display: flex;
  flex-direction: column;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: var(--tile);
  padding: var(--tile) var(--tile-2x);
  margin: 0 calc(-1 * var(--panel-padding));
  transition: background var(--duration) var(--ease-out);
}

.leaderboard-entry:hover {
  background: rgba(46, 229, 157, 0.06);
}

/* Rank badge - pixel medal tiles */
.leaderboard-rank {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: var(--text-meta);
  font-weight: 700;
  flex-shrink: 0;
}

/* Medal sprites for top 3 */
.leaderboard-rank.gold {
  background: var(--rune-gold);
  color: #000;
}

.leaderboard-rank.silver {
  background: #C0C0C0;
  color: #000;
}

.leaderboard-rank.bronze {
  background: #CD7F32;
  color: #000;
}

.leaderboard-rank.normal {
  background: var(--panel-border);
  color: var(--text-dim);
}

/* Role indicator */
.leaderboard-role {
  width: 16px;
  text-align: center;
  font-size: 14px;
}

.role-attacker { color: var(--rune-red); }
.role-defender { color: var(--rune-cyan); }

/* Name */
.leaderboard-name {
  flex: 1;
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ELO */
.leaderboard-elo {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--rune-green);
}

/* W-L */
.leaderboard-record {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
  min-width: 48px;
  text-align: right;
}

.view-all-link {
  display: block;
  text-align: center;
  padding: var(--tile) 0;
  margin-top: var(--tile);
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--rune-cyan);
  text-decoration: none;
  border-top: 1px solid var(--panel-border-dark);
}

.view-all-link:hover {
  color: var(--text-primary);
}

/* ========== STATS PANEL ========== */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--tile) 0;
  border-bottom: 1px solid var(--panel-border-dark);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-label {
  font-family: var(--font-body);
  font-size: var(--text-body);
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--text-primary);
}

.stat-value.attacker { color: var(--rune-red); }
.stat-value.defender { color: var(--rune-cyan); }

/* ========== EVENTS (Parchment Scroll Combat Log) ========== */
#events-panel {
  max-height: 200px;
  overflow-y: auto;
}

#events-list {
  display: flex;
  flex-direction: column;
}

/* Log row: icon left, message, damage colored, timestamp right */
.event {
  display: flex;
  align-items: center;
  gap: var(--tile);
  padding: 6px var(--tile);
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-primary);
  animation: eventSlide 0.2s var(--ease-out);
}

/* Alternating dither bands */
.event:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

@keyframes eventSlide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Event icon placeholder */
.event::before {
  content: '';
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  opacity: 0.7;
}

/* Event types */
.event.damage::before { background: var(--rune-red); }
.event.kill::before { background: var(--rune-green); }
.event.leak::before { background: var(--rune-gold); }
.event.spawn::before { background: var(--rune-cyan); }

.event.wave {
  background: rgba(58, 230, 255, 0.08);
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--rune-cyan);
  justify-content: center;
  letter-spacing: 0.1em;
}

.event.wave::before { display: none; }

/* ========== MENU TILE BUTTONS (Zelda menu items) ========== */
button,
.menu-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tile);
  height: var(--tile-5x);
  padding: 0 var(--tile-2x);

  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--text-primary);

  background: var(--panel-fill);
  border: 2px solid var(--panel-border);
  box-shadow:
    inset 1px 1px 0 0 var(--panel-border-light),
    inset -1px -1px 0 0 var(--panel-border-dark),
    2px 2px 0 0 rgba(0, 0, 0, 0.3);

  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

button:hover,
.menu-tile:hover {
  border-color: var(--rune-green);
  color: var(--rune-green);
  box-shadow:
    inset 1px 1px 0 0 rgba(46, 229, 157, 0.3),
    inset -1px -1px 0 0 rgba(46, 229, 157, 0.1),
    2px 2px 0 0 rgba(0, 0, 0, 0.3),
    0 0 8px rgba(46, 229, 157, 0.2);
}

button:active,
.menu-tile:active {
  transform: translate(2px, 2px);
  box-shadow:
    inset 1px 1px 0 0 var(--panel-border-dark),
    inset -1px -1px 0 0 var(--panel-border-light);
}

/* Primary button (Start Match) */
#demo-btn,
.btn--primary {
  background: var(--rune-cyan);
  border-color: var(--rune-cyan);
  color: #000;
}

#demo-btn:hover,
.btn--primary:hover {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: #000;
}

/* Adaptive button */
#adaptive-demo-btn {
  background: var(--rune-gold);
  border-color: var(--rune-gold);
  color: #000;
}

#adaptive-demo-btn:hover {
  background: #FFE066;
  border-color: #FFE066;
}

/* Sound button - speaker icon tile */
#sound-btn,
.sound-btn {
  width: var(--tile-5x);
  padding: 0;
}

/* ========== VOLUME CONTROL ========== */
.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 8px;
  background: var(--panel-border);
  border: 1px solid var(--panel-border-light);
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--rune-cyan);
  cursor: pointer;
  border: none;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--rune-cyan);
  cursor: pointer;
  border: none;
}

.volume-slider:hover::-webkit-slider-thumb {
  background: var(--text-primary);
  box-shadow: 0 0 8px rgba(58, 230, 255, 0.5);
}

.volume-slider:hover::-moz-range-thumb {
  background: var(--text-primary);
  box-shadow: 0 0 8px rgba(58, 230, 255, 0.5);
}

#volume-value {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-muted);
  min-width: 32px;
  text-align: right;
}

/* ========== SPEED SELECTOR (Inventory Slots) ========== */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--tile-2x);
  flex-wrap: wrap;
}

.speed-controls,
.speed-selector {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-base);
  border: 2px solid var(--panel-border);
}

.speed-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-dim);
  padding: 0 var(--tile);
  display: flex;
  align-items: center;
}

/* Inventory slot button */
.speed-btn {
  width: var(--tile-4x);
  height: var(--tile-4x);
  padding: 0;
  font-family: var(--font-body);
  font-size: var(--text-meta);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--panel-fill);
  border: 2px solid var(--panel-border);
  box-shadow: none;
}

.speed-btn:hover {
  border-color: var(--rune-green);
  color: var(--rune-green);
  transform: none;
  box-shadow: none;
}

/* Selected slot = bright rune border */
.speed-btn.active {
  background: rgba(46, 229, 157, 0.15);
  border-color: var(--rune-green);
  color: var(--rune-green);
  box-shadow: 0 0 8px rgba(46, 229, 157, 0.4);
}

/* ========== QUEUE PANEL ========== */
#live-matches-section {
  margin-bottom: var(--tile-2x);
  padding-bottom: var(--tile-2x);
  border-bottom: 2px solid var(--panel-border-dark);
}

/* Subtle breathing glow when queue has items */
#live-matches-section.has-activity {
  animation: queuePulse 2s ease-in-out infinite;
}

@keyframes queuePulse {
  0%, 100% {
    border-bottom-color: var(--panel-border-dark);
    box-shadow: none;
  }
  50% {
    border-bottom-color: var(--rune-green);
    box-shadow: 0 4px 12px rgba(46, 229, 157, 0.15);
  }
}

/* Button-style waiting agent entries with glowing background */
#queue-waiting .queue-entry {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 4px;
  transition: all 0.3s ease;
}

/* Attacker queue entries - red glow */
#queue-attackers-list .queue-entry {
  border-color: rgba(255, 77, 94, 0.3);
}

#queue-waiting.has-waiting #queue-attackers-list .queue-entry {
  animation: attackerEntryGlow 2s ease-in-out infinite;
}

@keyframes attackerEntryGlow {
  0%, 100% {
    background: rgba(255, 77, 94, 0.08);
    border-color: rgba(255, 77, 94, 0.3);
    box-shadow: none;
  }
  50% {
    background: rgba(255, 77, 94, 0.18);
    border-color: var(--rune-red);
    box-shadow: 0 0 12px rgba(255, 77, 94, 0.4), inset 0 0 8px rgba(255, 77, 94, 0.1);
  }
}

/* Defender queue entries - cyan glow */
#queue-defenders-list .queue-entry {
  border-color: rgba(58, 230, 255, 0.3);
}

#queue-waiting.has-waiting #queue-defenders-list .queue-entry {
  animation: defenderEntryGlow 2s ease-in-out infinite;
}

@keyframes defenderEntryGlow {
  0%, 100% {
    background: rgba(58, 230, 255, 0.08);
    border-color: rgba(58, 230, 255, 0.3);
    box-shadow: none;
  }
  50% {
    background: rgba(58, 230, 255, 0.18);
    border-color: var(--rune-cyan);
    box-shadow: 0 0 12px rgba(58, 230, 255, 0.4), inset 0 0 8px rgba(58, 230, 255, 0.1);
  }
}

/* Agent name styling inside buttons */
#queue-attackers-list .queue-agent-name {
  color: var(--rune-red);
  font-weight: 500;
}

#queue-defenders-list .queue-agent-name {
  color: var(--rune-cyan);
  font-weight: 500;
}

.queue-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--tile) var(--tile-2x);
  margin-bottom: var(--tile);
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid;
}

.queue-header.attacker {
  border-color: var(--rune-red);
  color: var(--rune-red);
  background: rgba(255, 77, 94, 0.08);
}

.queue-header.defender {
  border-color: var(--rune-cyan);
  color: var(--rune-cyan);
  background: rgba(58, 230, 255, 0.08);
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.queue-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--tile) var(--tile-2x);
  background: rgba(255, 255, 255, 0.02);
}

.queue-agent-name {
  font-family: var(--font-body);
  font-size: var(--text-body);
  color: var(--text-primary);
}

.queue-wait-time {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
}

.queue-empty {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
  font-style: italic;
  padding: var(--tile);
}

.queue-section {
  margin-bottom: var(--tile-2x);
}

.queue-section:last-child {
  margin-bottom: 0;
}

/* Live match entry - green rune panel */
.live-match-entry {
  padding: var(--tile-2x);
  margin-bottom: var(--tile);
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.live-match-entry:hover {
  box-shadow:
    inset 2px 2px 0 0 rgba(46, 229, 157, 0.4),
    inset -2px -2px 0 0 rgba(46, 229, 157, 0.15),
    4px 4px 0 0 rgba(0, 0, 0, 0.4),
    0 0 20px rgba(46, 229, 157, 0.25);
}

.live-match-players {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 500;
}

.live-attacker { color: var(--rune-red); }
.live-vs { color: var(--text-dim); font-size: var(--text-meta); }
.live-defender { color: var(--rune-cyan); }

.live-match-info {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-meta);
  margin-top: var(--tile);
}

.live-wave {
  color: var(--rune-green);
  font-weight: 500;
}

.live-spectate-icon {
  opacity: 0;
  transition: opacity var(--duration);
}

.live-match-entry:hover .live-spectate-icon {
  opacity: 1;
}

/* ========== BATTLE LOGS (Chronicle) ========== */
#battles-panel {
  max-height: 400px;
  overflow-y: auto;
}

#battles-list {
  display: flex;
  flex-direction: column;
  gap: var(--tile);
}

.battle-entry {
  padding: var(--tile-2x);
  margin: 0 calc(-1 * var(--tile));
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease-out);
}

.battle-entry:hover {
  background: rgba(58, 230, 255, 0.04);
  border-color: var(--rune-cyan);
}

.battle-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--tile);
  padding-bottom: var(--tile);
  border-bottom: 1px solid var(--panel-border-dark);
}

.battle-time,
.battle-match-id {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
}

.battle-matchup {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--tile);
}

.battle-player {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.battle-player.attacker-side { align-items: flex-start; }
.battle-player.defender-side { align-items: flex-end; }

.battle-attacker {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--rune-red);
}

.battle-defender {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--rune-cyan);
}

.battle-vs {
  font-size: var(--text-meta);
  color: var(--text-dim);
}

.battle-elo {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-muted);
}

.elo-change {
  font-weight: 600;
}

.elo-gain { color: var(--rune-green); }
.elo-loss { color: var(--rune-red); }

.battle-stats {
  display: flex;
  gap: var(--tile);
  margin-bottom: var(--tile);
}

.battle-stat {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.3);
}

.battle-stat.kills { color: var(--rune-green); }
.battle-stat.leaked { color: var(--rune-red); }
.battle-stat.waves { color: var(--rune-gold); }

.battle-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.battle-winner {
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.battle-winner.attacker { color: var(--rune-red); }
.battle-winner.defender { color: var(--rune-cyan); }

.battle-duration {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
}

.battle-play-icon {
  opacity: 0;
  color: var(--rune-green);
  transition: opacity var(--duration);
}

.battle-entry:hover .battle-play-icon {
  opacity: 1;
}

/* ========== LOADING STATE ========== */
.loading {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: var(--tile-3x) 0;
}

/* ========== FOOTER ========== */
footer {
  background: var(--panel-fill);
  border-top: 2px solid var(--panel-border);
  padding: var(--tile-2x) var(--page-padding);
  text-align: center;
}

footer p {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--tile);
  flex-wrap: wrap;
}

footer a {
  color: var(--rune-cyan);
  text-decoration: none;
}

footer a:hover {
  color: var(--text-primary);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--panel-border);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--panel-border-light);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1279px) {
  :root {
    --rail-width: 220px;
    --page-padding: var(--tile);
  }
}

@media (max-width: 1023px) {
  main.dashboard {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap);
  }

  .sidebar.right {
    order: 1;
  }
}

@media (max-width: 767px) {
  :root {
    --page-padding: var(--tile);
    --panel-padding: var(--tile);
    --gap: var(--tile);
  }

  header h1 {
    font-size: 14px;
  }

  header .subtitle {
    display: none;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  #info-bar {
    grid-template-columns: 1fr;
    gap: var(--tile);
  }

  .agent-info.defender {
    text-align: left;
  }

  #match-info {
    order: -1;
  }

  #controls {
    flex-direction: column;
  }

  .speed-controls {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 479px) {
  .leaderboard-record {
    display: none;
  }

  #wave-info {
    font-size: 22px;
  }

  button {
    font-size: var(--text-meta);
    padding: 0 var(--tile);
  }

  .speed-btn {
    width: 28px;
    height: 28px;
    font-size: 10px;
  }
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
