/* ====================================================
   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-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
}

.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;
}

.boot-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-dark);
  z-index: 300;
}

.boot-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(88, 166, 255, 0.25);
  border-top-color: var(--accent-blue2);
  animation: boot-spin 0.8s linear infinite;
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

@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;
  }
}

/* ---------- 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 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent-gold);
}
.top-actions { display: flex; flex-shrink: 0; gap: 6px; }

/* ---------- Info Modal ---------- */
.info-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 7, 12, 0.82);
}
.info-modal-backdrop[hidden] { display: none; }
.info-modal-panel {
  width: min(100%, 520px);
  max-height: min(82vh, 620px);
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent-gold);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.65);
}
.info-modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.info-modal-heading h2 { color: var(--accent-gold); font-size: 19px; }
.info-modal-panel h3 { margin: 16px 0 5px; color: var(--accent-blue2); font-size: 14px; }
.info-modal-panel p { color: var(--text-dim); font-size: 14px; }
.info-modal-panel .info-discord { color: var(--text-main); font-weight: 700; }
.info-modal-close {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card2);
  color: var(--text-main);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 420px) {
  .top-bar { padding: 0 6px; }
  .game-title { font-size: 13px; }
  .top-actions { gap: 4px; }
  .top-actions .btn-small { padding: 5px 7px; }
  .info-modal-backdrop { align-items: end; padding: 8px; }
  .info-modal-panel { max-height: 86vh; padding: 16px 14px; }
}

/* ---------- 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;
  overscroll-behavior-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;
}
.troop-count-input {
  width: 68px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card2);
  color: var(--text-main);
  padding: 3px 5px;
}

/* ---------- Map Screen ---------- */
.scoreboard {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.scoreboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.scoreboard-top {
  font-weight: 700;
  margin-bottom: 4px;
}
#scoreboard-countdown {
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
}
.scoreboard-scores {
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
}
.scoreboard-scores small {
  color: var(--text-dim);
  font-size: 11px;
}
.sb-blue  { color: #7ab8ff; }
.sb-red   { color: #ff7070; }
.sb-green { color: #66cc77; }
.scoreboard-note {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  justify-content: flex-start;
}

.season-history-list {
  font-size: 12px;
  margin-top: 10px;
}
.season-history-card summary { cursor: pointer; font-weight: 700; color: var(--faction-accent-bright); }
.season-history-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.season-history-row:last-child { border-bottom: none; }
.season-history-result { font-weight: 700; color: var(--accent-gold); }

@media (max-width: 450px) {
  .scoreboard { font-size: 12px; padding: 7px 8px; }
  .scoreboard-scores { font-size: 12px; gap: 6px; }
}

.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; }
.territory-capital-marker { font-size: 14px; }

.map-container {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
  padding: 6px;
}
.map-workspace { min-width: 0; }
#map-svg {
  width: 100%;
  max-width: 820px;
  min-width: 420px;
  height: auto;
  display: block;
  margin: 0 auto;
}
.map-controls { display: none; }

.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); }

.territory-link {
  stroke: rgba(139, 148, 158, 0.45);
  stroke-width: 2;
  pointer-events: none;
}

#map-svg text {
  pointer-events: none;
  user-select: none;
}

.ter-label {
  font-size: 11px; 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);
}
.territory-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.territory-panel-close {
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
}
.territory-quantity-row {
  display: grid;
  grid-template-columns: auto minmax(54px, 1fr) auto auto auto;
  gap: 5px;
  align-items: center;
  margin-bottom: 8px;
}
.territory-quantity-row .btn-small { min-width: 0; padding: 7px 6px; }
.territory-quantity-row .troop-count-input { width: 100%; min-width: 0; }
.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; }

@media (max-width: 900px) {
  #map-svg {
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .map-container {
    margin-left: -2px;
    margin-right: -2px;
    padding: 4px;
  }

  #map-svg {
    min-width: 380px;
  }
}

/* ---------- Activity Feed ---------- */
.activity-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin: 0 4px 14px;
  border-bottom: 1px solid var(--border);
}
.activity-tab {
  min-height: 40px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.activity-tab.active {
  border-bottom-color: var(--accent-gold);
  color: var(--text-main);
}
.activity-panel { display: none; }
.activity-panel.active { display: block; }
.activity-feed {
  padding: 0 4px;
}
.activity-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.activity-headline {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}
.activity-result {
  font-size: 13px;
  color: var(--accent-gold);
  margin-bottom: 4px;
}
.activity-losses {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.activity-time {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
}
.activity-ranking-section { margin-bottom: 18px; }
.activity-ranking-title {
  margin: 0 4px 6px;
  color: var(--accent-gold);
  font-size: 14px;
}
.activity-ranking-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.activity-ranking-value { font-weight: 700; }
.activity-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 4px;
}
.activity-stat {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.activity-stat-value { display: block; font-size: 20px; font-weight: 700; }
.activity-stat-label { color: var(--text-dim); font-size: 11px; }

@media (max-width: 380px) {
  .activity-tab { font-size: 11px; }
  .activity-stats-grid { grid-template-columns: 1fr; }
}

/* ---------- Chat ---------- */
.chat-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-emoji-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-input {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  max-height: 160px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-main);
  padding: 10px 12px;
  font: inherit;
}
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 290px);
  overflow-y: auto;
  padding-right: 2px;
}
.chat-entry {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.chat-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.chat-message {
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Admin Panel ---------- */
.admin-player-row, .admin-territory-row {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.admin-badge {
  font-size: 11px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 6px;
  color: var(--text-dim);
}
.admin-badge-bonus {
  font-size: 11px;
  color: var(--accent-gold);
  margin-left: 6px;
}
.admin-badge-protected {
  color: var(--accent-gold);
}
.admin-player-stats {
  font-size: 12px;
  color: var(--text-dim);
  margin: 4px 0;
}
.admin-player-actions, .admin-territory-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.admin-world-controls {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.admin-player-actions select, .admin-territory-actions select,
.admin-player-actions input[type=number], .admin-territory-actions input[type=number] {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}
.admin-player-actions > *,
.admin-territory-actions > * {
  flex: 1 1 110px;
  min-width: 0;
}
.btn-danger {
  background: #7a1a1a;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger:hover { background: #a02020; }
.btn-secondary {
  background: var(--bg-card2);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-card); }
.btn-secondary.wide { width: 100%; }
.btn-danger.wide { width: 100%; }

@media (max-width: 640px) {
  .admin-player-row, .admin-territory-row {
    padding: 12px;
  }

  .admin-badge, .admin-badge-bonus {
    display: inline-flex;
    margin: 6px 6px 0 0;
  }

  .admin-player-actions, .admin-territory-actions {
    align-items: stretch;
  }

  .admin-player-actions > *,
  .admin-territory-actions > * {
    flex-basis: 100%;
    width: 100%;
  }
}

/* ---------- Building bonus line ---------- */
.building-bonus {
  font-size: 11px;
  color: var(--accent-gold);
}

/* ---------- SaiWars game-shell polish ---------- */
.game-shell {
  --faction-accent: var(--accent-blue);
  --faction-accent-bright: var(--accent-blue2);
  --faction-glow: rgba(31, 111, 235, 0.16);
  --faction-map-bg: #0a1628;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0, var(--faction-glow), transparent 38%), var(--bg-dark);
}
.game-shell[data-faction="red"] {
  --faction-accent: var(--accent-red);
  --faction-accent-bright: #ff7972;
  --faction-glow: rgba(248, 81, 73, 0.16);
  --faction-map-bg: #280d12;
}
.game-shell[data-faction="green"] {
  --faction-accent: var(--accent-green);
  --faction-accent-bright: #65d879;
  --faction-glow: rgba(63, 185, 80, 0.16);
  --faction-map-bg: #0b2415;
}
.game-shell .top-bar { border-bottom-color: color-mix(in srgb, var(--faction-accent) 45%, var(--border)); }
.game-shell .game-title, .game-shell .screen-title { color: var(--faction-accent-bright); }
.player-identity { display: block; color: var(--text-dim); font-size: 11px; line-height: 1.1; }
.game-shell .btn-primary { background: var(--faction-accent); box-shadow: 0 8px 18px var(--faction-glow); }
.game-shell .btn-primary:hover { background: var(--faction-accent-bright); }
.game-shell .nav-btn.active { color: var(--faction-accent-bright); border-top-color: var(--faction-accent-bright); }
.game-shell .section-card h3 { color: var(--faction-accent-bright); }
.game-shell .map-container { background: var(--faction-map-bg); }

.faction-bonuses-card { padding-bottom: 10px; }
.faction-bonuses { display: flex; flex-wrap: wrap; gap: 6px; }
.faction-bonuses span { background: var(--bg-card2); border: 1px solid var(--border); border-radius: 5px; padding: 4px 6px; color: var(--text-main); font-size: 11px; font-weight: 600; }

.territory.attackable { stroke: var(--accent-gold) !important; stroke-width: 2.5 !important; filter: drop-shadow(0 0 4px rgba(227, 179, 65, 0.8)); }
.territory.selected { stroke: #fff !important; stroke-width: 3.5 !important; filter: brightness(1.35); }
.territory-bonus-icon { font-size: 11px; }

#screen-chat.active { display: flex; flex-direction: column; gap: 10px; }
#screen-chat .screen-title { flex: none; margin-bottom: 0; }
#screen-chat > .section-card { margin-bottom: 0; }
#screen-chat > .section-card:first-of-type { flex: none; }
#screen-chat .chat-card { flex: 1; min-height: 0; }
.chat-messages { flex: 1; max-height: none; min-height: 120px; }
.chat-composer { position: sticky; bottom: -6px; padding: 8px 0 2px; background: var(--bg-card); border-top: 1px solid var(--border); }
.chat-input { min-height: 64px; max-height: 110px; }

@media (min-width: 760px) {
  :root { --top-h: 56px; --res-h: 44px; }
  .top-bar, .resource-bar, .bottom-nav { padding-left: max(20px, calc((100vw - 1120px) / 2)); padding-right: max(20px, calc((100vw - 1120px) / 2)); }
  .screen { padding: 20px max(20px, calc((100vw - 1120px) / 2)) 14px; }
  .screen-title { font-size: 22px; }
  .bottom-nav { height: 54px; justify-content: center; gap: 4px; }
  .nav-btn { flex: 0 1 130px; }
  .building-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .building-card { margin-bottom: 0; }
  #screen-map.active { display: flex; flex-direction: column; overflow: hidden; }
  #screen-map > .screen-title, #screen-map > .scoreboard, #screen-map > .map-legend { flex: none; }
  .map-workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: 14px; align-items: stretch; flex: 1; min-height: 0; overflow: hidden; }
  .map-container { display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; height: 100%; padding: 12px; margin-bottom: 0; overflow: hidden; box-sizing: border-box; }
  #map-svg { width: 100%; height: 100%; min-width: 0; max-width: 100%; max-height: 100%; }
  .territory-panel { position: sticky; top: 0; min-height: 0; max-height: 100%; overflow-y: auto; }
  .faction-bonuses { gap: 8px; }
  .faction-bonuses span { font-size: 12px; }
}

@media (max-width: 520px) {
  .top-bar { padding: 0 8px; }
  .game-title { font-size: 14px; }
  .res-item { gap: 2px; font-size: 11px; }
  .res-icon { font-size: 13px; }
  .screen { padding-left: 8px; padding-right: 8px; }
  .faction-bonuses span { font-size: 10px; }
  #map-svg { min-width: 0; }
  .map-container { overflow: hidden; touch-action: none; }
  .map-controls {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    gap: 4px;
    align-items: center;
  }
  .map-controls .btn-circle { width: 32px; height: 32px; min-height: 32px; }
  .map-controls .btn-small { min-height: 32px; padding: 5px 8px; }
  .territory-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    z-index: 120;
    max-height: min(62vh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
    margin: 0;
    border-color: color-mix(in srgb, var(--faction-accent) 55%, var(--border));
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.55);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .territory-panel h3 { margin-bottom: 4px; }
  .tp-grid { gap: 4px; }
  .tp-item { padding: 5px 7px; }
  .territory-quantity-row { grid-template-columns: auto minmax(48px, 1fr) auto auto auto; }
}
