* { box-sizing: border-box; }
:root {
  --ink: #26140b; --ink2: #6b4a35; --paper: #fff3e2; --wood: #8a5a33; --wood2: #5e3a1f; --stone: #3a2a22;
  --orange: #ff6b35; --yellow: #ffcf4a; --green: #7cc43a; --blue: #3aa0d8; --purple: #8a5ad0; --red: #ff5a4f;
  --font: "Baloo 2", "Nunito", system-ui, "Noto Sans", sans-serif;
}
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #140a05; color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; background: #1a0e07; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }
button, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ------------------------------------------------ icons (Codex art with CSS fallback) */
.ic { display: inline-block; width: 30px; height: 30px; flex: none; background-size: contain; background-repeat: no-repeat; background-position: center; }
.ic-coin { background-image: url(assets/icon_coin.webp), radial-gradient(circle at 35% 35%, #fff3b0 0 18%, #ffca3a 20% 60%, #e09a00 62%); border-radius: 50%; }
.ic-gem { background-image: url(assets/icon_gem.webp), linear-gradient(135deg, #9ff 0 40%, #1bb 60%); clip-path: none; }
.ic-worm { background-image: url(assets/icon_worm.webp), radial-gradient(circle, #ffd84a 0 55%, transparent 60%); }
.ic.big { width: 58px; height: 58px; }
.ic.sm { width: 20px; height: 20px; vertical-align: -4px; }

/* ------------------------------------------------ HUD */
#hud { position: absolute; left: 10px; top: 8px; width: 790px; height: 52px; display: flex; align-items: center; gap: 8px; pointer-events: none; z-index: 5; }
.pill {
  pointer-events: auto; display: flex; align-items: center; gap: 6px; height: 46px; padding: 0 14px 0 8px; border-radius: 23px;
  background: var(--paper); border: 3px solid var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.55), inset 0 -4px 0 rgba(0,0,0,.08);
  font-weight: 800; white-space: nowrap;
}
.pill b { font-size: 25px; line-height: 1; }
.pill small { font-size: 14px; color: var(--ink2); font-weight: 800; }
.pill.coins { min-width: 190px; }
.pill.gems b { color: #0f8a93; }
.pill.worms b { color: #b07a00; }
.pill.depth { margin-left: auto; background: linear-gradient(#ffcf4a, #f09a2a); flex-direction: column; justify-content: center; gap: 0; height: 52px; padding: 0 16px; min-width: 116px; }
.pill.depth b { font-size: 26px; }
.pill.depth small { font-size: 12.5px; color: #5a2c0c; margin-top: -2px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.pill.bump { animation: bump .25s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }
#hud-btns { position: absolute; top: 10px; right: 12px; display: flex; gap: 8px; z-index: 6; }
.hbtn {
  position: relative; width: 52px; height: 48px; border-radius: 15px; cursor: pointer; font-size: 25px; padding: 0;
  background: linear-gradient(#fff6e8, #f0d9b8); border: 3px solid var(--ink); box-shadow: 0 4px 0 rgba(0,0,0,.55); transition: transform .1s;
}
.hbtn:hover { transform: translateY(-2px) scale(1.05); }
.hbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.55); }
#btn-boost { width: auto; min-width: 52px; padding: 0 8px; display: flex; align-items: center; gap: 2px; }
#btn-boost em { font-style: normal; font-size: 15px; font-weight: 800; }
#btn-boost.on { background: linear-gradient(#ffe38a, #ff9f3a); animation: throb .8s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.06); } }
.badge { position: absolute; top: -9px; right: -9px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: var(--red); color: #fff; font-size: 15px; line-height: 20px; border: 2px solid #fff; font-weight: 800; }
#goal { position: absolute; left: 12px; top: 66px; max-width: 560px; z-index: 5; pointer-events: none;
  background: rgba(20,10,5,.72); color: #ffe9b8; font-weight: 800; font-size: 16px; padding: 3px 12px; border-radius: 12px; border: 2px solid rgba(255,207,74,.5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dps { position: absolute; left: 12px; bottom: 10px; z-index: 5; display: flex; gap: 8px; pointer-events: none; }
#dps span { background: rgba(20,10,5,.72); color: #ffe9b8; font-weight: 800; font-size: 16px; padding: 3px 12px; border-radius: 12px; border: 2px solid rgba(255,255,255,.18); }
#btn-fight { position: absolute; left: 400px; top: 170px; transform: translateX(-50%); z-index: 6; cursor: pointer;
  font-size: 30px; font-weight: 800; color: #fff; padding: 8px 30px 11px; border-radius: 20px; border: 3px solid var(--ink);
  background: linear-gradient(#ff7a5a, #d2321f); box-shadow: 0 6px 0 rgba(0,0,0,.6); text-shadow: 0 2px 0 rgba(0,0,0,.3); }
#btn-fight:disabled { background: linear-gradient(#8a6a5a, #5a4034); cursor: default; }
#btn-fight:not(:disabled) { animation: throbc 0.9s ease-in-out infinite; }
@keyframes throbc { 50% { transform: translateX(-50%) scale(1.07); } }

/* ------------------------------------------------ right panel */
#panel {
  position: absolute; left: 812px; top: 66px; width: 458px; height: 644px; z-index: 4; display: flex; flex-direction: column;
  background: linear-gradient(#4a2d1a, #2e1a0e); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 rgba(0,0,0,.6), inset 0 2px 0 rgba(255,255,255,.12);
  padding: 8px; color: #ffeedd;
}
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.tab { position: relative; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 3px 2px 4px; border-radius: 14px; border: 3px solid var(--ink);
  background: linear-gradient(#7a5236, #5a3a22); color: #f4dcc0; box-shadow: 0 3px 0 rgba(0,0,0,.5); line-height: 1.05; min-width: 0; }
.tab span { font-size: 22px; }
.tab b { font-size: 14.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.on { background: linear-gradient(#ffcf4a, #f09a2a); color: var(--ink); transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.5); }
.dot { position: absolute; top: -5px; right: -5px; width: 16px; height: 16px; border-radius: 50%; background: var(--red); border: 2px solid #fff; }
.tabpane { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }

/* merge grid */
.grid { display: grid; grid-template-columns: repeat(4, 102px); grid-auto-rows: 102px; gap: 7px; justify-content: center; padding: 8px; border-radius: 18px;
  background: repeating-linear-gradient(45deg, #3a2414 0 14px, #34200f 14px 28px); border: 3px solid #1a0d05; }
.slot { position: relative; border-radius: 14px; background: radial-gradient(circle at 50% 40%, #6a4a30, #4a2f1c); border: 3px solid #241206;
  box-shadow: inset 0 4px 8px rgba(0,0,0,.45); display: grid; place-items: center; cursor: pointer; touch-action: none; }
.slot.over { background: radial-gradient(circle, #9a7a40, #6a4a20); border-color: var(--yellow); }
.slot.match { box-shadow: inset 0 0 0 3px rgba(124,196,58,.8), 0 0 12px rgba(124,196,58,.7); }
.slot.sel { border-color: #fff; box-shadow: 0 0 0 3px var(--yellow), 0 0 16px var(--yellow); }
.item { position: absolute; inset: 6px; display: grid; place-items: center; pointer-events: none; }
.item img { width: 86%; height: 86%; object-fit: contain; filter: drop-shadow(0 4px 0 rgba(0,0,0,.4)); }
.item .fb { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; font-weight: 800; color: var(--ink); }
.item .tier { position: absolute; left: -4px; top: -4px; min-width: 26px; height: 26px; padding: 0 5px; border-radius: 13px; font-size: 15px; font-weight: 800; line-height: 21px;
  text-align: center; background: var(--paper); color: var(--ink); border: 2px solid var(--ink); }
.item.pop { animation: itempop .35s cubic-bezier(.3,1.8,.5,1); }
@keyframes itempop { 0% { transform: scale(.3) rotate(-20deg); } }
.toolrow { display: flex; gap: 6px; margin: 8px 0; align-items: stretch; }
.btn.buy { flex: 1; display: flex; align-items: center; gap: 8px; padding: 4px 10px 6px; text-align: left; background: linear-gradient(#a6e04a, #5f9e1c); min-width: 0; }
.btn.buy .bico { width: 44px; height: 44px; flex: none; background: rgba(0,0,0,.18); border-radius: 12px; display: grid; place-items: center; }
.btn.buy .bico img { width: 40px; height: 40px; object-fit: contain; }
.btn.buy .bl { display: flex; flex-direction: column; min-width: 0; }
.btn.buy b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.buy small { font-size: 16px; display: flex; align-items: center; gap: 4px; }
.btn.sm { font-size: 15px; padding: 4px 8px 6px; max-width: 110px; line-height: 1.05; }
.btn.xs { font-size: 14px; padding: 2px 10px 4px; }

.strip { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.mcard { position: relative; border-radius: 14px; border: 3px solid #241206; background: linear-gradient(#6a4a30, #4a2f1c); height: 116px; cursor: pointer; overflow: hidden; touch-action: none; }
.mcard img.face { position: absolute; left: 50%; top: 2px; width: 62px; transform: translateX(-50%); pointer-events: none; }
.mcard .tool { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); width: 58px; height: 50px; border-radius: 10px; background: rgba(0,0,0,.35); display: grid; place-items: center; pointer-events: none; }
.mcard .tool img { width: 46px; height: 46px; object-fit: contain; }
.mcard .tool .tier { position: absolute; right: -4px; top: -6px; font-size: 12px; font-weight: 800; background: var(--paper); color: var(--ink); border: 2px solid var(--ink); border-radius: 9px; padding: 0 4px; line-height: 15px; }
.mcard .tool .none { font-size: 11px; color: #ffb0a0; font-weight: 800; text-align: center; line-height: 1; }
.mcard.locked { filter: grayscale(1) brightness(.45); cursor: default; }
.mcard.locked img.face { filter: brightness(0); }
.mcard.over { border-color: var(--yellow); box-shadow: 0 0 12px var(--yellow); }
.mcard.match { box-shadow: inset 0 0 0 3px rgba(124,196,58,.8); }
.mcard.sel { border-color: #fff; box-shadow: 0 0 0 3px var(--yellow); }
.mcard .zz { position: absolute; right: 3px; top: 2px; font-size: 14px; pointer-events: none; }

#ghost { position: absolute; z-index: 40; width: 86px; height: 86px; margin: -43px 0 0 -43px; pointer-events: none; filter: drop-shadow(0 10px 6px rgba(0,0,0,.5)); transform: scale(1.12) rotate(-8deg); }
#ghost img { width: 100%; height: 100%; object-fit: contain; }

/* crew / shop / perk lists */
.list { display: flex; flex-direction: column; gap: 7px; }
.modebar { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 6px; font-weight: 800; font-size: 16px; color: #ffd98a; }
.row3 { display: grid; grid-template-columns: 64px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 14px; background: rgba(255,240,220,.08); border: 2px solid rgba(255,220,180,.18); }
.row3.can { border-color: rgba(124,196,58,.8); background: rgba(124,196,58,.12); }
.row3.locked { opacity: .55; }
.row3 .pic { width: 64px; height: 64px; display: grid; place-items: center; font-size: 34px; }
.row3 .pic img { max-width: 64px; max-height: 64px; object-fit: contain; }
.row3.locked .pic img { filter: brightness(0) opacity(.6); }
.row3 .nm { font-weight: 800; font-size: 18px; line-height: 1.1; color: #fff3e2; }
.row3 .nm small { font-size: 13px; color: #ffcf4a; margin-left: 6px; }
.row3 .ds { font-size: 14.5px; line-height: 1.2; color: #e8cdb0; }
.row3 .st { font-size: 14px; color: #9fe3ff; font-weight: 800; }
.row3 .bts { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.row3 .btn { font-size: 14px; padding: 2px 8px 4px; border-radius: 12px; display: flex; align-items: center; justify-content: center; gap: 3px; white-space: nowrap; min-width: 96px; }
.row3 .btn .ic { width: 17px; height: 17px; }
.stars { color: #ffcf4a; letter-spacing: -1px; }
.stars .off { color: rgba(255,255,255,.25); }
.shop-h { font-weight: 800; color: #ffd98a; margin: 8px 4px 0; font-size: 16px; }
.burrow-card { text-align: center; padding: 8px 10px; border-radius: 16px; background: linear-gradient(#5a3a8a, #3a2460); border: 3px solid #1a0d25; }
.burrow-card h3 { margin: 0; font-size: 24px; }
.burrow-card .sub { font-size: 13.5px; margin: 2px 0 4px; color: #e8dcff; line-height: 1.25; }
.burrow-card .gain { font-size: 21px; font-weight: 800; color: #ffd84a; margin: 2px 0 6px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.perk-head { display: flex; justify-content: space-between; align-items: center; margin: 8px 4px 5px; color: #ffd98a; font-size: 16px; }

/* ------------------------------------------------ tutorial + toast */
#tut {
  position: absolute; top: 100px; left: 400px; transform: translateX(-50%); z-index: 12; display: flex; align-items: center; gap: 12px;
  max-width: 760px; padding: 8px 10px 8px 18px; border-radius: 18px; background: var(--yellow); border: 3px solid var(--ink);
  box-shadow: 0 5px 0 rgba(0,0,0,.55); font-size: 20px; font-weight: 800; animation: popc .3s ease both; width: max-content; max-width: 740px; line-height: 1.2;
}
#tut-skip { flex: none; white-space: nowrap; cursor: pointer; border: 0; background: rgba(0,0,0,.12); border-radius: 10px; padding: 2px 10px; font-size: 14px; font-weight: 800; }
.toast {
  position: absolute; bottom: 52px; left: 400px; transform: translateX(-50%); z-index: 30; pointer-events: none; max-width: 760px;
  background: var(--paper); border: 3px solid var(--ink); font-weight: 800; font-size: 19px; text-align: center;
  padding: 7px 20px; border-radius: 16px; box-shadow: 0 5px 0 rgba(0,0,0,.5); animation: popc .3s ease both;
}

/* ------------------------------------------------ overlays */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(30,15,5,.5), rgba(10,4,0,.85)); animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { transform: scale(.85); opacity: 0 } }
@keyframes popc { from { transform: translateX(-50%) scale(.85); opacity: 0 } }
.loader { text-align: center; font-size: 22px; color: #fff; }
.spin { width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 50%; border: 7px solid rgba(255,255,255,.25); border-top-color: var(--yellow); animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg) } }
.modal {
  background: var(--paper); border: 4px solid var(--ink); border-radius: 26px; padding: 18px 28px; min-width: 460px; max-width: 1060px; max-height: 690px;
  text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,.6), 0 30px 60px rgba(0,0,0,.5); animation: pop .25s cubic-bezier(.3,1.6,.5,1) both; overflow-y: auto;
}
.modal.wide { width: 900px; }
.modal h2 { margin: 0 0 4px; font-size: 34px; line-height: 1.1; }
.modal .h2b { font-size: 26px; margin-top: 14px; }
.modal .sub { margin: 0 0 10px; color: var(--ink2); font-size: 17px; line-height: 1.3; }
.modal .sub.small { font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; align-items: stretch; margin-top: 8px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; min-width: 0; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }
.keys { font-size: 14px !important; margin-top: 12px !important; }
.btn {
  cursor: pointer; font-weight: 800; font-size: 20px; color: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 7px 20px 9px;
  box-shadow: 0 4px 0 rgba(0,0,0,.6), inset 0 -4px 0 rgba(0,0,0,.15), inset 0 3px 0 rgba(255,255,255,.35);
  text-shadow: 0 2px 0 rgba(0,0,0,.25); transition: transform .1s, filter .1s; line-height: 1.15;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.6); }
.btn:disabled { filter: grayscale(.85) brightness(.85); cursor: not-allowed; transform: none; }
.btn.green { background: linear-gradient(#a6e04a, #5f9e1c); }
.btn.blue { background: linear-gradient(#5ab8ea, #1570a8); }
.btn.purple { background: linear-gradient(#a57ae0, #5a3a93); }
.btn.dark { background: linear-gradient(#7a5a44, #4a3222); }
.btn.red { background: linear-gradient(#ff7a6e, #d2321f); }
.btn.gold { background: linear-gradient(#ffd84a, #e08a10); color: var(--ink); text-shadow: none; }
.btn.big { font-size: 32px; padding: 10px 46px 13px; }
.btn.small { font-size: 16px; padding: 4px 14px 6px; }
.btn.off { opacity: .55; text-decoration: line-through; }
textarea { width: 100%; height: 70px; font: 13px/1.3 monospace; border: 2px solid var(--ink2); border-radius: 10px; background: #fff; resize: none; user-select: text; -webkit-user-select: text; }
.langrow { display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 800; font-size: 19px; }
select { font-size: 18px; font-weight: 700; padding: 4px 10px; border-radius: 12px; border: 3px solid var(--ink); background: #fff; cursor: pointer; color: var(--ink); }
.big-reward { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 8px 0; }
.big-reward b { font-size: 56px; color: #b97a00; -webkit-text-stroke: 1.5px var(--ink); }

/* title */
.overlay.title { background: linear-gradient(rgba(20,10,5,.1), rgba(20,10,5,.55)), url(assets/bg_surface.webp) center/cover, #3a2414; }
.title-card { text-align: center; animation: pop .45s cubic-bezier(.3,1.6,.5,1) both; }
.logo { display: flex; flex-direction: column; line-height: .85; filter: drop-shadow(0 8px 0 rgba(0,0,0,.7)); }
.logo .l1 { font-size: 78px; font-weight: 800; color: var(--yellow); -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; letter-spacing: 5px; }
.logo .l2 { font-size: 128px; font-weight: 800; color: var(--orange); -webkit-text-stroke: 12px var(--ink); paint-order: stroke fill; letter-spacing: 10px; animation: wobble 2.4s ease-in-out infinite; }
@keyframes wobble { 25% { transform: rotate(-2deg) scale(1.02); } 75% { transform: rotate(2deg); } }
.tagline { font-size: 24px; color: #fff; font-weight: 800; margin: 14px auto 14px; text-shadow: 0 3px 0 var(--ink), 0 0 10px rgba(0,0,0,.6); max-width: 760px; }
.title-cast { display: flex; justify-content: center; gap: 2px; height: 104px; margin: 0 0 10px; }
.title-cast img { height: 100px; animation: hop 1.1s ease-in-out infinite; filter: drop-shadow(0 6px 0 rgba(0,0,0,.4)); }
@keyframes hop { 50% { transform: translateY(-12px) scaleY(1.04); } }
.hint { font-size: 16px; color: #fff; margin: 12px 0 0; font-weight: 700; text-shadow: 0 2px 0 var(--ink); }
.title-lang { display: inline-flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 20px; }
.title-lang select { font-size: 15px; padding: 2px 8px; }

/* quests + achievements */
.qlist { display: grid; gap: 8px; text-align: left; }
.quest { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 8px 14px; border-radius: 14px; background: #fff; border: 3px solid rgba(38,20,11,.2); }
.quest .qn { font-weight: 800; font-size: 18px; line-height: 1.15; }
.quest .qr { font-size: 14px; color: var(--ink2); font-weight: 700; display: flex; gap: 4px; align-items: center; }
.quest .prog { height: 10px; border-radius: 5px; background: #eadbc8; overflow: hidden; margin-top: 4px; }
.quest .prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #b8ea70); }
.quest .btn { font-size: 16px; padding: 3px 14px 5px; }
.achs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: left; }
.ach { padding: 6px 10px; border-radius: 14px; background: #fff; border: 3px solid rgba(38,20,11,.18); min-height: 78px; display: flex; flex-direction: column; gap: 2px; }
.ach.done { border-color: var(--green); background: #f3ffe6; }
.ach.claimed { opacity: .6; }
.ach .an { font-weight: 800; font-size: 15px; line-height: 1.1; }
.ach .ad { font-size: 12.5px; color: var(--ink2); line-height: 1.15; flex: 1; }
.ach .btn { font-size: 13px; padding: 1px 8px 3px; align-self: flex-start; }
.howto { text-align: left; font-size: 19px; line-height: 1.45; margin: 6px 0; padding-left: 28px; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 760px) and (pointer: coarse) {
  #rotate { display: block; position: fixed; left: 0; right: 0; bottom: 0; padding: 12px; text-align: center; z-index: 50; background: var(--yellow); color: var(--ink); font-weight: 800; }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .modal, .toast, #tut, .logo .l2, .title-cast img, #btn-boost.on, #btn-fight, .item.pop { animation: none !important; }
}
.btn.glow { animation: throb 1s ease-in-out infinite; box-shadow: 0 0 0 4px var(--yellow), 0 4px 0 rgba(0,0,0,.6); }
.mcard .tool.pop { animation: toolpop .35s cubic-bezier(.3,1.8,.5,1); }
@keyframes toolpop { 0% { transform: translateX(-50%) scale(.3) rotate(-20deg); } }
