:root { --sab: env(safe-area-inset-bottom);
  --bg: #1a0b3a; --panel: rgba(38, 18, 78, .92); --line: rgba(255, 255, 255, .16); --text: #fff7ff; --dim: #c9b6e8;
  --pink: #ff5fa8; --gold: #ffd54a; --ok: #5ee38f;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: fixed; inset: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
[hidden] { display: none !important; }

/* HUD */
#hud { position: absolute; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 10px) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); max-width: 560px; margin: 0 auto; pointer-events: none; }
#hud > * { pointer-events: auto; }
.hud-top { display: flex; align-items: center; gap: 10px; }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; background: rgba(255, 255, 255, .12); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 5px; flex: none; }
.icon-btn span { width: 4px; height: 15px; background: #fff; border-radius: 2px; }
.hud-title { flex: 1; font-weight: 900; font-size: 18px; letter-spacing: 1px; text-shadow: 0 2px 0 rgba(0, 0, 0, .3); }
.moves { min-width: 76px; height: 54px; padding: 0 12px; border-radius: 18px; background: linear-gradient(180deg, #ff7ab8, #c2318a); box-shadow: 0 4px 0 #7d1556, inset 0 2px 0 rgba(255, 255, 255, .35); display: flex; align-items: baseline; justify-content: center; gap: 3px; padding-top: 6px; }
.moves b { font-size: 30px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.moves small { font-size: 12px; font-weight: 800; opacity: .85; }
.moves.low { animation: throb .6s ease-in-out infinite; background: linear-gradient(180deg, #ff8a5c, #d43b2b); box-shadow: 0 4px 0 #7d1c12; }
@keyframes throb { 50% { transform: scale(1.08); } }
.goals { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; min-height: 40px; }
.goal { display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 6px; border-radius: 999px; background: rgba(255, 255, 255, .1); border: 1px solid var(--line); font-weight: 900; font-size: 17px; font-variant-numeric: tabular-nums; transition: transform .15s; }
.goal img, .goal .jelly-ico { width: 30px; height: 30px; }
.goal .jelly-ico { border-radius: 8px; background: rgba(255, 128, 205, .55); border: 2px solid rgba(255, 170, 225, .9); }
.goal .score-ico { font-size: 20px; padding-left: 4px; }
.goal.done { background: rgba(94, 227, 143, .2); border-color: rgba(94, 227, 143, .6); }
.goal.done b::after { content: " ✓"; color: var(--ok); }
.goal.bump { transform: scale(1.12); }
.scorebar { position: relative; height: 22px; margin-top: 10px; border-radius: 999px; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); overflow: visible; }
.scorebar .fill { position: absolute; left: 2px; top: 2px; bottom: 2px; width: 0; max-width: calc(100% - 4px); border-radius: 999px; background: linear-gradient(90deg, #ffb347, #ff5fa8, #b065ff); transition: width .3s ease-out; }
.scorebar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 900; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); font-variant-numeric: tabular-nums; }
.marks i { position: absolute; top: 50%; transform: translate(-50%, -50%); font-style: normal; font-size: 17px; filter: grayscale(1) brightness(.7); transition: filter .3s, transform .3s; z-index: 1; }
.marks i.on { filter: none; transform: translate(-50%, -50%) scale(1.2); }

#foot { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 14px); display: flex; justify-content: center; gap: 12px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 20px; min-height: 50px; border-radius: 18px; font-weight: 900; font-size: 17px; letter-spacing: 1px; background: linear-gradient(180deg, #8c5cff, #5a2fd1); box-shadow: 0 5px 0 #321382, inset 0 2px 0 rgba(255, 255, 255, .3); transition: transform .08s, box-shadow .08s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #321382, inset 0 2px 0 rgba(255, 255, 255, .3); }
.btn.pink { background: linear-gradient(180deg, #ff7ab8, #e0368d); box-shadow: 0 5px 0 #8a1752, inset 0 2px 0 rgba(255, 255, 255, .35); }
.btn.pink:active { box-shadow: 0 1px 0 #8a1752; }
.btn.gold { background: linear-gradient(180deg, #ffe066, #ffab2e); color: #5a2a00; box-shadow: 0 5px 0 #a55a00, inset 0 2px 0 rgba(255, 255, 255, .5); }
.btn.gold:active { box-shadow: 0 1px 0 #a55a00; }
.btn.ghost { background: rgba(255, 255, 255, .12); box-shadow: none; border: 1px solid var(--line); }
.btn.small { min-height: 42px; padding: 8px 16px; font-size: 15px; border-radius: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn small { font-size: 12px; opacity: .85; font-weight: 700; letter-spacing: 0; }

/* Screens */
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding: calc(env(safe-area-inset-top) + 14px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 16px) max(16px, env(safe-area-inset-left)); }
.screen.veil { background: radial-gradient(ellipse at 50% 30%, rgba(40, 14, 80, .55), rgba(14, 5, 34, .88)); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.inner { width: 100%; max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; flex: 1; min-height: 0; }

.home .logo { text-align: center; margin-top: 7vh; }
.logo h1 { margin: 0; font-size: clamp(46px, 14vw, 72px); font-weight: 900; letter-spacing: 4px; line-height: 1.05; background: linear-gradient(180deg, #fff 10%, #ffc2e6 45%, #ff5fa8 80%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 #6d1a6e) drop-shadow(0 0 24px rgba(255, 95, 168, .5)); }
.logo p { margin: 10px 0 0; letter-spacing: 10px; padding-left: 10px; color: var(--gold); font-size: 14px; font-weight: 900; }
.gem-row { display: flex; justify-content: center; gap: 6px; margin: 4vh 0 0; }
.gem-row img { width: 44px; height: 44px; animation: hop 2.4s ease-in-out infinite; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-12px); } }
.home .spacer { flex: 1; }
.menu { display: flex; flex-direction: column; gap: 14px; }
.menu .btn.big { min-height: 66px; font-size: 22px; flex-direction: column; gap: 0; }
.menu .row { display: flex; gap: 12px; }
.menu .row .btn { flex: 1; flex-direction: column; gap: 0; min-height: 62px; }
.home-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; color: var(--dim); font-size: 14px; font-weight: 800; }
.home-foot b { color: var(--gold); }

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.topbar h2 { flex: 1; margin: 0; font-size: 22px; font-weight: 900; }
.topbar .icon-btn { font-size: 20px; font-weight: 900; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 4px 2px 20px; }
.chapter { margin: 14px 0 8px; color: var(--dim); font-size: 13px; font-weight: 900; letter-spacing: 2px; }
.lv-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.lv { aspect-ratio: 1; border-radius: 18px; background: linear-gradient(180deg, #8c5cff, #5a2fd1); box-shadow: 0 4px 0 #321382, inset 0 2px 0 rgba(255, 255, 255, .3); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; font-size: 20px; gap: 1px; }
.lv:active { transform: translateY(3px); box-shadow: 0 1px 0 #321382; }
.lv .st { font-size: 10px; letter-spacing: -1px; color: var(--gold); min-height: 12px; }
.lv .st .off { color: rgba(255, 255, 255, .25); }
.lv.cur { background: linear-gradient(180deg, #ff7ab8, #e0368d); box-shadow: 0 4px 0 #8a1752, 0 0 18px rgba(255, 95, 168, .6), inset 0 2px 0 rgba(255, 255, 255, .35); }
.lv.lock { background: rgba(255, 255, 255, .07); box-shadow: none; color: rgba(255, 255, 255, .3); font-size: 16px; pointer-events: none; }

/* Modals */
.modal-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 3, 26, .62); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 360px; background: linear-gradient(180deg, rgba(70, 34, 140, .97), rgba(38, 16, 82, .97)); border: 1px solid rgba(255, 255, 255, .2); border-radius: 28px; padding: 24px 20px 20px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); animation: pop .35s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.modal h3 { margin: 0 0 6px; font-size: 28px; font-weight: 900; letter-spacing: 2px; }
.modal p { margin: 6px 0; color: var(--dim); font-weight: 700; }
.modal .btns { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.modal .btns .row { display: flex; gap: 10px; }
.modal .btns .row .btn { flex: 1; }
.modal .goals { justify-content: center; margin: 14px 0 4px; }
.big-stars { display: flex; justify-content: center; gap: 6px; margin: 8px 0 6px; font-size: 52px; line-height: 1; }
.big-stars i { font-style: normal; filter: grayscale(1) brightness(.45); transform: scale(.8); transition: filter .2s, transform .35s cubic-bezier(.2, 1.8, .4, 1); }
.big-stars i:nth-child(2) { transform: translateY(-10px) scale(.8); }
.big-stars i.on { filter: drop-shadow(0 0 12px rgba(255, 213, 74, .8)); transform: scale(1.1); }
.big-stars i.on:nth-child(2) { transform: translateY(-10px) scale(1.25); }
.final { font-size: 34px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.newbest { display: inline-block; margin-top: 4px; padding: 4px 12px; border-radius: 999px; background: var(--gold); color: #5a2a00; font-weight: 900; font-size: 13px; }
.toggle-row { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.how { text-align: left; font-size: 14px; line-height: 1.7; color: var(--dim); font-weight: 700; margin: 10px 0 0; padding: 0; list-style: none; }
.how li { display: flex; gap: 10px; align-items: center; }
.how img { width: 30px; height: 30px; flex: none; }
.how b { color: var(--text); }
