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

html, body {
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  background: #1a1a2e;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e0e0e0;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#ui {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#ui * {
  pointer-events: auto;
}

#game-ui {
  pointer-events: none;
}

.screen {
  width: 100%;
  height: 100%;
}

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
}

.login-box {
  background: #2a2a3e;
  padding: 2.5rem 2rem;
  border-radius: 10px;
  border: 1px solid #444;
  text-align: center;
  min-width: 320px;
}

.login-box h1 {
  font-size: 2.2rem;
  margin-bottom: 0.3rem;
  color: #f0c040;
  letter-spacing: 3px;
  font-weight: 700;
}

.login-sub {
  color: #888;
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

.login-box input {
  display: block;
  width: 100%;
  padding: 0.7rem;
  margin-bottom: 0.8rem;
  background: #1a1a2e;
  border: 1px solid #555;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.95rem;
}

.login-box button {
  padding: 0.65rem 2rem;
  background: #4a6fa5;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.15s;
}

.login-box button:hover {
  background: #5a8fd5;
}

.error {
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* ── Main Menu ── */
#main-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #0d0d1a;
  overflow: hidden;
}

#menu-bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  filter: blur(4px);
  transform: scale(1.03);
}

#main-menu::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 26, 0.55);
  pointer-events: none;
}

.menu-box {
  text-align: center;
  width: 420px;
  max-width: 90vw;
  position: relative;
  z-index: 1;
  background: rgba(10, 10, 26, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 2rem 2rem 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.menu-title {
  font-size: 3.5rem;
  color: #f0c040;
  letter-spacing: 6px;
  font-weight: 700;
  margin-bottom: 0.3rem;
  text-shadow: 0 2px 20px rgba(240, 192, 64, 0.3);
}

.menu-sub {
  color: #888;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  letter-spacing: 2px;
}

.menu-config-area {
  position: relative;
  width: 100%;
}

.menu-config-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.menu-nickname-row {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.menu-nickname-input {
  width: 220px;
  padding: 8px 12px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #16213e;
  color: #eee;
  font-size: 0.95rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.menu-nickname-input:focus {
  border-color: #f0c040;
}

.menu-nickname-input::placeholder {
  color: #555;
}

/* ── Menu Tabs ── */
.menu-tabs {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #444;
  width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.menu-tab {
  flex: 1;
  padding: 10px 0;
  background: #1a1a2e;
  border: none;
  color: #888;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, color 0.15s;
}

.menu-tab:hover {
  color: #ccc;
  background: #252540;
}

.menu-tab-active {
  background: #2a2a4a;
  color: #f0c040;
}

.menu-mode-desc {
  font-size: 0.78rem;
  color: #666;
  text-align: center;
  margin-top: -4px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.menu-btn {
  width: 320px;
  padding: 14px 0;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.menu-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.menu-btn:active {
  transform: translateY(0);
}

.menu-btn-primary {
  background: linear-gradient(135deg, #f0c040, #e0a020);
  color: #1a1a2e;
}

.menu-btn-primary:hover {
  background: linear-gradient(135deg, #f5d060, #f0c040);
}

.player-stats {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.08);
  width: 100%;
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 0.8rem;
  color: #999;
}

.stats-item strong {
  color: #ccc;
}

.ach-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.ach-row::-webkit-scrollbar {
  height: 4px;
}

.ach-row::-webkit-scrollbar-track {
  background: transparent;
}

.ach-row::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
}

.ach-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.ach-done {
  background: rgba(255, 204, 0, 0.2);
  color: #ffcc00;
  border: 1px solid rgba(255, 204, 0, 0.3);
}

.ach-locked {
  background: rgba(255, 255, 255, 0.04);
  color: #555;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.menu-option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #bbb;
  font-size: 1rem;
  width: 320px;
}
.menu-option-row label {
  font-weight: 600;
  min-width: 70px;
}
.option-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pc-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #555;
  border-radius: 6px;
  background: #2a2a4a;
  color: #eee;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.pc-btn:hover { background: #3a3a5a; }
#player-count-val, #map-size-val, #water-level-val, #difficulty-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f0c040;
  width: 100px;
  text-align: center;
}

/* ── Game Modifiers ── */
.menu-modifiers {
  width: 320px;
  margin-top: 8px;
}
.mod-toggle-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  font-size: 0.8rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  cursor: pointer;
  text-align: left;
  padding: 0;
  transition: color 0.15s;
}
.mod-toggle-btn:hover { color: #bbb; }
.mod-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mod-btn {
  padding: 4px 8px;
  font-size: 0.72rem;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1e1e38;
  color: #999;
  cursor: pointer;
  transition: all 0.15s;
}
.mod-btn:hover { border-color: #666; color: #ccc; }
.mod-btn.mod-active {
  background: #2a3a5a;
  border-color: #5588cc;
  color: #88bbff;
}

/* ── Settle Banner ── */
#settle-banner {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.settle-content {
  text-align: center;
  background: rgba(15, 15, 28, 0.88);
  border: 1px solid #555;
  border-radius: 12px;
  padding: 28px 48px;
  backdrop-filter: blur(4px);
}

.settle-icon {
  font-size: 3rem;
  color: #f0c040;
  margin-bottom: 6px;
}

.settle-content h2 {
  font-size: 1.3rem;
  color: #f0c040;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.settle-content p {
  color: #aaa;
  font-size: 0.9rem;
}

.settle-tip {
  color: #888;
  font-size: 0.78rem;
  font-style: italic;
  margin-top: 4px;
}

.settle-timer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.settle-timer-bar-bg {
  flex: 1;
  height: 6px;
  background: #2a2a3e;
  border-radius: 3px;
  overflow: hidden;
}

.settle-timer-bar {
  height: 100%;
  background: linear-gradient(90deg, #f0c040, #e08030);
  border-radius: 3px;
  transition: width 1s linear;
}

.settle-timer-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f0c040;
  min-width: 30px;
  text-align: right;
}

/* ── HUD Bar ── */
#hud-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(12, 12, 24, 0.92);
  padding: 0 16px;
  display: flex;
  align-items: center;
  height: 48px;
  gap: 2px;
  border-bottom: 1px solid #2a2a3e;
  font-size: 0.82rem;
  z-index: 15;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}

.hud-icon {
  font-size: 1.2rem;
  width: 20px;
  text-align: center;
}

.hud-icon-img {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.hud-icon-tiles { color: #ccc; }
.hud-icon-pop { color: #aaa; }
.hud-icon-econ { color: #f0c040; }
.hud-icon-def { color: #5b9bd5; }
.hud-icon-mil { color: #e05050; }
.hud-icon-tech { color: #50c878; }

.hud-stat-body {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.hud-stat-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

.hud-stat-label {
  font-size: 0.65rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tech-progress-wrap {
  width: 100%;
  height: 3px;
  background: #333;
  border-radius: 2px;
  margin-top: 2px;
  overflow: hidden;
}

.tech-progress-bar {
  height: 100%;
  background: #9b59b6;
  border-radius: 2px;
  width: 0%;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.hud-divider {
  width: 1px;
  height: 28px;
  background: #333;
  margin: 0 6px;
}

.hud-spacer {
  flex: 1;
}

/* ── Investment Delta ── */
.hud-delta {
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 2px;
  min-width: 50px;
  transition: color 0.3s;
  color: #777;
}

.hud-delta.delta-up {
  color: #50c878;
}

.hud-delta.delta-down {
  color: #e05050;
  opacity: 0.6;
}

.hud-delta.delta-capped {
  color: #f0c040;
  opacity: 0.8;
}

/* ── Right panel (leaderboard + status bar) ── */
#right-panel {
  position: absolute;
  top: 60px;
  right: 12px;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
  transition: transform 0.25s ease;
}

/* ── Status Bar (buffs/debuffs/weariness) — below leaderboard ── */
#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  background: rgba(12, 12, 24, 0.88);
  border: 1px solid #2a2a3e;
  border-radius: 8px;
}

#status-bar:empty {
  display: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-icon {
  font-size: 0.7rem;
}

.status-pill-buff {
  background: rgba(80, 200, 120, 0.18);
  border: 1px solid rgba(80, 200, 120, 0.35);
  color: #5ddf5d;
}

.status-pill-debuff {
  background: rgba(224, 80, 80, 0.18);
  border: 1px solid rgba(224, 80, 80, 0.35);
  color: #e85454;
}

.status-pill-war {
  background: rgba(224, 80, 80, 0.18);
  border: 1px solid rgba(224, 80, 80, 0.35);
  color: #e85454;
}

.status-timer {
  color: inherit;
  opacity: 0.55;
  font-size: 0.6rem;
  margin-left: auto;
}

/* ── Investment Panel ── */
#invest-panel {
  position: absolute;
  top: 60px;
  left: 12px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  border-radius: 10px;
  padding: 16px;
  width: 260px;
  backdrop-filter: blur(4px);
  transition: transform 0.25s ease;
}

/* ── Panel collapse tabs (landscape) ── */
.panel-tab {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 6px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  color: #999;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  z-index: 10;
  writing-mode: vertical-lr;
  white-space: nowrap;
}

.panel-tab:hover {
  color: #f0c040;
}

.panel-tab-left {
  left: 0;
  border-radius: 0 6px 6px 0;
  border-left: none;
}

.panel-tab-right {
  right: 0;
  border-radius: 6px 0 0 6px;
  border-right: none;
}

@media (max-width: 1400px) {
  #hud-bar {
    padding: 0 8px;
    gap: 1px;
    height: 42px;
    font-size: 0.75rem;
  }

  .hud-stat {
    gap: 4px;
    padding: 0 5px;
  }

  .hud-icon-img {
    width: 16px;
    height: 16px;
  }

  .hud-stat-val {
    font-size: 0.82rem;
  }

  .hud-stat-label {
    font-size: 0.58rem;
  }

  .hud-delta {
    font-size: 0.62rem;
    min-width: 36px;
  }

  .hud-divider {
    height: 22px;
    margin: 0 3px;
  }

  .hud-timer {
    font-size: 0.78rem;
    padding: 0 4px;
  }

  .hud-menu-btn {
    padding: 3px 8px;
    font-size: 0.68rem;
  }

  .hud-music-btn {
    font-size: 0.8rem;
  }

  #invest-panel {
    top: 46px;
  }

  #right-panel {
    top: 54px;
  }
}

@media (max-height: 800px) and (max-width: 1200px) and (orientation: landscape) {
  .panel-tab {
    display: block;
    top: calc(50% + 24px);
  }

  #invest-panel {
    top: 52px;
    left: 0;
    border-radius: 0 10px 10px 0;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    padding: 10px 12px;
    width: 230px;
  }

  #invest-panel.panel-collapsed {
    display: none !important;
  }

  #right-panel {
    top: 52px;
    right: 0;
    border-radius: 10px 0 0 10px;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }

  #right-panel.panel-collapsed {
    display: none !important;
  }
}

.invest-header {
  margin-bottom: 14px;
}

.invest-header h3 {
  font-size: 0.9rem;
  color: #f0c040;
  letter-spacing: 1px;
  font-weight: 600;
}

.invest-slider {
  margin-bottom: 14px;
}

.invest-slider:last-child {
  margin-bottom: 0;
}

.invest-label-row {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
}

.invest-icon {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  margin-right: 6px;
}

.invest-icon-img {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
  margin-right: 6px;
  flex-shrink: 0;
}

.invest-name {
  flex: 1;
  font-size: 0.82rem;
  color: #ccc;
  font-weight: 500;
}

.invest-pct {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  min-width: 36px;
  text-align: right;
}

.invest-track {
  position: relative;
  height: 8px;
  background: #1a1a2e;
  border-radius: 4px;
}

.invest-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease-out, opacity 0.3s ease;
  opacity: 0.7;
}

.invest-fill-maxed {
  opacity: 1;
  animation: invest-pulse 1.5s ease-in-out infinite;
}

@keyframes invest-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.invest-unallocated {
  text-align: center;
  font-size: 0.78rem;
  color: #f0c040;
  margin-top: 6px;
  animation: invest-pulse 1.5s ease-in-out infinite;
}

.invest-track input[type="range"] {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 20px;
  margin: 0;
  transform: translateY(-50%);
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  outline: none;
}

.invest-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #555;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
  cursor: pointer;
  margin-top: -4px;
}

.invest-track input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #555;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
  cursor: pointer;
}

.invest-track input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
}

.invest-track input[type="range"]::-moz-range-track {
  height: 8px;
  background: transparent;
  border: none;
}

/* ── Expand Toggle ── */
/* toggles-panel removed — toggles are now in hud-bar */

#mil-reserve-wrap {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.expand-toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.expand-toggle-label input {
  display: none;
}

.expand-toggle-slider {
  width: 36px;
  height: 20px;
  background: #333;
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
}

.expand-toggle-slider::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #888;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}

.expand-toggle-label input:checked + .expand-toggle-slider {
  background: rgba(204, 204, 204, 0.3);
}

.expand-toggle-label input:checked + .expand-toggle-slider::after {
  transform: translateX(16px);
  background: #ccc;
}

.expand-toggle-text {
  font-size: 0.82rem;
  color: #ccc;
  font-weight: 500;
}

.hud-toggle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  padding: 0 4px;
}
.hud-toggle-label input { display: none; }
.hud-toggle-slider {
  width: 28px;
  height: 14px;
  background: #333;
  border-radius: 7px;
  position: relative;
  transition: background 0.2s;
}
.hud-toggle-slider::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: #666;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.hud-toggle-label input:checked + .hud-toggle-slider {
  background: rgba(240, 192, 64, 0.3);
}
.hud-toggle-label input:checked + .hud-toggle-slider::after {
  transform: translateX(14px);
  background: #f0c040;
}
.hud-toggle-text {
  font-size: 0.68rem;
  color: #888;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.hud-toggle-label input:checked ~ .hud-toggle-text {
  color: #ccc;
}
.hud-toggle-label input:checked + .auto-expand-slider {
  background: rgba(68, 221, 85, 0.3);
}
.hud-toggle-label input:checked + .auto-expand-slider::after {
  background: #44dd55;
}
.hud-btn-active {
  color: #f0c040 !important;
  border-color: rgba(240, 192, 64, 0.4) !important;
}

/* ── Dashboard ── */
#dashboard {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 260px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.8rem;
  backdrop-filter: blur(4px);
}

.dash-row {
  display: flex;
  align-items: center;
  padding: 3px 0;
}

.dash-label {
  color: #888;
  flex: 1;
  font-size: 0.78rem;
}

.dash-val {
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  min-width: 40px;
  text-align: right;
}

.dash-negative {
  color: #e57373;
}

.dash-trend {
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 4px;
  min-width: 20px;
}

.dash-trend.trend-up {
  color: #50c878;
}

.dash-trend.trend-down {
  color: #e05050;
}

.dash-rival-bar {
  width: 80px;
  height: 8px;
  background: #e05050;
  border-radius: 4px;
  overflow: hidden;
  margin-left: 8px;
}

.dash-rival-me {
  height: 100%;
  border-radius: 4px 0 0 4px;
  transition: width 0.3s ease-out;
}

.dash-toggle {
  margin-top: 6px;
  text-align: center;
  color: #666;
  font-size: 0.72rem;
  cursor: pointer;
  user-select: none;
}

.dash-toggle:hover {
  color: #999;
}

/* ── Tile Panel ── */

#tile-info {
  margin-bottom: 8px;
}

.tp-header {
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: capitalize;
  margin-bottom: 6px;
}

.tp-coords {
  font-weight: 400;
  color: #777;
  font-size: 0.8rem;
}

.tp-terrain-desc {
  color: #888;
  font-size: 0.78rem;
  font-style: italic;
  margin-bottom: 6px;
}

.tp-owner {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  color: #ccc;
}

.tp-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.tp-troops {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 3px;
  color: #e87070;
  font-size: 0.85em;
}

.tp-stats {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tp-stat {
  font-size: 0.85rem;
  color: #ccc;
}

.tp-stat-icon {
  margin-right: 4px;
}

.tp-stat-icon-img {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  margin-right: 4px;
  vertical-align: middle;
}

.tp-base {
  color: #666;
  font-size: 0.75rem;
}

.tp-building {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid #3a3a4e;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
}

.tp-building-img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.tp-building-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tp-building-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: #e8d8a0;
}

.tp-building-bonus {
  font-size: 0.78rem;
  color: #8bc34a;
}

.tp-building-level {
  font-size: 0.72rem;
  color: #777;
}

.tp-no-building {
  color: #555;
  font-size: 0.78rem;
  font-style: italic;
  margin: 4px 0;
}

.tp-player-stats {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid #2a2a3e;
  border-radius: 6px;
  padding: 6px 8px;
  margin: 4px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 8px;
}

.tp-profile {
  grid-column: 1 / -1;
  font-weight: 700;
  font-size: 0.8rem;
  color: #c0a0ff;
  margin-bottom: 2px;
}

.tp-pstat {
  font-size: 0.78rem;
  color: #bbb;
  white-space: nowrap;
}

.tp-fog {
  color: #666;
  font-style: italic;
  font-size: 0.72rem;
  padding: 4px 0;
}

/* Garrison strength labels */
.str-vstrong { color: #2ecc71; font-weight: 700; }
.str-strong { color: #4ecb7b; font-weight: 600; }
.str-moderate { color: #f0c040; font-weight: 600; }
.str-weak { color: #e67e22; font-weight: 600; }
.str-minimal { color: #e74c3c; font-weight: 600; }

#tile-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.action-btn {
  padding: 6px 12px;
  background: #4a6fa5;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s;
}

.action-btn:hover {
  background: #5a8fd5;
}

.settle-btn {
  padding: 10px 16px;
  background: linear-gradient(135deg, #f0c040, #d4a020);
  border: none;
  border-radius: 8px;
  color: #1a1a2e;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(240, 192, 64, 0.3);
}

.settle-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(240, 192, 64, 0.45);
}

/* ── New Game Button ── */
#btn-new-game {
  padding: 0.65rem 2rem;
  background: linear-gradient(135deg, #f0c040, #d4a020);
  border: none;
  border-radius: 6px;
  color: #1a1a2e;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  transition: transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(240, 192, 64, 0.3);
}

#btn-new-game:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(240, 192, 64, 0.45);
}

.hud-new-game-wrap {
  margin-right: 8px;
}

.hud-new-game-btn {
  padding: 4px 12px;
  background: rgba(240, 192, 64, 0.15);
  border: 1px solid rgba(240, 192, 64, 0.3);
  border-radius: 4px;
  color: #f0c040;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background 0.15s;
}

.hud-new-game-btn:hover {
  background: rgba(240, 192, 64, 0.25);
}

/* ── Diplomacy Buttons ── */
.action-btn-war {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  font-weight: 600;
}

.action-btn-war:hover {
  background: linear-gradient(135deg, #ff6b5b, #e74c3c);
}

.action-btn-peace {
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  color: #fff;
  font-weight: 600;
}

.action-btn-peace:hover {
  background: linear-gradient(135deg, #4edc91, #2ecc71);
}

.action-btn:disabled, .action-btn-disabled {
  opacity: 0.5;
  cursor: default;
}

.action-btn-rush {
  background: linear-gradient(135deg, #f0c040, #e6a020);
  color: #1a1a2e;
  font-weight: 600;
}

.action-btn-rush:hover:not(:disabled) {
  background: linear-gradient(135deg, #f5d060, #f0c040);
}

.expand-mode-btn {
  position: fixed;
  bottom: 70px;
  right: 12px;
  z-index: 200;
  padding: 8px 14px;
  border: 2px solid #00b894;
  border-radius: 8px;
  background: rgba(26, 26, 46, 0.85);
  color: #00b894;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  display: none;
}

.expand-mode-btn:hover {
  background: rgba(0, 184, 148, 0.15);
}

.expand-mode-active {
  background: #00b894 !important;
  color: #1a1a2e !important;
  border-color: #00d9a7 !important;
}

@media (max-width: 900px) {
  .expand-mode-btn {
    bottom: 60px;
    right: 8px;
    padding: 6px 10px;
    font-size: 0.75rem;
  }
}

.action-btn-attack {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  font-weight: 600;
}

.action-btn-attack:hover {
  background: linear-gradient(135deg, #ff6b5b, #e74c3c);
}

.action-btn-expand {
  background: linear-gradient(135deg, #00b894, #00a67d);
  color: #fff;
  font-weight: 600;
}

.action-btn-expand:hover {
  background: linear-gradient(135deg, #00d9a7, #00b894);
}

/* ── Peace Panel (persistent, replaces ephemeral proposals) ── */
#peace-panel {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 26, 46, 0.95);
  border: 1px solid rgba(46, 204, 113, 0.4);
  border-radius: 8px;
  padding: 10px 16px;
  z-index: 210;
  min-width: 260px;
  max-width: 400px;
}

.peace-panel-header {
  font-size: 0.78rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  text-align: center;
}

.peace-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid #333;
}

.peace-entry:first-child {
  border-top: none;
}

.peace-entry-text {
  flex: 1;
  font-size: 0.85rem;
  color: #e0e0e0;
  font-weight: 600;
}

.peace-entry-btn {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* ── War Confirm Dialog ── */
#war-confirm {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.war-confirm-box {
  background: #2a2a3e;
  border: 1px solid #e74c3c;
  border-radius: 10px;
  padding: 24px 32px;
  text-align: center;
  max-width: 340px;
}

.war-confirm-text {
  font-size: 1rem;
  font-weight: 700;
  color: #e0e0e0;
  margin-bottom: 6px;
}

.war-confirm-sub {
  font-size: 0.82rem;
  color: #999;
  margin-bottom: 16px;
}

.war-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ── Settlement Tooltip ── */
#settle-tooltip {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 15, 28, 0.95);
  border: 2px solid #f0c040;
  border-radius: 8px;
  padding: 14px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #f0c040;
  z-index: 200;
  text-align: center;
  animation: settle-pulse 2s ease-in-out infinite;
}

.settle-confirm-btn {
  margin-top: 10px;
  padding: 8px 24px;
  background: #f0c040;
  color: #1a1a2e;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.settle-confirm-btn:hover {
  background: #ffd866;
}

@keyframes settle-pulse {
  0%, 100% { border-color: #f0c040; box-shadow: 0 0 8px rgba(240,192,64,0.3); }
  50% { border-color: #ffd866; box-shadow: 0 0 16px rgba(240,192,64,0.5); }
}

.stt-terrain {
  text-transform: capitalize;
  font-weight: 700;
  color: #f0c040;
  margin-bottom: 2px;
}

.stt-desc {
  color: #999;
  font-size: 0.75rem;
  font-style: italic;
  margin-bottom: 4px;
}

.stt-stats {
  display: flex;
  gap: 12px;
  font-weight: 600;
}

/* ── Peace Proposal (legacy compat, hidden) ── */
.peace-proposal {
  display: none;
}

/* ── Waiting Screen ── */
#waiting-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
}

.waiting-box {
  text-align: center;
  background: #2a2a3e;
  padding: 2.5rem 3rem;
  border-radius: 12px;
  border: 1px solid #444;
}

.waiting-box h2 {
  color: #f0c040;
  font-size: 1.6rem;
  margin-bottom: 12px;
  letter-spacing: 2px;
}

.waiting-dots {
  font-size: 2rem;
  color: #f0c040;
  letter-spacing: 6px;
}

.waiting-dots span {
  animation: waitDot 1.4s infinite;
  opacity: 0;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes waitDot {
  0%, 80%, 100% { opacity: 0; }
  40% { opacity: 1; }
}

.waiting-count {
  color: #ccc;
  font-size: 1.1rem;
  margin-top: 16px;
  font-weight: 600;
}

.waiting-timer {
  color: #f0c040;
  font-size: 1.4rem;
  font-weight: 700;
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

.waiting-hint {
  color: #888;
  font-size: 0.85rem;
  margin-top: 8px;
}

.lobby-player-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 16px 0;
  max-width: 400px;
}

.lobby-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.lobby-slot-filled {
  background: rgba(80, 200, 120, 0.12);
  border: 1px solid rgba(80, 200, 120, 0.3);
}

.lobby-slot-empty {
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed #444;
}

.lobby-slot-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.lobby-slot-icon {
  width: 12px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.lobby-slot-name {
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-slot-empty .lobby-slot-name {
  color: #555;
  font-style: italic;
}

.waiting-cancel-btn {
  margin-top: 20px;
  padding: 8px 28px;
  background: transparent;
  border: 1px solid #666;
  color: #aaa;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.waiting-cancel-btn:hover {
  border-color: #e74c3c;
  color: #e74c3c;
}

/* ── Game Timer ── */
.hud-timer {
  font-size: 0.9rem;
  font-weight: 700;
  color: #aaa;
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  letter-spacing: 0.5px;
}

/* ── Leaderboard ── */
#leaderboard {
  background: rgba(12, 12, 24, 0.88);
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.78rem;
}

.lb-header {
  color: #888;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-align: center;
}

.lb-entry {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
}

.lb-me {
  background: rgba(255, 255, 255, 0.08);
  font-weight: 700;
}

.lb-rank {
  color: #888;
  min-width: 22px;
  font-size: 0.72rem;
}

.lb-color {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  color: #ccc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-tiles {
  color: #fff;
  font-weight: 700;
  min-width: 24px;
  text-align: right;
}

/* ── Kill Feed ── */
#kill-feed {
  position: absolute;
  top: 60px;
  right: 260px;
  width: 240px;
  max-height: 50vh;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.kf-entry {
  background: rgba(12, 12, 24, 0.8);
  padding: 4px 10px;
  margin-bottom: 3px;
  border-radius: 4px;
  border-left: 3px solid #fff;
  font-size: 0.75rem;
  color: #ccc;
  transition: opacity 0.5s;
  pointer-events: none;
}

.kf-viking {
  background: linear-gradient(90deg, rgba(139, 0, 0, 0.9), rgba(180, 130, 0, 0.7));
  border-left: 4px solid #ffd700;
  color: #fff;
  font-size: 0.9rem;
  font-weight: bold;
  padding: 6px 12px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  animation: kf-viking-flash 0.6s ease-out;
}

@keyframes kf-viking-flash {
  0% { transform: scale(1.3); filter: brightness(2); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* ── Minimap ── */
#minimap-wrap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  border: 1px solid #2a2a3e;
  border-radius: 4px;
  overflow: hidden;
  background: #0c0c18;
}

#minimap-canvas {
  display: block;
  image-rendering: pixelated;
  width: 120px;
  height: 120px;
}

/* ── Game Event Popup ── */
#game-event-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 250;
  animation: eventFadeIn 0.3s ease;
}
@keyframes eventFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.event-box {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E"),
    linear-gradient(170deg, #4a3a22 0%, #3a2c18 30%, #2c2010 70%, #3a2c18 100%);
  border: none;
  border-radius: 2px;
  max-width: 380px;
  overflow: visible;
  box-shadow:
    0 0 0 3px #6b5020,
    0 0 0 5px #3a2a10,
    0 0 0 6px #8b6914,
    0 4px 30px rgba(0,0,0,0.6),
    inset 0 0 80px rgba(0,0,0,0.3);
  animation: eventSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}
.event-box::before,
.event-box::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 12px;
  background: radial-gradient(ellipse, rgba(139,105,20,0.25) 0%, transparent 70%);
}
.event-box::before { top: -6px; }
.event-box::after { bottom: -6px; }

@keyframes eventSlideIn {
  from { transform: scale(0.9) translateY(-20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.event-img-wrap {
  width: 100%;
  height: 180px;
  overflow: hidden;
  border-bottom: 2px solid #8b6914;
  position: relative;
}
.event-img-wrap::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to top, #3a2c18, transparent);
}
.event-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.event-body {
  padding: 18px 22px 22px;
}

.event-title {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: #f0c040;
  text-align: center;
  letter-spacing: 1px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.7), 0 0 12px rgba(240,192,64,0.2);
}

.event-divider {
  width: 80px;
  height: 2px;
  margin: 10px auto 12px;
  background: linear-gradient(90deg, transparent, #8b6914 30%, #c89820, #8b6914 70%, transparent);
  position: relative;
}
.event-divider::before {
  content: '\2726';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #c89820;
  font-size: 10px;
  background: #3a2c18;
  padding: 0 6px;
}

.event-desc {
  color: #c4a878;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 0.88rem;
  margin-bottom: 16px;
  line-height: 1.5;
  text-align: center;
  font-style: italic;
}

.event-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-choice-btn {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  background: rgba(50, 40, 20, 0.6);
  border: 1px solid rgba(139, 105, 20, 0.35);
  border-left: 3px solid #8b6914;
  border-radius: 2px;
  color: #e0d0b0;
  cursor: pointer;
  transition: all 0.15s;
}

.event-choice-btn:hover {
  background: rgba(139, 105, 20, 0.3);
  border-color: #c89820;
  border-left-color: #f0c040;
  box-shadow: 0 0 12px rgba(240, 192, 64, 0.15);
}

.event-choice-label {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #f0c040;
}

.event-choice-effect {
  font-size: 0.78rem;
  margin-top: 3px;
  line-height: 1.4;
  color: #b0a080;
}
.event-effect-buff {
  color: #5ddf5d;
  font-weight: 600;
}
.event-effect-debuff {
  color: #e85454;
  font-weight: 600;
}

/* ── Attack Controls ── */
.attack-controls {
  margin-top: 4px;
}

.attack-slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: #ccc;
  margin-bottom: 4px;
}

.attack-slider-troops {
  color: #e05050;
  font-weight: 600;
}

.attack-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 3px;
  outline: none;
}

.attack-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #e05050;
  border-radius: 50%;
  cursor: pointer;
}

.attack-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #e05050;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* ── Priority Buttons ── */
.action-btn-prio {
  background: linear-gradient(135deg, #555, #444);
  color: #ccc;
  border: 1px solid #666;
}

.action-btn-prio:hover {
  background: linear-gradient(135deg, #665, #554);
  color: #ffcc00;
}

.action-btn-prio-active {
  background: linear-gradient(135deg, #6a5a10, #554810);
  color: #ffcc00;
  border: 1px solid #ffcc00;
  font-weight: 700;
}

.action-btn-prio-active:hover {
  background: linear-gradient(135deg, #7a6a20, #665920);
}

/* ── Results Screen ── */
#results-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.results-box {
  background: #2a2a3e;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  min-width: 360px;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

#results-rankings {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.results-box h2 {
  color: #f0c040;
  font-size: 1.5rem;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.results-desc {
  color: #ccc;
  font-size: 0.95rem;
  margin-bottom: 16px;
  text-align: center;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.85rem;
}

.results-table th {
  color: #888;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 8px;
  border-bottom: 1px solid #444;
  text-align: left;
}

.results-table td {
  padding: 6px 8px;
  color: #ccc;
}

.results-me td {
  color: #fff;
  font-weight: 700;
  background: rgba(240, 192, 64, 0.1);
}

.results-stats {
  margin: 12px 0 4px;
  padding: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
}

.results-stats-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #f0c040;
  margin-bottom: 6px;
}

.results-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  font-size: 0.75rem;
  color: #aaa;
}

.play-again-btn {
  padding: 12px 32px;
  background: linear-gradient(135deg, #f0c040, #d4a020);
  border: none;
  border-radius: 8px;
  color: #1a1a2e;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 1px;
  transition: transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(240, 192, 64, 0.3);
}

.play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(240, 192, 64, 0.5);
}

.results-btn-row {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.results-btn-row .play-again-btn {
  flex: 1;
}

.results-btn-secondary {
  background: linear-gradient(135deg, #555, #444);
  color: #ddd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.results-btn-secondary:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.results-defeat {
  color: #e05050 !important;
}

/* ── Simulate Button ── */
.menu-btn-simulate {
  background: linear-gradient(135deg, #4a6fa5, #3a5f95);
  color: #e0e0e0;
}

.menu-btn-simulate:hover {
  background: linear-gradient(135deg, #5a8fd5, #4a6fa5);
}

.menu-btn-online {
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  color: #fff;
}

.menu-btn-online:hover {
  background: linear-gradient(135deg, #3ddb80, #2ecc71);
}

/* ── Simulation Speed Controls ── */
#sim-controls {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  border-radius: 8px;
  padding: 6px 14px;
  z-index: 10;
}

.sim-back-btn {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid #444;
  border-radius: 5px;
  color: #ccc;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.sim-back-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.sim-divider {
  width: 1px;
  height: 20px;
  background: #444;
}

.sim-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-right: 4px;
}

.sim-speed-btn {
  padding: 4px 10px;
  background: #2a2a4a;
  border: 1px solid #444;
  border-radius: 5px;
  color: #ccc;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.sim-speed-btn:hover {
  background: #3a3a5a;
  border-color: #666;
}

.sim-speed-btn.sim-speed-active {
  background: rgba(240, 192, 64, 0.2);
  border-color: #f0c040;
  color: #f0c040;
}

.sim-toggle-btn {
  padding: 4px 10px;
  background: #2a2a4a;
  border: 1px solid #444;
  border-radius: 5px;
  color: #ccc;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.sim-toggle-btn:hover {
  background: #3a3a5a;
  border-color: #666;
}

.sim-toggle-btn.sim-toggle-active {
  background: rgba(240, 192, 64, 0.2);
  border-color: #f0c040;
  color: #f0c040;
}

.sim-timer {
  font-size: 0.85rem;
  font-weight: 700;
  color: #f0c040;
  letter-spacing: 1px;
  margin-left: 4px;
}

/* ── HUD Menu Button ── */
.hud-menu-btn {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #444;
  border-radius: 5px;
  color: #888;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.hud-menu-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ccc;
}

.hud-menu-btn.hud-toggle-active {
  background: rgba(240, 192, 64, 0.15);
  border-color: rgba(240, 192, 64, 0.4);
  color: #f0c040;
}

.hud-music-btn {
  font-size: 0.9rem;
  min-width: 28px;
  text-align: center;
}
.hud-music-btn.music-active {
  color: #f0c040;
  border-color: rgba(240, 192, 64, 0.4);
}

.menu-music-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.menu-music-btn {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #444;
  border-radius: 5px;
  color: #888;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.menu-music-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ccc;
}
.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 2px;
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #f0c040;
  border-radius: 50%;
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #f0c040;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.menu-music-btn.music-active {
  color: #f0c040;
  border-color: rgba(240, 192, 64, 0.4);
}

/* ── Tech Bonus Label ── */
.tech-bonus-label {
  color: #50c878;
  font-weight: 700;
  font-size: 0.65rem;
}

.econ-output-label {
  color: #f0c040;
  font-weight: 700;
  font-size: 0.65rem;
}

.def-progress-label {
  color: #5b9bd5;
  font-weight: 700;
  font-size: 0.65rem;
}

/* ── Attack Allocation Panel ── */
#attack-panel {
  position: absolute;
  top: 60px;
  left: 284px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 200px;
  max-width: 240px;
  backdrop-filter: blur(4px);
}

/* ── CrazyGames iframe safety ── */
body {
  user-select: none;
  -webkit-user-select: none;
}

/* ── Investment Presets ── */
.invest-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.invest-preset-btn {
  flex: 1;
  padding: 5px 2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #3a3a4e;
  border-radius: 5px;
  color: #aaa;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.invest-preset-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #e0e0e0;
  border-color: #555;
}

.invest-preset-btn.preset-active {
  background: rgba(240, 192, 64, 0.15);
  border-color: rgba(240, 192, 64, 0.4);
  color: #f0c040;
}

.invest-toggles {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #2a2a3e;
}
.invest-toggles .hud-toggle-label {
  padding: 0;
  gap: 3px;
}
.invest-toggles .hud-toggle-text {
  font-size: 0.62rem;
}
.invest-toggles .hud-menu-btn {
  font-size: 0.62rem;
  padding: 3px 8px;
}

/* ── Panel Close Button ── */
.panel-close-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: #666;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.panel-close-btn:hover {
  color: #e0e0e0;
  background: rgba(255, 255, 255, 0.1);
}

#tile-panel {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #2a2a3e;
  border-radius: 10px;
  padding: 14px;
  padding-top: 28px;
  min-width: 200px;
  max-width: 280px;
  font-size: 0.85rem;
  backdrop-filter: blur(4px);
}

/* ── Controls Hint ── */
#controls-hint {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 12, 24, 0.92);
  border: 1px solid #3a3a4e;
  border-radius: 10px;
  padding: 14px 22px;
  z-index: 100;
  pointer-events: none;
  transition: opacity 1s ease;
}

.controls-hint-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ch-row {
  font-size: 0.82rem;
  color: #bbb;
  white-space: nowrap;
}

.ch-row kbd {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid #555;
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: monospace;
  color: #f0c040;
  margin: 0 2px;
}

/* ── Settle Prompt ── */
.settle-prompt-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f0c040;
  margin-bottom: 4px;
}

.settle-prompt-hint {
  font-size: 0.82rem;
  color: #aaa;
  margin-bottom: 6px;
}

.settle-stats-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 8px;
}

.settle-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: #ccc;
  font-weight: 600;
}

.settle-stat-icon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
}

/* ── Minimap click cursor ── */
#minimap-canvas {
  cursor: pointer;
}

/* ── Bot badge in leaderboard ── */
.lb-bot {
  font-size: 0.6rem;
  color: #888;
  font-weight: 400;
}
.lb-viking {
  font-size: 0.6rem;
  color: #e44;
  font-weight: 600;
}

.lb-entry:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ── Mobile Bottom Nav ── */
#mobile-nav {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(12, 12, 24, 0.95);
  border-top: 1px solid #2a2a3e;
  z-index: 200;
  padding: 0 4px;
  align-items: center;
  justify-content: space-around;
  gap: 2px;
}

.mob-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: #888;
  font-size: 1.2rem;
  padding: 6px 8px;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  transition: color 0.15s;
}

.mob-nav-btn img {
  width: 22px !important;
  height: 22px !important;
}

.mob-nav-btn span {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.mob-nav-btn.mob-nav-active {
  color: #f0c040;
}

/* ── Mobile Panel Drawer ── */
.mobile-drawer {
  display: none;
  position: absolute;
  bottom: 52px;
  left: 0;
  right: 0;
  max-height: 45vh;
  overflow-y: auto;
  background: rgba(12, 12, 24, 0.95);
  border-top: 1px solid #2a2a3e;
  z-index: 199;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.mobile-drawer.drawer-open {
  transform: translateY(0);
}

/* ── Mobile HUD (compact top bar) ── */
#mobile-hud-bar {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(12, 12, 24, 0.94);
  border-bottom: 1px solid #2a2a3e;
  padding: 6px 10px;
  z-index: 50;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
}

.mob-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: #ccc;
  white-space: nowrap;
}

.mob-stat img {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
}

.mob-stat-val {
  font-weight: 700;
  color: #fff;
  font-size: 0.9rem;
}

.mob-hud-timer {
  font-weight: 700;
  color: #f0c040;
  font-size: 0.9rem;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ── Mobile: Landscape ── */
@media (max-width: 900px) and (orientation: landscape) {
  #mobile-nav {
    flex-direction: column;
    height: auto;
    width: 52px;
    bottom: 0;
    top: 0;
    left: auto;
    right: 0;
    border-top: none;
    border-left: 1px solid #2a2a3e;
    padding: 4px 0;
    justify-content: center;
  }

  .mob-nav-btn span {
    display: none;
  }

  .mobile-drawer {
    bottom: 0;
    right: 52px;
    left: auto;
    width: 280px;
    max-height: 100vh;
    border-top: none;
    border-left: 1px solid #2a2a3e;
    transform: translateX(100%);
  }

  .mobile-drawer.drawer-open {
    transform: translateX(0);
  }

  #mobile-hud-bar {
    right: 52px;
  }
}

/* ── Mobile Responsive: Small screens ── */
@media (max-width: 768px) {
  /* Hide desktop-only elements */
  #hud-bar,
  #invest-panel,
  #right-panel,
  #kill-feed,
  #minimap-wrap,
  #dashboard,
  #deployment-panel,
  #controls-hint {
    display: none !important;
  }

  /* Show mobile elements */
  #mobile-nav {
    display: flex;
  }

  #mobile-hud-bar {
    display: flex;
  }

  .mobile-drawer {
    display: block;
  }

  /* Tile panel becomes bottom drawer on mobile */
  #tile-panel {
    position: absolute;
    bottom: 52px;
    left: 0;
    right: 0;
    top: auto;
    max-width: none;
    min-width: 0;
    border-radius: 10px 10px 0 0;
    max-height: 40vh;
    overflow-y: auto;
    z-index: 198;
  }

  /* Settle tooltip adjustments */
  #settle-tooltip {
    top: auto;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 90vw;
    font-size: 0.95rem;
    padding: 10px 18px;
  }

  /* Peace panel */
  #peace-panel {
    top: auto;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 90vw;
  }

  /* War confirm dialog */
  .war-confirm-box {
    max-width: 90vw;
    padding: 18px 20px;
  }

  /* Event popup mobile */
  .event-box {
    max-width: 90vw;
    margin: 12px;
  }

  .event-body {
    padding: 14px 16px 18px;
  }

  /* Results screen mobile */
  .results-box {
    min-width: 0;
    max-width: 90vw;
    padding: 20px;
  }

  /* Menu adjustments */
  .menu-title {
    font-size: 2.2rem;
    letter-spacing: 3px;
  }

  .menu-box {
    padding: 1.5rem 1.2rem 1rem;
  }

  .menu-btn {
    width: 100%;
    max-width: 320px;
  }

  .menu-tabs {
    width: 100%;
    max-width: 320px;
  }

  .menu-option-row {
    width: 100%;
    max-width: 320px;
  }

  .menu-modifiers {
    width: 100%;
    max-width: 320px;
  }

  /* Sim controls mobile */
  #sim-controls {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    border-radius: 0;
    border-top: 1px solid #2a2a3e;
    justify-content: center;
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 4px;
  }

  .sim-speed-btn,
  .sim-back-btn,
  .sim-toggle-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
  }

  /* Investment sliders touch-friendly */
  .invest-track input[type="range"] {
    height: 36px;
  }

  .invest-track input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  .invest-track input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  /* Attack slider touch-friendly */
  .attack-slider::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
  }

  .attack-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }
}

/* ── Mobile Responsive: Landscape small screens ── */
/* ── Short viewport (landscape phones/tablets) — two-column menu ── */
@media (max-height: 700px) and (max-width: 1200px) and (orientation: landscape) {
  #main-menu {
    align-items: center;
    padding: 0;
  }

  .menu-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "title   title"
      "sub     sub"
      "tabs    tabs"
      "config  stats"
      "music   music";
    gap: 0 16px;
    padding: 8px 14px;
    width: 620px;
    max-width: 95vw;
    max-height: 98vh;
    text-align: left;
  }

  .menu-title {
    grid-area: title;
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 0;
  }

  .menu-sub {
    grid-area: sub;
    text-align: center;
    font-size: 0.7rem;
    margin-bottom: 4px;
  }

  .menu-tabs {
    grid-area: tabs;
    margin-bottom: 6px;
    max-width: none;
    width: 100%;
  }

  .menu-buttons {
    grid-area: config;
    align-items: stretch;
  }

  .menu-btn {
    width: 100%;
    padding: 8px 0;
    font-size: 0.95rem;
  }

  .menu-config-options {
    width: 100%;
  }

  .menu-option-row {
    padding: 2px 0;
    max-width: none;
    width: 100%;
  }

  .menu-option-row label {
    font-size: 0.8rem;
  }

  .option-stepper span {
    font-size: 0.85rem;
    min-width: 50px;
  }

  .menu-modifiers {
    max-width: none;
    width: 100%;
  }

  .menu-mode-desc {
    font-size: 0.7rem;
    margin: 2px 0;
  }

  .player-stats {
    grid-area: stats;
    align-self: start;
    padding-top: 4px;
  }

  .stats-row {
    font-size: 0.75rem;
    justify-content: flex-start;
  }

  .ach-row {
    gap: 3px;
    justify-content: flex-start;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .ach-badge {
    font-size: 0.6rem;
    padding: 2px 6px;
  }

  .menu-music-wrap {
    grid-area: music;
    justify-content: center;
    margin-top: 4px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  #hud-bar,
  #invest-panel,
  #right-panel,
  #kill-feed,
  #minimap-wrap,
  #dashboard,
  #deployment-panel,
  #controls-hint {
    display: none !important;
  }

  #mobile-nav {
    display: flex;
  }

  #mobile-hud-bar {
    display: flex;
    right: 52px;
  }

  .mobile-drawer {
    display: block;
  }

  #tile-panel {
    position: absolute;
    bottom: 0;
    right: 52px;
    left: auto;
    top: auto;
    width: 280px;
    max-width: none;
    min-width: 0;
    border-radius: 10px 0 0 0;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 198;
  }

  #settle-tooltip {
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    right: 64px;
    max-width: 60vw;
  }

  .results-box {
    max-height: 95vh;
  }

  .event-box {
    max-height: 90vh;
    overflow-y: auto;
  }

  .event-img-wrap {
    height: 100px;
  }

  /* Sim controls landscape */
  #sim-controls {
    top: auto;
    bottom: 0;
    left: 0;
    right: 52px;
    transform: none;
    border-radius: 0;
  }
}

/* ── Very small phones (< 380px) ── */
@media (max-width: 380px) {
  .menu-title {
    font-size: 1.8rem;
    letter-spacing: 2px;
  }

  .menu-sub {
    font-size: 0.85rem;
  }

  .menu-box {
    padding: 1rem 0.8rem;
  }

  .mob-stat {
    font-size: 0.65rem;
  }

  .mob-stat-val {
    font-size: 0.7rem;
  }
}
