:root {
  --bg: #e9f2df; --panel: #fff; --ink: #1d2a1a; --muted: #6b7a66; --line: #d5e3c8;
  --accent: #2f9e44; --accent-ink: #fff; --soft: #e3f0d6; --gold: #b7791f; --bad: #e03131;
  --r0: #8a99a6; --r1: #3b82f6; --r2: #f59f00;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111a10; --panel: #1c2a1a; --ink: #edf5e8; --muted: #94a58d; --line: #2c3d29; --accent: #51cf66; --accent-ink: #0b1a0d; --soft: #24361f; --gold: #fcc419; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body { font: 17px/1.4 -apple-system, system-ui, sans-serif; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

/* ---------- game screen ---------- */
#game { height: 100%; display: flex; flex-direction: column; }
.hud {
  display: flex; align-items: center; gap: 6px;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: var(--panel); box-shadow: 0 1px 0 var(--line);
}
.stat { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; font-size: 18px; min-width: 64px; }
.stat b { font-weight: 800; }
.stat .ic { font-size: 16px; }
.stat.wave { flex: 1; justify-content: center; font-size: 16px; color: var(--muted); flex-direction: column; gap: 0; line-height: 1.05; }
.stat.wave small { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat.wave small.boss { color: var(--bad); }
.stat.wave b { color: var(--ink); font-size: 17px; }
.money b { color: var(--gold); font-size: 21px; }
#money-box.pop { animation: pop-money .45s; }
@keyframes pop-money { 30% { transform: scale(1.3); } }
#lives-box.hurt { animation: hurt .4s; }
@keyframes hurt { 30% { transform: scale(1.25); color: var(--bad); } }
.hbtn { min-width: 44px; height: 44px; border: 0; border-radius: 12px; background: var(--soft); font-weight: 800; font-size: 16px; padding: 0 10px; }

#stage { flex: 1; position: relative; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); pointer-events: none;
  font-size: 34px; font-weight: 900; color: #fff; letter-spacing: .02em; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 18px rgba(0,0,0,.35); animation: banner 1.6s ease-out forwards;
}
.banner.boss { color: #ffd43b; font-size: 42px; }
.banner small { display: block; font-size: 17px; font-weight: 700; text-align: center; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 25% { transform: translate(-50%, -50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }

.toast {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: calc(100% - 24px);
  background: rgba(20, 28, 18, .92); color: #fff; padding: 10px 14px; border-radius: 14px; font-size: 15px; text-align: center; pointer-events: none;
}

.dock {
  background: var(--panel); box-shadow: 0 -1px 0 var(--line);
  padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  display: grid; gap: 8px;
}
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.tw {
  position: relative; border: 0; border-radius: 12px; background: var(--soft); padding: 4px 0 3px; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; touch-action: none;
}
.tw img { width: 40px; height: 40px; pointer-events: none; }
.tw span { font-size: 14px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.tw.poor { opacity: .45; }
.tw.locked img { filter: grayscale(1); opacity: .35; }
.tw.locked span { color: var(--muted); }
.tw.on { background: var(--accent); }
.tw.on span { color: var(--accent-ink); }

.preview { display: flex; gap: 6px; align-items: center; min-height: 30px; overflow-x: auto; scrollbar-width: none; }
.preview::-webkit-scrollbar { display: none; }
.chip { display: flex; align-items: center; gap: 2px; border: 0; background: var(--soft); border-radius: 15px; padding: 0 9px 0 3px; height: 30px; font-size: 14px; font-weight: 700; flex: none; font-variant-numeric: tabular-nums; }
.chip img { width: 26px; height: 26px; }
.chip.new { box-shadow: inset 0 0 0 2px var(--accent); }
.chip.trait { padding: 0 10px; background: #fff3bf; color: #7a5800; }
.chip.bossy { background: #ffe3e3; color: #a51111; }
@media (prefers-color-scheme: dark) { .chip.trait { background: #4a3d0a; color: #ffe066; } .chip.bossy { background: #4c1414; color: #ffa8a8; } }

.go { border: 0; border-radius: 14px; min-height: 52px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 18px; }
.go:disabled { background: var(--soft); color: var(--muted); }

.dock { position: relative; }
/* tower info slides up over the bottom of the board, so the board never changes size */
.info {
  position: absolute; left: 0; right: 0; bottom: 100%; z-index: 5; display: grid; gap: 8px;
  background: var(--panel); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 18px rgba(0,0,0,.18);
  padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); animation: up .18s ease-out;
}
.info-actions .btn { white-space: nowrap; font-size: 15px; padding: 6px 8px; }
.info-head { display: flex; align-items: center; gap: 10px; }
.info-head img { width: 40px; height: 40px; }
.info-title { flex: 1; display: grid; line-height: 1.2; }
.info-title small { color: var(--muted); font-size: 14px; }
.info-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; font-size: 12px; color: var(--muted); }
.info-stats b { display: block; font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }
.info-stats b i { font-style: normal; color: var(--accent); font-size: 13px; }
.info-actions { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 6px; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 14px; min-height: 48px; padding: 6px 12px; font-weight: 700; font-size: 16px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--soft); color: var(--ink); }
.btn:disabled { opacity: .45; }
.btn.big { min-height: 56px; font-size: 19px; width: 100%; }
.btn small { display: block; font-size: 13px; font-weight: 600; opacity: .8; }
.icon-btn { border: 0; background: none; min-width: 44px; min-height: 44px; font-size: 18px; color: var(--muted); }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: 44px; }
.center-btn { display: block; margin: 0 auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg); border-radius: 12px; padding: 3px; }
.seg button { border: 0; border-radius: 10px; background: none; min-height: 40px; padding: 0 12px; font-size: 15px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 10; }
.menu { background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; -webkit-user-select: none; }
.menu-inner {
  max-width: 480px; margin: 0 auto; display: grid; gap: 14px;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.title { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 8px; }
.title .logo { width: 64px; height: 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.title h1 { margin: 0; font-size: 40px; font-weight: 900; letter-spacing: -.01em; }
.tagline { margin: -4px 0 4px; text-align: center; color: var(--muted); }
.menu-buttons { display: grid; gap: 10px; }
.daily small { font-size: 13px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats3 div { background: var(--panel); border-radius: 14px; padding: 10px 4px; text-align: center; }
.stats3 b { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats3 span { font-size: 13px; color: var(--muted); }
.unlocks { display: grid; gap: 4px; }
.unlock-row { display: flex; justify-content: center; gap: 6px; }
.unlock-row img { width: 46px; height: 46px; }
.unlock-row img.locked { filter: grayscale(1); opacity: .3; }
.unlocks p { margin: 0; }
.card { background: var(--panel); border-radius: 16px; padding: 12px 16px; }
.card summary { font-weight: 700; min-height: 28px; cursor: pointer; }
.card p { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.settings { display: grid; padding: 4px 16px; }
.account { display: grid; gap: 6px; justify-items: center; }
.account p { margin: 0; }
.hint { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 14px; padding: 6px 4px 6px 14px; font-size: 15px; }
.hint span { flex: 1; }

.sheet-wrap { background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--panel); border-radius: 22px 22px 0 0; display: grid; gap: 12px;
  padding: 18px max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0; font-size: 24px; }
.sheet p { margin: 0; }
.big-text { font-size: 20px; font-weight: 700; }
.good { color: var(--accent); font-weight: 800; font-size: 18px; }
.unlock-msg { font-weight: 800; color: var(--gold); }

.cards { display: grid; gap: 10px; }
.cardpick {
  display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 16px; padding: 12px 14px; min-height: 72px;
  background: var(--soft); box-shadow: inset 0 0 0 2px var(--rc, var(--r0)); animation: pop .3s ease-out backwards;
}
.cardpick:nth-child(2) { animation-delay: .06s; }
.cardpick:nth-child(3) { animation-delay: .12s; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.cardpick .ci { width: 44px; height: 44px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 26px; background: var(--panel); }
.cardpick .ci img { width: 40px; height: 40px; }
.cardpick b { display: block; font-size: 17px; }
.cardpick span { display: block; font-size: 15px; color: var(--muted); line-height: 1.3; }
.cardpick small { display: block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--rc); }
.cardpick.r1 { --rc: var(--r1); }
.cardpick.r2 { --rc: var(--r2); background: linear-gradient(135deg, var(--soft), rgba(245, 159, 0, .18)); }

.debug { display: grid; gap: 6px; border-top: 1px dashed var(--line); padding-top: 10px; }
.debug-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.debug-grid .btn { font-size: 14px; min-height: 44px; padding: 4px; }

/* small phones: a bit tighter */
@media (max-height: 700px) {
  .tw { min-height: 56px; }
  .tw img { width: 34px; height: 34px; }
  .go { min-height: 48px; }
}

/* ---------- relic bar ---------- */
.bar { display: flex; gap: 8px; align-items: center; padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); background: var(--panel); box-shadow: 0 1px 0 var(--line); }
.relics { flex: 1; display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.jk {
  position: relative; border: 0; height: 46px; border-radius: 12px; padding: 0; display: grid; place-items: center; font-size: 24px; line-height: 1;
  background: linear-gradient(160deg, #fff, #e8eef5); box-shadow: inset 0 0 0 2.5px var(--rc, var(--r0)), 0 2px 0 rgba(0,0,0,.18);
}
@media (prefers-color-scheme: dark) { .jk { background: linear-gradient(160deg, #3a4a3a, #263326); } }
.jk.r1 { --rc: var(--r1); }
.jk.r2 { --rc: var(--r2); background: linear-gradient(160deg, #fff6db, #ffe8a3); }
@media (prefers-color-scheme: dark) { .jk.r2 { background: linear-gradient(160deg, #5c4a12, #3d3010); } }
.jk.slot { background: none; box-shadow: inset 0 0 0 2px var(--line); opacity: .6; font-size: 11px; color: var(--muted); }
.jk.wig { animation: wig .35s; }
@keyframes wig { 25% { transform: rotate(-12deg) scale(1.15); } 60% { transform: rotate(9deg) scale(1.1); } }
.relics.big .jk { height: 52px; }

/* ---------- combo meter (top left of the board) ---------- */
.combo {
  position: absolute; left: 10px; top: 8px; z-index: 2; pointer-events: none; display: grid; justify-items: start; gap: 2px;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.4), 0 0 10px rgba(0,0,0,.3);
}
.combo b { font-size: 30px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.combo span { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; margin-top: -2px; }
.combo i { display: block; width: 80px; height: 6px; border-radius: 3px; background: rgba(0,0,0,.35); overflow: hidden; }
.combo em { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd43b, #ff6b2b, #e03131); }
.combo.hot b { color: #ffd43b; } .combo.hotter b { color: #ff922b; } .combo.max b { color: #ff6b6b; animation: hotpulse .5s infinite alternate; }
.combo.bump b { animation: bump .3s; }
@keyframes bump { 40% { transform: scale(1.35); } }
@keyframes hotpulse { to { transform: scale(1.08); } }

.info-els { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.el-chip { padding: 3px 9px; border-radius: 10px; font-weight: 800; color: #fff; font-size: 13px; }
.mod-chip { padding: 3px 9px; border-radius: 10px; font-weight: 700; background: var(--soft); font-size: 13px; }

.codex { display: grid; gap: 8px; margin-top: 10px; }
.codex div { display: grid; gap: 1px; font-size: 14px; }
.codex b { font-size: 15px; }
.codex span { color: var(--muted); }
.codex .unknown { opacity: .5; }
.chest-items { display: grid; gap: 8px; }

.banner.hand { font-size: 30px; color: #fff; top: 30%; }

/* ---------- cash out ---------- */
.cash-lines { display: grid; gap: 4px; }
.cash-line { display: flex; justify-content: space-between; font-size: 17px; padding: 8px 2px; border-bottom: 1px dashed var(--line); animation: pop .3s ease-out backwards; }
.cash-line b { color: var(--gold); font-variant-numeric: tabular-nums; }
.btn.gold { background: #f59f00; color: #1f1300; }

/* ---------- shop ---------- */
.shop { max-height: 88vh; overflow-y: auto; }
.shop-head { display: flex; align-items: center; justify-content: space-between; }
.money-big { font-size: 26px; color: var(--gold); font-variant-numeric: tabular-nums; }
.shop-items { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.offer {
  display: grid; gap: 4px; align-content: start; text-align: left; border: 0; border-radius: 14px; padding: 10px; min-height: 120px;
  background: var(--soft); box-shadow: inset 0 0 0 2px var(--rc, var(--r0)); animation: pop .3s ease-out backwards;
}
.offer:nth-child(2) { animation-delay: .05s; } .offer:nth-child(3) { animation-delay: .1s; } .offer:nth-child(4) { animation-delay: .15s; }
.offer.r1 { --rc: var(--r1); } .offer.r2 { --rc: var(--r2); } .offer.mod { --rc: #be4bdb; }
.offer .top { display: flex; align-items: center; justify-content: space-between; }
.offer .em { font-size: 30px; line-height: 1; }
.offer .price { font-weight: 900; color: var(--gold); font-size: 18px; }
.offer small { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--rc); }
.offer b { font-size: 15px; line-height: 1.2; }
.offer span { font-size: 13px; color: var(--muted); line-height: 1.3; }
.offer.sold { opacity: .35; }
.offer.no .price { color: var(--bad); }

/* ---------- joker / scroll close up ---------- */
.detail-head { display: flex; gap: 14px; align-items: flex-start; }
.detail-head h2 { font-size: 22px; }
.detail-head p { margin: 4px 0 0; }
.big-card { width: 72px; height: 96px; font-size: 40px; flex: none; }
.rarity { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.d-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }

