/* ============================================================
   DESIGN TOKENS
   Palette: dusk-lit forest village, not the generic cream/terracotta
   or single-neon-on-black defaults. Warm mossy darks, aged bronze,
   torch-ember accent used sparingly for calls to action.
   Type: Cinzel (engraved display serif) for headings/labels that
   need weight; Karla (humanist sans) for body/UI text at small sizes.
   ============================================================ */
:root {
  --bg-deep: #12160e;
  --bg-panel: #1d2415;
  --bg-panel-raised: #242c1a;
  --panel-border: #3a4429;
  --wood: #8a5a34;
  --wood-dark: #5e3c22;
  --gold: #c9a15a;
  --ember: #cf6a35;
  --ember-hot: #e07f45;
  --parchment: #ece3c6;
  --parchment-dim: #b9b193;
  --hp-red: #b8393f;
  --mp-blue: #3f7fb0;
  --xp-green: #7ca84a;
  --font-display: "Cinzel", serif;
  --font-body: "Karla", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--parchment);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-deep);
  position: relative;
}

/* ---------------- HEADER ---------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #171d10, #12160e);
}
.app-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 0.5px;
}
.header-resources {
  display: flex;
  gap: 8px;
  font-size: 13px;
  color: var(--parchment-dim);
}

/* ---------------- SCREEN ROOT ---------------- */
.screen-root {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 90px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- BOTTOM NAV ---------------- */
.tab-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-panel);
  border-top: 1px solid var(--panel-border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--parchment-dim);
  font-family: var(--font-body);
  font-size: 11px;
  padding: 6px 0;
  border-radius: 10px;
  cursor: pointer;
}
.tab-btn .tab-icon { font-size: 20px; }
.tab-btn.active {
  color: var(--gold);
  background: var(--bg-panel-raised);
}

/* ---------------- SHARED ---------------- */
.section-label {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--gold);
  margin: 18px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  background: var(--ember);
  color: #fff;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.cost-chip {
  background: var(--bg-panel-raised);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  margin-right: 6px;
  display: inline-block;
}
.btn-small {
  background: var(--bg-panel-raised);
  border: 1px solid var(--panel-border);
  color: var(--parchment);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.btn-small:disabled { opacity: 0.5; }
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ember);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}

/* ---------------- VILLAGE ---------------- */
.resource-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.resource-pill {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.building-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.building-card {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
}
.building-card.unbuilt { opacity: 0.85; border-style: dashed; }
.building-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.building-icon { font-size: 26px; }
.building-name { font-family: var(--font-display); font-size: 15px; color: var(--parchment); }
.building-level { font-size: 11px; color: var(--parchment-dim); }
.building-desc { font-size: 12.5px; color: var(--parchment-dim); margin-bottom: 8px; line-height: 1.4; }
.building-cost { margin-bottom: 8px; }
.building-maxed {
  text-align: center;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 12px;
  padding: 6px;
}
.btn-upgrade {
  width: 100%;
  background: var(--ember);
  color: #fff;
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.btn-upgrade:disabled { background: var(--wood-dark); color: var(--parchment-dim); }

/* ---------------- COMBAT / ADVENTURE ---------------- */
.combat-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.combat-distance { font-family: var(--font-display); color: var(--gold); font-size: 15px; }
.btn-retreat {
  background: var(--bg-panel-raised);
  border: 1px solid var(--panel-border);
  color: var(--parchment);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.combat-stage {
  position: relative;
  height: 220px;
  background: linear-gradient(180deg, #263a1e 0%, #1a2413 70%, #14190f 100%);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 14px;
}
.ground {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 34px;
  background-image: repeating-linear-gradient(90deg, var(--wood-dark) 0 24px, #4a3018 24px 48px);
  background-repeat: repeat-x;
  background-size: 48px 100%;
  opacity: 0.6;
}
.scene-far {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 100%;
  background-image:
    radial-gradient(circle at 30px 70%, rgba(255,255,255,0.05) 10px, transparent 11px),
    radial-gradient(circle at 140px 55%, rgba(255,255,255,0.04) 16px, transparent 17px),
    radial-gradient(circle at 220px 75%, rgba(255,255,255,0.05) 8px, transparent 9px);
  background-repeat: repeat-x;
  background-size: 260px 100%;
  opacity: 0.7;
}
.hero-unit, .enemy-unit {
  position: absolute;
  bottom: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90px;
}
.hero-unit { left: 20%; transform: translateX(-50%); }
.enemy-unit { right: 18%; transform: translateX(50%); animation: approach 0.4s ease-out; }
.enemy-unit.boss .unit-icon { font-size: 46px; }
@keyframes approach {
  from { transform: translateX(50%) translateX(40px); opacity: 0; }
  to { transform: translateX(50%) translateX(0); opacity: 1; }
}
.unit-icon { font-size: 34px; margin-bottom: 4px; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)); }
.enemy-name { font-size: 11px; color: var(--parchment-dim); margin-bottom: 3px; }
.marching-text {
  position: absolute;
  right: 18px; bottom: 44px;
  font-size: 12px;
  color: var(--parchment-dim);
  font-style: italic;
}
.bar {
  width: 100%;
  height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 2px;
}
.bar-fill { height: 100%; background: var(--hp-red); transition: width 0.25s ease; }
.bar-fill.enemy { background: var(--hp-red); }
.mp-bar .bar-fill { background: var(--mp-blue); }
.xp-bar .bar-fill.xp { background: var(--xp-green); }

.skill-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.skill-btn {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 4px;
  color: var(--parchment);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.skill-btn:disabled { opacity: 0.45; }
.skill-icon { font-size: 20px; }
.skill-name { font-size: 10.5px; text-align: center; }
.skill-cd, .skill-cost { font-size: 10px; color: var(--parchment-dim); }
.combat-loot { margin-bottom: 12px; }
.combat-log {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  color: var(--parchment-dim);
  min-height: 90px;
}
.log-line { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.log-line:first-child { color: var(--parchment); }

.run-summary {
  text-align: center;
  padding: 30px 10px;
}
.run-summary-title { font-family: var(--font-display); font-size: 20px; color: var(--gold); margin-bottom: 8px; }
.run-summary-distance { font-size: 14px; margin-bottom: 4px; }
.run-summary-note { font-size: 12px; color: var(--parchment-dim); margin-bottom: 10px; }
.run-summary-loot { margin: 14px 0; }
.run-summary-levelup { color: var(--xp-green); font-weight: 700; margin-bottom: 14px; }

/* ---------------- HERO SCREEN ---------------- */
.hero-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.hero-portrait {
  font-size: 42px;
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
}
.hero-level { font-family: var(--font-display); color: var(--gold); font-size: 15px; margin-bottom: 4px; }
.xp-label { font-size: 11px; color: var(--parchment-dim); margin-top: 2px; }
.derived-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.derived-chip {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
}
.stat-grid { display: flex; flex-direction: column; gap: 8px; }
.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat-info { flex: 1; }
.stat-name { font-size: 13.5px; font-weight: 700; }
.stat-desc { font-size: 11px; color: var(--parchment-dim); }
.stat-value { font-family: var(--font-display); font-size: 16px; color: var(--gold); min-width: 24px; text-align: center; }
.btn-plus {
  background: var(--ember);
  color: #fff;
  border: none;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
.btn-plus:disabled { background: var(--wood-dark); color: var(--parchment-dim); }

.talent-branch { margin-bottom: 12px; }
.talent-branch-name {
  font-size: 12px;
  text-transform: none;
  color: var(--parchment-dim);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 4px;
}
.talent-row-group { display: flex; flex-direction: column; gap: 6px; }
.talent-node {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 10px;
}
.talent-icon { font-size: 20px; }
.talent-info { flex: 1; }
.talent-name { font-size: 13px; font-weight: 700; }
.talent-pts { font-size: 11px; color: var(--gold); font-weight: 400; }
.talent-desc { font-size: 11px; color: var(--parchment-dim); }

/* ---------------- INVENTORY ---------------- */
.equip-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.equip-slot {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.equip-slot-label { font-size: 10px; color: var(--parchment-dim); text-transform: capitalize; margin-bottom: 6px; }
.item-icon { font-size: 26px; }
.item-name { font-size: 12px; font-weight: 700; margin: 4px 0; }
.item-empty { font-size: 12px; color: var(--parchment-dim); padding: 10px 0; }
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.inventory-card {
  background: var(--bg-panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.inventory-card.equipped { border-color: var(--gold); }
.item-desc { font-size: 10.5px; color: var(--parchment-dim); margin-bottom: 4px; }
.item-stats { font-size: 10.5px; color: var(--gold); display: flex; justify-content: center; gap: 8px; margin-bottom: 6px; }

/* scrollbar cleanup for webview */
::-webkit-scrollbar { width: 0; height: 0; }
