/* ==========================================================================
   GamesJi Top War — Stylesheet
   Original design system. No third-party CSS frameworks.
   ========================================================================== */

/* ---------- Fonts (bundled locally, SIL Open Font License — see assets/fonts/OFL-LICENSE.txt) ---------- */
@font-face {
  font-family: 'WarSans';
  src: url('assets/fonts/LiberationSans-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'WarSans';
  src: url('assets/fonts/LiberationSans-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

/* ---------- Design tokens ---------- */
:root {
  /* Palette */
  --navy-950: #070f18;
  --navy-900: #0d1b2a;
  --navy-800: #16293d;
  --navy-700: #22384c;
  --navy-600: #2f4a61;
  --steel-400: #788c9c;
  --steel-200: #c4d1db;
  --olive-700: #425c33;
  --olive-500: #63824f;
  --olive-300: #8ca86e;
  --sand-300: #d6c59b;
  --gold-600: #c7850f;
  --gold-400: #ffb727;
  --gold-200: #ffd977;
  --orange-600: #c4481e;
  --orange-400: #ff6b35;
  --cyan-500: #3fd9f5;
  --cyan-700: #1796ad;
  --green-500: #4fc981;
  --green-700: #2c9459;
  --red-500: #e64444;
  --red-700: #aa2828;
  --purple-500: #ac6cf0;
  --white-100: #f5f8fa;

  /* Semantic */
  --bg-app: var(--navy-950);
  --panel: var(--navy-800);
  --panel-light: var(--navy-700);
  --accent: var(--gold-400);
  --accent-danger: var(--red-500);
  --text-main: var(--white-100);
  --text-dim: var(--steel-200);

  /* Type */
  --font-display: 'WarSans', 'Arial Black', system-ui, -apple-system, sans-serif;
  --font-body: 'WarSans', system-ui, -apple-system, sans-serif;

  /* Radii / shadow */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 999px;
  --shadow-panel: 0 6px 18px rgba(0,0,0,0.35);
  --shadow-btn: 0 4px 0 rgba(0,0,0,0.35);

  /* Layout */
  --hud-top-h: 64px;
  --bottom-nav-h: 68px;
  --ad-banner-h: 50px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- Reset ---------- */
* , *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overscroll-behavior: none;
}
body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-main);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
  position: fixed;
  inset: 0;
}
img { -webkit-user-drag: none; user-drag: none; pointer-events: none; }
button {
  font-family: var(--font-body);
  border: none; background: none; color: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Visible keyboard focus (accessibility) */
button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--cyan-500);
  outline-offset: 2px;
}

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  overflow: hidden;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 15px;
  padding: 13px 22px;
  border-radius: var(--r-md);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.08s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(3px); box-shadow: none !important; }
.btn-icon { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(180deg, var(--gold-200), var(--gold-400) 55%, var(--gold-600));
  color: #3a2405;
  box-shadow: var(--shadow-btn), inset 0 1px 0 rgba(255,255,255,0.5);
  border: 2px solid #8a5a08;
}
.btn-secondary {
  background: linear-gradient(180deg, var(--navy-600), var(--navy-700));
  color: var(--text-main);
  box-shadow: var(--shadow-btn), inset 0 1px 0 rgba(255,255,255,0.08);
  border: 2px solid var(--navy-950);
}
.btn-gold {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-600));
  color: #3a2405;
  border: 2px solid #8a5a08;
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}
.btn-danger {
  background: linear-gradient(180deg, #ee6b6b, var(--red-500) 60%, var(--red-700));
  color: #fff;
  border: 2px solid #6e1414;
  box-shadow: var(--shadow-btn);
}
.btn-large { padding: 17px 30px; font-size: 19px; border-radius: var(--r-lg); width: 100%; }
.btn-tiny { padding: 7px 12px; font-size: 12px; border-radius: var(--r-pill); }
.btn-icon-round {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(180deg, var(--navy-600), var(--navy-800));
  border: 2px solid var(--navy-950);
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
  padding: 0;
}
.btn-icon-round img { width: 22px; height: 22px; }
.btn-icon-round.btn-small { width: 38px; height: 38px; }
.btn-icon-round.btn-small img { width: 18px; height: 18px; }
.btn:disabled { filter: grayscale(0.6) brightness(0.7); pointer-events: none; }

/* Notification dot */
.notif-dot {
  position: absolute; top: -4px; right: -4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--red-500); border: 2px solid var(--navy-900);
}

/* ==========================================================================
   LOADING SCREEN
   ========================================================================== */
#loading-screen {
  background: radial-gradient(circle at 50% 30%, var(--navy-700), var(--navy-950) 75%);
  display: flex; align-items: center; justify-content: center;
}
.loading-wrap { display: flex; flex-direction: column; align-items: center; padding: 0 32px; text-align: center; }
.loading-logo { width: 110px; height: 110px; margin-bottom: 14px; animation: floatY 2.4s ease-in-out infinite; filter: drop-shadow(0 8px 18px rgba(0,0,0,0.5)); }
.loading-title {
  font-family: var(--font-display); font-size: 40px; letter-spacing: 0.08em; color: var(--white-100);
  text-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 0 26px rgba(255,183,39,0.35);
}
.loading-title span { color: var(--gold-400); }
.loading-sub { color: var(--text-dim); margin-top: 4px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.loading-bar-track {
  width: min(280px, 70vw); height: 16px; border-radius: var(--r-pill);
  background: var(--navy-900); border: 2px solid var(--navy-600);
  margin-top: 30px; overflow: hidden;
}
.loading-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--orange-400), var(--gold-400));
  border-radius: var(--r-pill);
  transition: width 0.25s ease;
  box-shadow: 0 0 12px rgba(255,183,39,0.6);
}
.loading-tip { margin-top: 18px; font-size: 12.5px; color: var(--text-dim); max-width: 280px; min-height: 32px; }

@keyframes floatY { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ==========================================================================
   SPLASH SCREEN
   ========================================================================== */
#splash-screen { color: var(--text-main); }
.splash-bg {
  position: absolute; inset: 0;
  background: url('assets/images/bg_menu.jpg') center/cover no-repeat;
}
.splash-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7,15,24,0.15), rgba(7,15,24,0.85) 80%);
}
.splash-content {
  position: relative; z-index: 1;
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 24px calc(36px + var(--safe-bottom));
  text-align: center;
}
.splash-logo { width: 92px; height: 92px; margin-bottom: 6px; filter: drop-shadow(0 6px 14px rgba(0,0,0,0.5)); }
.splash-title {
  font-family: var(--font-display); font-size: 46px; letter-spacing: 0.1em;
  text-shadow: 0 4px 0 rgba(0,0,0,0.45), 0 0 30px rgba(255,183,39,0.3);
}
.splash-title span { color: var(--gold-400); }
.splash-tagline { color: var(--sand-300); font-size: 13.5px; margin-top: 6px; letter-spacing: 0.03em; }
.splash-buttons { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; margin-top: 28px; }
.btn-large#btn-play { font-size: 22px; padding: 19px; position: relative; overflow: hidden; }
.splash-row { display: flex; justify-content: center; gap: 14px; margin-top: 4px; }
.splash-version { margin-top: 18px; font-size: 11px; color: var(--steel-400); }

/* ==========================================================================
   GAME SCREEN — LAYOUT SHELL
   ========================================================================== */
#game-screen { display: flex; flex-direction: column; background: var(--bg-app); }

.ad-slot {
  flex-shrink: 0; width: 100%; height: var(--ad-banner-h);
  background: repeating-linear-gradient(45deg, #1a1a1a, #1a1a1a 10px, #222 10px, #222 20px);
  border: 1px dashed #555;
  display: flex; align-items: center; justify-content: center;
  color: #888; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase;
}
.ad-slot-top { padding-top: var(--safe-top); height: calc(var(--ad-banner-h) + var(--safe-top)); }
.ad-slot-bottom { }

.hud-top {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; padding-top: calc(8px + 0px);
  height: var(--hud-top-h);
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border-bottom: 2px solid var(--navy-950);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  position: relative; z-index: 20;
}
.hq-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex-shrink: 0; width: 52px; height: 52px; border-radius: var(--r-md);
  background: var(--navy-700); border: 2px solid var(--navy-600);
  position: relative;
}
.hq-badge img { width: 30px; height: 30px; }
.hq-badge-level {
  position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
  background: var(--gold-400); color: #3a2405; font-size: 9px; font-weight: 700;
  padding: 1px 6px; border-radius: var(--r-pill); border: 1.5px solid var(--navy-950);
  white-space: nowrap;
}
.resource-bar {
  flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  -ms-overflow-style: none;
}
.resource-bar::-webkit-scrollbar { display: none; }
.resource-pill {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 5px;
  background: var(--navy-900); border: 1.5px solid var(--navy-600);
  border-radius: var(--r-pill); padding: 5px 10px 5px 5px;
  font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.resource-pill img { width: 22px; height: 22px; }
.resource-pill-diamond { border-color: var(--purple-500); }
.resource-pill.pulse { animation: pillPulse 0.35s ease; }
@keyframes pillPulse { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ==========================================================================
   MAIN VIEW
   ========================================================================== */
.main-view { flex: 1; position: relative; overflow: hidden; background: var(--navy-950); }
.view-panel { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ==========================================================================
   BASE VIEW — buildings grid + merge yard
   ========================================================================== */
.base-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  background: url('assets/images/bg_battle.jpg') center/cover;
  padding: 14px 10px 10px;
}
.base-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 480px;
  margin: 0 auto;
}
.building-tile {
  position: relative;
  background: linear-gradient(180deg, rgba(34,56,76,0.92), rgba(13,27,42,0.92));
  border: 2px solid var(--navy-600);
  border-radius: var(--r-md);
  padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: var(--shadow-panel);
  transition: transform 0.12s ease;
}
.building-tile:active { transform: scale(0.95); }
.building-tile.locked { filter: grayscale(0.85) brightness(0.55); }
.building-tile.locked::after {
  content: ""; position: absolute; inset: 0;
}
.building-tile img.building-icon { width: 52px; height: 52px; }
.building-tile .building-name { font-size: 11px; font-weight: 700; text-align: center; text-transform: uppercase; letter-spacing: 0.02em; }
.building-tile .building-level-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--gold-400); color: #3a2405;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: var(--r-pill);
  border: 1.5px solid var(--navy-950);
}
.building-tile .building-lock-icon { position: absolute; width: 22px; height: 22px; top: 8px; left: 8px; }
.building-tile.hq-tile { grid-column: span 3; flex-direction: row; justify-content: center; gap: 14px; padding: 14px; }
.building-tile.hq-tile img.building-icon { width: 62px; height: 62px; }
.building-tile.maxed .building-level-badge { background: var(--green-500); }
.building-tile .building-upgrade-flag {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  background: var(--green-500); color: #06331b; font-size: 9px; font-weight: 700;
  padding: 2px 7px; border-radius: var(--r-pill); border: 1.5px solid var(--navy-950);
  white-space: nowrap;
  animation: bounceFlag 1.1s ease-in-out infinite;
}
@keyframes bounceFlag { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-3px); } }

.merge-yard-wrap {
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-900));
  border-top: 2px solid var(--navy-950);
  padding: 10px 10px calc(10px + var(--safe-bottom));
  box-shadow: 0 -6px 16px rgba(0,0,0,0.3);
}
.merge-yard-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.merge-yard-header h2 { font-family: var(--font-display); font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase; flex-shrink: 0; }
.merge-yard-tabs { display: flex; gap: 4px; flex: 1; }
.tab-chip {
  flex: 1; text-align: center; font-size: 11px; font-weight: 700; text-transform: uppercase;
  padding: 6px 4px; border-radius: var(--r-pill); background: var(--navy-700); color: var(--text-dim);
  border: 1.5px solid transparent;
}
.tab-chip.active { background: var(--gold-400); color: #3a2405; border-color: var(--gold-600); }

.merge-yard-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-width: 480px;
  margin: 0 auto;
}
.merge-cell {
  aspect-ratio: 1;
  background: var(--navy-900);
  border: 2px solid var(--navy-600);
  border-radius: var(--r-sm);
  position: relative;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.merge-cell.drag-over { border-color: var(--gold-400); background: rgba(255,183,39,0.15); }
.merge-cell.can-merge { box-shadow: 0 0 0 2px var(--green-500) inset; }
.unit-chip {
  width: 90%; height: 90%; border-radius: var(--r-sm);
  background: radial-gradient(circle at 35% 30%, var(--navy-600), var(--navy-800));
  border: 2px solid var(--steel-400);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  cursor: grab;
  touch-action: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.unit-chip.dragging { opacity: 0.35; }
.unit-chip.selected { box-shadow: 0 0 0 3px var(--cyan-500); }
.unit-chip img { width: 68%; height: 68%; object-fit: contain; }
.unit-chip .unit-level-badge {
  position: absolute; bottom: -4px; right: -4px;
  background: var(--navy-950); color: var(--gold-400);
  font-size: 9px; font-weight: 700; padding: 0px 4px; border-radius: var(--r-pill);
  border: 1.5px solid var(--gold-600); line-height: 1.4;
}
.unit-chip.tier-2 { border-color: var(--cyan-500); }
.unit-chip.tier-3 { border-color: var(--gold-400); }
.drag-ghost {
  position: fixed; width: 54px; height: 54px; pointer-events: none; z-index: 500;
  transform: translate(-50%,-50%) scale(1.15);
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.5));
}
.drag-ghost img { width: 100%; height: 100%; }

/* merge burst effect */
.merge-burst {
  position: absolute; width: 120%; height: 120%; left: -10%; top: -10%;
  pointer-events: none;
  background: url('assets/icons/fx_merge_glow.png') center/contain no-repeat;
  opacity: 0; z-index: 30;
}
.merge-burst.play { animation: mergeBurst 0.5s ease-out forwards; }
@keyframes mergeBurst { 0% { opacity: 0; transform: scale(0.3) rotate(0deg);} 40% {opacity:1;} 100% { opacity: 0; transform: scale(1.6) rotate(40deg);} }

/* ==========================================================================
   MAP VIEW — chapters + level grid
   ========================================================================== */
#view-map { background: url('assets/images/bg_menu.jpg') center/cover; }
.map-header {
  flex-shrink: 0; text-align: center; padding: 14px 16px 8px;
  background: linear-gradient(180deg, rgba(13,27,42,0.9), rgba(13,27,42,0.3));
}
.map-header h2 { font-family: var(--font-display); font-size: 18px; letter-spacing: 0.03em; }
.map-header p { color: var(--gold-200); font-size: 12px; margin-top: 2px; }
.chapter-scroll {
  flex-shrink: 0; display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px;
  scrollbar-width: none;
}
.chapter-scroll::-webkit-scrollbar { display: none; }
.chapter-chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: var(--r-pill);
  background: rgba(22,42,61,0.85); border: 2px solid var(--navy-600);
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.chapter-chip.active { background: var(--gold-400); color: #3a2405; border-color: var(--gold-600); }
.chapter-chip.locked { opacity: 0.5; }
.level-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 10px; padding: 10px 14px calc(14px + var(--safe-bottom));
  align-content: start;
}
.level-node {
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--olive-300), var(--olive-700));
  border: 3px solid var(--navy-950);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
}
.level-node.locked { background: radial-gradient(circle at 35% 30%, #556, #223); filter: grayscale(0.6); }
.level-node.locked .level-lock { width: 20px; height: 20px; }
.level-node.completed { background: radial-gradient(circle at 35% 30%, var(--gold-200), var(--gold-600)); color: #3a2405; }
.level-node.boss { background: radial-gradient(circle at 35% 30%, #ff9a6b, var(--orange-600)); border-color: #5a1a00; }
.level-node.boss::before { content: "👑"; position: absolute; top: -14px; font-size: 16px; }
.level-node .level-stars { position: absolute; bottom: -8px; display: flex; gap: 1px; }
.level-node .level-stars img { width: 11px; height: 11px; }
.level-node:active { transform: scale(0.92); }

/* ==========================================================================
   BATTLE VIEW
   ========================================================================== */
#view-battle { background: var(--navy-950); }
.battle-topbar {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: linear-gradient(180deg, var(--navy-900), transparent);
  position: relative; z-index: 5;
}
.battle-level-label { font-family: var(--font-display); font-size: 14px; letter-spacing: 0.05em; }
#battle-canvas {
  flex: 1; width: 100%; display: block;
  background: linear-gradient(180deg, #3a4d63 0%, #4a5f4a 45%, #3d5237 100%);
  touch-action: none;
}
.battle-hud-overlay {
  position: absolute; top: 50px; left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0 12px;
  pointer-events: none; z-index: 4;
}
.battle-base-hp { width: 42%; }
.battle-base-hp-enemy { text-align: right; }
.battle-base-label { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; color: var(--text-dim); }
.hp-track { height: 10px; border-radius: var(--r-pill); background: rgba(0,0,0,0.5); border: 1.5px solid rgba(255,255,255,0.15); overflow: hidden; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green-700), var(--green-500)); transition: width 0.25s ease; }
.hp-fill-enemy { background: linear-gradient(90deg, var(--red-700), var(--red-500)); margin-left: auto; }
.battle-controls {
  flex-shrink: 0; display: flex; gap: 10px; padding: 10px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--navy-900), transparent);
}
.battle-controls .btn-primary { flex: 1; }
.battle-controls .btn-secondary { width: 60px; flex-shrink: 0; }

/* ==========================================================================
   BOTTOM NAV
   ========================================================================== */
.bottom-nav {
  flex-shrink: 0; display: flex;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-950));
  border-top: 2px solid var(--navy-950);
  padding-bottom: var(--safe-bottom);
  position: relative; z-index: 20;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 2px 7px; color: var(--text-dim); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.02em;
  position: relative;
}
.nav-btn img { width: 22px; height: 22px; opacity: 0.6; }
.nav-btn.active { color: var(--gold-400); }
.nav-btn.active img { opacity: 1; filter: drop-shadow(0 0 6px rgba(255,183,39,0.6)); }
.nav-icon-map { transform: rotate(90deg); }
.nav-btn-center {
  position: relative; margin-top: -22px;
}
.nav-center-icon {
  width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--orange-400), var(--orange-600));
  border: 3px solid var(--navy-950); font-size: 22px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  color: white;
}
.nav-btn-center span:last-child { margin-top: 3px; color: var(--text-dim); }
.nav-btn-center.active span:last-child { color: var(--gold-400); }

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,9,15,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  display: none;
  width: 100%; max-width: 360px;
  background: linear-gradient(180deg, var(--navy-700), var(--navy-900));
  border: 2px solid var(--navy-600);
  border-radius: var(--r-lg);
  padding: 22px 20px 20px;
  position: relative;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  max-height: 86vh; overflow-y: auto;
  animation: popIn 0.22s cubic-bezier(.2,1.4,.4,1);
}
.modal.active { display: block; }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-tall { max-width: 400px; }
.modal-close {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--navy-950); color: var(--text-dim); font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.modal h3 {
  font-family: var(--font-display); font-size: 19px; letter-spacing: 0.03em; text-transform: uppercase;
  text-align: center; margin-bottom: 12px;
}
.modal-icon { width: 64px; height: 64px; display: block; margin: 0 auto 8px; }
.modal-desc { color: var(--text-dim); font-size: 13px; text-align: center; margin-bottom: 14px; }
.modal-stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 4px; border-bottom: 1px solid var(--navy-700);
  font-size: 13.5px;
}
.modal-stat-row span { color: var(--text-dim); }
.modal-stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px;
}
.modal-stat-grid > div {
  background: var(--navy-900); border: 1.5px solid var(--navy-700); border-radius: var(--r-sm);
  padding: 8px 10px; display: flex; justify-content: space-between; font-size: 12.5px;
}
.modal-stat-grid span { color: var(--text-dim); }
.modal-cost-row {
  display: flex; justify-content: center; gap: 12px; margin: 14px 0;
}
.cost-chip { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; }
.cost-chip img { width: 20px; height: 20px; }
.cost-chip.insufficient { color: var(--red-500); }

.modal-result { text-align: center; }
.result-banner {
  font-family: var(--font-display); font-size: 30px; letter-spacing: 0.06em;
  color: var(--gold-400); text-shadow: 0 3px 0 rgba(0,0,0,0.4);
  margin-bottom: 6px;
}
.result-banner.defeat { color: var(--red-500); }
.result-stars { display: flex; justify-content: center; gap: 8px; margin: 10px 0 16px; }
.result-stars .star { width: 42px; height: 42px; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.4)); }
.result-stars .star.earned { animation: starPop 0.4s cubic-bezier(.2,1.6,.4,1) backwards; }
.result-stars .star:nth-child(1).earned { animation-delay: 0.05s; }
.result-stars .star:nth-child(2).earned { animation-delay: 0.2s; }
.result-stars .star:nth-child(3).earned { animation-delay: 0.35s; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0deg); } }
.result-rewards { display: flex; justify-content: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.reward-chip { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; }
.reward-chip img { width: 34px; height: 34px; }
.result-buttons { display: flex; gap: 10px; }
.result-buttons .btn { flex: 1; }
.modal-confirm { text-align: center; max-width: 300px; }
.modal-confirm p { margin-bottom: 16px; font-size: 14.5px; }

.ad-spinner {
  width: 46px; height: 46px; margin: 0 auto 14px;
  border: 5px solid var(--navy-600); border-top-color: var(--gold-400);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Settings switches */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 2px; border-bottom: 1px solid var(--navy-700); font-size: 14px;
}
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--navy-950); border-radius: var(--r-pill); border: 1.5px solid var(--navy-600); transition: 0.2s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 2.5px; background: var(--steel-200); border-radius: 50%; transition: 0.2s; }
input:checked + .slider { background: var(--green-700); border-color: var(--green-500); }
input:checked + .slider::before { transform: translateX(20px); background: white; }
.settings-footer { text-align: center; font-size: 11px; color: var(--steel-400); margin-top: 16px; line-height: 1.6; }
#btn-install-pwa { width: 100%; margin: 14px 0 8px; }
#btn-reset-progress { width: 100%; }

/* Achievements */
.achievement-list { display: flex; flex-direction: column; gap: 10px; }
.achievement-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--navy-900); border: 1.5px solid var(--navy-700); border-radius: var(--r-md);
  padding: 10px;
}
.achievement-item img { width: 38px; height: 38px; flex-shrink: 0; }
.achievement-info { flex: 1; min-width: 0; }
.achievement-info .a-title { font-size: 13px; font-weight: 700; }
.achievement-info .a-desc { font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.achievement-progress-track { height: 6px; background: var(--navy-950); border-radius: var(--r-pill); margin-top: 6px; overflow: hidden; }
.achievement-progress-fill { height: 100%; background: linear-gradient(90deg, var(--cyan-700), var(--cyan-500)); }
.achievement-item .btn-tiny { flex-shrink: 0; }
.achievement-item.claimed { opacity: 0.55; }

/* Shop */
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shop-card {
  background: var(--navy-900); border: 1.5px solid var(--navy-700); border-radius: var(--r-md);
  padding: 12px 8px; text-align: center;
}
.shop-card img { width: 40px; height: 40px; margin-bottom: 6px; }
.shop-card .shop-title { font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.shop-card .btn { width: 100%; font-size: 11px; padding: 9px 6px; }

/* Daily rewards */
.daily-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.daily-day {
  background: var(--navy-900); border: 1.5px solid var(--navy-700); border-radius: var(--r-sm);
  padding: 8px 4px; text-align: center; position: relative;
}
.daily-day.today { border-color: var(--gold-400); background: rgba(255,183,39,0.12); }
.daily-day.claimed { opacity: 0.5; }
.daily-day img { width: 26px; height: 26px; }
.daily-day .d-label { font-size: 9px; color: var(--text-dim); margin-bottom: 3px; text-transform: uppercase; }
.daily-day .d-amount { font-size: 10px; font-weight: 700; margin-top: 2px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: rgba(13,27,42,0.95); border: 1.5px solid var(--navy-600);
  padding: 10px 18px; border-radius: var(--r-pill); font-size: 13px; font-weight: 700;
  z-index: 200; box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease;
  max-width: 86vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%,0); } }

/* Interstitial ad placeholder */
.ad-slot-interstitial { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center; }
.ad-interstitial-box {
  width: 86%; max-width: 340px; aspect-ratio: 9/16; max-height: 80vh;
  background: repeating-linear-gradient(45deg, #1a1a1a, #1a1a1a 10px, #222 10px, #222 20px);
  border: 1px dashed #666; border-radius: var(--r-md);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  color: #999; font-size: 12px; text-align: center; padding: 20px;
}

/* Damage numbers & floating text (battle canvas overlay, positioned via JS) */
.dmg-float {
  position: absolute; pointer-events: none; font-family: var(--font-display);
  font-weight: 700; font-size: 15px; color: #fff;
  text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
  animation: dmgFloat 0.7s ease-out forwards;
  z-index: 6;
}
.dmg-float.crit { color: var(--gold-400); font-size: 19px; }
.dmg-float.heal { color: var(--green-500); }
@keyframes dmgFloat { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-34px); opacity: 0; } }

/* Generic loading spinner reused in a couple spots */
.spinner-sm { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,0.25); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; display: inline-block; }

/* ==========================================================================
   PARTICLES / SCREEN EFFECTS
   ========================================================================== */
.screen-shake { animation: shake 0.3s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0,0); }
  20% { transform: translate(-4px,2px); }
  40% { transform: translate(4px,-2px); }
  60% { transform: translate(-3px,-1px); }
  80% { transform: translate(3px,2px); }
}
.flash-white {
  position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 250;
  animation: flashFade 0.35s ease-out forwards;
}
@keyframes flashFade { 0% { opacity: 0.55; } 100% { opacity: 0; } }

/* ==========================================================================
   RESPONSIVE — landscape phones
   ========================================================================== */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --hud-top-h: 50px; --bottom-nav-h: 54px; --ad-banner-h: 34px; }
  .hq-badge { width: 42px; height: 42px; }
  .hq-badge img { width: 24px; height: 24px; }
  .resource-pill { font-size: 11px; padding: 4px 8px 4px 4px; }
  .resource-pill img { width: 18px; height: 18px; }

  #view-base { flex-direction: row; }
  .base-scroll { flex: 1.4; padding: 8px; }
  .base-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .merge-yard-wrap { flex: 1; border-top: none; border-left: 2px solid var(--navy-950); overflow-y: auto; padding: 8px; }
  .merge-yard-grid { grid-template-columns: repeat(4, 1fr); }

  .splash-content { flex-direction: row; justify-content: center; gap: 36px; padding: 14px; }
  .splash-logo { width: 70px; height: 70px; margin-bottom: 0; }
  .splash-title { font-size: 32px; }
  .splash-buttons { margin-top: 0; max-width: 260px; }
  .splash-tagline { display: none; }

  .level-grid { grid-template-columns: repeat(8, 1fr); }
  .nav-btn span:last-child { display: none; }
  .nav-btn img { width: 20px; height: 20px; }
  .nav-btn-center { margin-top: -14px; }
  .nav-center-icon { width: 40px; height: 40px; font-size: 18px; }
}

/* ==========================================================================
   RESPONSIVE — tablets / desktop browser testing (keep app centered)
   ========================================================================== */
@media (min-width: 640px) {
  body { background: var(--navy-950); }
  #loading-screen, #splash-screen, #game-screen {
    max-width: 480px; left: 50%; transform: translateX(-50%);
    box-shadow: 0 0 60px rgba(0,0,0,0.6);
  }
  .modal-overlay { max-width: 480px; left: 50%; transform: translateX(-50%); }
  .ad-slot-interstitial { max-width: 480px; left: 50%; transform: translateX(-50%); }
  .toast { max-width: 420px; }
}
@media (min-width: 640px) and (orientation: landscape) {
  #loading-screen, #splash-screen, #game-screen, .modal-overlay, .ad-slot-interstitial {
    max-width: 100%; left: 0; transform: none;
  }
}

/* Small phones — tighten spacing */
@media (max-width: 360px) {
  .base-grid { gap: 8px; }
  .merge-yard-grid { gap: 5px; }
  .resource-pill { font-size: 11px; padding: 4px 7px 4px 4px; }
  .btn-large { font-size: 16px; padding: 15px; }
}

/* Utility: hide scrollbar helper reused anywhere */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }
