/* Global reset and design system */
:root {
  --blue-paper: #0b1e33;
  --grid-line: rgba(101, 159, 196, 0.08);
  --grid-line-bold: rgba(101, 159, 196, 0.15);
  --blueprint-white: #e3f2fd;
  --blueprint-muted: #81d4fa;
  --glass-bg: rgba(11, 30, 51, 0.45);
  --glass-border: rgba(129, 212, 250, 0.2);
  --accent: #ffd54f; /* ELO rating gold */
  --btn-green: #388e3c;
  --btn-red: #d32f2f;
}

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

body {
  background-color: #06111f;
  color: var(--blueprint-white);
  font-family: 'Courier Prime', Courier, 'Courier New', monospace;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.app-container {
  display: flex;
  width: 100%;
  height: 100%;
  padding: 15px;
  gap: 15px;
  box-sizing: border-box;
}

/* Sidebar: Glassmorphic panel */
.sidebar-glass {
  width: 340px;
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1.5px solid var(--glass-border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  max-height: 100%;
  overflow: hidden;
}

.sidebar-header {
  border-bottom: 1px dashed var(--glass-border);
  padding-bottom: 12px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.logo-link {
  display: block;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.logo-link:hover {
  transform: scale(1.06);
}

.logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  border: 1.5px dashed var(--glass-border);
  transition: filter 0.3s ease;
}

.logo-link:hover .logo-img {
  filter: drop-shadow(0 0 8px rgba(129, 212, 250, 0.5));
}

.sidebar-header .subtitle {
  font-size: 0.75rem;
  color: var(--blueprint-muted);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid rgba(129, 212, 250, 0.1);
  padding-bottom: 15px;
}

.panel-section.flex-grow {
  flex-grow: 1;
  border-bottom: none;
  padding-bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-section h3 {
  font-size: 0.9rem;
  color: var(--blueprint-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Forms & Inputs */
.input-group {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  flex-grow: 1;
  background: rgba(11, 30, 51, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--blueprint-white);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--blueprint-muted);
  box-shadow: 0 0 5px rgba(129, 212, 250, 0.2);
}

select {
  background: rgba(11, 30, 51, 0.8);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  padding: 6px;
  color: var(--blueprint-white);
  font-family: inherit;
  font-size: 0.8rem;
  outline: none;
}

.bots-config {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--blueprint-muted);
  margin-top: 5px;
}

.user-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-top: 4px;
}

.elo-val {
  color: var(--accent);
}

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: bold;
  padding: 8px 12px;
  border: 1px solid rgba(227, 242, 253, 0.3);
  border-radius: 4px;
  background: rgba(227, 242, 253, 0.1);
  color: var(--blueprint-white);
  transition: all 0.2s;
  outline: none;
}

button:hover {
  background: rgba(227, 242, 253, 0.25);
  border-color: var(--blueprint-white);
}

.btn-primary {
  background: rgba(129, 212, 250, 0.15);
  border-color: var(--blueprint-muted);
}
.btn-primary:hover {
  background: rgba(129, 212, 250, 0.3);
}

.btn-success {
  background: rgba(76, 175, 80, 0.15);
  border-color: #4caf50;
  padding: 10px;
}
.btn-success:hover {
  background: rgba(76, 175, 80, 0.35);
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.2);
}

.btn-secondary {
  background: rgba(129, 212, 250, 0.05);
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.custom-room-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.custom-room-row input[type="text"] {
  flex: 1.2;
  min-width: 0;
}

.custom-room-row button {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Leaderboard */
.leaderboard-container {
  flex-grow: 1;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: rgba(6, 17, 31, 0.4);
}

#leaderboard-list {
  list-style: none;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.75rem;
  border-bottom: 1px solid rgba(129, 212, 250, 0.05);
}

.leaderboard-item:last-child {
  border-bottom: none;
}

.leaderboard-item.loading {
  text-align: center;
  color: var(--blueprint-muted);
  padding: 20px;
}

.leaderboard-item.empty {
  text-align: center;
  color: var(--blueprint-muted);
  padding: 20px;
}

.leaderboard-item:hover {
  background: rgba(129, 212, 250, 0.05);
}

.lead-rank {
  font-weight: bold;
  width: 20px;
}
.lead-rank.top1 { color: #ffd700; }
.lead-rank.top2 { color: #c0c0c0; }
.lead-rank.top3 { color: #cd7f32; }

.lead-name {
  flex-grow: 1;
  margin-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lead-elo {
  color: var(--accent);
  font-weight: bold;
}

/* Custom Scrollbar for Leaderboard */
.leaderboard-container::-webkit-scrollbar {
  width: 6px;
}
.leaderboard-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
.leaderboard-container::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}
.leaderboard-container::-webkit-scrollbar-thumb:hover {
  background: var(--blueprint-muted);
}

.main-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow: hidden;
  max-height: 100%;
  min-width: 0;
}

/* HUD Top */
.hud-top {
  display: flex;
  justify-content: space-between;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid var(--glass-border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.85rem;
}

.hud-item {
  display: flex;
  align-items: center;
}

.match-timer {
  color: var(--accent);
  font-weight: bold;
}

/* Canvas Wrapper */
.canvas-wrapper {
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  flex-grow: 1;
  min-height: 0;
  position: relative;
  background: var(--blue-paper);
  border: 2px dashed var(--blueprint-muted);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6);
}

.blueprint-paper-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: 
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    linear-gradient(var(--grid-line-bold) 1.5px, transparent 1.5px),
    linear-gradient(90deg, var(--grid-line-bold) 1.5px, transparent 1.5px);
  background-size: 20px 20px, 20px 20px, 100px 100px, 100px 100px;
  pointer-events: none;
  opacity: 0.8;
}

#game-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Screen Overlay */
.screen-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(11, 30, 51, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.3s;
}

.screen-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  max-width: 480px;
  padding: 30px;
  border: 1.5px dashed var(--blueprint-muted);
  border-radius: 8px;
  background: rgba(6, 17, 31, 0.7);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.overlay-content h2 {
  font-size: 2rem;
  letter-spacing: 2px;
  margin-bottom: 15px;
  color: var(--blueprint-white);
  text-shadow: 0 0 10px var(--blueprint-muted);
}

.overlay-content p {
  font-size: 0.9rem;
  color: var(--blueprint-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

#overlay-extra {
  font-size: 0.85rem;
  color: var(--accent);
}

/* Real-time self HUD inside live match panel */
.hud-my-status {
  border-top: 1.5px dashed var(--glass-border);
  padding-top: 12px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-status-segment {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Sidebar Active Room Info Card */
.sidebar-room-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(129, 212, 250, 0.08);
  border: 1.2px dashed var(--glass-border);
  border-radius: 4px;
  padding: 6px 12px;
  margin-top: 4px;
  font-size: 0.78rem;
}

.room-status-label {
  color: var(--blueprint-muted);
}

.room-code-badge {
  font-family: inherit;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 1px;
  background: rgba(11, 30, 51, 0.6);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(129, 212, 250, 0.2);
}

.btn-copy {
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.1s;
  color: var(--blueprint-white);
}

.btn-copy:hover {
  transform: scale(1.15);
  background: transparent;
  border-color: transparent;
}

.btn-copy:active {
  transform: scale(0.9);
}

/* Centered Room Badge in Overlay */
.overlay-room-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(11, 30, 51, 0.9);
  border: 1px solid var(--blueprint-muted);
  border-radius: 6px;
  padding: 8px 16px;
  margin: 15px auto;
  font-size: 0.9rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.overlay-room-badge strong {
  color: var(--accent);
  font-size: 1.2rem;
  letter-spacing: 1px;
  font-family: inherit;
}

/* Responsiveness Media Queries */
@media (max-height: 768px) {
  .sidebar-glass {
    gap: 12px;
    padding: 12px;
  }
  .panel-section {
    gap: 6px;
    padding-bottom: 10px;
  }
  .legend-grid {
    gap: 6px;
  }
  .app-container {
    padding: 8px;
    gap: 8px;
  }
  .main-viewport {
    gap: 8px;
  }
}

@media (max-height: 600px) {
  .sidebar-glass {
    overflow-y: auto;
  }
  .panel-section.flex-grow {
    flex-grow: 0;
    flex-shrink: 0;
    height: 140px;
  }
}

.hud-bar-label {
  font-size: 0.7rem;
  color: var(--blueprint-muted);
  letter-spacing: 0.5px;
}

.hud-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(227, 242, 253, 0.1);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(129, 212, 250, 0.15);
}

.hud-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.1s linear;
}

.hp-fill {
  background: #388e3c;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.reload-fill {
  background: #0288d1;
  box-shadow: 0 0 8px rgba(2, 136, 209, 0.6);
}

.hud-bar-text {
  font-size: 0.75rem;
  font-weight: bold;
  margin-top: 2px;
}

/* Legend Grid Styles */
.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 2px;
  display: inline-block;
  box-sizing: border-box;
}

.brick-icon {
  border: 1px solid #ff8a80;
  background: rgba(255, 138, 128, 0.15);
  position: relative;
}
.brick-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  background: rgba(255, 138, 128, 0.35);
}

.steel-icon {
  border: 1.2px solid #81d4fa;
  background: rgba(129, 212, 250, 0.08);
}

.water-icon {
  background: linear-gradient(to bottom, transparent 20%, #90caf9 20%, #90caf9 30%, transparent 30%, transparent 50%, #90caf9 50%, #90caf9 60%, transparent 60%);
  border: 1px solid rgba(144, 202, 249, 0.2);
}

.grass-icon {
  background: rgba(11, 30, 51, 0.4);
  border: 1.2px solid #a5d6a7;
  border-radius: 50%;
}

.legend-text {
  font-size: 0.68rem;
  color: var(--blueprint-muted);
  line-height: 1.2;
}

/* Right Sidebar Live Player Match Status Panel */
.hud-live-players {
  width: 240px;
  flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1.5px solid var(--glass-border);
  border-radius: 12px;
  padding: 20px 15px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}

.hud-live-header {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--blueprint-muted);
  border-bottom: 1px dashed var(--glass-border);
  padding-bottom: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-align: center;
}

.hud-live-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-live-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-live-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
}

.hud-live-name {
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}

.hud-live-score-hp {
  font-size: 0.65rem;
  color: var(--blueprint-muted);
}

.hud-live-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(227, 242, 253, 0.1);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(129, 212, 250, 0.1);
}

.hud-live-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.2s ease-out;
}

.enemy-hp-fill {
  background: #ff3d00;
  box-shadow: 0 0 6px rgba(255, 61, 0, 0.6);
}

.hud-live-destroyed-text {
  font-size: 0.68rem;
  color: #ff3d00;
  font-weight: bold;
  letter-spacing: 0.5px;
  text-align: right;
  line-height: 6px;
}

/* Game Lobby Dashboard */
.lobby-dashboard {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(11, 30, 51, 0.96);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  padding: 25px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  z-index: 5;
  box-sizing: border-box;
}

.lobby-dashboard.hidden {
  display: none !important;
}

.lobby-dashboard h2 {
  font-size: 1.5rem;
  letter-spacing: 1.5px;
  color: var(--blueprint-white);
  text-shadow: 0 0 10px rgba(227, 242, 253, 0.4);
  text-align: center;
  margin-top: 10px;
}

.lobby-history-container {
  flex-grow: 1;
  overflow-y: auto;
  border: 1.5px dashed var(--glass-border);
  border-radius: 8px;
  background: rgba(6, 17, 31, 0.5);
  padding: 10px;
}

.lobby-history-container::-webkit-scrollbar {
  width: 6px;
}
.lobby-history-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
.lobby-history-container::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}
.lobby-history-container::-webkit-scrollbar-thumb:hover {
  background: var(--blueprint-muted);
}

.lobby-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  color: var(--blueprint-white);
  text-align: left;
}

.lobby-history-table th, .lobby-history-table td {
  padding: 10px 8px;
  border-bottom: 1px dashed rgba(129, 212, 250, 0.15);
  vertical-align: middle;
}

.lobby-history-table th {
  color: var(--blueprint-muted);
  text-transform: uppercase;
  font-weight: bold;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.lobby-history-table tbody tr:hover {
  background: rgba(129, 212, 250, 0.05);
}

/* Status styles inside lobby history */
.status-matching {
  color: var(--accent);
  font-weight: bold;
  animation: i18n-blink 1.5s infinite;
}

.status-playing {
  color: #ff5252;
  font-weight: bold;
}

.status-finished {
  color: var(--blueprint-muted);
}

@keyframes i18n-blink {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

/* Battle Details Modal styling */
.battle-details-modal {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(6, 17, 31, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  box-sizing: border-box;
  transition: opacity 0.25s ease;
}

.battle-details-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  width: 100%;
  max-width: 440px;
  border: 1.5px dashed var(--blueprint-muted);
  border-radius: 10px;
  background: rgba(11, 30, 51, 0.95);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.6);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-content h3 {
  font-size: 1.15rem;
  color: var(--blueprint-white);
  text-align: center;
  text-shadow: 0 0 8px rgba(129, 212, 250, 0.4);
}

.details-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  background: rgba(6, 17, 31, 0.4);
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid rgba(129, 212, 250, 0.1);
}

.details-scoreboard-container {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: rgba(6, 17, 31, 0.3);
}

.details-scoreboard-container::-webkit-scrollbar {
  width: 6px;
}
.details-scoreboard-container::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
.details-scoreboard-container::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}

.details-scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
  text-align: left;
}

.details-scoreboard-table th, .details-scoreboard-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(129, 212, 250, 0.05);
}

.details-scoreboard-table th {
  color: var(--blueprint-muted);
  font-weight: bold;
  text-transform: uppercase;
}

.details-scoreboard-table tbody tr:hover {
  background: rgba(129, 212, 250, 0.03);
}

/* Spectators Deck */
.hud-spectator-deck {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hud-spectators-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 4px;
}

.spectator-badge {
  background: rgba(129, 212, 250, 0.08);
  border: 1px solid rgba(129, 212, 250, 0.15);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.65rem;
  color: var(--blueprint-muted);
}

