/* Interface kit — chunky, bevelled, colourful (art bible §9).
   No browser default button, font, scrollbar or alert appears anywhere. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --panel: #FFFFFFF2;
  --panel-edge: #78909C;
  --ink: #1C2B33;
  --accent: #039BE5;
  --gold: #FFC93C;
  --green: #43A047;
  --red: #F4511E;
  --shadow: 0 6px 0 #B0BEC555;
  --bevel-light: #FFFFFFAA;
}

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #CFEEFF;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-weight: 700;
  color: var(--ink);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }

.hidden { display: none !important; }

/* ------------------------------------------------------------- panels */
.panel {
  background: linear-gradient(180deg, #FFFFFF 0%, #EAF3F8 100%);
  border: 3px solid var(--panel-edge);
  border-radius: 12px;
  box-shadow: inset 0 3px 0 var(--bevel-light), inset 0 -4px 0 #78909C44, var(--shadow);
}

/* ------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  min-height: 48px;
  min-width: 48px;
  padding: 10px 18px;
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(180deg, #29B6F6, #0277BD);
  border: 3px solid #01579B;
  border-radius: 12px;
  box-shadow: inset 0 3px 0 #FFFFFF66, inset 0 -5px 0 #00000033, 0 4px 0 #01579B66;
  cursor: pointer;
  text-shadow: 0 2px 0 #00000055;
  transition: transform 60ms ease-out, filter 60ms ease-out;
}
.btn:active, .btn.pressed { transform: translateY(3px); filter: brightness(0.9); box-shadow: inset 0 3px 0 #FFFFFF44, inset 0 -2px 0 #00000033, 0 1px 0 #01579B66; }
.btn:disabled, .btn.disabled { background: linear-gradient(180deg, #CFD8DC, #90A4AE); border-color: #78909C; color: #ECEFF1; cursor: default; }
.btn.wide { flex: 1 1 auto; font-size: 18px; background: linear-gradient(180deg, #FFD54F, #FB8C00); border-color: #E65100; box-shadow: inset 0 3px 0 #FFFFFF88, inset 0 -5px 0 #00000022, 0 4px 0 #E6510066; }
.btn.big { font-size: 26px; padding: 16px 44px; background: linear-gradient(180deg, #66D9C8, #00897B); border-color: #004D40; box-shadow: inset 0 3px 0 #FFFFFF88, inset 0 -6px 0 #00000033, 0 6px 0 #004D4066; }
.btn.danger { background: linear-gradient(180deg, #FF8A65, #D84315); border-color: #BF360C; }
.btn.icon { padding: 8px; border-radius: 10px; }
.btn.skill { position: relative; width: 62px; height: 62px; padding: 0; border-radius: 50%; background: linear-gradient(180deg, #CE93D8, #6A1B9A); border-color: #4A148C; }
.btn.skill .cd { position: absolute; inset: 0; border-radius: 50%; background: #26323888; transform-origin: bottom; transform: scaleY(0); }
.btn.close { background: linear-gradient(180deg, #A5D6A7, #2E7D32); border-color: #1B5E20; }

/* ------------------------------------------------------------- layout */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topbar {
  position: absolute; top: 8px; left: 8px; right: 8px;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; min-height: 56px;
}
#topbar .spacer { flex: 1; }
.counter { display: flex; align-items: center; gap: 6px; font-size: 20px; padding: 4px 10px; background: #FFFFFFAA; border: 2px solid #B0BEC5; border-radius: 10px; min-width: 96px; }
.counter .num { font-variant-numeric: tabular-nums; }
.counter .ico { width: 26px; height: 26px; display: inline-block; background-size: contain; background-repeat: no-repeat; }
.floorbadge { font-size: 17px; padding: 6px 14px; background: #FFC93C; border: 3px solid #E65100; border-radius: 999px; color: #5D4037; }

#left-col { position: absolute; left: 8px; bottom: 96px; display: flex; flex-direction: column; gap: 8px; }
#portrait { padding: 6px; width: 116px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#portrait-canvas { width: 96px; height: 96px; border-radius: 8px; background: linear-gradient(180deg, #CFEEFF, #EAF8FF); }
.hpwrap, .energywrap { width: 100%; }
.bar { position: relative; height: 22px; border: 3px solid #455A64; border-radius: 8px; background: #37474F44; overflow: hidden; }
.bar i { position: absolute; inset: 0; width: 100%; transform-origin: left; transform: scaleX(1); }
.bar.hp i { background: linear-gradient(180deg, #FF8A8A, #E53935); }
.bar.energy i { background: linear-gradient(180deg, #7ED8FF, #039BE5 60%, #FFC93C); }
.bar em { position: absolute; inset: 0; display: grid; place-items: center; font-style: normal; font-size: 13px; color: #fff; text-shadow: 0 1px 2px #000A; }
#skill-row { display: flex; gap: 8px; }

#bottom-bar {
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  display: flex; gap: 8px; align-items: center; padding: 8px 10px;
}
.energywrap { flex: 1 1 auto; max-width: 340px; }
.energywrap .bar { height: 28px; }
.energy-label { display: block; font-size: 11px; letter-spacing: 0.18em; color: #546E7A; margin-top: 2px; }

/* damage numbers, toasts, fps */
#numbers { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.dmg { position: absolute; transform: translate(-50%, -50%); font-size: 26px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 #B71C1C, 0 0 8px #B71C1C88; animation: dmgpop 0.9s ease-out forwards; }
.dmg.crit { font-size: 40px; color: #FFF3C4; text-shadow: 0 3px 0 #E65100, 0 0 14px #FFC93C; }
.dmg.heal { color: #C8F08E; text-shadow: 0 2px 0 #2E7D32; }
.dmg.ore { color: #BFF5EC; text-shadow: 0 2px 0 #00695C; }
@keyframes dmgpop { 0% { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%,-50%) scale(1.25); }
  30% { transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-140%) scale(1); } }

#toasts { position: absolute; top: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { display: flex; gap: 10px; align-items: center; padding: 10px 18px; font-size: 17px;
  background: linear-gradient(180deg,#FFF,#EAF3F8); border: 3px solid #039BE5; border-radius: 12px;
  box-shadow: 0 6px 0 #0277BD55; animation: toastin 0.35s cubic-bezier(.2,1.6,.4,1); }
.toast .ico { width: 32px; height: 32px; background-size: contain; }
@keyframes toastin { from { transform: translateY(-30px) scale(0.8); opacity: 0; } }

#fps { position: absolute; right: 8px; top: 70px; font-size: 13px; background: #263841CC; color: #BFF5EC;
  padding: 6px 10px; border-radius: 8px; font-family: ui-monospace, monospace; }

/* ------------------------------------------------------------- screens */
.screen { position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(120% 90% at 50% 0%, #EAF8FF 0%, #CFEEFF 60%, #A8DCFA 100%); z-index: 10; }
#screen-loading { gap: 18px; align-content: center; }
.logo-mini { font-size: 64px; letter-spacing: 0.2em; color: #0277BD; text-shadow: 0 5px 0 #B0BEC5; }
.loadbar { width: min(70vw, 420px); height: 22px; border: 3px solid #546E7A; border-radius: 10px; background: #FFFFFFAA; overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg,#66D9C8,#039BE5); transition: width 0.2s; }
.loadtext { color: #546E7A; font-size: 15px; }

#screen-title { z-index: 9; background: radial-gradient(120% 90% at 50% 0%, #EAF8FFCC 0%, #CFEEFF66 60%, #A8DCFA44 100%); }
#title-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-actions { position: absolute; bottom: 5%; display: flex; flex-direction: column; gap: 12px; align-items: center; z-index: 2; }
.title-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
.title-row .btn { font-size: 14px; padding: 8px 16px; min-height: 44px; }
.title-actions .hint { color: #546E7A; font-size: 14px; background: #FFFFFFCC; padding: 6px 12px; border-radius: 8px; }

.dialog { padding: 20px; display: flex; flex-direction: column; gap: 12px; width: min(92vw, 460px); max-height: 88vh; overflow: auto; }
.dialog.wide { width: min(94vw, 760px); }
.dialog h2 { margin: 0 0 6px; font-size: 24px; color: #0277BD; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 17px; min-height: 44px; }
.row.buttons { justify-content: flex-start; flex-wrap: wrap; }
input[type=range] { width: 55%; accent-color: #039BE5; height: 32px; }
input[type=checkbox] { width: 28px; height: 28px; accent-color: #039BE5; }
select { font: inherit; font-size: 16px; padding: 8px 10px; min-height: 44px; border: 3px solid #78909C; border-radius: 10px; background: #fff; color: var(--ink); }
.credits { font-size: 14px; line-height: 1.5; max-height: 60vh; overflow: auto; }
.credits h3 { margin: 14px 0 4px; color: #0277BD; font-size: 16px; }
.credits div { padding: 2px 0; border-bottom: 1px dashed #B0BEC5; }

/* town / tree / bag screens */
#screen-town { align-items: end; background: transparent; pointer-events: none; }
#screen-town .town-head, #screen-town .town-panel { pointer-events: auto; }
.town-head h2 { margin: 0; font-size: 20px; color: #0277BD; }
.town-head .spendable { font-size: 16px; flex: 1; }
.btn:disabled { cursor: default; }
.town-panel { position: absolute; bottom: 8px; left: 8px; right: 8px; padding: 12px; display: flex; gap: 10px; overflow-x: auto; }
.town-card { flex: 1 1 0; min-width: 168px; padding: 10px; background: #FFFFFFDD; border: 3px solid #90A4AE; border-radius: 12px; display: flex; flex-direction: column; gap: 6px; }
.town-card h3 { margin: 0; font-size: 18px; }
.town-card .lvl { font-size: 13px; color: #546E7A; }
.town-card p { margin: 0; font-size: 13px; font-weight: 400; color: #455A64; min-height: 34px; }
.town-card canvas { width: 100%; height: 84px; background: linear-gradient(180deg,#EAF8FF,#CFEEFF); border-radius: 8px; }

#screen-tree, #screen-bag { align-items: start; }
.tree-head, .bag-head, .town-head, .biome-head { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 12px; align-items: center; padding: 8px 14px; }
.tree-head h2, .bag-head h2 { margin: 0; font-size: 20px; color: #0277BD; }
.tree-head .spendable { font-size: 16px; flex: 1; }
.tree-body { position: absolute; inset: 72px 8px 8px; overflow: auto; touch-action: none;
  background: #FFFFFF88; border: 3px solid #90A4AE; border-radius: 12px; }
.tree-grid { position: relative; }
.node { position: absolute; width: 64px; height: 64px; border-radius: 12px; border: 3px solid #78909C;
  background: #ECEFF1; display: grid; place-items: center; font-size: 11px; text-align: center; padding: 2px;
  cursor: pointer; overflow: hidden; }
.node .ico { width: 34px; height: 34px; background-size: contain; background-repeat: no-repeat; }
.node.available { background: #FFFFFF; border-color: #039BE5; box-shadow: 0 0 0 3px #039BE533, 0 4px 0 #0277BD55; }
.node.bought { background: linear-gradient(180deg,#8FD65A,#43A047); border-color: #1B5E20; color: #fff; }
.node.maxed { background: linear-gradient(180deg,#FFD54F,#FB8C00); border-color: #E65100; color: #fff; }
.node.locked { filter: grayscale(0.8) brightness(0.9); opacity: 0.75; }
.node .cost { position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px; background: #263841CC; color: #FFC93C; }
.node.affordable .cost { color: #8FD65A; }
.node.unaffordable .cost { color: #FF8A8A; }

.bag-body { position: absolute; inset: 72px 8px 8px; overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); align-content: start; gap: 12px; padding: 12px; background: #FFFFFF88; border: 3px solid #90A4AE; border-radius: 12px; }
.item-card { padding: 12px; min-height: 96px; background: #FFF; border: 3px solid #90A4AE; border-radius: 12px; display: flex; gap: 8px; align-items: center; }
.item-card canvas { width: 72px; height: 72px; background: linear-gradient(180deg,#EAF8FF,#CFEEFF); border-radius: 8px; }
.item-card .meta { font-size: 12px; font-weight: 400; }
.item-card .name { font-size: 14px; }
.rarity-common { border-color: #90A4AE; }
.rarity-uncommon { border-color: #43A047; }
.rarity-rare { border-color: #039BE5; }
.rarity-epic { border-color: #8E24AA; }
.rarity-legendary { border-color: #FB8C00; box-shadow: 0 0 10px #FFC93C; }

/* --------------------------------------------------- orientation layouts */
/* landscape: play area on the left, panels on the right */
@media (min-aspect-ratio: 1/1) {
  #left-col { left: 8px; bottom: 92px; }
  #bottom-bar { right: 8px; max-width: 70%; }
  .town-panel { left: auto; right: 8px; top: 72px; bottom: 8px; width: 46%; flex-direction: column; overflow-y: auto; }
  #screen-town { align-items: center; }
}
/* portrait: play area on top, controls below within thumb reach */
@media (max-aspect-ratio: 999/1000) {
  #left-col { left: 8px; bottom: 150px; flex-direction: row; align-items: flex-end; }
  #bottom-bar { flex-wrap: wrap; justify-content: space-between; padding-bottom: 12px; }
  #bottom-bar .btn { flex: 1 1 22%; font-size: 14px; padding: 10px 6px; }
  .energywrap { flex: 1 1 100%; max-width: none; }
  #topbar { flex-wrap: wrap; }
  .counter { font-size: 17px; min-width: 76px; }
  .town-panel { flex-direction: column; max-height: 46vh; overflow-y: auto; }
}
@media (max-width: 480px) {
  .counter { min-width: 64px; font-size: 15px; }
  .btn { font-size: 14px; }
}

#rotate-hint { position: fixed; bottom: 4px; left: 50%; transform: translateX(-50%); font-size: 12px;
  background: #263841AA; color: #fff; padding: 4px 10px; border-radius: 8px; z-index: 50; }
/* ---- dungeons, achievements, ascension -------------------------------- */
.biome-list, .ach-list { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow-y: auto; padding: 4px; }
.biome-card { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: #FFFFFF;
  border: 3px solid #90A4AE; border-radius: 12px; cursor: pointer; }
.biome-card.current { border-color: #43A047; box-shadow: 0 0 0 3px #43A04733; }
.biome-card.locked { opacity: 0.6; filter: grayscale(0.7); cursor: default; }
.biome-card .swatch { width: 46px; height: 46px; border-radius: 10px; border: 3px solid #FFFFFF; box-shadow: 0 0 0 2px #90A4AE; flex: 0 0 auto; }
.biome-card h3 { margin: 0; font-size: 17px; }
.biome-card p { margin: 2px 0 0; font-size: 13px; font-weight: 400; color: #546E7A; }
.biome-card .lock { margin-left: auto; font-size: 13px; color: #F4511E; text-align: right; }
.biome-card .here { margin-left: auto; font-size: 13px; color: #2E7D32; text-align: right; }

.ach-row { display: flex; gap: 12px; align-items: center; padding: 8px 12px; background: #FFFFFF;
  border: 3px solid #B0BEC5; border-radius: 12px; }
.ach-row.done { border-color: #43A047; background: #F1FBE9; }
.ach-row .ico { width: 40px; height: 40px; background-size: contain; background-repeat: no-repeat; flex: 0 0 auto; }
.ach-row .meta { flex: 1; font-size: 13px; font-weight: 400; }
.ach-row .name { font-size: 15px; font-weight: 700; }
.ach-row .bar { width: 130px; height: 16px; border: 2px solid #78909C; border-radius: 6px; background: #ECEFF1; overflow: hidden; flex: 0 0 auto; }
.ach-row .bar i { display: block; height: 100%; background: linear-gradient(90deg, #66D9C8, #039BE5); }
.ach-row .doneMark { font-size: 20px; color: #43A047; flex: 0 0 auto; }

.prestige-node { position: absolute; width: 72px; height: 72px; border-radius: 14px; border: 3px solid #78909C;
  background: #FFFFFF; display: grid; place-items: center; text-align: center; font-size: 11px; padding: 2px; cursor: pointer; }
.prestige-node .ico { width: 34px; height: 34px; background-size: contain; background-repeat: no-repeat; }
.prestige-node.bought { background: linear-gradient(180deg, #FFD54F, #FB8C00); border-color: #E65100; color: #fff; }
.prestige-node.locked { opacity: 0.55; filter: grayscale(0.7); }
.prestige-node.unaffordable .cost { color: #FF8A8A; }
.prestige-node.affordable .cost { color: #43A047; }
.prestige-node .cost { position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; background: #263841CC; color: #FFC93C; border-radius: 0 0 10px 10px; }

/* ---- hero classes ------------------------------------------------------- */
.hero-list { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-height: 62vh; overflow-y: auto; padding: 4px; }
.hero-card { flex: 1 1 200px; max-width: 260px; padding: 12px; background: #FFFFFF; border: 3px solid #90A4AE;
  border-radius: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center; }
.hero-card.current { border-color: #43A047; box-shadow: 0 0 0 3px #43A04733; }
.hero-card canvas { width: 120px; height: 140px; background: linear-gradient(180deg, #EAF8FF, #CFEEFF); border-radius: 10px; }
.hero-card h3 { margin: 0; font-size: 19px; }
.hero-card p { margin: 0; font-size: 13px; font-weight: 400; color: #546E7A; }
.hero-card .hint { font-size: 13px; color: #039BE5; font-weight: 700; }
.hero-card .stats { font-size: 13px; color: #263841; background: #EAF3F8; border-radius: 8px; padding: 4px 8px; }

/* ---- fork doors, merchant, smith --------------------------------------- */
.fork-bar { position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  display: flex; gap: 12px; padding: 10px 12px; background: linear-gradient(180deg,#FFFFFF,#EAF3F8);
  border: 3px solid #78909C; border-radius: 14px; box-shadow: 0 6px 0 #B0BEC566; }
.fork-bar .door { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 120px;
  min-height: 84px; font-size: 14px; }
.fork-bar .door .ico { width: 40px; height: 40px; background-size: contain; background-repeat: no-repeat; }
.fork-bar .label { position: absolute; }
.fork-title { width: 100%; text-align: center; font-size: 13px; color: #546E7A; letter-spacing: .08em; }

.shop-list { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; }
.shop-row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: #FFF;
  border: 3px solid #B0BEC5; border-radius: 12px; }
.shop-row .ico { width: 52px; height: 52px; background-size: contain; background-repeat: no-repeat; flex: 0 0 auto; }
.shop-row .meta { flex: 1; font-size: 13px; font-weight: 400; }
.shop-row .name { font-size: 15px; font-weight: 700; }
.shop-row .cost { font-size: 13px; color: #546E7A; }
.shop-row .cost b.ok { color: #2E7D32; }
.shop-row .cost b.no { color: #F4511E; }
.shop-head { display: flex; gap: 16px; font-size: 15px; color: #546E7A; }
.shop-head b { color: #0277BD; }
.town-card .rowBtns { display: flex; flex-direction: column; gap: 6px; }
