/* TACTICA — global styles */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; width: 100%; }
html, body {
  background: #0a0506;
  color: #f1e5c8;
  font-family: 'Trebuchet MS', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: relative; }
button { font: inherit; cursor: pointer; }

/* ==== Screens ==== */
.screen {
  position: absolute; inset: 0;
  display: none;
  background-size: cover; background-position: center;
  background-color: #1a0e08;
}
.screen.active { display: flex; align-items: center; justify-content: center; }

#menuScreen, #factionScreen, #rosterScreen,
#resultScreen, #shopScreen, #upgradeScreen, #loadingScreen, #settingsScreen {
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(255,160,80,.15), transparent 60%),
    linear-gradient(180deg, #2b1a10 0%, #0d0604 100%),
    url('fantasy-strategy-game-ui/PNG/menu/bg.png');
  background-size: cover, cover, cover;
  background-blend-mode: normal, normal, overlay;
}

/* ==== Loading ==== */
.loading-inner { text-align: center; padding: 30px; }
.bar {
  margin: 16px auto 6px;
  width: min(420px, 80vw); height: 22px;
  background: #1d100a; border: 2px solid #6b4823; border-radius: 12px;
  overflow: hidden; position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6);
}
.bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(180deg, #ffba66, #c2761b 60%, #7a4310);
  transition: width .15s ease;
}
.bar-text { font-size: 14px; opacity: .7; }

/* ==== Titles ==== */
.game-title {
  font-size: clamp(40px, 9vw, 80px);
  letter-spacing: .15em;
  font-weight: 900;
  background: linear-gradient(180deg, #ffd58a 10%, #c47e1f 60%, #5b2c08 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 14px rgba(0,0,0,.6);
}
.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%,100%{ transform: scale(1); filter: drop-shadow(0 0 4px #c47e1f);}
  50%{ transform: scale(1.04); filter: drop-shadow(0 0 14px #ffba66);}
}
.subtitle {
  font-style: italic;
  opacity: .8;
  margin: 4px 0 14px;
  font-size: clamp(14px, 2.4vw, 18px);
}

/* ==== Menu ==== */
.menu-inner { text-align: center; padding: 30px; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin: 18px auto; align-items: center; }
.menu-stats {
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
  margin-top: 16px;
  font-size: 14px;
  background: rgba(0,0,0,.45);
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid rgba(255,200,120,.2);
}
.menu-stats b { color: #ffd58a; }
.credit { margin-top: 10px; opacity: .4; font-size: 12px; }

/* ==== Buttons ==== */
.btn {
  background: linear-gradient(180deg, #6a3d1a, #3b1f0a);
  border: 2px solid #c47e1f;
  border-radius: 10px;
  color: #ffe9c0;
  padding: 12px 28px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  min-width: 220px;
  box-shadow: 0 4px 0 #1c0a02, 0 6px 14px rgba(0,0,0,.6);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #1c0a02, 0 2px 6px rgba(0,0,0,.6); }
.btn.primary {
  background: linear-gradient(180deg, #d68a2c, #7c3f0a);
  border-color: #ffd58a;
  color: #1c0a02;
}
.btn.small { padding: 6px 16px; font-size: 13px; min-width: 0; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ==== Panels ==== */
.panel {
  background:
    linear-gradient(180deg, rgba(50,28,14,.95), rgba(20,10,5,.95)),
    radial-gradient(ellipse at 50% 0%, rgba(255,160,80,.15), transparent 50%);
  border: 2px solid #c47e1f;
  border-radius: 16px;
  padding: 22px 24px;
  max-width: 92vw;
  max-height: 92vh;
  overflow: auto;
  width: 480px;
  box-shadow: 0 12px 40px rgba(0,0,0,.7), inset 0 0 30px rgba(0,0,0,.5);
}
.panel.wide { width: min(820px, 92vw); }
.panel h2 {
  text-align: center; letter-spacing: .15em; color: #ffd58a;
  margin-bottom: 6px; font-size: clamp(20px, 4vw, 28px);
}
.panel h3 {
  color: #ffba66; font-size: 16px; letter-spacing: .1em;
  margin: 14px 0 8px; text-transform: uppercase;
}
.panel .hint { text-align: center; opacity: .75; font-size: 14px; margin-bottom: 14px; }
.panel .row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ==== Faction grid ==== */
.faction-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.fac-card {
  border: 2px solid #6b4823; border-radius: 12px;
  background: rgba(0,0,0,.4);
  padding: 10px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  transition: transform .1s, border-color .1s, background .1s;
}
.fac-card:hover { transform: translateY(-2px); border-color: #ffba66; }
.fac-card.selected { border-color: #ffd58a; background: rgba(255,200,120,.12); box-shadow: 0 0 18px rgba(255,180,90,.3); }
.fac-card.locked { opacity: .45; filter: grayscale(.6); }
.fac-portrait {
  width: 90px; height: 90px;
  background: radial-gradient(circle, rgba(255,200,120,.18), transparent 70%);
  background-color: rgba(0,0,0,.35);
  border-radius: 50%;
  background-size: 90px auto;
  background-repeat: no-repeat;
  background-position: center;
  border: 2px solid #6b4823;
  margin-bottom: 6px;
}
.fac-name { font-weight: 800; color: #ffd58a; letter-spacing: .05em; }
.fac-tag { font-size: 12px; opacity: .75; text-align: center; line-height: 1.2; }
.fac-cost { font-size: 12px; color: #ffba66; margin-top: 4px; }

/* ==== Roster grid ==== */
.roster-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.roster-card {
  position: relative;
  border: 2px solid #6b4823;
  border-radius: 10px;
  background: rgba(0,0,0,.35);
  padding: 8px;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: transform .08s, border-color .08s;
}
.roster-card:hover { border-color: #ffba66; }
.roster-card.selected { border-color: #ffd58a; background: rgba(255,200,120,.12); }
.roster-portrait {
  width: 56px; height: 56px;
  background-size: 56px auto;
  background-repeat: no-repeat;
  background-position: bottom center;
  background-color: rgba(0,0,0,.3);
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid #4d3015;
}
.roster-info { flex: 1; min-width: 0; }
.roster-name { font-weight: 700; color: #ffd58a; font-size: 13px; letter-spacing: .03em; }
.roster-stats { font-size: 11px; opacity: .85; line-height: 1.4; margin-top: 2px; }
.roster-summary {
  text-align: center; margin-top: 12px;
  font-size: 14px; opacity: .85;
}
.roster-summary b { color: #ffba66; }

/* ==== Upgrade grid ==== */
.upgrade-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.upgrade-card {
  border: 2px solid #6b4823; border-radius: 10px;
  background: rgba(0,0,0,.35);
  padding: 10px;
  display: flex; gap: 10px; align-items: center;
}
.upgrade-portrait {
  width: 64px; height: 64px;
  background-size: 64px auto;
  background-repeat: no-repeat;
  background-position: bottom center;
  background-color: rgba(0,0,0,.3);
  border-radius: 8px;
  flex-shrink: 0;
}
.upgrade-info { flex: 1; min-width: 0; }
.upgrade-name { font-weight: 700; color: #ffd58a; font-size: 14px; }
.upgrade-stats { font-size: 11px; opacity: .8; line-height: 1.3; }
.upgrade-card button { margin-top: 4px; }

/* ==== Battle HUD ==== */
#battleScreen { background: #1a0e08; }
#battleScreen canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
.topbar {
  position: absolute; top: 8px; left: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: center;
  pointer-events: none;
  z-index: 5;
  gap: 8px;
}
.hudbox {
  pointer-events: auto;
  background: rgba(20,10,5,.85);
  border: 2px solid #c47e1f;
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 14px;
  display: flex; gap: 8px; align-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.6);
}
.hudbox b { color: #ffd58a; }
.hud-btn {
  pointer-events: auto;
  background: linear-gradient(180deg, #d68a2c, #7c3f0a);
  border: 2px solid #ffd58a;
  border-radius: 10px;
  color: #1c0a02;
  padding: 8px 14px;
  font-weight: 800;
  letter-spacing: .05em;
  font-size: 13px;
  box-shadow: 0 3px 0 #1c0a02;
}
.hud-btn.small { background: linear-gradient(180deg, #aa4848, #5d1c1c); color: #fff; border-color: #ff9494; padding: 6px 10px;}
.hud-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1c0a02; }

.unit-info {
  position: absolute; bottom: 12px; left: 12px;
  background: rgba(20,10,5,.92);
  border: 2px solid #c47e1f;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  z-index: 5;
  pointer-events: none;
  max-width: 220px;
  box-shadow: 0 3px 8px rgba(0,0,0,.6);
}
.unit-info.hidden { display: none; }
.unit-info .name { font-weight: 800; color: #ffd58a; font-size: 14px; }
.unit-info .hp-bar {
  height: 8px; background: #3a1809; border-radius: 4px; margin: 4px 0;
  overflow: hidden; border: 1px solid #6b4823;
}
.unit-info .hp-fill { height: 100%; background: linear-gradient(180deg, #6dde3d, #297b14); transition: width .2s; }
.unit-info .stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; opacity: .9; }

.battle-log {
  position: absolute; bottom: 12px; right: 12px;
  width: clamp(180px, 30vw, 280px);
  max-height: 140px;
  overflow: hidden;
  font-size: 12px;
  z-index: 4;
  pointer-events: none;
  display: flex; flex-direction: column-reverse; gap: 2px;
}
.log-line {
  background: rgba(20,10,5,.78);
  border-left: 3px solid #c47e1f;
  padding: 4px 8px;
  border-radius: 4px;
  animation: slideIn .2s ease-out;
}
.log-line.crit { border-left-color: #ff8444; color: #ffd58a; }
.log-line.ai { border-left-color: #c44444; }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==== Result rewards ==== */
.rewards {
  background: rgba(0,0,0,.35);
  border: 1px dashed #6b4823;
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0;
  text-align: center;
  font-size: 14px;
  line-height: 1.7;
}
.rewards b { color: #ffd58a; }

/* ==== Shop section ==== */
.shop-section { margin-bottom: 14px; }

/* ==== Mobile tweaks ==== */
@media (max-width: 600px) {
  .btn { padding: 10px 18px; font-size: 14px; min-width: 160px; }
  .panel { padding: 14px; }
  .topbar { top: 4px; left: 4px; right: 4px; font-size: 12px; }
  .hudbox { padding: 4px 8px; font-size: 11px; }
  .hud-btn { padding: 5px 8px; font-size: 11px; }
  .menu-stats { gap: 8px; padding: 6px 10px; font-size: 12px; }
  .battle-log { width: 46vw; max-height: 80px; bottom: 6px; right: 6px; font-size: 10px; }
  .battle-log .log-line { padding: 3px 6px; }
  .unit-info { bottom: 6px; left: 6px; font-size: 11px; max-width: 46vw; padding: 6px 8px;}
  .unit-info .name { font-size: 12px; }
  .unit-info .stats { font-size: 10px; gap: 5px; }
  .fac-portrait { width: 70px; height: 70px; background-size: 80px auto;}
  .roster-portrait { width: 44px; height: 44px; background-size: 48px auto !important; }
  .roster-card { padding: 6px; }
  .roster-name { font-size: 12px; }
  .roster-stats { font-size: 10px; }
  .upgrade-portrait { width: 50px; height: 50px; }
}
@media (max-width: 380px) {
  .battle-log { display: none; } /* save space on very narrow */
}
@media (orientation: portrait) and (max-width: 700px) {
  .topbar { flex-wrap: wrap; }
}

/* Settings */
.settings-section { margin: 10px 0; }
.diff-row { gap: 8px; justify-content: center; }
.diff-row .btn { min-width: 100px; padding: 8px 12px; font-size: 13px; }
.diff-row .btn.selected {
  background: linear-gradient(180deg, #d68a2c, #7c3f0a);
  border-color: #ffd58a; color: #1c0a02;
  box-shadow: 0 0 14px rgba(255,180,90,.5);
}
#diffDesc { margin-top: 10px; min-height: 1.5em; }

/* XP / promotion display */
.xp-list {
  background: rgba(0,0,0,.3);
  border: 1px dashed #6b4823;
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 12px;
}
.xp-line { padding: 2px 0; }
.xp-line b { color: #ffd58a; }
.xp-bar {
  display: inline-block;
  width: 120px; height: 8px;
  background: #2b1606; border: 1px solid #6b4823; border-radius: 4px;
  vertical-align: middle; margin: 0 6px;
  overflow: hidden;
}
.xp-fill { height: 100%; background: linear-gradient(90deg, #66deff, #2982c4); transition: width .3s; }

/* Status icons (above unit in battle) */
.status-pill {
  display: inline-block;
  font-size: 11px;
  background: rgba(0,0,0,.55);
  border: 1px solid #6b4823;
  border-radius: 4px;
  padding: 1px 5px;
  margin-right: 3px;
}

/* Helpers */
.row { display: flex; gap: 10px; }
.hidden { display: none !important; }
