/* ====================================================
   TERRITORY CONQUEST — style.css
   Dark mobile-first strategy game interface
   360–450px portrait phone screens
   ==================================================== */

:root {
  --bg-dark:      #0d1117;
  --bg-card:      #161b22;
  --bg-card2:     #1c2230;
  --border:       #30363d;
  --accent-blue:  #1f6feb;
  --accent-blue2: #388bfd;
  --accent-green: #3fb950;
  --accent-red:   #f85149;
  --accent-gold:  #e3b341;
  --text-main:    #e6edf3;
  --text-dim:     #8b949e;
  --nav-h:        60px;
  --top-h:        46px;
  --res-h:        40px;
  --radius:       10px;
  --shadow:       0 2px 8px rgba(0,0,0,0.5);
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(31, 111, 235, 0.22), transparent 34%),
    linear-gradient(180deg, rgba(8, 12, 18, 0.96), rgba(13, 17, 23, 1));
  z-index: 200;
  padding: 18px;
}

.auth-card {
  width: min(100%, 380px);
  background: rgba(17, 24, 39, 0.94);
  border: 1px solid rgba(125, 143, 166, 0.28);
  border-radius: 20px;
  padding: 22px 18px 18px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.auth-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
}

.auth-logo {
  font-size: 1.8rem;
}

.auth-card h2 {
  text-align: center;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: 0.04em;
  color: #f8d874;
}

.auth-subtitle {
  text-align: center;
  color: #a9b2c1;
  margin-bottom: 18px;
  font-size: 0.96rem;
}

.auth-mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-mode-btn {
  background: rgba(28, 34, 48, 0.95);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 10px;
  padding: 12px 10px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.auth-mode-btn:hover {
  transform: translateY(-1px);
}

.auth-mode-btn.active {
  background: linear-gradient(135deg, #1f6feb, #2a8cff);
  border-color: rgba(118, 176, 255, 0.9);
  box-shadow: 0 8px 18px rgba(31, 111, 235, 0.35);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input,
.auth-form select,
.dropdown {
  width: 100%;
  min-height: 48px;
  background: rgba(28, 34, 48, 0.9);
  border: 1px solid rgba(118, 131, 149, 0.45);
  border-radius: 10px;
  color: var(--text-main);
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input:focus,
.auth-form select:focus,
.dropdown:focus {
  border-color: rgba(88, 166, 255, 0.95);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.2);
}

.auth-faction-panel {
  margin-top: 2px;
}

.auth-section-label {
  margin: 0 0 8px;
  color: #b7c1d0;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

.auth-faction-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.faction-choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 74px;
  background: rgba(28, 34, 48, 0.9);
  border: 1px solid rgba(118, 131, 149, 0.35);
  border-radius: 12px;
  color: var(--text-main);
  cursor: pointer;
  font-weight: 700;
  transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.faction-choice-btn span {
  font-size: 1.4rem;
}

.faction-choice-btn.active {
  border-color: rgba(129, 185, 255, 0.9);
  box-shadow: 0 0 0 2px rgba(56, 139, 253, 0.18);
  background: rgba(25, 47, 77, 0.92);
}

.auth-message {
  min-height: 20px;
  margin-top: 10px;
  font-size: 0.82rem;
  color: #f5cd70;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, #1f6feb, #2d8cff);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  min-height: 48px;
  box-shadow: 0 10px 18px rgba(31, 111, 235, 0.28);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.btn-primary.wide {
  width: 100%;
  margin-top: 4px;
}

.game-shell {
  display: none;
}

@media (max-width: 420px) {
  .auth-card {
    padding: 20px 14px 16px;
    border-radius: 16px;
  }

  .auth-mode-row {
    gap: 6px;
  }

  .auth-form input,
  .auth-form select,
  .dropdown {
    min-height: 46px;
  }

  .auth-faction-grid {
    gap: 6px;
  }
}

@media (min-width: 421px) {
  .auth-screen {
    display: flex !important;
  }

  .game-shell {
    display: none !important;
  }
}

/* ---------- Top Bar ---------- */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--top-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  z-index: 100;
}
.game-title { font-weight: 700; font-size: 15px; color: var(--accent-gold); }
.top-actions { display: flex; gap: 6px; }

/* ---------- Resource Bar ---------- */
.resource-bar {
  position: fixed;
  top: var(--top-h); left: 0; right: 0;
  height: var(--res-h);
  background: var(--bg-card2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 99;
  padding: 0 4px;
}
.res-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600;
}
.res-icon { font-size: 15px; }

/* ---------- Screen Layout ---------- */
.screen {
  display: none;
  position: fixed;
  top: calc(var(--top-h) + var(--res-h));
  left: 0; right: 0;
  bottom: var(--nav-h);
  overflow-y: auto;
  padding: 10px 10px 6px;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: block; }

.screen-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 10px;
  color: var(--accent-gold);
}

/* ---------- Cards ---------- */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.section-card h3 {
  font-size: 14px; font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent-blue2);
}
.section-card p { margin-bottom: 5px; font-size: 13px; }

.stat-row {
  display: flex; justify-content: space-between;
  align-items: center;
  font-size: 14px; padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-of-type { border-bottom: none; }
.stat-row span { color: var(--text-dim); }
.stat-row strong { color: var(--text-main); }

/* ---------- Building Cards ---------- */
.building-list { margin-bottom: 10px; }

.building-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.building-info { flex: 1; }
.building-name { font-weight: 700; font-size: 14px; margin-bottom: 1px; }
.building-level { font-size: 11px; color: var(--text-dim); }
.building-prod  { font-size: 12px; color: var(--accent-green); margin-top: 2px; }
.building-cost  { font-size: 11px; color: var(--accent-gold); margin-top: 2px; }
.cost-line { font-size: 13px; margin-bottom: 6px; }
.info-text { color: var(--text-dim); font-size: 13px; margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--accent-blue);
  color: #fff; border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 44px;
}
.btn-primary:hover { background: var(--accent-blue2); }
.btn-primary.wide  { width: 100%; margin-top: 8px; }
.btn-attack { background: var(--accent-red); }
.btn-attack:hover { background: #ff6b6b; }

.btn-small {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
}
.btn-small:hover { background: var(--border); }

.btn-circle {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 17px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-circle:hover { background: var(--border); }

.btn-upgrade {
  background: var(--accent-gold);
  color: #000; border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px; font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  margin-left: 10px;
  flex-shrink: 0;
}
.btn-upgrade:disabled { opacity: 0.4; cursor: default; }

/* ---------- Row helpers ---------- */
.row-center {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin: 8px 0; flex-wrap: wrap;
}
.train-count {
  font-size: 22px; font-weight: 700;
  min-width: 40px; text-align: center;
}

/* ---------- Map Screen ---------- */
.map-legend {
  display: flex; gap: 8px; flex-wrap: wrap;
  font-size: 11px; margin-bottom: 6px; padding: 0 2px;
}
.leg-blue   { color: #7ab8ff; font-weight: 700; }
.leg-red    { color: #ff7070; font-weight: 700; }
.leg-green  { color: #66cc77; font-weight: 700; }
.leg-target { color: var(--accent-gold); font-weight: 700; }

.map-container {
  background: #0a1628;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
#map-svg { width: 100%; display: block; }

.territory {
  cursor: pointer;
  transition: filter 0.12s;
}
.territory:hover { filter: brightness(1.4); }
.territory.selected { stroke: #fff !important; stroke-width: 3 !important; filter: brightness(1.5); }

.ter-label {
  font-size: 8px; font-weight: 700;
  fill: #fff;
  pointer-events: none;
  dominant-baseline: middle;
  text-anchor: middle;
}

/* ---------- Territory Panel ---------- */
.territory-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.territory-panel h3 {
  font-size: 16px; font-weight: 700;
  margin-bottom: 8px; color: var(--accent-gold);
}
.tp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 4px;
}
.tp-item {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}
.tp-item.tp-wide { grid-column: span 2; }
.tp-label { display: block; font-size: 10px; color: var(--text-dim); margin-bottom: 2px; }
.tp-item span:last-child { font-size: 13px; font-weight: 600; }

.divider { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.attack-hint { font-size: 14px; font-weight: 700; color: var(--accent-red); margin-bottom: 4px; }

/* ---------- Battle Popup ---------- */
.battle-popup {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card2);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius);
  padding: 20px 22px;
  text-align: center;
  z-index: 200;
  box-shadow: 0 4px 24px rgba(0,0,0,0.8);
  min-width: 250px;
  max-width: 90vw;
}
.battle-popup p { font-size: 14px; margin-bottom: 14px; line-height: 1.8; }
.result-victory { font-size: 20px; font-weight: 700; color: var(--accent-green); }
.result-defeat  { font-size: 20px; font-weight: 700; color: var(--accent-red); }

/* ---------- Faction Screen ---------- */
.faction-blue  { color: var(--accent-blue2); font-weight: 700; }
.faction-red   { color: var(--accent-red);   font-weight: 700; }
.faction-green { color: var(--accent-green); font-weight: 700; }

.dropdown {
  width: 100%;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  margin-bottom: 4px;
  appearance: none;
}

.leaderboard { width: 100%; border-collapse: collapse; font-size: 13px; }
.leaderboard th {
  background: var(--bg-card2); color: var(--text-dim);
  padding: 7px 6px; text-align: left; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.leaderboard td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
.leaderboard tr:last-child td { border-bottom: none; }

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
  z-index: 100;
}
.nav-btn {
  flex: 1; background: transparent; border: none;
  color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer;
  transition: color 0.15s, background 0.15s;
  border-top: 2px solid transparent;
}
.nav-btn:hover { background: var(--bg-card2); }
.nav-btn.active { color: var(--accent-blue2); border-top-color: var(--accent-blue2); }
.nav-icon  { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%; transform: translateX(-50%);
  background: #333; color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 300;
  opacity: 1; transition: opacity 0.5s;
  pointer-events: none; white-space: nowrap;
}
.toast.fade { opacity: 0; }

/* ---------- Scrollbar ---------- */
.screen::-webkit-scrollbar { width: 4px; }
.screen::-webkit-scrollbar-track { background: transparent; }
.screen::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
