/* RealmRush - Telegram Mini App */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #21262d;
  --border: #30363d;
  --accent: #f0a500;
  --accent2: #e05252;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --green: #3fb950;
  --red: #f85149;
  --blue: #58a6ff;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== SCREENS ===== */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.97);
}

/* ===== LOADING SCREEN ===== */

#screen-loading {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.logo-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 72px;
  line-height: 1;
  filter: drop-shadow(0 0 20px rgba(240, 165, 0, 0.6));
  animation: pulse 2s ease-in-out infinite;
}

.logo-title {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, #f0a500, #ff6b35);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.logo-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.loading-bar {
  width: 200px;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ff6b35);
  border-radius: 2px;
  animation: loadbar 1.5s ease-in-out infinite;
}

/* ===== MENU SCREEN ===== */

#screen-menu {
  background: var(--bg);
  overflow-y: auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.menu-header {
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-logo {
  font-size: 48px;
  filter: drop-shadow(0 0 12px rgba(240, 165, 0, 0.5));
}

.menu-title {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, #f0a500, #ff6b35);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.menu-tagline {
  color: var(--text-muted);
  font-size: 12px;
}

.menu-body {
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-section-title {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 4px 4px 0;
}

.btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
  text-align: left;
}

.btn:active {
  transform: scale(0.97);
  background: var(--surface2);
}

.btn-primary {
  background: linear-gradient(135deg, #f0a500, #e08000);
  color: #000;
}

.btn-primary:active {
  background: linear-gradient(135deg, #d89500, #c07000);
}

.btn-danger {
  background: var(--surface);
  border: 1px solid var(--red);
  color: var(--red);
}

.btn-icon {
  font-size: 22px;
  width: 30px;
  text-align: center;
  flex-shrink: 0;
}

.btn-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 2px;
}

.btn-label {
  font-size: 15px;
  font-weight: 600;
}

.btn-desc {
  font-size: 12px;
  font-weight: 400;
  opacity: 0.7;
}

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

.game-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.15s;
}

.game-item:active { background: var(--surface2); }

.game-item-name {
  font-weight: 600;
  font-size: 14px;
}

.game-item-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.game-item-join {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.no-games {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 13px;
}

/* ===== GAME SCREEN ===== */

#screen-game {
  background: #0a1520;
  position: relative;
}

/* Top HUD */
.game-hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: var(--safe-top) 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.08);
  flex: 1;
}

.hud-stat-icon { font-size: 14px; }
.hud-stat-val  { font-weight: 700; }

/* Power bar (troops %) — territorial.io style */
.hud-power-stat { gap: 5px; }

.power-bar-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.power-bar-track {
  flex: 1;
  height: 7px;
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  overflow: hidden;
}

.power-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.4s ease, background 0.4s ease;
  background: #2ecc71;
}

.power-bar-label {
  font-size: 12px;
  font-weight: 700;
  min-width: 34px;
  text-align: right;
}

.hud-btn {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
}

.hud-btn:active { opacity: 0.7; }

.hud-exit-btn {
  background: rgba(248,81,73,0.25);
  border-color: rgba(248,81,73,0.4);
  color: #f85149;
}

/* Gold stat */
#hud-gold .hud-stat-val {
  color: #f0a500;
  font-weight: 800;
}

/* Canvas */
#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  cursor: default;
  touch-action: none;
}

/* ===== ATTACK BAR — permanent bottom control ===== */

.attack-bar {
  position: fixed;
  bottom: calc(12px + var(--safe-bottom, 0px));
  left: 12px;
  right: 12px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10,14,20,0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 10px 14px;
  pointer-events: auto;
}

.attack-bar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.attack-bar-icon { font-size: 16px; }

.attack-bar-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.attack-bar-val {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
  min-width: 38px;
}

/* The big slider — easy to grab on mobile */
.attack-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  outline: none;
  cursor: pointer;
}
.attack-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.3);
}
.attack-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.3);
}

/* ===== EXPAND STATUS PANEL ===== */

.expand-panel {
  position: fixed;
  bottom: calc(72px + var(--safe-bottom, 0px)); /* sit above attack-bar */
  left: 12px;
  right: 12px;
  z-index: 9998;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  opacity: 0;
  transform: translateY(8px);
}

.expand-panel.hidden  { opacity: 0; pointer-events: none; transform: translateY(8px); }
.expand-panel.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

.expand-status {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  padding: 6px 12px;
  background: rgba(10,14,20,0.82);
  border-radius: 20px;
  border: 1px solid rgba(240,165,0,0.25);
  margin-bottom: 6px;
  backdrop-filter: blur(8px);
}

.expand-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-expand-cancel, .btn-expand-stop {
  background: rgba(22,27,34,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.btn-expand-stop { border-color: rgba(231,76,60,0.4); color: #e74c3c; }
.btn-expand-cancel:active, .btn-expand-stop:active { opacity: 0.7; }

/* keep old expand-active-label for legacy */
.expand-active-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  animation: hintPulse 1.5s ease-in-out infinite;
}

.btn-expand-stop {
  background: rgba(248,81,73,0.2);
  color: var(--red);
  border: 1px solid rgba(248,81,73,0.35);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* Phase banner */
.phase-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  background: rgba(22,27,34,0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 24px 32px;
  text-align: center;
  max-width: 80vw;
  pointer-events: auto;
  box-shadow: 0 0 40px rgba(240, 165, 0, 0.3);
}

.phase-banner.hidden { display: none; }

.phase-banner-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.phase-banner-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.phase-banner-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Game log */
.game-log {
  position: absolute;
  top: 80px;
  right: 10px;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  max-width: 200px;
}

.log-entry {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--text-muted);
  border-left: 2px solid var(--accent);
  animation: logIn 0.3s ease;
  transition: opacity 0.5s;
}

/* ===== MODALS ===== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  padding-bottom: var(--safe-bottom);
  transition: opacity 0.2s;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0s 0.2s;
}

.modal-sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--border);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 4px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-text {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus { border-color: var(--accent); }

.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  min-width: 30px;
  text-align: center;
}

/* ===== WIN SCREEN ===== */

#screen-win {
  background: radial-gradient(ellipse at center, #1a1200 0%, var(--bg) 70%);
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 32px;
}

.win-icon {
  font-size: 80px;
  animation: bounce 1s ease infinite alternate;
}

.win-title {
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(135deg, #f0a500, #ffdd57);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.win-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
}

.win-stats {
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.win-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.win-stat-label { color: var(--text-muted); }
.win-stat-val { font-weight: 700; }

/* ===== MINIMAP ===== */

.minimap {
  position: absolute;
  bottom: 100px;
  right: 10px;
  z-index: 9;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  overflow: hidden;
  opacity: 0.8;
  cursor: pointer;
}

.minimap:active { opacity: 1; }

/* ===== PLAYER LIST ===== */

.players-panel-container {
  position: absolute;
  top: 80px;
  left: 10px;
  z-index: 9;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  max-width: 160px;
  pointer-events: none;
}

.btn-toggle-players {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  color: #fff;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s;
}

.btn-toggle-players:active {
  background: rgba(0,0,0,0.9);
}

.players-panel {
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
}

.players-panel.hidden {
  display: none !important;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  padding: 4px 10px 4px 6px;
  font-size: 11px;
  font-weight: 600;
  max-width: 160px;
}

.player-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.player-chip-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-chip-cells {
  color: var(--text-muted);
  font-size: 10px;
  flex-shrink: 0;
}

.player-chip.eliminated {
  opacity: 0.4;
}

/* Tick countdown */
#tick-countdown {
  font-weight: 700;
  letter-spacing: -0.3px;
  animation: tickPulse 1s ease-in-out infinite;
}

@keyframes tickPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Attack hint in cell panel */
.attack-hint {
  font-size: 11px;
  color: var(--accent);
  text-align: center;
  padding: 2px 0;
  animation: hintPulse 1.5s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ===== ANIMATIONS ===== */

@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 20px rgba(240, 165, 0, 0.6)); }
  50% { transform: scale(1.05); filter: drop-shadow(0 0 30px rgba(240, 165, 0, 0.9)); }
}

@keyframes loadbar {
  0% { width: 0%; margin-left: 0; }
  50% { width: 60%; margin-left: 0; }
  100% { width: 0%; margin-left: 100%; }
}

@keyframes logIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

/* ===== BUILD MENU ===== */

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

.build-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.build-item:active {
  background: var(--surface2);
  border-color: var(--accent);
}

.build-item.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.build-item-icon {
  font-size: 28px;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.build-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.build-item-name {
  font-size: 14px;
  font-weight: 700;
}

.build-item-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.build-item-cost {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}
