:root {
  --ink: #12304f;
  --gold: #ffd27a;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1a2c; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; overflow: hidden; font-family: var(--font); color: #fff; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.outl {
  text-shadow: 2px 0 var(--ink), -2px 0 var(--ink), 0 2px var(--ink), 0 -2px var(--ink),
    1.5px 1.5px var(--ink), -1.5px 1.5px var(--ink), 1.5px -1.5px var(--ink), -1.5px -1.5px var(--ink),
    0 4px 0 rgba(0, 0, 0, .35);
}
.glass {
  background: linear-gradient(180deg, rgba(255,255,255,.28), rgba(140,190,240,.16));
  border: 1.5px solid rgba(255,255,255,.55);
  box-shadow: 0 4px 14px rgba(10,30,60,.35), inset 0 1px 0 rgba(255,255,255,.6);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-radius: 14px;
}
button { font-family: inherit; }

/* ---------- buttons & panels ---------- */
.btn {
  all: unset; box-sizing: border-box; cursor: pointer; position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; min-width: 50px; padding: 4px 18px;
  border-style: solid; border-width: 16px 22px;
  border-image: url(assets/ui-button.webp) 30% 16% fill / 16px 22px stretch;
  font-weight: 900; font-size: 18px; color: #fff; letter-spacing: .02em;
  text-shadow: 2px 0 var(--ink), -2px 0 var(--ink), 0 2px var(--ink), 0 -2px var(--ink), 0 3px 0 rgba(0,0,0,.3);
  transition: transform .12s cubic-bezier(.3,1.6,.5,1), filter .12s;
  filter: drop-shadow(0 4px 6px rgba(10,30,60,.35));
}
.btn > * { margin: -12px 0; }
.btn img { width: 28px; height: 28px; object-fit: contain; }
.btn:active, .btn.pressed { transform: scale(.92); }
.btn.focus { transform: scale(1.06); filter: drop-shadow(0 0 8px #fff) drop-shadow(0 0 4px var(--gold)) brightness(1.15); }
.btn[disabled] { filter: grayscale(.8) brightness(.7); pointer-events: none; }
.btn.primary { filter: drop-shadow(0 4px 6px rgba(10,30,60,.35)) hue-rotate(-160deg) saturate(1.4) brightness(1.1); }
.btn.primary.focus { filter: drop-shadow(0 0 8px #fff) hue-rotate(-160deg) saturate(1.4) brightness(1.3); transform: scale(1.06); }
.btn.small { min-height: 46px; min-width: 46px; padding: 0 10px; font-size: 16px; }
.btn.icon-only { padding: 0 12px; }

.panel {
  box-sizing: border-box; position: relative;
  border-style: solid; border-width: 30px;
  border-image: url(assets/ui-panel.webp) 18% fill / 30px stretch;
}
.overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(8, 20, 40, .45); z-index: 20; }
.overlay.on { display: flex; }
.panel.big { width: min(88%, 380px); padding: 6px 8px; text-align: center; }
.pop { animation: pop .32s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.p-title { font-size: 30px; font-weight: 900; color: var(--gold); margin: 2px 0 8px; }
.p-sub { font-size: 16px; font-weight: 700; color: #eaf4ff; margin-bottom: 10px; text-shadow: 0 1px 2px var(--ink); }
.p-msg { min-height: 20px; font-size: 15px; font-weight: 700; color: #ffd0c0; margin-top: 6px; text-shadow: 0 1px 2px var(--ink); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.row .btn { flex: 1; }
.row .btn.icon-only { flex: 0 0 auto; }
.col { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.stars { font-size: 46px; letter-spacing: 6px; margin: -4px 0 6px; }
.stars span { color: rgba(20, 40, 70, .55); text-shadow: 0 2px 0 rgba(255,255,255,.35); display: inline-block; }
.stars span.on { color: #ffd34d; text-shadow: 0 0 10px #ffb300, 0 3px 0 #8a5a00; animation: starIn .45s cubic-bezier(.3,1.8,.5,1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.stat { display: flex; justify-content: space-between; align-items: center; font-size: 17px; font-weight: 800; padding: 4px 10px; color: #e8f3ff; text-shadow: 0 1px 2px var(--ink); }
.stat b { font-size: 22px; color: #fff; }
.earn { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 24px; margin: 6px 0 0; }
.earn img { width: 30px; height: 30px; }
.help-text { text-align: left; font-size: 16px; line-height: 1.55; font-weight: 600; color: #f2f8ff; text-shadow: 0 1px 2px var(--ink); white-space: pre-line; max-height: 52vh; overflow: auto; padding: 0 4px; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 90px; pointer-events: none; z-index: 5; }
.hud-left { position: absolute; left: calc(10px + env(safe-area-inset-left)); top: calc(10px + env(safe-area-inset-top)); padding: 6px 12px 4px; min-width: 104px; }
#hud-level { font-size: 14px; font-weight: 800; color: #eaf4ff; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
#hud-time { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
#hud-time.warn { color: #ff7a6a; animation: pulse .5s infinite; }
.hud-right { position: absolute; right: calc(66px + env(safe-area-inset-right)); top: calc(10px + env(safe-area-inset-top)); padding: 5px 10px; }
.hud-row { display: flex; align-items: center; gap: 6px; font-size: 19px; font-weight: 900; height: 26px; }
.hud-row img { width: 24px; height: 24px; object-fit: contain; }
.ball-ico { width: 20px; height: 20px; border-radius: 50%; margin: 0 2px; background: radial-gradient(circle at 35% 30%, #fff, #d8dde4 45%, #8a96a6 100%); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.hud-mid { position: absolute; left: 50%; top: calc(64px + env(safe-area-inset-top)); width: 46px; height: 46px; margin-left: -23px; border-radius: 50%; display: none; }
#tilt-ring { position: absolute; inset: 9px; border-radius: 50%; border: 1.5px dashed rgba(255,255,255,.6); }
#tilt-dot { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #8fd0ff); box-shadow: 0 0 6px #8fd0ff; }
#tilt-mode { position: absolute; left: -20px; right: -20px; top: 47px; text-align: center; font-size: 12px; font-weight: 800; text-shadow: 0 1px 2px var(--ink); }
#hint { position: absolute; left: 50%; top: calc(124px + env(safe-area-inset-top)); transform: translateX(-50%); width: min(86%, 360px); text-align: center; font-size: 17px; font-weight: 800; line-height: 1.4; padding: 10px 14px; border-radius: 16px; background: linear-gradient(180deg, rgba(40,110,180,.62), rgba(12,36,66,.66)); border: 1.5px solid rgba(255,210,122,.75); box-shadow: 0 4px 14px rgba(10,30,60,.35), inset 0 1px 0 rgba(255,255,255,.5); text-shadow: 2px 0 var(--ink), -2px 0 var(--ink), 0 2px var(--ink), 0 -2px var(--ink), 1.5px 1.5px var(--ink), -1.5px -1.5px var(--ink); z-index: 6; pointer-events: none; animation: hintIn .35s cubic-bezier(.3,1.6,.5,1) both; box-sizing: border-box; }
@keyframes hintIn { from { transform: translate(-50%, -20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#banner { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-size: 64px; font-weight: 900; color: #fff; z-index: 7; pointer-events: none; letter-spacing: .03em;
  text-shadow: 4px 0 var(--ink), -4px 0 var(--ink), 0 4px var(--ink), 0 -4px var(--ink), 3px 3px var(--ink), -3px 3px var(--ink), 3px -3px var(--ink), -3px -3px var(--ink), 0 8px 0 rgba(0,0,0,.35); }
#banner.slam { animation: slam .5s cubic-bezier(.3,1.7,.5,1) both; }
#banner.gold { color: var(--gold); }
#banner.red { color: #ff8a7a; }
@keyframes slam { from { transform: scale(2.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .65; transform: scale(.97); } }

/* ---------- Title ---------- */
.screen { position: absolute; inset: 0; display: none; z-index: 10; }
.screen.on { display: block; }
.title-bg { position: absolute; inset: -4%; background: #8fc1ea url(assets/cover-bg.webp) center/cover no-repeat; animation: kb 24s ease-in-out infinite alternate; }
.title-bg.blur { filter: blur(5px) brightness(.85); animation: none; inset: -20px; }
@keyframes kb { from { transform: scale(1) translateY(0); } to { transform: scale(1.06) translateY(-1.5%); } }
.title-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,0) 60%, rgba(10,30,60,.45)); }
#title-logo { position: absolute; left: 50%; top: 8%; width: 82%; max-height: 30%; object-fit: contain; transform: translateX(-50%); animation: logoIn .7s cubic-bezier(.3,1.6,.5,1) both, float 4s ease-in-out .7s infinite; filter: drop-shadow(0 6px 10px rgba(10,30,60,.35)); }
@keyframes logoIn { from { transform: translate(-50%, -60px) scale(.6); opacity: 0; } to { transform: translate(-50%, 0) scale(1); opacity: 1; } }
@keyframes float { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -6px); } }
#title-prompt { position: absolute; left: 0; right: 0; bottom: 13%; text-align: center; font-size: 24px; font-weight: 900; animation: pulse 1.8s ease-in-out infinite; }
#title-keys { position: absolute; left: 6%; right: 6%; bottom: 6%; text-align: center; font-size: 14px; font-weight: 700; opacity: .9; }
.corner-btn { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); width: 48px; height: 48px; min-height: 0; min-width: 0; padding: 0;
  border: 1.5px solid rgba(255,255,255,.6); border-image: none; border-radius: 50%; background: rgba(20, 50, 90, .45); }
.corner-btn > * { margin: 0; }

/* ---------- Select ---------- */
.select-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10,30,60,.35), rgba(10,30,60,.55)); }
.sel-head { position: absolute; left: 10px; right: 10px; top: calc(10px + env(safe-area-inset-top)); height: 50px; display: flex; align-items: center; gap: 8px; }
.sel-title { flex: 1; font-size: 24px; font-weight: 900; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arrow { font-size: 18px; }
.chip { display: flex; align-items: center; gap: 4px; padding: 4px 10px 4px 6px; border-radius: 999px; font-size: 18px; font-weight: 900; }
.chip img { width: 26px; height: 26px; }
#world-list { position: absolute; left: 12px; right: 12px; top: calc(68px + env(safe-area-inset-top)); bottom: 210px; overflow-y: auto; }
.world { margin-bottom: 8px; }
.world-name { font-size: 16px; font-weight: 900; color: var(--gold); margin: 2px 4px 4px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile.btn { min-height: 0; aspect-ratio: 1 / .92; padding: 0; flex-direction: column; gap: 0; font-size: 26px; border-width: 14px 16px; border-image-width: 14px 16px; }
.tile .tn { margin: -6px 0 0; line-height: 1; }
.tile .ts { margin: 2px 0 -8px; font-size: 13px; letter-spacing: 1px; color: rgba(255,255,255,.35); text-shadow: none; }
.tile .ts .on { color: #ffd34d; text-shadow: 0 1px 0 #8a5a00; }
.tile.locked { filter: grayscale(.9) brightness(.6); }
.tile .lock { font-size: 22px; margin: 0; }
.skin-box { position: absolute; left: 10px; right: 10px; bottom: 76px; height: 128px; border-width: 22px; border-image-width: 22px; }
.skin-label { font-size: 15px; font-weight: 900; margin: -8px 0 2px 2px; }
#skin-row { display: flex; gap: 6px; justify-content: space-between; }
.skin.btn { flex: 1; min-width: 0; min-height: 0; height: 74px; padding: 0; border-width: 10px; border-image-width: 10px 12px; flex-direction: column; gap: 0; font-size: 12px; }
.skin img { width: 42px; height: 42px; margin: -4px 0 0; }
.skin .sk-price { display: flex; align-items: center; gap: 2px; margin: 0 0 -6px; font-size: 12px; }
.skin .sk-price img { width: 14px; height: 14px; margin: 0; }
.skin.sel { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 3px var(--gold)) brightness(1.2); }
.skin.lockd img { filter: grayscale(.6) brightness(.7); }
.sel-foot { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; }
.btn.wide { min-width: 200px; }

/* ---------- Intro ---------- */
#intro-wrap { position: absolute; inset: 0; z-index: 40; background: #000 url(assets/cover-bg.webp) center/cover; }
#intro-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#btn-skip { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); }

#fade { position: absolute; inset: 0; background: #0b1a2c; opacity: 0; pointer-events: none; z-index: 60; transition: opacity .3s; }
#fade.on { opacity: 1; }
#fade.white { background: #fff; }
