:root {
  --ink: #140c1c;
  --panel: #241a33;
  --panel2: #2f2342;
  --edge: #6d5a8c;
  --hi: #ffcd38;
  --txt: #f4f4f4;
  --muted: #a99bbf;
  --red: #e23d4b;
  --green: #5cc85c;
  --blue: #3b74e6;
  --font: "Press Start 2P", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); overflow: hidden; color: var(--txt); font-family: var(--font); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
img.ico { image-rendering: pixelated; width: 18px; height: auto; vertical-align: middle; }
img.ico.big { width: 36px; }
img.ico.huge { width: 96px; }

#ui { position: fixed; inset: 0; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#ui.on { display: block; }

.screen { min-height: 100%; padding: 16px max(16px, env(safe-area-inset-left)) 32px; max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; }
.overlay { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20, 12, 28, 0.55); }
.panel { background: var(--panel); border: 3px solid var(--edge); box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px rgba(0, 0, 0, 0.45); padding: 18px; width: min(560px, 100%); }
.panel.wide { width: min(900px, 100%); }

h2 { font-size: clamp(14px, 3.4vw, 24px); margin: 0; text-align: center; color: var(--hi); text-shadow: 3px 3px 0 var(--ink); letter-spacing: 1px; }
h3 { font-size: 12px; color: var(--hi); margin: 22px 0 10px; }
p, .hint { font-size: 10px; line-height: 1.8; color: var(--muted); }
.hint { text-align: center; margin-top: 18px; }
.sub { font-size: 10px; text-align: center; color: var(--muted); margin: 8px 0 14px; line-height: 1.6; }
.muted { color: var(--muted); font-size: 10px; }
.ok { color: var(--green); font-size: 10px; }
b { color: var(--txt); }

/* ---------- buttons & cards */
.btn {
  font-family: var(--font); font-size: 12px; color: var(--txt); background: #3a2d52; border: 3px solid var(--ink);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.35), inset 3px 3px 0 rgba(255, 255, 255, 0.12); padding: 12px 18px; cursor: pointer;
  text-transform: uppercase; letter-spacing: 1px;
}
.btn.big { font-size: 15px; padding: 15px 26px; background: #b8323f; }
.btn.small { font-size: 9px; padding: 8px 10px; }
.btn.danger { background: #6b1f2b; }
.btn.active { background: var(--blue); }
.btn.focused, .btn:hover { outline: 3px solid var(--hi); outline-offset: 1px; filter: brightness(1.15); }
.btn:active { transform: translateY(2px); }

.card {
  font-family: var(--font); color: var(--txt); text-align: left; background: var(--panel2); border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--edge); padding: 12px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
.card.focused, .card:hover { box-shadow: inset 0 0 0 3px var(--hi); background: #3b2c55; }
.card.locked { opacity: 0.55; }
.card.locked .portrait { filter: brightness(0); }
.card[disabled] { cursor: not-allowed; }
.cname { font-size: 11px; color: var(--txt); }
.ctitle { font-size: 8px; color: var(--muted); }
.cdesc { font-size: 9px; color: #d8cfe8; line-height: 1.7; }
.cweap { font-size: 9px; color: var(--hi); display: flex; align-items: center; gap: 6px; }
.cost { font-size: 10px; color: var(--hi); margin-top: auto; }
.gold { font-size: 12px; color: var(--hi); display: inline-flex; align-items: center; gap: 6px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.hdr { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-bottom: 18px; }
.hdr > :first-child { justify-self: start; }
.hdr > :last-child { justify-self: end; }
.grid { display: grid; gap: 12px; }
.grid.chars { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.stages { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.shop { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.portrait { image-rendering: pixelated; width: 60px; height: auto; align-self: center; filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.4)); }

/* ---------- title */
.title { align-items: center; justify-content: center; text-align: center; gap: 18px; }
.topbar { position: absolute; top: 14px; right: 16px; }
.logo { line-height: 1.1; margin-top: 10px; }
.logo .l1, .logo .l2 { font-size: clamp(26px, 7.4vw, 72px); color: #fff; text-shadow: 4px 4px 0 var(--red), 8px 8px 0 var(--ink); letter-spacing: 2px; }
.logo .l2 { color: var(--hi); text-shadow: 4px 4px 0 #9c2133, 8px 8px 0 var(--ink); }
.tagline { font-size: clamp(9px, 1.8vw, 13px); color: #9fd3ff; min-height: 1.5em; animation: blink 2.6s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.55; } }
.menu { display: flex; flex-direction: column; gap: 10px; min-width: min(320px, 90vw); }
.foot { font-size: 8px; color: var(--muted); max-width: 520px; line-height: 1.8; margin-top: 10px; }

/* ---------- stages */
.card.stage { min-height: 170px; justify-content: flex-end; }
.stage-er { background: linear-gradient(180deg, rgba(36, 26, 51, 0.15), rgba(36, 26, 51, 0.95)), repeating-conic-gradient(#cfe3df 0 25%, #bcd6d1 0 50%) 0 0 / 32px 32px; }
.stage-hq { background: linear-gradient(180deg, rgba(36, 26, 51, 0.15), rgba(36, 26, 51, 0.95)), #5b6274; }
.sname { font-size: 14px; color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.ssub { font-size: 9px; color: var(--hi); }
.sdesc { font-size: 9px; color: #e6def2; line-height: 1.7; }
.sbest { font-size: 9px; color: #9fd3ff; }

/* ---------- level up */
.levelup h2.flash { animation: flash 0.6s steps(2) 3; }
@keyframes flash { 50% { color: #fff; } }
.choices { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.card.choice { flex-direction: row; align-items: center; gap: 12px; width: 100%; }
.card.choice .cbody { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.crow { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.ctag { font-size: 9px; color: var(--muted); white-space: nowrap; }
.new { color: var(--hi); }
.evohint { font-size: 8px; color: #9fd3ff; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.evohint img.ico { width: 14px; }
.loadout { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.loadout > div { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.loadout.names { align-items: stretch; }
.loadout.names > div { flex-direction: column; gap: 4px; }
.lo { display: inline-flex; align-items: center; gap: 4px; font-size: 9px; background: rgba(0, 0, 0, 0.3); padding: 4px 6px; }
.lo b { color: var(--hi); font-weight: normal; }

/* ---------- chest */
.chest .panel { text-align: center; }
.chestbox { margin: 4px 0 10px; }
.shake { animation: shake 0.5s steps(4) 2; }
@keyframes shake { 25% { transform: translate(-4px, 2px) rotate(-6deg); } 50% { transform: translate(4px, -2px) rotate(5deg); } 75% { transform: translate(-2px, -3px); } }
.loots { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.loot { display: flex; align-items: center; gap: 12px; background: var(--panel2); padding: 10px; text-align: left; border: 2px solid var(--edge); }
.loot > div { display: flex; flex-direction: column; gap: 6px; }
.loot.evo { border-color: var(--hi); background: #4a3a1c; animation: glow 0.8s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 16px var(--hi); } }
.goldgain { color: var(--hi); font-size: 14px; margin: 12px 0 16px; display: flex; justify-content: center; align-items: center; gap: 8px; }

/* ---------- pause / results */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 700px) { .cols { grid-template-columns: 1fr; } }
.stats { display: flex; flex-direction: column; gap: 6px; }
.st { display: flex; justify-content: space-between; gap: 10px; font-size: 9px; padding: 4px 6px; background: rgba(0, 0, 0, 0.22); }
.stats.big .st { font-size: 10px; padding: 7px 8px; }
.st.debt span:last-child { color: #ff6b5e; }
.goldtxt { color: var(--hi); }
h2.win { color: var(--green); }
h2.lose { color: #ff6b5e; }
table { border-collapse: collapse; width: 100%; font-size: 9px; }
th, td { padding: 6px; text-align: left; border-bottom: 2px solid rgba(255, 255, 255, 0.07); }
th { color: var(--muted); font-weight: normal; }
td img.ico { width: 16px; }
.unlock { text-align: center; color: var(--hi); font-size: 11px; margin-top: 14px; animation: blink 1s steps(1) infinite; }
.submit { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; align-items: center; min-height: 44px; }
.submit input { font-family: var(--font); font-size: 11px; padding: 11px; background: var(--ink); color: var(--txt); border: 3px solid var(--edge); width: 200px; -webkit-user-select: text; user-select: text; }

/* ---------- shop */
.card.pu { align-items: center; text-align: center; }
.card.pu.maxed { opacity: 0.7; }
.pips { display: flex; gap: 3px; }
.pips i { width: 10px; height: 10px; background: var(--ink); border: 2px solid var(--edge); }
.pips i.on { background: var(--hi); }

/* ---------- records */
.records p { max-width: 760px; }
.evos { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px; }
.evo-row { display: flex; align-items: center; gap: 8px; background: var(--panel2); padding: 8px; font-size: 12px; }
.evo-row img.ico.big { width: 28px; }
.foes { display: flex; flex-wrap: wrap; gap: 8px; }
.foe { display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--panel2); padding: 10px; font-size: 8px; width: 120px; text-align: center; }
.foe img.ico.big { width: auto; height: 40px; }

/* ---------- options & leaderboard */
.opts { display: flex; flex-direction: column; gap: 12px; max-width: 460px; margin: 0 auto; width: 100%; }
.opts label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 11px; background: var(--panel2); padding: 12px; }
.opts input[type=range] { width: 50%; accent-color: var(--hi); }
.tabs { margin: 0 0 14px; }
.board { background: var(--panel); border: 3px solid var(--edge); padding: 12px; min-height: 160px; }
.lb td:first-child { color: var(--hi); width: 40px; }

@media (max-width: 520px) {
  .btn { font-size: 10px; padding: 11px 12px; }
  .btn.big { font-size: 12px; padding: 13px 16px; }
  .hdr h2 { font-size: 11px; }
  .panel { padding: 12px; }
  .grid.chars { grid-template-columns: 1fr 1fr; }
  .card { padding: 9px; }
  .cname { font-size: 9px; }
  .cdesc { font-size: 8px; }
  .evos { grid-template-columns: 1fr; }
}

/* ---------- saves */
.btn.cont { display: flex; flex-direction: column; align-items: center; gap: 8px; background: #2c7d35; }
.btn small { font-size: 8px; color: #e6f5e0; text-transform: none; letter-spacing: 0; line-height: 1.5; }
.btn small.inl { color: var(--muted); }
.btn.warnbtn { background: #9c6a10; }
.topbar { display: flex; gap: 14px; align-items: center; }
.cloudtag { font-size: 10px; color: #9fd3ff; }
.cloudtag.warn { color: var(--hi); }
.notice { font-size: 10px; line-height: 1.7; color: var(--hi); background: rgba(0, 0, 0, 0.3); border: 2px solid var(--edge); padding: 10px 12px; margin-bottom: 14px; max-width: 560px; }
.title .notice { margin: 0 auto; }
p.warn { text-align: center; color: var(--hi); font-size: 9px; margin: -6px 0 14px; }
.sub.small { font-size: 8px; margin: 12px 0 0; }
.cloudbox { max-width: 680px; width: 100%; margin: 0 auto; background: var(--panel); border: 3px solid var(--edge); box-shadow: 0 0 0 3px var(--ink); padding: 18px; }
.cloudbox p { color: #d8cfe8; }
.cloudbox .stats { margin-bottom: 14px; }
.cloudbox .opts { margin: 16px 0 4px; }
.opts input[type=text], .opts input:not([type]), .opts input[type=password] {
  font-family: var(--font); font-size: 11px; padding: 10px; background: var(--ink); color: var(--txt); border: 3px solid var(--edge);
  width: 60%; -webkit-user-select: text; user-select: text;
}
.grid.choose { grid-template-columns: 1fr 1fr; margin: 14px 0; }
@media (max-width: 520px) { .grid.choose { grid-template-columns: 1fr; } .opts input { width: 100% !important; } .opts label { flex-direction: column; align-items: stretch; } }

/* ---------- full screen */
.topleft { position: absolute; top: 14px; left: 16px; }
.fsico { width: 1.1em; height: 1.1em; vertical-align: -0.2em; fill: currentColor; shape-rendering: crispEdges; }
.btn.fsbtn { white-space: nowrap; }
.fstip { margin: 0 auto 14px; }
.title .fstip { margin: 44px auto 0; }
@media (max-width: 520px) { .topleft .btn.small { font-size: 8px; padding: 7px 8px; } }
