* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #1b1b1b; color: #111;
  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(17,17,17,.55); animation: fade .2s ease;
  background-image: radial-gradient(rgba(0,0,0,.25) 1.5px, transparent 1.6px); background-size: 9px 9px; }
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.8) rotate(-2deg); opacity: 0 } to { transform: scale(1) rotate(0); opacity: 1 } }
@keyframes wob { 0%,100% { transform: rotate(-3deg) } 50% { transform: rotate(1deg) } }
@keyframes bounce { 0%,100% { transform: translateY(0) rotate(-1deg) } 50% { transform: translateY(-6px) rotate(1deg) } }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-3px) } 75% { transform: translateX(3px) } }

#loading { background: #ffde00 url(assets/menu_bg.webp) center/cover; }
.loader { text-align: center; font-size: 24px; font-weight: 800; background: #fff; padding: 22px 40px; border: 4px solid #111; border-radius: 6px; box-shadow: 8px 8px 0 #111; }
.spin { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; border: 7px solid #ddd; border-top-color: #e4002b; animation: rot .8s linear infinite; }
.bar { width: 260px; height: 14px; border: 3px solid #111; background: #fff; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; background: #e4002b; transition: width .2s; }
@keyframes rot { to { transform: rotate(360deg) } }

/* ---------------- menu (the attract-mode chase runs behind it) */
#menu { display: block; background: linear-gradient(90deg, rgba(255,222,0,.94) 0%, rgba(255,222,0,.82) 36%, rgba(255,222,0,0) 58%); background-size: auto; }
.menu-left { position: absolute; left: 40px; top: 26px; width: 560px; }
.menu-right { position: absolute; right: 26px; top: 20px; width: 440px; display: flex; flex-direction: column; gap: 12px; }
.logo { display: flex; flex-direction: column; line-height: .82; margin-bottom: 14px; transform-origin: left center; animation: wob 3.4s ease-in-out infinite; }
.logo .l1, .logo .l2 { font-weight: 900; letter-spacing: 3px; -webkit-text-stroke: 3px #111; paint-order: stroke fill; text-shadow: 6px 6px 0 #111; }
.logo .l1 { font-size: 86px; color: #fff; }
.logo .l2 { font-size: 112px; color: #e4002b; margin-left: 30px; }
.logo .l3 { align-self: flex-start; margin-top: 14px; font-size: 22px; font-weight: 800; background: #fff; border: 3px solid #111; padding: 2px 14px; transform: rotate(-2deg); box-shadow: 4px 4px 0 #111; }
.playbox { display: flex; gap: 14px; align-items: stretch; margin-top: 18px; }
.daily { display: flex; flex-direction: column; justify-content: center; line-height: 1.05; text-align: left; max-width: 240px; }
.daily b { font-size: 21px; }
.daily small { font-size: 14px; font-weight: 700; opacity: .9; }
.bestline { margin-top: 16px; font-size: 20px; font-weight: 800; }
.goal { margin-top: 8px; display: inline-block; font-size: 17px; font-weight: 800; background: #fff; border: 3px solid #111; padding: 4px 12px; box-shadow: 4px 4px 0 #111; max-width: 540px; }
.menu-nav { position: absolute; left: 40px; bottom: 24px; display: flex; gap: 10px; flex-wrap: wrap; max-width: 1200px; }

.card { background: #fff; border: 4px solid #111; border-radius: 6px; box-shadow: 7px 7px 0 #111; padding: 10px 14px; }
.runnerbox { position: relative; padding: 0; overflow: hidden; cursor: pointer; background: #0057b8;
  background-image: radial-gradient(rgba(255,255,255,.18) 2px, transparent 2.2px); background-size: 12px 12px; }
.runnerbox canvas { display: block; width: 100%; height: auto; }
.rname { position: absolute; left: 12px; bottom: 10px; font-size: 26px; font-weight: 900; color: #fff; -webkit-text-stroke: 1.5px #111; paint-order: stroke fill; text-shadow: 3px 3px 0 #111; }
.rgems { position: absolute; right: 12px; top: 10px; font-size: 24px; font-weight: 900; color: #fff; background: #111; border-radius: 20px; padding: 2px 14px; }
.mcard { padding: 8px 14px 10px; }
.mhead { display: flex; justify-content: space-between; font-size: 18px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
.streak { color: #e4002b; font-size: 16px; text-transform: none; letter-spacing: 0; }
.mmini { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.mm { font-size: 15px; font-weight: 700; line-height: 1.1; display: flex; gap: 8px; align-items: center; }
.mm .t { flex: 1; }
.mm .pb { width: 90px; height: 10px; border: 2px solid #111; background: #eee; flex: none; }
.mm .pb i { display: block; height: 100%; background: #0057b8; }

.btn { font: inherit; font-weight: 900; font-size: 20px; color: #111; border: 3.5px solid #111; cursor: pointer; padding: 7px 18px 9px; border-radius: 6px; position: relative;
  box-shadow: 5px 5px 0 #111; transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { transform: translate(-1px, -2px) rotate(-1deg); box-shadow: 7px 7px 0 #111; }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 #111; }
.btn:disabled { filter: grayscale(1); opacity: .6; cursor: not-allowed; }
.btn.big { font-size: 42px; padding: 6px 42px 10px; letter-spacing: 2px; }
.btn.red { background: #e4002b; color: #fff; -webkit-text-stroke: 1px #111; }
#btn-play { animation: bounce 1.3s ease-in-out infinite; }
.btn.blue { background: #0057b8; color: #fff; }
.btn.yellow { background: #ffde00; }
.btn.white { background: #fff; }
.btn.green { background: #2ecc40; color: #fff; -webkit-text-stroke: .6px #111; }
.badge { background: #e4002b; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 14px; margin-left: 4px; }

.modal { background: #fff; border: 5px solid #111; border-radius: 8px; padding: 18px 28px; min-width: 440px; max-width: 900px; max-height: 690px; text-align: center; box-shadow: 12px 12px 0 #111; animation: pop .22s ease both; display: flex; flex-direction: column; }
.modal.wide { width: 860px; }
.modal.xwide { width: 1140px; max-width: 1140px; }
.modal h2 { margin: 0 0 8px; font-size: 40px; line-height: 1; color: #ffde00; -webkit-text-stroke: 2px #111; paint-order: stroke fill; text-shadow: 4px 4px 0 #111; letter-spacing: 1px; }
.sub { margin: 0 0 8px; color: #333; font-size: 16px; font-weight: 700; }
.actions { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 14px; }
.coins { font-size: 24px; font-weight: 900; margin-right: auto; } .coins b { color: #0057b8; }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 280px; margin: 8px auto; }

.tribe { display: flex; gap: 18px; text-align: left; min-height: 0; }
.tprev { width: 380px; flex: none; display: flex; flex-direction: column; gap: 6px; }
.tprev canvas { width: 100%; height: auto; display: block; border: 4px solid #111; background: #ffde00;
  background-image: radial-gradient(rgba(228,0,43,.25) 2px, transparent 2.2px); background-size: 11px 11px; }
.tname { font-size: 28px; font-weight: 900; line-height: 1; }
.tdesc { font-size: 16px; font-weight: 700; color: #333; min-height: 40px; line-height: 1.2; }
.tstats { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 14px; font-weight: 800; align-items: center; }
.tstats .sb { height: 12px; border: 2px solid #111; background: #eee; }
.tstats .sb i { display: block; height: 100%; background: #e4002b; }
.tgrid { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; align-content: start; max-height: 520px; overflow-y: auto; padding: 4px 8px 8px 4px; }
.titem { background: #fff; border: 3.5px solid #111; border-radius: 6px; padding: 6px; cursor: pointer; text-align: center; font: inherit; position: relative; box-shadow: 4px 4px 0 #111; transition: transform .1s; }
.titem:hover { transform: translateY(-2px) rotate(-1deg); }
.titem.on { background: #ffde00; }
.titem canvas { width: 100%; height: auto; display: block; }
.titem .tn { font-size: 15px; font-weight: 900; line-height: 1.05; min-height: 32px; overflow-wrap: anywhere; display: flex; align-items: center; justify-content: center; }
.titem .tc { font-size: 15px; font-weight: 900; color: #0057b8; }
.titem.locked canvas { filter: brightness(0) opacity(.55); }
.titem .sel { position: absolute; top: -10px; right: -8px; background: #e4002b; color: #fff; border: 2.5px solid #111; border-radius: 12px; font-size: 12px; padding: 0 7px; font-weight: 900; }

.list { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.qrow { display: flex; align-items: center; gap: 12px; background: #f3f3f3; border: 3px solid #111; border-radius: 6px; padding: 8px 12px; }
.qrow .ic { font-size: 30px; width: 44px; text-align: center; flex: none; }
.qrow .qt { flex: 1; font-weight: 800; font-size: 17px; line-height: 1.15; }
.qrow .qt small { display: block; font-weight: 700; font-size: 14px; color: #555; }
.qrow .qp { width: 170px; flex: none; }
.pips { display: flex; gap: 4px; }
.pips i { width: 24px; height: 14px; border: 2px solid #111; background: #fff; }
.pips i.on { background: #0057b8; }
.qrow .pb { height: 14px; border: 2.5px solid #111; background: #fff; }
.qrow .pb i { display: block; height: 100%; background: #2ecc40; }
.qrow .qp small { display: block; font-size: 13px; font-weight: 800; text-align: center; }
.qrow .qr { width: 80px; text-align: right; font-weight: 900; color: #0057b8; font-size: 18px; flex: none; }
.qrow .btn { font-size: 16px; padding: 4px 12px 6px; min-width: 110px; }

.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(4, 1fr); gap: 8px; text-align: left; margin: 8px 0; }
.hitem { display: flex; gap: 6px; align-items: center; background: #f3f3f3; border: 2.5px solid #111; border-radius: 6px; padding: 4px 6px; font-size: 13px; line-height: 1.1; font-weight: 600; }
.hitem canvas { width: 54px; height: 40px; flex: none; }
.hitem b { display: block; font-size: 14px; }
.keys { margin: 4px 0; color: #333; font-size: 15px; font-weight: 700; }

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

.result .rtitle { display: flex; justify-content: center; }
.result h2 { font-size: 64px; color: #e4002b; transform: rotate(-2deg); animation: shake .3s ease 2; }
.quip { font-size: 19px; font-style: italic; }
.rbody { display: flex; gap: 20px; align-items: stretch; text-align: left; }
.rstats { width: 440px; flex: none; display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; font-size: 20px; font-weight: 800; align-content: start; background: #f3f3f3; border: 3px solid #111; border-radius: 6px; padding: 10px 16px; }
.rstats .v { text-align: right; }
.rstats .big { font-size: 30px; color: #e4002b; }
.rstats .nb { display: inline-block; background: #ffde00; border: 2.5px solid #111; font-size: 13px; padding: 0 6px; margin-left: 6px; transform: rotate(-4deg); animation: pop .3s ease both; }
.rright { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.rewards { background: #0057b8; color: #fff; border: 3px solid #111; border-radius: 6px; padding: 10px 16px; font-size: 18px; font-weight: 800; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.rewards .tot { font-size: 30px; color: #ffde00; -webkit-text-stroke: 1px #111; }
.rextra { display: flex; flex-direction: column; gap: 5px; font-size: 16px; font-weight: 800; max-height: 190px; overflow-y: auto; }
.rextra .ms { background: #2ecc40; color: #fff; border: 2.5px solid #111; border-radius: 6px; padding: 3px 10px; animation: pop .3s ease both; -webkit-text-stroke: .4px #111; }
.rextra .nx { background: #f3f3f3; border: 2.5px solid #111; border-radius: 6px; padding: 3px 10px; }

.toast { position: absolute; top: 150px; left: 50%; transform: translateX(-50%); background: #fff; border: 4px solid #111; box-shadow: 6px 6px 0 #111; padding: 8px 22px; border-radius: 6px; 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: 14px; right: 16px; width: 54px; height: 54px; border-radius: 6px; border: 3.5px solid #111; background: #fff; color: #111; font-size: 18px; font-weight: 900; cursor: pointer; z-index: 5; box-shadow: 4px 4px 0 #111; }
#rotate { display: none; position: fixed; inset: 0; background: #ffde00; color: #111; 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, .result h2 { animation: none; } }
