* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c1026; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { font-family: 'Fredoka', system-ui, sans-serif; color: #fff7ea; position: fixed; inset: 0; }
canvas#c { display: block; width: 100%; height: 100%; touch-action: none; position: fixed; inset: 0; }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; touch-action: manipulation; }
.ui { pointer-events: auto; }

#topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 10px 0; z-index: 50; pointer-events: none; }
#topbar .spacer { flex: 1; }
.icon { width: 50px; height: 50px; border-radius: 16px; background: rgba(40,18,48,.72); color: #ffe3a8; font-size: 22px; font-weight: 700; border: 2px solid rgba(255,210,140,.45); box-shadow: 0 3px 0 rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.icon:active { transform: translateY(2px); box-shadow: none; }
.icon.off { color: #8a7a8a; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hudRow { position: absolute; top: calc(env(safe-area-inset-top) + 66px); left: 0; right: 0; display: flex; justify-content: center; gap: 6px; }
.chip { background: rgba(40,18,48,.75); border: 2px solid rgba(255,210,140,.35); padding: 6px 12px; border-radius: 14px; font-weight: 600; font-size: 16px; white-space: nowrap; }
.eye { color: #ffd36b; margin: 0 2px; transition: color .3s; }
.eye.lost { color: #5b3a4a; }
#alertWrap { position: absolute; top: calc(env(safe-area-inset-top) + 108px); left: 50%; transform: translateX(-50%); width: 180px; text-align: center; }
#alertLabel { font-size: 11px; letter-spacing: 2px; opacity: .8; }
#alertBar { height: 10px; border-radius: 6px; background: rgba(0,0,0,.45); overflow: hidden; border: 1px solid rgba(255,255,255,.2); }
#alertFill { height: 100%; width: 0%; background: linear-gradient(90deg,#ffd36b,#ff5a4a); transition: width .1s; }
#tiptoeChip { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 22px); left: 50%; transform: translateX(-50%); background: rgba(80,200,180,.85); color: #13302c; font-weight: 700; padding: 8px 18px; border-radius: 20px; letter-spacing: 2px; }
#toast { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 70px); left: 50%; transform: translateX(-50%) translateY(20px); max-width: 88vw; background: rgba(40,18,48,.88); border: 2px solid rgba(255,210,140,.5); padding: 10px 16px; border-radius: 16px; font-size: 16px; text-align: center; opacity: 0; transition: opacity .35s, transform .35s; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#hint { position: absolute; top: 46%; left: 50%; transform: translate(-50%,-50%); background: rgba(40,18,48,.85); padding: 14px 20px; border-radius: 18px; border: 2px solid #ffd36b; text-align: center; font-size: 17px; display: flex; gap: 12px; align-items: center; }
.finger { font-size: 34px; animation: tap 1.2s infinite; }
@keyframes tap { 0%,100% { transform: translateY(0) } 50% { transform: translateY(8px) scale(.9) } }
#banner { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-size: 34px; font-weight: 700; color: #ffe3a8; text-shadow: 0 3px 0 #6a2a3a, 0 0 20px rgba(255,160,80,.6); opacity: 0; transition: opacity .4s; }
#banner small { display: block; font-size: 18px; font-weight: 400; color: #fff; }
#banner.show { opacity: 1; }
#vignette { position: absolute; inset: 0; box-shadow: inset 0 0 120px 40px rgba(255,40,40,.0); transition: box-shadow .15s; }

.screen { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 70px 16px 20px; background: radial-gradient(ellipse at center, rgba(40,15,45,.55), rgba(20,8,26,.85)); }
#scrTitle { background: linear-gradient(180deg, rgba(30,12,50,.35), rgba(60,20,40,.7)); }
.panel { background: rgba(48,20,52,.94); border: 3px solid #e8b46a; border-radius: 24px; padding: 18px 18px 20px; width: min(420px, 100%); max-height: 100%; overflow-y: auto; touch-action: pan-y; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 10px; }
h2 { margin: 0 0 4px; color: #ffd36b; font-size: 28px; }
.titleBox { text-align: center; }
.titleBox h1 { font-size: clamp(52px, 15vw, 84px); line-height: .95; margin: 8px 0; color: #ffd36b; text-shadow: 0 5px 0 #8c2f45, 0 0 30px rgba(255,170,90,.7); letter-spacing: 1px; }
.endTitle { font-size: clamp(44px, 13vw, 76px) !important; }
.sub { font-size: 18px; margin: 6px 0 18px; opacity: .95; }
.lights { color: #ffd36b; letter-spacing: 6px; font-size: 20px; animation: twinkle 2s infinite alternate; }
@keyframes twinkle { from { opacity: .5 } to { opacity: 1 } }
.big { min-height: 56px; padding: 0 28px; border-radius: 18px; background: linear-gradient(180deg,#ffcf6b,#f39a3d); color: #4a1a2a; font-size: 22px; font-weight: 700; box-shadow: 0 5px 0 #a8522a; }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #a8522a; }
.big.alt { background: linear-gradient(180deg,#e88cae,#c45a86); color: #fff; box-shadow: 0 5px 0 #7a2d55; }
.big:disabled { opacity: .6; }
.row { display: flex; gap: 10px; justify-content: center; }
.row .big { flex: 1; }
#loadBar { width: 220px; height: 8px; margin: 0 auto 16px; background: rgba(0,0,0,.4); border-radius: 4px; overflow: hidden; }
#loadFill { height: 100%; width: 0; background: #ffd36b; transition: width .2s; }
#totalStars { color: #ffd36b; font-size: 18px; }
#levelGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lvl { min-height: 64px; border-radius: 16px; background: linear-gradient(180deg,#6b2c5a,#4a1d42); color: #fff; border: 2px solid #e8b46a; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; }
.lvl b { font-size: 20px; }
.lvl span { font-size: 12px; opacity: .85; }
.lvl .st { color: #ffd36b; font-size: 15px; letter-spacing: 2px; opacity: 1; }
.lvl:active { transform: scale(.96); }
.how ul { text-align: left; padding-left: 20px; margin: 0; font-size: 16px; line-height: 1.4; overflow-y: auto; flex: 1 1 auto; min-height: 0; touch-action: pan-y; }
.how, #scrLevels .panel { overflow: hidden; }
.how > button, .panel > h2 { flex: 0 0 auto; }
#levelGrid { overflow-y: auto; flex: 1 1 auto; min-height: 0; touch-action: pan-y; padding: 2px; }
.how li { margin-bottom: 6px; }
#resStars { font-size: 52px; letter-spacing: 6px; }
#resStars span { color: #4a3048; display: inline-block; transition: color .3s, transform .3s; }
#resStars span.on { color: #ffd36b; transform: scale(1.15); text-shadow: 0 0 16px rgba(255,200,90,.8); }
#resStats { font-size: 17px; line-height: 1.6; }
#endStars { font-size: 26px; color: #ffd36b; margin-bottom: 18px; }
@media (max-height: 640px) { .lvl { min-height: 52px; } .titleBox h1 { font-size: 48px; } }
