:root {
  --bg: #0d0a09;
  --panel: #2b2523;
  --panel-dark: #1f1a19;
  --card: #2f2927;
  --card-hi: #3d3532;
  --line: #9a8f86;
  --line-dim: #4e4540;
  --text: #f4ede1;
  --text-dim: #a2968d;
  --cost: #ff7b47;
  --cost-poor: #8f5a48;
  --accent: #ff9a3c;
  --accent-dark: #b85f1c;
  --gold: #ffd25a;
  --splinter: #f2b766;
  --ui-unit: 1;
  --panel-w: 340px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Galmuri11, 'Courier New', monospace;
  font-size: 12px;
  overflow: hidden;
  -webkit-font-smoothing: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }
img { image-rendering: pixelated; }
.hidden { display: none !important; }

/* ---------- Layout: the play area fills everything the panel does not ---------- */

#app {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

#game {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  image-rendering: pixelated;
  cursor: none;
  touch-action: none;
}

/* ---------- HUD (Keep on Mining style counters) ---------- */

.hud {
  position: absolute;
  left: 12px;
  top: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
  z-index: 2;
}
.hud-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px 4px 6px;
  border-radius: 8px;
  background: rgba(18, 12, 10, 0.72);
  border: 2px solid rgba(154, 143, 134, 0.35);
  line-height: 1;
  transform-origin: 20% 50%;
}
.hud-bar span {
  text-shadow: 2px 2px 0 #120c0a, -1px -1px 0 #120c0a, 1px -1px 0 #120c0a, -1px 1px 0 #120c0a;
}
.hud-bar.coin { font-size: 36px; color: var(--gold); min-width: 180px; }
.hud-bar.coin img { width: 36px; height: 36px; filter: drop-shadow(2px 2px 0 #120c0a); }
.hud-bar.spl { font-size: 24px; color: var(--splinter); }
.hud-bar.spl img { width: 24px; height: 24px; filter: drop-shadow(2px 2px 0 #120c0a); }
.hud-bar.bump { animation: bump 0.12s ease-out; }
@keyframes bump { 40% { transform: scale(1.1); } }

.hud-stage {
  position: absolute;
  right: 10px;
  top: 10px;
  width: 190px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(18, 12, 10, 0.72);
  border: 2px solid rgba(154, 143, 134, 0.35);
  pointer-events: none;
  z-index: 2;
}
.hud-stage-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.hud-stage-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Panel (PC: right sidebar) ---------- */

.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border-left: 3px solid #4e4540;
  box-shadow: inset 2px 0 0 #1a1514;
}

.stage-box {
  padding: 8px;
  border-radius: 6px;
  background: var(--panel-dark);
  border: 2px solid var(--line-dim);
}
.stage-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.stage-badge {
  min-width: 24px;
  padding: 3px 5px;
  text-align: center;
  background: var(--accent);
  color: #2a1608;
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 var(--accent-dark);
  white-space: nowrap;
}
.stage-name { font-size: 12px; }
.bar {
  position: relative;
  height: 16px;
  border-radius: 3px;
  background: #1a1514;
  border: 2px solid var(--line-dim);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(180deg, #ffb45e 0%, var(--accent) 50%, #d9731f 100%);
  transition: width 0.15s;
}
.bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  text-shadow: 1px 1px 0 #120c0a;
}

.tree-btn {
  position: relative;
  padding: 10px;
  border-radius: 6px;
  border: 2px solid var(--line);
  background: var(--panel-dark);
  letter-spacing: 1px;
  box-shadow: inset 0 -2px 0 #1a1514;
}
.tree-btn:hover { background: var(--card-hi); }
.badge {
  position: absolute;
  right: 8px;
  top: -8px;
  padding: 1px 4px;
  font-size: 12px;
  color: #2a1608;
  background: #9be26a;
  border-radius: 3px;
  animation: blink 0.8s steps(2) infinite;
}
@keyframes blink { 50% { transform: translateY(-2px); } }

.tabs { display: flex; gap: 6px; justify-content: center; }
.tab {
  position: relative;
  width: 44px;
  height: 38px;
  border-radius: 6px;
  border: 2px solid var(--line-dim);
  background: var(--panel-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tab span { display: none; }
.tab img { width: 18px; height: 18px; opacity: 0.6; }
.tab.active { border-color: var(--accent); background: var(--card-hi); }
.tab.active img { opacity: 1; }
.tab-tree { display: none; }
.dot { position: absolute; top: 4px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: #9be26a; }

.tab-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  background: var(--panel-dark);
  border: 2px solid var(--line-dim);
  padding: 6px;
}
.page-title {
  position: relative;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 0 6px;
  border-bottom: 2px solid var(--line-dim);
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.buy-mode {
  display: none;
  position: absolute;
  right: 0;
  top: -3px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--text);
}
.buy-mode.on { border-color: var(--accent); color: var(--accent); }
.hint { margin-top: 6px; text-align: center; color: var(--text-dim); font-size: 12px; }

.cards {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}
.cards::-webkit-scrollbar { width: 6px; }
.cards::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

.card {
  position: relative;
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  padding: 6px 8px 6px 6px;
  border-radius: 6px;
  background: var(--card);
  border: 2px solid var(--line);
  cursor: pointer;
  box-shadow: inset 0 -2px 0 #1d1817;
}
.card:hover { background: var(--card-hi); }
.card:active { transform: translateY(1px); }
.card.bought { animation: pop 0.18s steps(3); }
@keyframes pop { 50% { transform: scale(1.03); } }
.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #1d1817;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-icon img { width: 18px; height: 18px; }
.card-title { font-size: 12px; line-height: 1.3; }
.card-sub { font-size: 12px; color: var(--text-dim); line-height: 1.3; }
.card-cost {
  position: absolute;
  right: 8px;
  bottom: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--cost);
  font-size: 12px;
  line-height: 1;
}
.card-cost img { width: 9px; height: 9px; }
.card.poor { cursor: default; }
.card.poor .card-cost { color: var(--cost-poor); }
.card.poor .card-cost img { opacity: 0.5; }
.card.max { cursor: default; opacity: 0.65; }
.card.max .card-cost { color: var(--text-dim); }
.card.max .card-cost img { display: none; }
.card-new {
  display: none;
  position: absolute;
  right: 6px;
  top: -7px;
  padding: 1px 4px;
  font-size: 12px;
  line-height: 1.2;
  color: #2a1608;
  background: #9be26a;
  border-radius: 3px;
}
.card.fresh .card-new { display: block; animation: blink 0.8s steps(2) infinite; }
.card.fresh { border-color: #9be26a; }

.stats { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.stat-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 4px; }
.stat-row span:last-child { color: var(--accent); }
.stat-sep { height: 2px; background: var(--line-dim); margin: 4px 0; }

.settings { display: flex; flex-direction: column; gap: 8px; }
.wide-btn {
  padding: 10px;
  border-radius: 6px;
  border: 2px solid var(--line);
  background: var(--card);
  box-shadow: inset 0 -2px 0 #1d1817;
}
.wide-btn:hover { background: var(--card-hi); }
.wide-btn.danger { border-color: #b04a3c; color: #ff9c8a; }

/* ---------- Skill tree overlay ---------- */

.overlay {
  position: absolute;
  inset: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: #050404;
  border: 3px solid var(--text);
  border-radius: 4px;
  line-height: 1.2;
  box-shadow: 0 0 0 3px #050404;
}
.overlay-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 2px solid #2a2523;
}
.overlay-title { font-size: 12px; letter-spacing: 2px; }
.overlay-currency { display: flex; align-items: center; gap: 4px; color: var(--splinter); font-size: 12px; }
.overlay-currency img { width: 18px; height: 18px; }
.overlay-count { color: var(--text-dim); font-size: 12px; }
.overlay-hint { color: #5e544e; font-size: 12px; margin-left: auto; }
.close-btn {
  width: 28px;
  height: 28px;
  border: 2px solid var(--text);
  background: transparent;
  font-size: 16px;
  line-height: 1;
}
.close-btn:hover { background: #222; }

.tree {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(circle, #1a1513 1px, transparent 1px) 0 0 / 16px 16px;
}
.tree:active { cursor: grabbing; }
.tree-board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-links { position: absolute; left: 0; top: 0; overflow: visible; }
.tree-links line { stroke: #3a3330; stroke-width: 2; }
.tree-links line.open { stroke: #8a7f76; }
.tree-links line.lit { stroke: var(--text); }
.tree-links line.hidden { display: none; }

.branch-label {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 1;
  padding: 1px 3px;
  color: #a2968d;
  background: #050404;
  border: 1px solid #3a3330;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid #8a7f76;
  background: #050404;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
}
.node.root { width: 52px; height: 52px; border-width: 3px; }
.node.unique { border-radius: 50%; }
.node img { width: 24px; height: 24px; pointer-events: none; }
.node.root img { width: 32px; height: 32px; }
.node-lvl {
  position: absolute;
  right: -9px;
  bottom: -9px;
  padding: 1px 2px;
  font-size: 12px;
  color: var(--text-dim);
  background: #050404;
  white-space: nowrap;
  line-height: 1;
  pointer-events: none;
}
.node-lvl:empty { display: none; }
.node:hover { background: #1d1817; }
.node.v-hidden { display: none; }
.node.v-hint { border-color: #2a2523; border-style: dashed; }
.node.v-stage { border-color: #4a3a5a; border-style: dashed; }
.node.v-owned { border-color: var(--accent); box-shadow: 0 0 0 2px #050404, 0 0 0 4px #5a2f10; }
.node.v-owned .node-lvl { color: var(--accent); }
.node.maxed { background: #2a1608; }
.node.affordable { border-color: var(--text); animation: glow 0.9s steps(2) infinite; }
.node.v-owned.affordable { border-color: #ffd28a; }
.node.bought { animation: pop 0.2s steps(3); }
@keyframes glow { 50% { box-shadow: 0 0 0 2px #050404, 0 0 0 4px #9be26a; } }

.tooltip {
  position: absolute;
  z-index: 5;
  width: 230px;
  padding: 8px 10px;
  background: #050404;
  border: 2px solid var(--text);
  pointer-events: none;
  font-size: 12px;
  line-height: 1.4;
}
.tip-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.tip-name { color: var(--text); }
.tip-lvl { color: var(--text-dim); }
.tip-desc { color: #d6ccbe; }
.tip-per { color: var(--text-dim); }
.tip-branch { color: #6d625c; margin-bottom: 4px; }
.tip-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; padding-top: 6px; border-top: 1px solid #2a2523; }
.tip-cost { display: flex; align-items: center; gap: 3px; color: var(--splinter); }
.tip-cost img { width: 9px; height: 9px; }
.tip-cost.poor { color: #8f5a48; }
.tip-act { color: #c88cff; }
.tip-max { color: var(--accent); }
.tip-lock { color: #8f5a48; }

/* ---------- Compact PC (short landscape screens, e.g. phones held sideways) ---------- */

body.compact { --panel-w: 270px; }
body.compact .hud-bar.coin { font-size: 24px; min-width: 120px; }
body.compact .hud-bar.coin img { width: 24px; height: 24px; }
body.compact .hud-bar.spl { font-size: 12px; }
body.compact .hud-bar.spl img { width: 12px; height: 12px; }
body.compact .tree-btn { padding: 6px; }
body.compact .card { min-height: 44px; }

/* ---------- PC only ---------- */

body.pc .hud-stage { display: none; }

/* ---------- Mobile: play area on top, panel below with a bottom tab bar ---------- */

body.mobile #app { flex-direction: column; }
body.mobile .stage { flex: 0 0 56%; }
body.mobile .panel {
  width: 100%;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  padding: 6px 8px 0;
  gap: 6px;
  border-left: 0;
  border-top: 3px solid #4e4540;
  box-shadow: inset 0 2px 0 #1a1514;
}
body.mobile .stage-box,
body.mobile .tree-btn,
body.mobile .hint { display: none; }
body.mobile .tabs {
  order: 10;
  margin: 0 -8px;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  gap: 0;
  background: var(--panel-dark);
  border-top: 2px solid var(--line-dim);
}
body.mobile .tab {
  flex: 1;
  width: auto;
  height: 48px;
  border: 0;
  background: transparent;
  border-radius: 6px;
}
body.mobile .tab span { display: block; font-size: 12px; color: var(--text-dim); }
body.mobile .tab.active { background: var(--card-hi); }
body.mobile .tab.active span { color: var(--accent); }
body.mobile .tab-tree { display: flex; }
body.mobile .tab-page { border: 0; padding: 2px 0 6px; background: transparent; }
body.mobile .page-title { margin-bottom: 6px; }
body.mobile .buy-mode { display: block; }
body.mobile .cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
  gap: 6px;
}
body.mobile .card {
  grid-template-columns: 30px 1fr;
  gap: 6px;
  min-height: 58px;
  padding: 5px 6px 18px 5px;
}
body.mobile .card-icon { width: 30px; height: 30px; }
body.mobile .card-icon img { width: 18px; height: 18px; }
body.mobile .card-sub .card-name { display: none; }
body.mobile .card:hover { background: var(--card); }

body.mobile .hud { left: 8px; top: 8px; gap: 4px; }
body.mobile .hud-bar { padding: 3px 10px 3px 4px; gap: 6px; }
body.mobile .hud-bar.coin { font-size: 24px; min-width: 110px; }
body.mobile .hud-bar.coin img { width: 24px; height: 24px; }
body.mobile .hud-bar.spl { font-size: 12px; }
body.mobile .hud-bar.spl img { width: 12px; height: 12px; }
body.mobile .hud-stage { width: 150px; right: 8px; top: 8px; padding: 4px 6px; }

/* Skill tree takes the whole phone screen; details dock at the bottom with a buy button. */
body.mobile .overlay { position: fixed; inset: 0; z-index: 20; border-width: 0; border-radius: 0; box-shadow: none; }
body.mobile .overlay-head { flex-wrap: wrap; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; }
body.mobile .overlay-hint { display: none; }
body.mobile .overlay-count { order: 5; width: 100%; }
body.mobile #tree-center { margin-left: auto; }
body.mobile .close-btn { width: 36px; height: 36px; }
body.mobile .tooltip {
  left: 8px !important;
  right: 8px;
  top: auto !important;
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: auto;
  pointer-events: auto;
  font-size: 12px;
}
.tip-buy {
  padding: 8px 18px;
  border-radius: 4px;
  border: 2px solid #9be26a;
  background: #1f3315;
  color: #9be26a;
}
.tip-buy:disabled { border-color: #4e4540; background: transparent; color: #6d625c; }
