:root {
	--navy: #0b1736;
	--navy2: #13265a;
	--gold: #ffc93c;
	--red: #ff3d4f;
	--cyan: #39e1ff;
	--white: #fffaf0;
	--ink: #1a1030;
	--display: 'Bungee', 'Arial Black', Impact, sans-serif;
	--ui: 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--sat: env(safe-area-inset-top, 0px);
	--sab: env(safe-area-inset-bottom, 0px);
	--sal: env(safe-area-inset-left, 0px);
	--sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1736; color: var(--white); font-family: var(--ui); user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
body.playing canvas#game { cursor: none; }
.hidden { display: none !important; }
button { font-family: var(--ui); font-weight: 900; letter-spacing: .06em; color: var(--white); background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.35); border-radius: 12px; padding: 10px 18px; cursor: pointer; transition: transform .12s, background .12s, border-color .12s; }
button:hover { background: rgba(255,255,255,.18); border-color: #fff; }
button:active { transform: scale(.96); }
button.big { font-family: var(--display); font-size: 22px; font-weight: 400; padding: 16px 40px; border: none; color: var(--ink); background: linear-gradient(180deg, #ffe17a, #ffb32c); box-shadow: 0 6px 0 #c06a0a, 0 10px 30px rgba(255,170,40,.45); }
button.big:hover { background: linear-gradient(180deg, #fff09a, #ffc03c); }
button.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #c06a0a; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 20; text-align: center; padding: 24px; }
#title { background: radial-gradient(ellipse at 50% 120%, rgba(255,120,60,.35), transparent 60%), linear-gradient(180deg, rgba(8,14,40,.25), rgba(8,14,40,.75)); }
#title .logo { display: flex; flex-direction: column; line-height: .9; transform: rotate(-4deg); filter: drop-shadow(0 8px 0 rgba(10,10,40,.5)); animation: logoIn .8s cubic-bezier(.2,1.6,.4,1) both; }
#title .logo .l1 { font-family: var(--display); font-size: clamp(44px, 10vw, 110px); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--red); }
#title .logo .l2 { font-family: var(--display); font-size: clamp(30px, 6.6vw, 72px); background: linear-gradient(180deg, #fff6b0, #ffc93c 55%, #ff8a1f); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 2px var(--ink); letter-spacing: .04em; }
#title .tag { font-weight: 700; font-size: 18px; opacity: .92; text-shadow: 0 2px 6px rgba(0,0,0,.6); margin: 4px 0 8px; }
.controls-help { font-size: 14px; opacity: .8; margin: 0; text-shadow: 0 1px 4px #000; }
body.touch .controls-help.desktop, body:not(.touch) .controls-help.touch { display: none; }
@keyframes logoIn { from { transform: rotate(-4deg) scale(.3); opacity: 0; } }
.side-pick, .opt-row { display: flex; align-items: center; gap: 8px; font-weight: 900; letter-spacing: .1em; font-size: 13px; }
.side-pick span, .opt-row span { opacity: .75; width: 64px; text-align: right; margin-right: 4px; }
.side-pick button, .opt-row button { padding: 8px 14px; font-size: 13px; }
.side-pick button.on, .opt-row button.on { background: var(--gold); color: var(--ink); border-color: var(--gold); }
#pause, #gameover { background: rgba(6,10,30,.72); backdrop-filter: blur(6px); }
#pause h2, #gameover h2, #upgrade h2 { font-family: var(--display); font-weight: 400; font-size: clamp(34px, 7vw, 60px); margin: 0; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--red); }
.sub { margin: 0 0 8px; font-weight: 700; opacity: .9; }
#loading { background: var(--navy); z-index: 40; transition: opacity .5s; }
#loading.fade { opacity: 0; pointer-events: none; }
.spinner { width: 56px; height: 56px; border-radius: 50%; border: 6px solid rgba(255,255,255,.15); border-top-color: var(--gold); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- upgrade ---------- */
#upgrade { background: radial-gradient(ellipse at 50% 40%, rgba(40,20,90,.6), rgba(5,8,25,.88)); backdrop-filter: blur(4px); }
#cards { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; max-width: 980px; }
.card { width: 250px; min-height: 300px; border-radius: 20px; padding: 22px 18px 18px; text-align: left; position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 10px; background: linear-gradient(165deg, var(--c1), var(--c2)); border: 3px solid rgba(255,255,255,.55); box-shadow: 0 10px 0 rgba(0,0,0,.35), 0 20px 40px rgba(0,0,0,.4); cursor: pointer; animation: cardIn .5s cubic-bezier(.2,1.5,.4,1) both; transition: transform .15s; }
.card:nth-child(2) { animation-delay: .08s; } .card:nth-child(3) { animation-delay: .16s; }
.card:hover, .card:focus-visible { transform: translateY(-8px) rotate(-1deg); outline: none; border-color: #fff; }
.card .icon { width: 64px; height: 64px; border-radius: 16px; background: rgba(255,255,255,.18); display: grid; place-items: center; }
.card .icon svg { width: 44px; height: 44px; fill: #fff; }
.card h3 { font-family: var(--display); font-weight: 400; font-size: 22px; margin: 4px 0 0; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.card p { margin: 0; font-weight: 500; font-size: 15px; line-height: 1.35; }
.card .stat { margin-top: auto; font-weight: 900; font-size: 13px; letter-spacing: .06em; background: rgba(0,0,0,.25); border-radius: 10px; padding: 8px 10px; }
.card .lvl { position: absolute; top: 14px; right: 14px; font-weight: 900; font-size: 12px; background: rgba(0,0,0,.3); padding: 4px 8px; border-radius: 8px; }
@keyframes cardIn { from { transform: translateY(60px) scale(.8); opacity: 0; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #swing-btn { pointer-events: auto; }
#topbar { position: absolute; top: calc(10px + var(--sat)); left: 50%; transform: translateX(-50%); width: min(560px, 62vw); }
#foe-name { font-weight: 900; font-size: 13px; letter-spacing: .08em; display: flex; gap: 8px; align-items: center; justify-content: center; text-shadow: 0 2px 4px rgba(0,0,0,.7); margin-bottom: 5px; white-space: nowrap; }
#foe-title { background: var(--red); padding: 2px 7px; border-radius: 6px; font-size: 11px; }
#foe-level { color: var(--gold); }
#resolve { position: relative; height: 18px; border-radius: 10px; background: rgba(10,10,35,.75); border: 2px solid rgba(255,255,255,.85); overflow: hidden; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
#resolve-fill, #resolve-ghost { position: absolute; inset: 0; transform-origin: left; }
#resolve-ghost { background: #fff; transition: transform .6s .25s ease-out; }
#resolve-fill { background: linear-gradient(180deg, #ff9a6b, #ff3d4f 60%, #c4123a); transition: transform .18s; z-index: 1; }
#resolve.critical #resolve-fill { background: linear-gradient(180deg, #fff27a, #ff8d1f 60%, #ff2a3a); animation: pulse .5s infinite alternate; }
#resolve-ticks { position: absolute; inset: 0; z-index: 2; background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), rgba(0,0,0,.35) calc(10% - 2px) 10%); }
#resolve-text { position: absolute; right: 8px; top: 21px; font-size: 10px; font-weight: 900; letter-spacing: .2em; opacity: .7; }
@keyframes pulse { to { filter: brightness(1.4); } }
#count { position: absolute; top: calc(12px + var(--sat)); left: calc(12px + var(--sal)); background: rgba(10,14,40,.72); border: 2px solid rgba(255,255,255,.25); border-radius: 14px; padding: 8px 12px; display: flex; flex-direction: column; gap: 5px; }
#count .row { display: flex; align-items: center; gap: 6px; }
#count .lbl { font-weight: 900; font-size: 12px; width: 38px; letter-spacing: .08em; opacity: .85; }
.pip { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); display: inline-block; transition: background .15s, transform .15s; }
.pip.on { transform: scale(1.1); }
.pip.b.on { background: #3ee07a; border-color: #b8ffd0; }
.pip.s.on { background: #ffcf3c; border-color: #fff2b0; }
.pip.o { border-radius: 4px; background: #39e1ff; border-color: #c4f6ff; }
.pip.o.lost { background: transparent; border-color: rgba(255,255,255,.25); }
#best { position: absolute; top: calc(12px + var(--sat)); right: calc(64px + var(--sar)); background: rgba(10,14,40,.72); border: 2px solid rgba(255,255,255,.25); border-radius: 14px; padding: 6px 12px; display: flex; flex-direction: column; align-items: flex-end; font-weight: 900; font-size: 11px; letter-spacing: .1em; }
#best b { font-family: var(--display); font-weight: 400; font-size: 18px; color: var(--gold); letter-spacing: 0; }
#best span { opacity: .75; }
#pause-btn { position: absolute; top: calc(12px + var(--sat)); right: calc(12px + var(--sar)); width: 44px; height: 44px; padding: 0; display: grid; place-items: center; background: rgba(10,14,40,.72); }
#pause-btn svg { width: 22px; height: 22px; fill: #fff; }
#pitch-call { position: absolute; left: 50%; top: calc(74px + var(--sat)); transform: translateX(-50%); font-weight: 900; font-size: 13px; letter-spacing: .18em; padding: 4px 12px; border-radius: 8px; background: rgba(10,14,40,.6); opacity: 0; transition: opacity .2s; }
#pitch-call.show { opacity: 1; }
#feedback { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: 0; }
#feedback.show { animation: fbIn 1.3s ease-out both; }
#fb-tier { font-family: var(--display); font-size: clamp(34px, 7vw, 64px); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 rgba(0,0,0,.4); white-space: nowrap; }
#fb-tier.perfect { color: #fff36b; text-shadow: 0 5px 0 #ff6a1f, 0 0 30px rgba(255,220,80,.8); }
#fb-tier.excellent { color: #7cf3ff; text-shadow: 0 5px 0 #1468c4; }
#fb-tier.good { color: #b9ff7a; text-shadow: 0 5px 0 #2f8a24; }
#fb-tier.weak { color: #ffd2a8; text-shadow: 0 4px 0 #8a4a24; font-size: clamp(28px, 5vw, 44px); }
#fb-tier.miss { color: #ff8a9a; text-shadow: 0 4px 0 #7a1630; font-size: clamp(28px, 5vw, 44px); }
#fb-timing { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 900; font-size: 13px; letter-spacing: .14em; text-shadow: 0 1px 3px #000; }
#fb-meter { position: relative; width: 200px; height: 10px; display: flex; border-radius: 6px; overflow: hidden; border: 2px solid rgba(255,255,255,.8); }
#fb-meter .z { flex: 1; } #fb-meter .early, #fb-meter .late { background: #5a6aa8; flex: 1.4; } #fb-meter .good { background: #5bd36b; } #fb-meter .perfect { background: #ffe14a; flex: .6; }
#fb-mark { position: absolute; top: -3px; width: 4px; height: 12px; background: #fff; box-shadow: 0 0 6px #fff; border-radius: 2px; transform: translateX(-50%); }
@keyframes fbIn { 0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(.95); } 20% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }
#distance { position: absolute; left: 50%; top: calc(64px + var(--sat)); transform: translateX(-50%); display: grid; grid-template-columns: auto auto; align-items: end; column-gap: 6px; opacity: 0; transition: opacity .25s; text-shadow: 0 3px 0 rgba(0,0,0,.45); }
#distance.show { opacity: 1; }
#dist-val { font-family: var(--display); font-size: clamp(44px, 9vw, 84px); line-height: .9; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
#distance.hr #dist-val { color: var(--gold); }
#dist-unit { font-family: var(--display); font-size: 22px; padding-bottom: 6px; }
#dist-stats { grid-column: 1 / 3; display: flex; gap: 12px; justify-content: center; font-weight: 900; font-size: 13px; letter-spacing: .1em; }
#dist-tag { grid-column: 1 / 3; text-align: center; font-family: var(--display); font-size: 20px; color: var(--gold); min-height: 24px; }
#reticle { position: absolute; left: 0; top: 0; width: 0; height: 0; transition: opacity .2s; }
#reticle .ring { position: absolute; left: calc(var(--r) * -1); top: calc(var(--r) * -1); width: calc(var(--r) * 2); height: calc(var(--r) * 2); border-radius: 50%; border: 3px solid rgba(255,255,255,.95); box-shadow: 0 0 0 2px rgba(20,10,50,.5), inset 0 0 0 2px rgba(20,10,50,.35), 0 0 16px rgba(120,220,255,.6); }
#reticle .dot { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--ink); }
#reticle.swing .ring { animation: retSwing .25s ease-out; }
#reticle.clash .ring { border-color: #ffdf5a; box-shadow: 0 0 0 2px rgba(80,10,40,.6), 0 0 22px rgba(255,120,40,.9); }
@keyframes retSwing { 50% { transform: scale(.82); } }
#reticle.off { opacity: 0; }
#swing-btn { position: absolute; right: calc(18px + var(--sar)); bottom: calc(22px + var(--sab)); width: 104px; height: 104px; border-radius: 50%; display: none; place-items: center; font-family: var(--display); font-size: 20px; color: var(--ink); background: radial-gradient(circle at 40% 35%, #fff4a6, #ffbf2c 60%, #e48a0c); box-shadow: 0 6px 0 #a85d06, 0 10px 24px rgba(0,0,0,.4); border: 3px solid #fff; touch-action: none; }
#swing-btn.down { transform: translateY(4px) scale(.96); box-shadow: 0 2px 0 #a85d06; }
body.touch #swing-btn { display: grid; }
#aim-hint { position: absolute; left: 50%; bottom: calc(18px + var(--sab)); transform: translateX(-50%); font-weight: 700; font-size: 13px; opacity: 0; transition: opacity .4s; text-shadow: 0 1px 4px #000; white-space: nowrap; }
body.touch #aim-hint.show { opacity: .85; }
#banner { position: absolute; left: 0; right: 0; top: 40%; height: 0; display: flex; align-items: center; justify-content: center; overflow: visible; }
#banner-text { font-family: var(--display); font-size: clamp(36px, 8vw, 80px); color: #fff; -webkit-text-stroke: 2px #4a0820; paint-order: stroke fill; text-shadow: 0 0 24px rgba(255,80,60,.9), 0 6px 0 #ff3d4f; opacity: 0; white-space: nowrap; }
#banner.show #banner-text { animation: banner 2.2s cubic-bezier(.2,.9,.3,1) both; }
@keyframes banner { 0% { opacity: 0; transform: scale(3) skewX(-12deg); letter-spacing: .5em; } 15% { opacity: 1; transform: scale(1) skewX(-12deg); letter-spacing: .02em; } 80% { opacity: 1; transform: scale(1.04) skewX(-12deg); } 100% { opacity: 0; transform: scale(1.1) skewX(-12deg); } }
#skip-btn { position: absolute; right: calc(16px + var(--sar)); bottom: calc(18px + var(--sab)); background: rgba(10,14,40,.7); }
body.cine #count, body.cine #best, body.cine #topbar, body.cine #pause-btn, body.cine #swing-btn { opacity: 0; transition: opacity .3s; }
#count, #best, #topbar, #pause-btn, #swing-btn { transition: opacity .3s; }

@media (max-width: 640px) {
	#topbar { width: 60vw; left: auto; right: calc(12px + var(--sar)); transform: none; top: calc(84px + var(--sat)); }
	#foe-name { font-size: 10px; justify-content: flex-end; }
	#foe-label { display: none; }
	#best { right: calc(62px + var(--sar)); }
	#count { padding: 6px 9px; } .pip { width: 12px; height: 12px; }
	#distance { top: calc(128px + var(--sat)); }
	.card { width: min(86vw, 330px); min-height: 0; padding: 14px; flex-direction: row; flex-wrap: wrap; gap: 6px 12px; }
	.card .icon { width: 48px; height: 48px; } .card .icon svg { width: 32px; height: 32px; }
	.card h3 { font-size: 18px; align-self: center; } .card p { font-size: 13px; width: 100%; } .card .stat { width: 100%; }
	#cards { gap: 10px; }
}
@media (max-height: 480px) {
	#upgrade h2 { font-size: 30px; } .sub { margin: 0; }
	.card { min-height: 0; width: 210px; padding: 12px; gap: 6px; } .card p { font-size: 12px; } .card .icon { display: none; }
}
