* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #16162a; color: #fff;
  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: radial-gradient(ellipse at center, rgba(34,34,59,.55), rgba(16,16,32,.88)); animation: fade .2s ease; }
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.85); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes wob { 0%,100% { transform: rotate(-2deg) } 50% { transform: rotate(2deg) } }
@keyframes bounce { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }

#loading { background: #22223b url(assets/menu.webp) center/cover; }
.loader { text-align: center; font-size: 24px; font-weight: 800; background: rgba(20,20,40,.75); padding: 24px 40px; border-radius: 24px; }
.spin { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; border: 6px solid #4a4e69; border-top-color: #ff6b35; animation: rot 1s linear infinite; }
.bar { width: 260px; height: 10px; border-radius: 5px; background: #4a4e69; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; background: #ff6b35; transition: width .2s; }
@keyframes rot { to { transform: rotate(360deg) } }

/* ---------------- menu */
#menu { background: linear-gradient(90deg, rgba(22,22,42,.92) 0%, rgba(22,22,42,.7) 45%, rgba(22,22,42,.15) 75%, rgba(22,22,42,.4) 100%); display: block; }
.menu-left { position: absolute; left: 36px; top: 22px; width: 610px; }
.menu-right { position: absolute; right: 30px; top: 22px; width: 440px; display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.logo { display: flex; flex-direction: column; line-height: .88; margin-bottom: 8px; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); transform-origin: left center; animation: wob 3s ease-in-out infinite; }
.logo .l1 { font-size: 58px; font-weight: 800; color: #ffd166; -webkit-text-stroke: 2px #7a3a00; letter-spacing: 2px; }
.logo .l2 { font-size: 74px; font-weight: 800; color: #ff6b35; -webkit-text-stroke: 2px #4a1a00; letter-spacing: 8px; }
.logo .l3 { font-size: 22px; font-weight: 700; color: #f2e9e4; margin-top: 6px; letter-spacing: .5px; }
.label { font-size: 15px; font-weight: 800; color: #c9ada7; text-transform: uppercase; letter-spacing: 1.5px; margin: 8px 0 4px; }
.label.inline { margin: 0 10px 0 0; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.play-row { margin-top: 14px; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mode { background: rgba(74,78,105,.85); border: 3px solid transparent; border-radius: 14px; padding: 6px 8px; cursor: pointer; text-align: left; color: #fff; font: inherit; transition: transform .1s, border-color .1s; min-height: 72px; overflow: hidden; }
.mode:hover:not(.locked) { transform: translateY(-2px); }
.mode.on { border-color: #ff6b35; background: rgba(255,107,53,.25); }
.mode b { display: block; font-size: 16px; line-height: 1.1; overflow-wrap: anywhere; }
.mode small { display: block; font-size: 12px; color: #d8d2dc; line-height: 1.15; margin-top: 3px; }
.mode.locked, .arena.locked { filter: grayscale(.9) brightness(.65); cursor: not-allowed; }
.arenas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.arena { position: relative; border-radius: 14px; overflow: hidden; border: 3px solid transparent; cursor: pointer; background: #22223b; padding: 0; font: inherit; color: #fff; transition: transform .1s; }
.arena:hover:not(.locked) { transform: translateY(-2px); }
.arena.on { border-color: #ff6b35; }
.arena canvas { display: block; width: 100%; height: 86px; }
.arena .an { position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 8px; background: linear-gradient(transparent, rgba(0,0,0,.8)); font-weight: 800; font-size: 15px; text-align: left; line-height: 1.1; }
.arena .lk { position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; font-weight: 800; background: rgba(0,0,0,.45); }
.seg { display: flex; gap: 6px; }
.seg button { font: inherit; font-weight: 800; font-size: 15px; color: #fff; background: rgba(74,78,105,.85); border: 2px solid transparent; border-radius: 10px; padding: 4px 14px; cursor: pointer; }
.seg button.on { border-color: #ff6b35; background: rgba(255,107,53,.3); }
.menu-nav { position: absolute; left: 36px; bottom: 22px; display: flex; gap: 10px; }

.card { background: rgba(34,34,59,.82); border: 2px solid rgba(255,255,255,.12); border-radius: 18px; padding: 10px 14px; }
.player { display: flex; gap: 12px; align-items: center; }
.lvl { width: 58px; height: 58px; flex: none; border-radius: 50%; background: radial-gradient(#ffb38a, #ff6b35); display: grid; place-items: center; font-size: 26px; font-weight: 800; border: 3px solid #fff; box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.lvl.small { width: 40px; height: 40px; font-size: 18px; }
.pinfo { flex: 1; }
.xp { height: 14px; border-radius: 7px; background: #4a4e69; overflow: hidden; }
.xp i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd166, #ff6b35); transition: width .5s; }
.prow { display: flex; justify-content: space-between; margin-top: 4px; font-size: 20px; font-weight: 800; }
.coins b { color: #ffd166; }
.streak { color: #ffb38a; font-size: 16px; }
.riderbox { position: relative; padding: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 70%, rgba(255,107,53,.35), rgba(34,34,59,.6) 70%); cursor: pointer; }
.riderbox canvas { display: block; width: 100%; height: auto; }
.rname { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 22px; font-weight: 800; text-shadow: 0 2px 0 #000; }
.goal { font-size: 16px; font-weight: 700; color: #ffd166; text-align: center; background: rgba(34,34,59,.82); border-radius: 12px; padding: 6px 10px; }

.btn { font: inherit; font-weight: 800; font-size: 19px; color: #fff; border: 0; cursor: pointer; padding: 9px 20px 11px; border-radius: 14px; position: relative;
  box-shadow: 0 5px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(3px) scale(.97); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; }
.btn.big { font-size: 30px; padding: 10px 44px 14px; }
.btn.orange { background: linear-gradient(#ff8c5a, #e5531f); }
#btn-play { animation: bounce 1.4s ease-in-out infinite; }
.btn.green { background: linear-gradient(#34d058, #15803d); }
.btn.blue { background: linear-gradient(#4f8cff, #1d4fb8); }
.btn.purple { background: linear-gradient(#9d6bff, #5b21b6); }
.btn.gold { background: linear-gradient(#ffd166, #d49a00); color: #3a2200; }
.btn.dark { background: linear-gradient(#5a5f7d, #2b2d42); }
.badge { background: #e63946; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 14px; margin-left: 4px; }

.modal { background: linear-gradient(180deg, #34365a, #22223b); border: 3px solid rgba(255,255,255,.15); border-radius: 24px; padding: 20px 30px; min-width: 440px; max-width: 900px; max-height: 690px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: pop .22s ease both; display: flex; flex-direction: column; }
.modal.wide { width: 860px; }
.modal.xwide { width: 1120px; max-width: 1120px; }
.modal h2 { margin: 0 0 6px; font-size: 32px; color: #ffd166; line-height: 1.1; }
.modal .h2b { margin-top: 12px; font-size: 26px; }
.sub { margin: 0 0 8px; color: #d8d2dc; font-size: 16px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; min-width: 280px; margin: 8px auto; }

.garage { display: flex; gap: 18px; text-align: left; min-height: 0; }
.gprev { width: 360px; flex: none; background: radial-gradient(ellipse at 50% 70%, rgba(255,107,53,.35), rgba(0,0,0,.2) 70%); border-radius: 18px; padding: 8px; text-align: center; }
.gprev canvas { width: 100%; height: auto; display: block; }
.gname { font-size: 22px; font-weight: 800; }
.gright { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { font: inherit; font-weight: 800; font-size: 17px; color: #fff; background: rgba(74,78,105,.85); border: 2px solid transparent; border-radius: 10px; padding: 4px 16px; cursor: pointer; }
.tab.on { border-color: #ff6b35; background: rgba(255,107,53,.3); }
.ggrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; overflow-y: auto; max-height: 470px; padding: 4px; }
.gitem { background: rgba(20,20,40,.55); border: 3px solid transparent; border-radius: 14px; padding: 6px; cursor: pointer; text-align: center; color: #fff; font: inherit; position: relative; transition: transform .1s; }
.gitem:hover { transform: translateY(-2px); }
.gitem.on { border-color: #ff6b35; }
.gitem canvas { width: 100%; height: auto; display: block; }
.gitem .gn { font-size: 13px; font-weight: 800; line-height: 1.1; min-height: 29px; overflow-wrap: anywhere; }
.gitem .gl { font-size: 13px; font-weight: 800; color: #ffd166; }
.gitem.locked canvas { filter: grayscale(1) brightness(.5); }

.list { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.list.scroll { max-height: 250px; overflow-y: auto; padding-right: 4px; }
.qrow { display: flex; align-items: center; gap: 12px; background: rgba(20,20,40,.5); border-radius: 12px; padding: 6px 12px; }
.qrow .qt { flex: 1; font-weight: 700; font-size: 16px; line-height: 1.15; }
.qrow .qp { width: 150px; }
.qrow .qp .xp { height: 10px; }
.qrow .qp small { display: block; font-size: 13px; color: #c9ada7; text-align: center; }
.qrow .qr { width: 70px; text-align: right; font-weight: 800; color: #ffd166; }
.qrow .btn { font-size: 15px; padding: 4px 12px 6px; min-width: 96px; }
.qrow.done { opacity: .55; }

.howto { text-align: left; font-size: 17px; margin: 4px 0; padding-left: 26px; line-height: 1.35; }
.hitems { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: left; margin: 8px 0; }
.hitem { display: flex; gap: 6px; align-items: center; background: rgba(20,20,40,.5); border-radius: 10px; padding: 4px 6px; font-size: 13px; line-height: 1.1; }
.hitem img { width: 38px; height: 38px; flex: none; }
.hitem b { display: block; font-size: 14px; }
.keys { margin: 4px 0; color: #d8d2dc; font-size: 15px; }

.setrow { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin: 6px 0; font-size: 19px; font-weight: 700; }
.setrow select { font: inherit; font-size: 17px; padding: 4px 10px; border-radius: 10px; background: #2b2d42; color: #fff; border: 2px solid #4a4e69; }
.toggle { min-width: 110px; font-size: 16px; }

.result h2 { font-size: 44px; }
.rbody { display: flex; gap: 20px; align-items: stretch; }
.podium { width: 430px; flex: none; height: 330px; }
.rright { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.rtable { width: 100%; border-collapse: collapse; font-size: 15px; }
.rtable th { color: #c9ada7; font-size: 13px; text-transform: uppercase; }
.rtable td, .rtable th { padding: 2px 6px; text-align: center; }
.rtable td.n { text-align: left; font-weight: 700; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rtable tr.me { background: rgba(255,107,53,.35); }
.rewards { display: flex; align-items: center; gap: 16px; background: rgba(20,20,40,.5); border-radius: 14px; padding: 8px 12px; }
.rxp { flex: 1; display: flex; align-items: center; gap: 10px; }
.rxp .xp { flex: 1; }
.rxp b { color: #ffd166; font-size: 20px; min-width: 90px; }
.rcoin { font-size: 22px; font-weight: 800; } .rcoin b { color: #ffd166; }
.rextra { min-height: 96px; display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 15px; font-weight: 700; max-height: 110px; overflow-y: auto; }
.rextra .up { color: #ffd166; animation: pop .3s ease both; }
.rextra .ul { display: flex; align-items: center; gap: 8px; animation: pop .3s ease both; }
.rextra .ul img { width: 34px; height: 34px; object-fit: contain; }

.toast { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); background: rgba(34,34,59,.95); border: 2px solid #ff6b35; padding: 8px 22px; border-radius: 16px; font-size: 20px; font-weight: 800; z-index: 20; animation: pop .2s ease; max-width: 900px; text-align: center; pointer-events: none; }
.pausebtn { position: absolute; top: 14px; left: 272px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(20,20,40,.6); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer; z-index: 5; }
#rotate { display: none; position: fixed; inset: 0; background: #22223b; color: #fff; font-size: 24px; font-weight: 800; 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; } }
