@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700;800&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #1c1917; }
body { font-family: 'IBM Plex Sans', system-ui, sans-serif; color: #e7e5e4; -webkit-user-select: none; user-select: none; }

#game-root { position: fixed; inset: 0; }
#game-canvas { position: absolute; inset: 0; }
#game-canvas canvas { display: block; }

/* HUD sits over the canvas; only its children catch pointer events */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

.font-display { font-family: 'Cinzel', serif; }
.font-num { font-family: 'IBM Plex Mono', monospace; }

/* ---- Top bar: kingdom + level + resources ---- */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(#0c0a09ee, #0c0a09aa 70%, #0c0a0900);
}
.hud-titlebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.hud-title { display: flex; align-items: center; gap: 6px; font-family: 'Cinzel', serif; font-size: 17px; letter-spacing: .04em; color: #f5f5f4; }
.hud-title .crest { color: #f0b429; }
.hud-lvwrap { display: flex; align-items: center; gap: 6px; }
.hud-lv { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #f0b429; }
.hud-xp { width: 74px; height: 5px; background: #292524; border-radius: 999px; overflow: hidden; }
.hud-xp > div { height: 100%; background: #f0b429; }
.hud-res { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.res-chip { background: #0c0a09cc; border: 1px solid #292524; border-radius: 7px; padding: 5px 7px; }
.res-chip .row { display: flex; align-items: center; gap: 5px; }
.res-chip .dot { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.res-chip .val { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #e7e5e4; }
.res-chip .rate { font-family: 'IBM Plex Mono', monospace; font-size: 10px; margin-top: 2px; color: #78716c; }
.res-chip .rate.neg { color: #ef4444; }

/* ---- Building panel (bottom sheet) ---- */
.panel {
  position: absolute; left: 0; right: 0;
  bottom: calc(50px + env(safe-area-inset-bottom));   /* sit ABOVE the tab bar */
  padding: 10px; z-index: 25;
  transform: translateY(135%); transition: transform .22s cubic-bezier(.2,.8,.3,1);
}
.panel.open { transform: translateY(0); }
.panel-card { background: #1c1917; border: 1px solid #44403c; border-radius: 12px; padding: 14px; max-width: 460px; margin: 0 auto; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-emb { width: 40px; height: 40px; border-radius: 9px; background: #292524; display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.panel-name { font-family: 'Cinzel', serif; font-size: 16px; color: #f5f5f4; }
.panel-sub { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: #a8a29e; margin-top: 1px; }
.panel-x { margin-left: auto; background: none; border: none; color: #78716c; font-size: 20px; cursor: pointer; padding: 2px 6px; }
.panel-effect { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #a3e635; margin-bottom: 10px; }
.cost-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.cost { display: flex; align-items: center; gap: 4px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #a8a29e; }
.cost.short { color: #ef4444; }
.cost .dot { width: 8px; height: 8px; border-radius: 2px; }
.btn {
  width: 100%; border: none; border-radius: 9px; padding: 11px; cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif; font-size: 14px; font-weight: 600;
  background: #d97706; color: #1c1917;
}
.btn:disabled { background: #292524; color: #57534e; cursor: not-allowed; }
.btn.ghost { background: #292524; color: #d6d3d1; margin-top: 8px; font-weight: 500; font-size: 12px; padding: 8px; }
.progress { height: 8px; background: #292524; border-radius: 999px; overflow: hidden; margin-bottom: 8px; }
.progress > div { height: 100%; background: #f0b429; transition: width .3s linear; }
.progress-label { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #fbbf24; text-align: center; }
.locked { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #78716c; text-align: center; padding: 6px; }

/* ---- Bottom tab bar ---- */
.tabs {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  background: #1c1917; border-top: 1px solid #44403c33;
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: none; cursor: pointer; color: #78716c; font-size: 11px; }
.tab .ic { font-size: 18px; line-height: 1; }
.tab.active { color: #f0b429; }
.tabs.hidden { display: none; }

/* ---- Offline welcome toast ---- */
.toast {
  position: absolute; left: 10px; right: 10px; top: 96px;
  max-width: 440px; margin: 0 auto;
  background: #422006cc; border: 1px solid #854d0e; border-radius: 10px; padding: 10px 12px;
  font-size: 12px; color: #fcd34d;
}
.toast .gains { display: flex; gap: 12px; margin-top: 4px; font-family: 'IBM Plex Mono', monospace; color: #fbbf24; }

.hint {
  position: absolute; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); text-align: center;
  font-size: 11px; color: #a8a29e; text-shadow: 0 1px 3px #000;
}

/* ---- troop send steppers (map attack panel) ---- */
.troop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.troop-row .tname { font-size: 12px; color: #d6d3d1; }
.troop-row .owned { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: #78716c; }
.stepper { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.stepper button { width: 26px; height: 26px; border-radius: 6px; border: none; background: #292524; color: #e7e5e4; font-size: 15px; cursor: pointer; line-height: 1; }
.stepper button:active { background: #44403c; }
.stepper .cnt { font-family: 'IBM Plex Mono', monospace; font-size: 13px; width: 30px; text-align: center; }
.stepper .mx { font-size: 11px; color: #a8a29e; background: none; border: none; cursor: pointer; width: auto; height: auto; padding: 2px 4px; }
.atk-summary { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 4px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #a8a29e; }
.atk-summary .good { color: #a3e635; } .atk-summary .bad { color: #ef4444; }
.btn.attack { background: #b91c1c; color: #fff; }
.btn.attack:disabled { background: #292524; color: #57534e; }
.loot-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 2px; }
.loot-row span { display: flex; align-items: center; gap: 4px; font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #fbbf24; }
.loot-row .dot { width: 8px; height: 8px; border-radius: 2px; }

/* ---- result overlay ---- */
.overlay { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.7); padding: 24px; }
.result-card { background: #1c1917; border: 2px solid #44403c; border-radius: 14px; padding: 22px; max-width: 300px; width: 100%; text-align: center; animation: pop .35s cubic-bezier(.2,.8,.3,1.1) both; }
.result-card.win { border-color: #4d7c0f; }
.result-card.loss { border-color: #991b1b; }
@keyframes pop { 0% { opacity: 0; transform: scale(1.3) rotate(-3deg); } 60% { opacity: 1; transform: scale(.97) rotate(1deg); } 100% { transform: scale(1) rotate(0); } }
.result-emoji { font-size: 40px; line-height: 1; }
.result-title { font-family: 'Cinzel', serif; font-size: 26px; letter-spacing: .12em; margin: 6px 0 2px; }
.result-title.win { color: #84cc16; }
.result-title.loss { color: #ef4444; }
.result-sub { font-size: 13px; color: #a8a29e; margin-bottom: 8px; }
.result-line { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: #a8a29e; margin: 3px 0; }
.result-line.loss { color: #ef4444; }
