:root { --sol1: #ffc145; --sol2: #ff4fa3; --luna1: #4fe3ff; --luna2: #8a5bff; --ink: #eafff6; --dim: #9fb8b4; --panel: rgba(8, 22, 30, .82); --line: rgba(160, 255, 220, .22); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #020608; color: var(--ink); overflow: hidden; overscroll-behavior: none; font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-user-select: none; user-select: none; }
#app { position: relative; height: 100dvh; width: min(100vw, calc(100dvh * .75)); margin: 0 auto; overflow: hidden; background: #04121a; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; padding: calc(env(safe-area-inset-top) + 10px) 12px 0; }
#score { position: absolute; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 8px); text-align: center; font-size: 34px; font-weight: 800; text-shadow: 0 2px 8px #000a; font-variant-numeric: tabular-nums; }
#motes { position: absolute; left: 14px; top: calc(env(safe-area-inset-top) + 16px); font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 6px; text-shadow: 0 2px 6px #000a; }
.mote { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, #ffe27a 45%, #ffa726); box-shadow: 0 0 8px #ffe27a; vertical-align: -1px; }
#pauseBtn { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 8px); width: 44px; height: 44px; border-radius: 14px; background: rgba(8, 22, 30, .6); border: 1px solid var(--line); pointer-events: auto; font-size: 14px; }
#chain { position: absolute; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 50px); text-align: center; font-weight: 800; font-size: 15px; color: #9dffd9; text-shadow: 0 2px 6px #000a; min-height: 18px; }
#meter { position: absolute; left: 10px; top: 22%; width: 14px; height: 34%; border-radius: 9px; background: rgba(0, 0, 0, .45); border: 1px solid var(--line); overflow: hidden; }
#meter i { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: linear-gradient(0deg, var(--luna2), var(--luna1), var(--sol1), var(--sol2)); transition: height .15s; }
#meter b { position: absolute; left: 20px; bottom: -4px; font-size: 9px; letter-spacing: 2px; color: var(--dim); transform-origin: left bottom; transform: rotate(-90deg); white-space: nowrap; }
#meter { overflow: visible; } #meter i { border-radius: 8px; }
#phaseTag { display: none; position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 60px); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: rgba(8, 22, 30, .6); border: 2px solid var(--sol1); box-shadow: 0 0 14px var(--sol1); }
body.luna #phaseTag { border-color: var(--luna1); box-shadow: 0 0 14px var(--luna1); }
#phaseTag::before { content: "☀"; color: var(--sol1); } body.luna #phaseTag::before { content: "☾"; color: var(--luna1); }
#powers { position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 116px); display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
#powers span { font-size: 11px; font-weight: 800; padding: 4px 8px; border-radius: 10px; background: rgba(8, 22, 30, .7); border: 1px solid var(--line); letter-spacing: .5px; }

/* ---------- screens ---------- */
#screen { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 18px); background: linear-gradient(180deg, rgba(2, 8, 12, .55), rgba(2, 8, 12, .82)); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
#screen.on { display: flex; }
#screen.title { background: linear-gradient(180deg, rgba(2, 8, 12, .15), rgba(2, 8, 12, .7) 70%); backdrop-filter: none; -webkit-backdrop-filter: none; justify-content: space-between; background-size: cover; background-position: center; }
#screen.center { justify-content: center; }
.logo { margin-top: 7dvh; text-align: center; font-weight: 900; font-size: clamp(44px, 14vmin, 76px); line-height: .92; letter-spacing: 1px; filter: drop-shadow(0 6px 18px #000c); }
.logo img { width: min(92%, 440px); display: block; margin: 0 auto; }
.logo .a { background: linear-gradient(90deg, var(--sol1), var(--sol2)); -webkit-background-clip: text; background-clip: text; color: transparent; display: block; }
.logo .b { background: linear-gradient(90deg, var(--luna1), var(--luna2)); -webkit-background-clip: text; background-clip: text; color: transparent; display: block; }
.tag { text-align: center; color: var(--dim); font-size: 13px; letter-spacing: 3px; margin-top: 10px; text-transform: uppercase; }
.col { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 380px; align-items: stretch; }
.btn { padding: 15px 18px; border-radius: 18px; font-weight: 800; font-size: 18px; letter-spacing: .5px; background: var(--panel); border: 1px solid var(--line); transition: transform .08s; }
.btn:active { transform: scale(.96); }
.btn.main { font-size: 24px; padding: 18px; color: #06131a; background: linear-gradient(90deg, var(--sol1), var(--sol2) 48%, var(--luna2) 52%, var(--luna1)); border: 0; box-shadow: 0 8px 30px rgba(255, 79, 163, .35), 0 8px 30px rgba(79, 227, 255, .25); }
.btn.sm { font-size: 14px; padding: 11px 10px; }
.btn small { display: block; font-size: 11px; font-weight: 600; color: var(--dim); letter-spacing: 0; margin-top: 2px; }
.btn.main small { color: #06131acc; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats { display: flex; justify-content: center; gap: 18px; font-weight: 800; font-size: 15px; color: var(--ink); text-shadow: 0 2px 6px #000a; }
.stats span b { color: var(--sol1); }
h2 { margin: 4px 0 12px; font-size: 26px; letter-spacing: 1px; text-align: center; }
.panel { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 16px; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; padding: 2px 2px 12px; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 11px 13px; text-align: left; width: 100%; }
.row .g { flex: 1; min-width: 0; } .row .g b { display: block; font-size: 15px; } .row .g small { color: var(--dim); font-size: 12px; }
.row.done { border-color: rgba(255, 226, 122, .6); } .row.locked { opacity: .55; }
.row .r { font-weight: 800; font-size: 13px; white-space: nowrap; }
.sw { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 20px; border: 2px solid #fff3; }
.bar { height: 7px; border-radius: 4px; background: #0008; margin-top: 6px; overflow: hidden; } .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--luna1), var(--sol1)); }
.tabs { display: flex; gap: 8px; margin-bottom: 10px; width: 100%; max-width: 420px; } .tabs .btn { flex: 1; } .tabs .btn.sel { border-color: var(--sol1); color: var(--sol1); }
.big { font-size: 58px; font-weight: 900; text-align: center; line-height: 1; font-variant-numeric: tabular-nums; }
.newbest { text-align: center; font-weight: 900; letter-spacing: 3px; color: var(--sol1); animation: pulse .8s infinite alternate; }
@keyframes pulse { to { color: var(--luna1); transform: scale(1.06); } }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 5px 14px; font-size: 14px; margin: 12px 0; } .kv span { color: var(--dim); } .kv b { text-align: right; }
.note { color: var(--dim); font-size: 12px; text-align: center; margin: 8px 0 0; line-height: 1.4; }
.foot { width: 100%; max-width: 420px; margin-top: 10px; display: flex; gap: 8px; } .foot .btn { flex: 1; }
input.name { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: #0008; color: var(--ink); font: inherit; font-weight: 800; font-size: 18px; -webkit-user-select: text; user-select: text; }
.how { display: grid; gap: 10px; font-size: 15px; line-height: 1.35; } .how b { color: var(--sol1); } .how i { font-style: normal; color: var(--luna1); font-weight: 800; }
.count { height: 8px; border-radius: 4px; background: #0008; overflow: hidden; margin: 12px 0; } .count i { display: block; height: 100%; width: 100%; background: var(--sol1); transform-origin: left; animation: shrink 5s linear forwards; }
@keyframes shrink { to { transform: scaleX(0); } }

#toasts { position: absolute; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 84px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.toast { background: rgba(8, 22, 30, .92); border: 1px solid rgba(255, 226, 122, .7); border-radius: 14px; padding: 8px 14px; font-size: 13px; font-weight: 800; animation: tin .25s ease-out, tout .4s 2.8s forwards; box-shadow: 0 6px 20px #0008; }
.toast small { display: block; color: var(--dim); font-weight: 600; }
@keyframes tin { from { transform: translateY(-14px); opacity: 0; } } @keyframes tout { to { opacity: 0; transform: translateY(-10px); } }

/* ---------- v2: hearts, level progress, form buttons, level select, tutorial cards ---------- */
#hearts { position: absolute; left: 14px; top: calc(env(safe-area-inset-top) + 42px); font-size: 20px; letter-spacing: 3px; color: #ff5f7a; text-shadow: 0 2px 6px #000a; }
#hearts i { font-style: normal; opacity: .25; }
#prog { position: absolute; left: 0; right: 0; top: 0; height: 5px; background: #0008; } #prog i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb347, #9be8ff, #5fe0b0, #ffd27a); }
#powers { top: calc(env(safe-area-inset-top) + 62px); }
#forms { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 14px); display: flex; justify-content: center; gap: 12px; pointer-events: none; }
#forms button { pointer-events: auto; width: 68px; height: 68px; border-radius: 50%; background: rgba(8, 22, 30, .72); border: 3px solid #fff3; font-size: 30px; display: grid; place-items: center; padding: 0; transition: transform .1s; opacity: .7; touch-action: manipulation; }
#forms button img { width: 100%; height: 100%; border-radius: 50%; display: block; pointer-events: none; }
#forms button.on { opacity: 1; transform: scale(1.18); border-color: var(--c); box-shadow: 0 0 18px var(--c); }
#forms button.cool { filter: grayscale(.8) brightness(.7); }
#forms small { position: absolute; bottom: 84px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 800; letter-spacing: 1.5px; color: var(--dim); text-shadow: 0 1px 4px #000; }
.lv { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; }
.lv .n { width: 46px; height: 46px; border-radius: 14px; flex: none; display: grid; place-items: center; font-weight: 900; font-size: 22px; background: linear-gradient(135deg, var(--sol1), var(--sol2)); color: #06131a; }
.lv .g { flex: 1; } .lv .g b { display: block; font-size: 17px; } .lv .g small { color: var(--dim); font-size: 12px; font-weight: 600; }
.lv .s { font-size: 20px; letter-spacing: 2px; color: #ffe27a; white-space: nowrap; } .lv .s i { font-style: normal; opacity: .22; }
.lv.locked { opacity: .45; } .lv.locked .n { background: #223; color: var(--dim); }
.starsBig { text-align: center; font-size: 54px; letter-spacing: 8px; color: #ffe27a; text-shadow: 0 0 22px #ffe27a88; } .starsBig i { font-style: normal; opacity: .2; }
.tutIcon { font-size: 44px; text-align: center; margin-bottom: 4px; }
.tutText { font-size: 16px; line-height: 1.45; text-align: center; margin: 0 0 14px; }
.unlock { text-align: center; font-weight: 800; color: var(--luna1); margin: 8px 0; }
#phaseTag { display: none !important; }

/* ---------- v3: in-world tip caption, world list ---------- */
#tip { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 92px); width: max-content; max-width: 88%; background: rgba(8, 22, 30, .9); border: 1px solid rgba(255, 255, 255, .55); border-radius: 16px; padding: 9px 14px; text-align: center; box-shadow: 0 6px 22px #000a; animation: tin .25s ease-out; }
#tip b { display: block; font-size: 16px; color: #fff6b0; } #tip span { font-size: 14px; line-height: 1.3; }
.world { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 12px; }
.world.locked { opacity: .45; }
.world h3 { margin: 0 0 2px; font-size: 18px; } .world p { margin: 0 0 10px; font-size: 12px; color: var(--dim); }
.world .st { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.world .st button { padding: 10px 4px; border-radius: 14px; background: #0006; border: 1px solid var(--line); font-weight: 800; font-size: 15px; }
.world .st button small { display: block; font-size: 10px; color: var(--dim); font-weight: 700; letter-spacing: .5px; }
.world .st button .s { display: block; font-size: 13px; color: #ffe27a; letter-spacing: 1px; } .world .st button .s i { font-style: normal; opacity: .22; }
.world .st button.locked { opacity: .4; } .world .st button.next { border-color: var(--sol1); box-shadow: 0 0 12px rgba(255, 193, 69, .4); }
#tip { top: auto; bottom: calc(env(safe-area-inset-bottom) + 122px); }

/* ---------- v5: shop preview, four tabs, ending ---------- */
#prev { width: 132px; height: 132px; flex: none; margin: -6px 0 4px; }
.tabs .btn.sm { padding: 10px 2px; font-size: 12px; }
#screen.ending .logo { margin-top: 9dvh; }
#prev { position: static; inset: auto; display: block; }
#screen.ending { background-position: center bottom; }
#screen.ending { background-size: auto 150%; background-position: center 93%; } /* zoom so Nim sits in the gap above the panel on short and tall screens alike */

/* ---------- v6: volume sliders ---------- */
.row.vol .g { display: block; } .row.vol .r { min-width: 34px; text-align: right; font-size: 16px; }
input[type=range] { width: 100%; margin: 10px 0 2px; accent-color: #ffc145; height: 28px; touch-action: pan-x; }

/* ---------- tap-to-continue tips ---------- */
#tipTap { position: absolute; inset: 0; pointer-events: auto; z-index: 3; background: rgba(2, 8, 12, .28); }
#tip { z-index: 4; pointer-events: none; }
#tip em { display: block; margin-top: 6px; font-style: normal; font-size: 11px; font-weight: 800; letter-spacing: 2px; color: #9dffd9; animation: pulse .8s infinite alternate; }
