* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0b0a2a; color: #2d1660;
  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; touch-action: none; display: block; }
.hidden { display: none !important; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: radial-gradient(ellipse at center, rgba(40,20,100,.55), rgba(8,4,30,.82));
  animation: fade .22s ease; z-index: 10;
}
.overlay.clear { background: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0 } 70% { transform: scale(1.05); opacity: 1 } 100% { transform: scale(1) } }
@keyframes wiggle { 0%, 100% { transform: rotate(0) } 25% { transform: rotate(-3deg) } 75% { transform: rotate(3deg) } }
@keyframes bounce { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes glow { 0%, 100% { filter: drop-shadow(0 0 6px rgba(255,210,63,.5)) } 50% { filter: drop-shadow(0 0 16px rgba(255,120,200,.8)) } }

.loader { text-align: center; font-size: 24px; color: #fff; font-weight: 800; }
.spin { width: 60px; height: 60px; margin: 0 auto 10px; border-radius: 50%; border: 7px solid rgba(255,255,255,.2); border-top-color: #ff6fb5; animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg) } }
.loader .bar { width: 260px; height: 12px; border-radius: 6px; background: rgba(255,255,255,.2); margin: 8px auto 0; overflow: hidden; }
.loader .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff6fb5, #ffd23f); transition: width .2s; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-weight: 800; font-size: 21px; color: #fff; border: 0; cursor: pointer;
  padding: 10px 24px 12px; border-radius: 18px; position: relative; line-height: 1.1;
  box-shadow: 0 6px 0 rgba(0,0,0,.3), inset 0 3px 0 rgba(255,255,255,.35), inset 0 -4px 0 rgba(0,0,0,.14);
  transition: transform .1s cubic-bezier(.3,1.6,.5,1), filter .15s;
  text-shadow: 0 2px 0 rgba(0,0,0,.22);
}
.btn:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.08); }
.btn:active { transform: translateY(4px) scale(.97); box-shadow: 0 2px 0 rgba(0,0,0,.3), inset 0 3px 0 rgba(255,255,255,.35); }
.btn:disabled { filter: grayscale(.9) brightness(.75); cursor: not-allowed; transform: none; }
.btn.pink { background: linear-gradient(#ff8ac6, #f1079f); }
.btn.gold { background: linear-gradient(#ffe45c, #ffac00); color: #5a3400; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.btn.green { background: linear-gradient(#5ff0b0, #16b070); }
.btn.blue { background: linear-gradient(#5fd3ff, #1a7fe0); }
.btn.purple { background: linear-gradient(#a877ff, #6a2ce0); }
.btn.dark { background: linear-gradient(#5a4a9e, #33246e); }
.btn.round { width: 54px; height: 54px; padding: 0; border-radius: 50%; font-size: 22px; }
.btn.big { width: 100%; font-size: 30px; padding: 10px 16px 12px; display: flex; flex-direction: column; align-items: center; }
.btn.big small { font-size: 16px; font-weight: 700; opacity: .92; margin-top: 1px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn .badge, .badge { position: absolute; top: -8px; right: -8px; background: #ff3b5c; color: #fff; border-radius: 12px; min-width: 24px; height: 24px; font-size: 15px; display: grid; place-items: center; padding: 0 6px; animation: bounce 1s infinite; }
.btn.toggle { min-width: 110px; font-size: 18px; padding: 6px 16px 8px; background: linear-gradient(#5ff0b0, #16b070); }
.btn.toggle.off { background: linear-gradient(#a99fc8, #6f6596); }

/* ---------------------------------------------------------------- menu */
#menu { align-items: flex-start; justify-content: center; padding-left: 48px; }
.menu-col { width: 520px; display: flex; flex-direction: column; gap: 10px; background: rgba(255,255,255,.8); border-radius: 30px; padding: 16px 26px 20px; box-shadow: 0 16px 50px rgba(0,0,0,.45); border: 4px solid rgba(255,255,255,.9); animation: pop .4s ease both; }
.logo { display: flex; flex-direction: column; align-items: center; line-height: .85; }
.logo .l1 { font-size: 78px; font-weight: 800; background: linear-gradient(90deg, #ffd23f, #ff6fb5 50%, #7ad7ff); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 2px #3a1466; filter: drop-shadow(0 6px 0 rgba(58,20,102,.55)); animation: wiggle 3.5s ease-in-out infinite; }
.logo .l2 { font-size: 40px; font-weight: 800; color: #6a2ce0; letter-spacing: 4px; text-shadow: 0 3px 0 rgba(255,111,181,.45); }
.tagline { margin: 0; text-align: center; font-size: 18px; font-weight: 700; color: #5a3a9a; }
.pick-row { display: flex; align-items: center; gap: 10px; }
.pick-row label { width: 110px; font-weight: 800; font-size: 17px; color: #5a3a9a; text-align: right; line-height: 1.05; }
.chips { display: flex; gap: 8px; flex: 1; }
.chip-btn { flex: 1; font: inherit; font-weight: 800; font-size: 17px; border: 3px solid #cdb8ff; background: #fff; color: #5a3a9a; border-radius: 14px; padding: 4px 6px; cursor: pointer; transition: transform .1s cubic-bezier(.3,1.6,.5,1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-btn:hover { transform: scale(1.05); }
.chip-btn.on { background: linear-gradient(#a877ff, #6a2ce0); color: #fff; border-color: #fff; box-shadow: 0 3px 0 rgba(60,20,140,.4); }
.chip-btn.locked { opacity: .55; }
.row2 { display: flex; gap: 10px; }
.row2 .btn.big { font-size: 24px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn { flex: 1; font-size: 18px; padding: 9px 8px 11px; }
.menu-row.small { justify-content: center; margin-top: 12px; }
.menu-row.small .btn { flex: none; }
.icon-btn span { white-space: nowrap; }
.wallet-row { position: absolute; top: 18px; right: 22px; display: flex; gap: 10px; }
.pill { background: rgba(40,20,90,.8); color: #fff; font-size: 24px; font-weight: 800; padding: 4px 18px; border-radius: 26px; border: 3px solid rgba(255,255,255,.5); }
.pill b { color: #ffe066; }

/* ---------------------------------------------------------------- HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#btn-pause { position: absolute; right: 18px; top: 14px; font-size: 18px; }
.chip { position: absolute; left: 340px; width: 616px; top: 16px; text-align: center; color: #fff; font-weight: 800; font-size: 22px; pointer-events: none !important; text-shadow: 0 2px 0 rgba(0,0,0,.4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-btns { position: absolute; left: 976px; width: 284px; top: 548px; display: flex; gap: 12px; }
.hud-btn { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 18px; padding: 8px 6px 10px; }
.hud-btn .ic { font-size: 30px; line-height: 1; }
.hud-btn span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-btn .n { position: absolute; top: -8px; right: -6px; background: #ffd23f; color: #5a3400; border-radius: 14px; min-width: 28px; height: 28px; display: grid; place-items: center; font-size: 17px; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.hud-btn.empty { filter: grayscale(.85) brightness(.8); }

.toast { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); background: rgba(255,255,255,.96); color: #4a1f96; font-weight: 800; font-size: 21px; padding: 8px 22px; border-radius: 20px; box-shadow: 0 8px 20px rgba(0,0,0,.35); animation: pop .3s ease both; z-index: 30; max-width: 900px; text-align: center; pointer-events: none; }

/* ---------------------------------------------------------------- modals */
.modal {
  background: linear-gradient(180deg, #fbf8ff, #ebe1ff); border: 5px solid #fff; border-radius: 30px; padding: 20px 32px 22px;
  min-width: 440px; max-width: 920px; text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.55), inset 0 -6px 0 rgba(106,44,224,.12);
  animation: pop .35s ease both; max-height: 694px; overflow-y: auto;
}
.modal.wide { width: 900px; }
.modal h2 { margin: 0 0 6px; font-size: 40px; line-height: 1.1; color: #6a2ce0; text-shadow: 0 3px 0 rgba(255,111,181,.35); }
.modal h3 { margin: 14px 0 2px; font-size: 22px; color: #7b4dd0; text-align: left; }
.modal .sub { margin: 0 0 10px; color: #6a5a90; font-size: 18px; font-weight: 700; }
.modal .sub.small { font-size: 15px; text-align: left; margin: 0 0 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.list { display: grid; gap: 10px; margin-top: 10px; text-align: left; }
.mission { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; background: #fff; border-radius: 18px; padding: 6px 14px; box-shadow: 0 3px 0 rgba(106,44,224,.15); }
.mission .ic { font-size: 34px; text-align: center; }
.mission .nm { font-size: 20px; font-weight: 800; }
.mission .pb { height: 12px; border-radius: 6px; background: #ece3fb; overflow: hidden; margin-top: 4px; }
.mission .pb i { display: block; height: 100%; background: linear-gradient(90deg, #ff6fb5, #ffd23f); border-radius: 6px; }
.mission .rw { font-size: 15px; color: #8a7ab0; font-weight: 700; }
.mission .btn { font-size: 17px; padding: 6px 16px 8px; min-width: 110px; }

.shop-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.card { background: #fff; border-radius: 18px; padding: 8px 8px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 3px 0 rgba(106,44,224,.15); }
.card .sky { width: 100%; height: 40px; border-radius: 12px; }
.card .nm { font-weight: 800; font-size: 17px; line-height: 1.1; min-height: 22px; display: flex; align-items: center; }
.card .btn { font-size: 16px; padding: 5px 12px 7px; width: 100%; }
.card.on { outline: 4px solid #ffd23f; }

.tabs { display: flex; gap: 8px; justify-content: center; margin: 4px 0 10px; }
.tabs .chip-btn { flex: none; min-width: 150px; }
.col-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.col-cell { background: #fff; border-radius: 16px; padding: 6px 4px 4px; cursor: pointer; border: 3px solid transparent; transition: transform .1s; }
.col-cell:hover { transform: scale(1.06); }
.col-cell.sel { border-color: #ff6fb5; }
.col-cell canvas { width: 76px; height: 76px; display: block; margin: 0 auto; }
.col-cell b { display: block; font-size: 13px; line-height: 1.1; color: #4a1f96; min-height: 28px; overflow: hidden; }
.col-cell small { font-size: 12px; color: #9a8ac0; font-weight: 700; }
.col-detail { margin-top: 12px; background: #fff; border-radius: 18px; padding: 10px 16px; display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: center; text-align: left; min-height: 120px; }
.col-detail canvas { width: 110px; height: 110px; }
.col-detail h4 { margin: 0; font-size: 26px; color: #6a2ce0; }
.col-detail p { margin: 2px 0 0; font-size: 18px; font-weight: 700; color: #5a4a80; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.stat-grid div { background: #fff; border-radius: 16px; padding: 8px 8px; }
.stat-grid b { display: block; font-size: 26px; color: #6a2ce0; }
.stat-grid small { color: #8a7ab0; font-size: 14px; font-weight: 700; line-height: 1.1; display: block; }

.howto { text-align: left; font-size: 19px; line-height: 1.45; margin: 8px 0; padding-left: 26px; font-weight: 600; }
.howto li { margin: 5px 0; }
.keys { color: #8a7ab0; font-size: 15px; font-weight: 700; }
.set-grid { display: grid; grid-template-columns: 1fr auto; gap: 12px 24px; align-items: center; text-align: left; font-size: 20px; font-weight: 800; margin: 14px 0; }
select { font: inherit; font-size: 18px; font-weight: 700; padding: 6px 10px; border-radius: 12px; border: 3px solid #c9a6ff; color: #4a1f96; background: #fff; max-width: 260px; }

#win-art { width: 220px; height: 220px; display: block; margin: 0 auto; animation: glow 1.6s ease-in-out infinite; }
.quip { margin: 0 0 6px; font-size: 20px; font-weight: 700; color: #7b4dd0; font-style: italic; }
.big-score { font-size: 72px; font-weight: 800; color: #ff6fb5; line-height: 1; -webkit-text-stroke: 3px #6a2ce0; margin: 6px 0; }
.badge-new { display: inline-block; background: linear-gradient(#ffe45c, #ffac00); color: #5a3400; font-weight: 800; font-size: 20px; padding: 3px 18px; border-radius: 16px; animation: wiggle .6s ease-in-out infinite; }
.medal { font-size: 24px; font-weight: 800; color: #b36b00; margin: 4px 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stats div { background: #fff; border-radius: 14px; padding: 6px 8px; }
.stats b { display: block; font-size: 24px; color: #6a2ce0; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats small { color: #8a7ab0; font-size: 14px; font-weight: 700; line-height: 1.1; display: block; }
.reward { font-size: 24px; font-weight: 800; color: #f1079f; }
.tip { font-size: 16px; color: #8a7ab0; font-weight: 700; margin: 6px 0 0; }

/* ---------------------------------------------------------------- portrait phones
   The stage becomes 500 logical px wide (0.72–0.86 CSS px per unit on 360–430 px phones), so 17 units ≥ 12 CSS px and
   66 units ≥ 47 CSS px touch targets. Canvas-side layout lives in render.js setLayout(). */
body.portrait #menu { justify-content: flex-start; align-items: center; padding: 84px 12px 12px; }
body.portrait .menu-col { width: 476px; padding: 14px 18px 18px; gap: 12px; }
body.portrait .logo .l1 { font-size: 72px; }
body.portrait .tagline { font-size: 20px; }
body.portrait .pick-row { flex-direction: column; align-items: stretch; gap: 6px; }
body.portrait .pick-row label { width: auto; text-align: left; font-size: 19px; }
body.portrait .chip-btn { min-height: 66px; font-size: 19px; white-space: normal; line-height: 1.1; padding: 4px 4px; }
body.portrait .btn { min-height: 66px; }
body.portrait .btn.round { min-height: 0; width: 70px; height: 70px; font-size: 26px; }
body.portrait .hud-btn .n { font-size: 19px; min-width: 32px; height: 32px; }
body.portrait .btn.big small { font-size: 18px; white-space: normal; }
body.portrait .row2 { flex-direction: column; }
body.portrait .row2 .btn.big { font-size: 28px; }
body.portrait .menu-row { flex-wrap: wrap; }
body.portrait .menu-row .btn { font-size: 20px; min-width: 130px; }
body.portrait .menu-row.small .btn { min-width: 0; }
body.portrait .wallet-row { top: 14px; right: auto; left: 50%; transform: translateX(-50%); }
body.portrait .pill { font-size: 26px; }
body.portrait #btn-pause { font-size: 24px; }
body.portrait .chip { font-size: 22px; }
body.portrait #hud-btns { gap: 12px; }
body.portrait .hud-btn { flex-direction: row; justify-content: center; gap: 10px; font-size: 24px; padding: 8px 10px; }
body.portrait .hud-btn .ic { font-size: 32px; }
body.portrait .hud-btn span { max-width: 170px; }
body.portrait .toast { top: 170px; max-width: 460px; font-size: 22px; }
body.portrait .modal { min-width: 0; width: 476px; max-width: 476px; max-height: calc(100% - 24px); padding: 16px 16px 18px; }
body.portrait .modal.wide { width: 476px; }
body.portrait .modal h2 { font-size: 36px; }
body.portrait .modal .sub { font-size: 19px; }
body.portrait .modal .sub.small { font-size: 18px; }
body.portrait .col-grid { grid-template-columns: repeat(4, 1fr); }
body.portrait .col-cell b { font-size: 17px; min-height: 38px; }
body.portrait .col-cell small { font-size: 17px; }
body.portrait .col-detail { grid-template-columns: 90px 1fr; }
body.portrait .col-detail canvas { width: 90px; height: 90px; }
body.portrait .col-detail p { font-size: 19px; }
body.portrait .tabs { flex-wrap: wrap; }
body.portrait .tabs .chip-btn { min-width: 0; flex: 1 1 140px; }
body.portrait .stat-grid, body.portrait .stats { grid-template-columns: repeat(2, 1fr); }
body.portrait .stat-grid small, body.portrait .stats small { font-size: 17px; }
body.portrait .shop-grid { grid-template-columns: repeat(2, 1fr); }
body.portrait .card .nm { font-size: 19px; }
body.portrait .card .btn { font-size: 19px; }
body.portrait .mission { grid-template-columns: 40px 1fr auto; gap: 8px; padding: 8px 10px; }
body.portrait .mission .ic { font-size: 30px; }
body.portrait .mission .nm { font-size: 19px; line-height: 1.15; }
body.portrait .mission .btn { font-size: 18px; min-width: 96px; padding: 6px 10px; }
body.portrait .mission .rw { font-size: 17px; }
body.portrait .howto { font-size: 20px; }
body.portrait .keys { font-size: 17px; }
body.portrait .set-grid { font-size: 21px; gap: 12px 14px; }
body.portrait select { font-size: 20px; min-height: 66px; max-width: 230px; }
body.portrait .tip { font-size: 18px; }
body.portrait .big-score { font-size: 64px; }
body.portrait #win-art { width: 180px; height: 180px; }
