* { box-sizing: border-box; }
:root { --ink: #1a1c2c; --navy: #29366f; --red: #d23c4b; --cream: #fdf1d8; --gold: #ffcd75; --lime: #a7f070; --sky: #41a6f6; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0e0f1c; color: var(--cream);
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(14,15,28,.62); animation: fade .2s ease; }
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.8); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes sway { 0%,100% { transform: rotate(-2deg) } 50% { transform: rotate(1.5deg) } }
@keyframes shake { 0%,100% { transform: translateX(0) rotate(0) } 25% { transform: translateX(-6px) rotate(-4deg) } 75% { transform: translateX(6px) rotate(4deg) } }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 4px var(--ink), 0 0 18px 4px rgba(255,205,117,.5) } 50% { box-shadow: 0 0 0 4px var(--ink), 0 0 34px 10px rgba(255,205,117,.9) } }
@keyframes cardin { from { transform: translateY(60px) rotate(4deg); opacity: 0 } to { transform: translateY(0) rotate(0); opacity: 1 } }

#loading { background: #14152a url(assets/cover.webp) center/cover; }
.loader { text-align: center; font-size: 24px; font-weight: 800; background: rgba(26,28,44,.92); padding: 22px 40px; border: 4px solid var(--gold); border-radius: 10px; }
.spin { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; border: 7px solid #3a3d5c; border-top-color: var(--red); animation: rot .8s linear infinite; }
.bar { width: 260px; height: 14px; border: 3px solid var(--cream); background: var(--ink); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }
@keyframes rot { to { transform: rotate(360deg) } }

/* ---------------- menu (the attract-mode demo runs behind it) */
#menu { display: block; background: linear-gradient(90deg, rgba(14,15,28,.9) 0%, rgba(14,15,28,.7) 40%, rgba(14,15,28,.15) 62%, rgba(14,15,28,.55) 100%); }
.menu-left { position: absolute; left: 40px; top: 28px; width: 600px; }
.menu-right { position: absolute; right: 26px; top: 20px; width: 470px; display: flex; flex-direction: column; gap: 12px; }
.logo { display: flex; flex-direction: column; line-height: .86; margin-bottom: 10px; transform-origin: left center; animation: sway 4s ease-in-out infinite; }
.logo .l1, .logo .l2 { font-weight: 900; letter-spacing: 3px; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink), 0 0 30px rgba(210,60,75,.6); }
.logo .l1 { font-size: 92px; color: var(--gold); }
.logo .l2 { font-size: 104px; color: var(--red); margin-left: 24px; }
.logo .l2 small { font-size: 46px; color: var(--cream); vertical-align: middle; }
.logo .l3 { align-self: flex-start; margin-top: 14px; font-size: 21px; font-weight: 800; background: var(--red); color: var(--cream); border: 3px solid var(--ink); padding: 2px 14px; border-radius: 6px; transform: rotate(-1.5deg); }
.playbox { display: flex; gap: 14px; align-items: stretch; margin-top: 18px; }
.playside { display: flex; flex-direction: column; gap: 10px; }
.daily, #btn-resume-run { display: flex; flex-direction: column; justify-content: center; line-height: 1.05; text-align: left; max-width: 280px; }
.daily b, #btn-resume-run b { font-size: 20px; }
.daily small, #btn-resume-run small { font-size: 14px; font-weight: 700; opacity: .9; }
.goal { margin-top: 18px; display: inline-block; font-size: 17px; font-weight: 800; background: rgba(26,28,44,.85); border: 3px solid var(--gold); color: var(--gold); padding: 5px 14px; border-radius: 8px; max-width: 580px; }
.menu-nav { position: absolute; left: 40px; bottom: 24px; display: flex; gap: 10px; flex-wrap: wrap; max-width: 1200px; }
.coinsbar { display: flex; justify-content: flex-end; gap: 10px; align-items: center; }
.coinpill { font-size: 24px; font-weight: 900; background: var(--ink); border: 3px solid var(--gold); border-radius: 20px; padding: 2px 16px; color: var(--gold); }
.streak { font-size: 16px; font-weight: 800; color: var(--cream); background: var(--red); border: 3px solid var(--ink); border-radius: 16px; padding: 2px 12px; }

.card { background: rgba(26,28,44,.9); border: 4px solid var(--cream); border-radius: 10px; box-shadow: 0 6px 0 var(--ink); padding: 10px 12px; }
.pick { display: flex; align-items: center; gap: 8px; }
.pick canvas { width: 150px; height: auto; flex: none; image-rendering: auto; }
.pinfo { flex: 1; min-width: 0; }
.plabel { font-size: 13px; font-weight: 800; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; }
.pname { font-size: 26px; font-weight: 900; line-height: 1; overflow-wrap: anywhere; }
.pdesc { font-size: 14px; font-weight: 700; color: #cfd3e8; line-height: 1.2; margin-top: 4px; }
.stagecard .pinfo { padding: 4px 6px; }
.arrow { font: inherit; font-size: 20px; width: 38px; height: 54px; flex: none; background: var(--navy); color: var(--cream); border: 3px solid var(--cream); border-radius: 8px; cursor: pointer; }
.arrow:hover { background: var(--red); }
.arrow:disabled { opacity: .3; cursor: default; }

.btn { font: inherit; font-weight: 900; font-size: 19px; color: var(--ink); border: 3.5px solid var(--ink); cursor: pointer; padding: 7px 18px 9px; border-radius: 8px; position: relative;
  box-shadow: 0 5px 0 var(--ink); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { filter: grayscale(1); opacity: .55; cursor: not-allowed; transform: none; }
.btn.big { font-size: 46px; padding: 6px 44px 10px; letter-spacing: 2px; }
.btn.red { background: var(--red); color: var(--cream); -webkit-text-stroke: 1px var(--ink); }
#btn-play { animation: bob 1.4s ease-in-out infinite; }
.btn.blue { background: var(--sky); color: var(--ink); }
.btn.yellow { background: var(--gold); }
.btn.white { background: var(--cream); }
.btn.green { background: #38b764; color: #fff; -webkit-text-stroke: .6px var(--ink); }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 14px; margin-left: 4px; }
.badge:empty { display: none; }

.modal { background: #20223a; border: 5px solid var(--cream); border-radius: 12px; padding: 16px 26px; min-width: 440px; max-width: 900px; max-height: 690px; text-align: center; box-shadow: 0 10px 0 var(--ink), 0 0 0 5px var(--ink); animation: pop .22s ease both; display: flex; flex-direction: column; color: var(--cream); }
.modal.wide { width: 880px; }
.modal.xwide { width: 1160px; max-width: 1160px; }
.modal h2 { margin: 0 0 6px; font-size: 40px; line-height: 1; color: var(--gold); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); letter-spacing: 1px; }
.sub { margin: 0 0 8px; color: #cfd3e8; font-size: 16px; font-weight: 700; }
.actions { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 12px; }
.coins { font-size: 24px; font-weight: 900; margin-right: auto; color: var(--gold); }
.stackrow { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }

.hgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.hcard { background: #2b2e4d; border: 3.5px solid var(--cream); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center; cursor: pointer; transition: transform .1s; }
.hcard:hover { transform: translateY(-3px); }
.hcard.on { border-color: var(--gold); animation: glow 1.6s ease-in-out infinite; }
.hcard.locked { opacity: .8; cursor: default; }
.hcard canvas { width: 100%; height: auto; }
.hcard .hn { font-size: 22px; font-weight: 900; line-height: 1; }
.hcard .hd { font-size: 14px; font-weight: 700; color: #cfd3e8; line-height: 1.2; min-height: 52px; }
.hcard .hw { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 800; color: var(--gold); }
.hcard .hw canvas { width: 30px; height: 30px; }
.hcard .hl { font-size: 13px; font-weight: 800; color: #ff9aa6; }

.sgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: left; overflow-y: auto; max-height: 470px; padding: 2px 4px; }
.srow { display: flex; align-items: center; gap: 10px; background: #2b2e4d; border: 3px solid #4a4e78; border-radius: 8px; padding: 6px 10px; }
.srow .ic { font-size: 28px; width: 38px; text-align: center; flex: none; }
.srow .st { flex: 1; min-width: 0; font-weight: 800; font-size: 16px; line-height: 1.1; }
.srow .st small { display: block; font-weight: 700; font-size: 13px; color: #cfd3e8; }
.pips { display: flex; gap: 3px; margin-top: 3px; }
.pips i { width: 14px; height: 8px; border: 2px solid var(--ink); background: #4a4e78; }
.pips i.on { background: var(--gold); }
.srow .btn { font-size: 15px; padding: 3px 10px 5px; min-width: 88px; box-shadow: 0 3px 0 var(--ink); }

.list { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.list.scroll { overflow-y: auto; max-height: 480px; padding-right: 6px; display: grid; grid-template-columns: 1fr 1fr; }
.qrow { display: flex; align-items: center; gap: 10px; background: #2b2e4d; border: 3px solid #4a4e78; border-radius: 8px; padding: 6px 10px; }
.qrow.done { border-color: #38b764; background: #243d35; }
.qrow .ic { font-size: 24px; width: 34px; text-align: center; flex: none; }
.qrow .qt { flex: 1; font-weight: 800; font-size: 15px; line-height: 1.15; min-width: 0; }
.qrow .qt small { display: block; font-weight: 700; font-size: 13px; color: var(--gold); }
.qrow .qp { width: 110px; flex: none; }
.qrow .pb { height: 10px; border: 2px solid var(--ink); background: #1a1c2c; }
.qrow .pb i { display: block; height: 100%; background: var(--lime); }
.qrow .qp small { display: block; font-size: 12px; font-weight: 800; text-align: center; }

.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.recipe { display: flex; align-items: center; gap: 8px; background: #2b2e4d; border: 3px solid #4a4e78; border-radius: 8px; padding: 6px 10px; text-align: left; }
.recipe canvas { width: 46px; height: 46px; flex: none; }
.recipe .op { font-size: 22px; font-weight: 900; color: var(--gold); }
.recipe .rn { flex: 1; font-weight: 800; font-size: 15px; line-height: 1.15; }
.recipe .rn small { display: block; font-weight: 700; font-size: 13px; color: #cfd3e8; }
.recipe.unknown canvas.evo { filter: brightness(0); }
.recipe.seen { border-color: var(--gold); }

.howto { text-align: left; font-size: 17px; margin: 4px 0; padding-left: 26px; line-height: 1.3; font-weight: 600; }
.hitems { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 8px 0; }
.hitem { display: flex; flex-direction: column; align-items: center; background: #2b2e4d; border: 2.5px solid #4a4e78; border-radius: 8px; padding: 2px 4px; font-size: 12px; line-height: 1.1; font-weight: 700; }
.hitem canvas { width: 64px; height: 56px; }
.keys { margin: 4px 0; color: #cfd3e8; font-size: 15px; font-weight: 700; }

.setrow { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin: 5px 0; font-size: 20px; font-weight: 800; }
.setrow select { font: inherit; font-size: 17px; padding: 4px 10px; border-radius: 6px; background: var(--cream); border: 3px solid var(--ink); }
.toggle { min-width: 120px; font-size: 17px; }

.build { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; }
.bitem { display: flex; align-items: center; gap: 8px; background: #2b2e4d; border: 2.5px solid #4a4e78; border-radius: 8px; padding: 4px 10px; font-weight: 800; font-size: 15px; }
.bitem canvas { width: 36px; height: 36px; flex: none; }
.bitem small { color: var(--gold); margin-left: auto; white-space: nowrap; }

/* ---------------- level up */
#levelup, #chest { background: radial-gradient(circle at 50% 45%, rgba(41,54,111,.72), rgba(14,15,28,.86)); }
.lvwrap, .chestwrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lvtitle { margin: 0; font-size: 58px; font-weight: 900; color: var(--gold); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); animation: pop .3s ease both; text-align: center; }
.lvcards { display: flex; gap: 16px; }
.lvcard { width: 250px; min-height: 270px; background: var(--cream); color: var(--ink); border: 5px solid var(--ink); border-radius: 12px; padding: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font: inherit;
  box-shadow: 0 8px 0 var(--ink); animation: cardin .35s cubic-bezier(.2,1.4,.4,1) both; transition: transform .1s; position: relative; }
.lvcard:nth-child(2) { animation-delay: .06s } .lvcard:nth-child(3) { animation-delay: .12s } .lvcard:nth-child(4) { animation-delay: .18s }
.lvcard:hover, .lvcard.sel { transform: translateY(-8px) rotate(-1deg); background: #fff7e3; }
.lvcard.evo { background: linear-gradient(#fff3c4, #ffd98a); }
.lvcard canvas { width: 96px; height: 96px; }
.lvcard .cn { font-size: 22px; font-weight: 900; line-height: 1.05; }
.lvcard .cl { font-size: 15px; font-weight: 900; color: var(--red); }
.lvcard .cd { font-size: 15px; font-weight: 700; line-height: 1.25; color: #3a3d5c; }
.lvcard .key { position: absolute; top: -12px; left: -12px; width: 30px; height: 30px; background: var(--ink); color: var(--gold); border-radius: 50%; font-weight: 900; line-height: 30px; font-size: 16px; }
.lvcard .newtag { position: absolute; top: -12px; right: -12px; background: var(--red); color: var(--cream); border: 3px solid var(--ink); border-radius: 12px; padding: 0 8px; font-size: 13px; font-weight: 900; transform: rotate(6deg); }
.lvcard .pair { font-size: 12px; font-weight: 800; color: #257179; }
.lvactions { display: flex; gap: 12px; }
.lvhint { margin: 0; font-size: 14px; font-weight: 700; color: #cfd3e8; }

.chestbox { width: 200px; height: 200px; }
.chestbox.shaking { animation: shake .12s linear infinite; }
.chestitems { display: flex; gap: 14px; min-height: 150px; }
.citem { width: 190px; background: var(--cream); color: var(--ink); border: 4px solid var(--ink); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; animation: cardin .4s cubic-bezier(.2,1.4,.4,1) both; box-shadow: 0 6px 0 var(--ink); }
.citem.evo { background: linear-gradient(#fff3c4, #ffc94a); width: 280px; }
.citem canvas { width: 72px; height: 72px; }
.citem.evo canvas { width: 110px; height: 110px; }
.citem b { font-size: 18px; line-height: 1.05; text-align: center; }
.citem small { font-size: 14px; font-weight: 800; color: var(--red); }

/* ---------------- result */
.result .rtitle { display: flex; justify-content: center; }
.result h2 { font-size: 66px; color: var(--red); animation: pop .3s ease both; }
.result h2.win { color: var(--gold); }
.quip { font-size: 18px; font-style: italic; }
.rbody { display: flex; gap: 14px; align-items: stretch; text-align: left; }
.rstats { width: 330px; flex: none; display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 18px; font-weight: 800; align-content: start; background: #2b2e4d; border: 3px solid #4a4e78; border-radius: 8px; padding: 10px 14px; }
.rstats .v { text-align: right; }
.rstats .big { font-size: 28px; color: var(--gold); }
.rstats .nb { display: inline-block; background: var(--red); color: var(--cream); border: 2px solid var(--ink); font-size: 12px; padding: 0 6px; margin-left: 6px; border-radius: 6px; animation: pop .3s ease both; }
.rmid { width: 330px; flex: none; background: #2b2e4d; border: 3px solid #4a4e78; border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.dmgrow { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 800; }
.dmgrow canvas { width: 28px; height: 28px; flex: none; }
.dmgrow .bar2 { flex: 1; height: 10px; background: #1a1c2c; border: 2px solid var(--ink); }
.dmgrow .bar2 i { display: block; height: 100%; background: var(--red); }
.dmgrow span { width: 64px; text-align: right; }
.rright { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.rewards { background: var(--navy); border: 3px solid var(--ink); border-radius: 8px; padding: 8px 14px; font-size: 17px; font-weight: 800; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.rewards .tot { font-size: 28px; color: var(--gold); }
.rextra { display: flex; flex-direction: column; gap: 5px; font-size: 15px; font-weight: 800; max-height: 200px; overflow-y: auto; }
.rextra .ms { background: #38b764; color: #fff; border: 2.5px solid var(--ink); border-radius: 8px; padding: 3px 10px; animation: pop .3s ease both; }
.rextra .nx { background: #2b2e4d; border: 2.5px solid #4a4e78; border-radius: 8px; padding: 3px 10px; }

.toast { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); background: var(--cream); color: var(--ink); border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); padding: 8px 22px; border-radius: 10px; font-size: 20px; font-weight: 900; z-index: 20; animation: pop .2s ease; max-width: 900px; text-align: center; pointer-events: none; }
.pausebtn { position: absolute; top: 64px; right: 16px; width: 52px; height: 52px; border-radius: 8px; border: 3.5px solid var(--ink); background: var(--cream); color: var(--ink); font-size: 18px; font-weight: 900; cursor: pointer; z-index: 5; box-shadow: 0 4px 0 var(--ink); }
#rotate { display: none; position: fixed; inset: 0; background: #14152a; color: var(--gold); font-size: 26px; font-weight: 900; align-items: center; justify-content: center; text-align: center; padding: 30px; z-index: 50; }
@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) { #rotate { display: flex; } }
@media (prefers-reduced-motion: reduce) { .logo, #btn-play, .hcard.on, .chestbox.shaking { animation: none; } }
/* phones: the 1280×720 stage is scaled ~0.55×, so give the menu buttons finger-sized heights (≈44 real px) */
@media (pointer: coarse) {
  .menu-nav .btn { min-height: 80px; }
}
@media (pointer: coarse) { #hero-prev, #hero-next, #stage-prev, #stage-next { min-width: 64px; min-height: 80px; } }
@media (pointer: coarse) { .pausebtn { width: 80px; height: 80px; font-size: 24px; } }
