/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0e17;
  --bg2: #1a1a2e;
  --bg3: #16213e;
  --card: #1e1e3a;
  --border: #2a2a5a;
  --primary: #e94560;
  --primary-dark: #c73652;
  --accent: #f5a623;
  --text: #eaeaea;
  --text-muted: #888;
  --success: #2ecc71;
  --danger: #e74c3c;
  --warning: #f39c12;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen { display: none; height: 100dvh; overflow-y: auto; }
.screen.active { display: flex; flex-direction: column; }

/* ===== SETUP SCREEN ===== */
#screen-setup {
  align-items: center;
  justify-content: flex-start;
  padding: 20px 16px 40px;
  background: linear-gradient(160deg, #0f0e17 0%, #1a1a2e 50%, #16213e 100%);
}

.setup-container { width: 100%; max-width: 480px; margin: 0 auto; }

.game-title {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 4px;
  background: linear-gradient(135deg, #e94560, #f5a623);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.player-count-section { margin-bottom: 24px; }
.player-count-section label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }

.count-buttons { display: flex; gap: 10px; }
.count-btn {
  flex: 1;
  padding: 12px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.count-btn.active { background: var(--primary); border-color: var(--primary); }
.count-btn:hover:not(.active) { border-color: var(--primary); }

.continent-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.continent-btn {
  padding: 12px 10px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.continent-btn.active { background: var(--primary); border-color: var(--primary); }
.continent-btn:hover:not(.active) { border-color: var(--primary); }
.continent-btn:nth-child(5) { grid-column: 1 / 3; }

/* ===== MAP SVG ===== */
#map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#map-continent-name { font-weight: 700; font-size: 1rem; }
#map-zoom-controls { display: flex; gap: 6px; }
#map-zoom-controls button {
  width: 32px;
  height: 32px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}
#map-zoom-controls button:hover { background: var(--border); }

#map-svg-wrapper {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 55vh;
  touch-action: none;
}

#map-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
#map-svg:active { cursor: grabbing; }

.country-path {
  stroke: #0f0e17;
  stroke-width: 0.5;
  cursor: pointer;
  transition: opacity 0.15s, stroke-width 0.15s;
}
.country-path:hover { opacity: 0.85; stroke-width: 1.2; }
.country-path.selected-for-buy { stroke: #f5a623; stroke-width: 2; }
.country-path.unowned { fill: #2a2a4a; }

.country-troops {
  fill: #fff;
  font-weight: 800;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: #0a0a1a;
  stroke-width: 1.5;
  stroke-linejoin: round;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.country-tiny-marker {
  pointer-events: none;
}

#map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.78rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--card);
  border-radius: 12px;
}
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ===== COUNTRY CHIPS LIST ===== */
#country-list-header {
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#country-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.country-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
  user-select: none;
}
.country-chip:hover { border-color: var(--primary); }
.country-chip:active { transform: scale(0.95); }
.country-chip .chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.country-chip .chip-soldiers {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ===== QUICK BUY EN MODAL ===== */
#territory-quick-buy {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.quick-buy-header {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#quick-buy-money { color: var(--accent); font-size: 0.85rem; }

.quick-buy-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.quick-buy-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.quick-buy-btn:hover { border-color: var(--primary); }
.quick-buy-btn.active { border-color: var(--accent); background: var(--bg2); }
.quick-buy-btn .qb-icon { font-size: 1.2rem; }
.quick-buy-btn .qb-name { font-size: 0.65rem; margin-top: 2px; line-height: 1.1; }
.quick-buy-btn .qb-price { font-size: 0.65rem; color: var(--accent); font-weight: 700; }

.quick-buy-qty {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.quick-buy-qty .qty-btn { width: 28px; height: 28px; font-size: 1rem; }
.quick-buy-qty .qty-value { min-width: 24px; font-size: 1rem; }
#qb-qty-total { margin-left: auto; color: var(--accent); font-weight: 700; font-size: 0.85rem; }
.qb-hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; text-align: center; }

/* ===== MINI MAP IN TERRITORY MODAL ===== */
#territory-mini-map {
  width: 100%;
  height: 160px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  overflow: hidden;
}
#mini-map-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.mini-country-path {
  stroke: #fff;
  stroke-width: 0.6;
}

.player-input-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.player-input-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-weight: 600;
}

.player-input-group input[type="text"] {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.2s;
}
.player-input-group input[type="text"]:focus { border-color: var(--primary); }

.color-picker-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.color-option.selected { border-color: white; transform: scale(1.2); }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary.btn-large { padding: 18px; font-size: 1.1rem; margin-top: 16px; }
.btn-primary:disabled { background: #444; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--border); }

.btn-cancel {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  cursor: pointer;
}

/* ===== GAME HEADER ===== */
#game-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

#current-player-info { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1rem; }

#game-stats { display: flex; gap: 12px; font-size: 0.82rem; color: var(--text-muted); }
#game-stats span { display: flex; align-items: center; gap: 3px; }

.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.player-dot.large { width: 60px; height: 60px; margin: 0 auto 12px; display: block; }

/* ===== TABS ===== */
#tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 10px 14px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== TAB CONTENT ===== */
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 14px; padding-bottom: 80px; }
.tab-content.active { display: block; }

.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.subsection-title { font-size: 0.95rem; font-weight: 600; margin: 16px 0 8px; color: var(--text-muted); }
.section-hint { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px; }

/* ===== MAP ===== */
#map-container { display: flex; flex-direction: column; gap: 16px; }

.continent-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.continent-header {
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.95rem;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.territories-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--border);
}

.territory-card {
  background: var(--card);
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.territory-card:hover { background: var(--bg3); }
.territory-card.selected-for-buy { outline: 2px solid var(--accent); }

.territory-owner-bar {
  height: 3px;
  border-radius: 2px;
  margin-bottom: 6px;
}

.territory-name {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.territory-stats {
  display: flex;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.territory-stat { display: flex; align-items: center; gap: 2px; }

/* ===== SHOP ===== */
.shop-grid { display: flex; flex-direction: column; gap: 12px; }

.shop-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.shop-icon { font-size: 1.8rem; margin-bottom: 4px; }
.shop-name { font-weight: 700; font-size: 1rem; }
.shop-price { color: var(--accent); font-weight: 600; font-size: 0.9rem; margin: 2px 0; }
.shop-desc { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 10px; }

.shop-quantity {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-btn:hover { background: var(--border); }

.qty-value { font-size: 1.2rem; font-weight: 700; min-width: 30px; text-align: center; }
.shop-total { font-size: 0.85rem; color: var(--accent); margin-bottom: 8px; }
.btn-buy { width: 100%; padding: 10px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-buy:hover { background: var(--primary); border-color: var(--primary); }

.selected-territory-info {
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  min-height: 40px;
  color: var(--accent);
}

/* ===== ALLIANCES ===== */
.alliance-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.alliance-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-single { background: #2d3a1a; color: #7ed321; }
.badge-long { background: #1a2a3a; color: #4a9eff; }

#alliance-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

#alliance-form label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; margin-top: 10px; }
#alliance-form label:first-child { margin-top: 0; }

#alliance-target, #loan-target {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.alliance-type-buttons { display: flex; gap: 8px; margin-bottom: 12px; }
.alliance-type-btn {
  flex: 1;
  padding: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.alliance-type-btn.active { background: var(--primary); border-color: var(--primary); }

/* ===== FINANCE ===== */
#loan-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
#loan-form label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; margin-top: 10px; }
#loan-form label:first-child { margin-top: 0; }
#loan-amount {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  margin-bottom: 10px;
}
.loan-warning { font-size: 0.8rem; color: var(--warning); margin-bottom: 10px; }

.loan-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.loan-card .loan-header { font-weight: 700; margin-bottom: 4px; }
.loan-card .loan-detail { font-size: 0.82rem; color: var(--text-muted); }
.loan-card .loan-urgent { color: var(--danger); font-weight: 600; }

.btn-repay {
  margin-top: 8px;
  padding: 8px 14px;
  background: var(--success);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

/* ===== PLAYERS STATUS ===== */
.player-status-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.player-status-card.eliminated { opacity: 0.4; }
.player-status-dot { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; }
.player-status-info { flex: 1; }
.player-status-name { font-weight: 700; margin-bottom: 4px; }
.player-status-stats { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== GAME FOOTER ===== */
#game-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.btn-end-turn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.2s;
}
.btn-end-turn:hover { opacity: 0.9; }

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
}
.modal-content.centered { text-align: center; }
.modal-content h2 { margin-bottom: 14px; font-size: 1.2rem; }

.modal-buttons { display: flex; gap: 10px; margin-top: 16px; flex-direction: column; }

.weapon-options { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.weapon-btn {
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.weapon-btn.active { background: var(--primary); border-color: var(--primary); }

#invasion-preview {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.notify-icon { font-size: 2.5rem; text-align: center; margin-bottom: 10px; }
#notify-message { text-align: center; margin-bottom: 14px; line-height: 1.5; }

/* ===== VICTORY SCREEN ===== */
#screen-victory {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f0e17, #1a1a2e);
}

.victory-container { text-align: center; padding: 30px 20px; }
.victory-crown { font-size: 4rem; margin-bottom: 12px; }
.victory-container h1 { font-size: 2.5rem; font-weight: 800; margin-bottom: 16px; }
#winner-info { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
#winner-territories { color: var(--text-muted); margin-bottom: 24px; }

/* ===== MISC ===== */
.hidden { display: none !important; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.9rem;
}

#new-turn-income {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
