/* ==========================================================================
   SCHIACCIALERT — Il gioco (gioco.html)
   ========================================================================== */
:root {
  --red: #C8161D; --red-2: #A50F15; --red-3: #6E080C; --cream: #F7EBD3; --paper: #FBF4E4; --ink: #1A1210; --yellow: #FFC72C; --green: #2BD46B;
  --f-display: 'Anton', 'Impact', 'Arial Narrow', sans-serif; --f-hand: 'Kaushan Script', cursive; --f-script: 'Lobster', cursive; --f-mono: 'Space Mono', ui-monospace, monospace;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { font-family: 'Jost', system-ui, sans-serif; font-size: 16px; line-height: 1.4; color: var(--cream); background: #120B09; overflow: hidden; -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }

.g { position: relative; width: 100%; max-width: 520px; height: 100vh; height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; background: radial-gradient(ellipse 90% 60% at 50% 20%, #E3262D, var(--red) 50%, var(--red-3) 120%); overflow: hidden; box-shadow: 0 0 80px rgba(0, 0, 0, .6); }
.g::before { content: ""; position: absolute; inset: 0; background: radial-gradient(rgba(0, 0, 0, .2) 1.2px, transparent 1.7px) 0 0 / 14px 14px; pointer-events: none; opacity: .6; }
.g__bar { position: relative; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--ink); border-bottom: 5px solid transparent; border-image: repeating-linear-gradient(-45deg, var(--yellow) 0 10px, var(--ink) 10px 20px) 5; }
.g__back { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1.5px solid rgba(247, 235, 211, .5); color: var(--cream); text-decoration: none; font-size: 18px; flex: none; }
.g__logo { font-family: var(--f-script); font-size: 20px; color: var(--cream); white-space: nowrap; }
.g__logo b { font-weight: 400; color: var(--yellow); }
.g__hud { margin-left: auto; display: flex; align-items: center; gap: 8px; font-family: var(--f-mono); font-size: 13px; }
.g__hud > span { background: rgba(247, 235, 211, .1); padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.g__time::before { content: "⏱ "; }
.g__time.is-low { background: var(--red); animation: pulse .5s infinite alternate; }
.g__score::before { content: "★ "; color: var(--yellow); }
.g__score b { font-weight: 700; }
.g__hud[hidden] + .lang { margin-left: auto; }
.lang { position: relative; display: inline-flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 999px; border: 1.5px solid rgba(247, 235, 211, .5); font-family: var(--f-mono); font-size: 12px; line-height: 1; flex: none; }
.lang svg { width: 14px; height: 14px; }
.lang select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; color: #1A1210; }
.g:not([data-state="door"]):not([data-state="end"]) .lang, .g:not([data-state="door"]):not([data-state="end"]) .g__logo { display: none; }
@keyframes pulse { to { transform: scale(1.08); } }

.sc { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); animation: scIn .45s var(--spring); }
@keyframes scIn { from { opacity: 0; transform: translateY(24px) scale(.97); } }
.kicker { font-family: var(--f-mono); font-size: 11.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }
h1, h2 { font-family: var(--f-display); font-weight: 400; text-transform: uppercase; line-height: .95; letter-spacing: .01em; }
h1 { font-size: clamp(38px, 11vw, 56px); margin: 6px 0 8px; }
.help { text-align: center; font-family: var(--f-mono); font-size: 12px; letter-spacing: .04em; opacity: .9; padding: 6px 0; }

/* ---- livello 1: la facciata ---- */
.sc--door { text-align: center; }
.sc--door .sc__copy p:last-child { max-width: 34ch; margin: 0 auto; opacity: .92; }
.facade { position: relative; flex: 1; min-height: 260px; margin: 14px -16px 0; background: linear-gradient(#E9D7AE, #D9C08D); border-top: 8px solid #B9975A; overflow: hidden; }
.facade::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(120, 84, 40, .16) 2px, transparent 2px) 0 0 / 100% 46px, linear-gradient(90deg, rgba(120, 84, 40, .13) 2px, transparent 2px) 0 0 / 92px 46px; }
.facade__sign { position: absolute; top: 5%; left: 50%; translate: -50% 0; background: var(--red); color: #fff; padding: 8px 20px 10px; border-radius: 12px; border: 3px solid var(--ink); box-shadow: 4px 5px 0 rgba(0, 0, 0, .3); font-family: var(--f-script); font-size: clamp(24px, 7.4vw, 36px); white-space: nowrap; rotate: -2deg; display: flex; align-items: center; gap: 10px; }
.facade__sign b { font-weight: 400; color: var(--yellow); }
.siren { width: 14px; height: 14px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 199, 44, .3), 0 0 18px 5px rgba(255, 199, 44, .8); animation: siren 1s steps(2) infinite; flex: none; }
@keyframes siren { 50% { opacity: .25; } }
.facade__lamp { position: absolute; top: 30%; left: 9%; width: 22px; height: 30px; background: var(--yellow); border: 3px solid var(--ink); border-radius: 4px 4px 9px 9px; box-shadow: 0 0 34px 12px rgba(255, 199, 44, .55); }
.facade__win { position: absolute; top: 34%; right: 6%; width: 22%; aspect-ratio: 3 / 4; background: linear-gradient(160deg, #FFE9A8, #F2B84A); border: 5px solid #6B4A22; border-radius: 6px; display: grid; place-items: center; font-family: var(--f-display); color: var(--red-2); font-size: clamp(14px, 4.4vw, 22px); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .35); }
.facade__num { position: absolute; top: 31%; left: 50%; translate: 96px 0; width: 30px; height: 30px; display: grid; place-items: center; background: #fff; color: #1B355C; border: 2px solid #1B355C; border-radius: 5px; font-weight: 700; }
.facade__street { position: absolute; left: 0; right: 0; bottom: 0; height: 13%; background: radial-gradient(ellipse 18px 9px at 18px 9px, #8C8377 60%, transparent 62%) 0 0 / 36px 18px, #6F675D; border-top: 5px solid #57503F; }
.door { position: absolute; left: 50%; bottom: 13%; translate: -50% 0; width: clamp(130px, 38%, 180px); height: 62%; border-radius: 90px 90px 0 0; border: 7px solid #5B3A1B; background: #1A1210; overflow: hidden; perspective: 700px; animation: doorHint 1.6s ease-in-out infinite; }
.door__in { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 70%, #FFD98A, #F0A236 55%, #8A4B12); }
.door__in::after { content: "🥪"; position: absolute; left: 50%; top: 52%; translate: -50% -50%; font-size: 54px; }
.door__leaf { position: absolute; top: 0; bottom: 0; width: 50%; background: linear-gradient(90deg, var(--red-2), var(--red)); border: 2px solid var(--red-3); transition: transform .7s cubic-bezier(.6, 0, .2, 1); box-shadow: inset 0 0 0 7px rgba(0, 0, 0, .12); }
.door__leaf--l { left: 0; transform-origin: left; }
.door__leaf--r { right: 0; transform-origin: right; }
.door__leaf--l::after, .door__leaf--r::after { content: ""; position: absolute; top: 55%; width: 9px; height: 9px; border-radius: 50%; background: var(--yellow); }
.door__leaf--l::after { right: 8px; } .door__leaf--r::after { left: 8px; }
.door.is-open { animation: none; }
.door.is-open .door__leaf--l { transform: rotateY(-105deg); }
.door.is-open .door__leaf--r { transform: rotateY(105deg); }
.door__tap { position: absolute; left: 50%; bottom: 12%; translate: -50% 0; background: var(--yellow); color: var(--ink); font-family: var(--f-display); text-transform: uppercase; font-size: 15px; padding: 6px 12px; border-radius: 8px; white-space: nowrap; box-shadow: 0 0 0 2px var(--ink); transition: opacity .2s; }
.door.is-open .door__tap { opacity: 0; }
@keyframes doorHint { 50% { scale: 1.03; } }
.best { text-align: center; font-family: var(--f-mono); font-size: 12.5px; padding-top: 10px; }

/* ---- livello 2: il bancone ---- */
.ticket { background: var(--paper); color: var(--ink); border-radius: 6px 6px 14px 14px; padding: 12px 14px 12px; box-shadow: 0 12px 24px -12px rgba(0, 0, 0, .6); position: relative; rotate: -.6deg; }
.ticket::before { content: ""; position: absolute; left: 0; right: 0; top: -7px; height: 8px; background: radial-gradient(circle at 6px 0, transparent 5px, var(--paper) 5.5px) 0 0 / 12px 8px; }
.ticket .kicker { color: var(--red); }
.ticket h2 { font-size: clamp(26px, 8vw, 36px); margin: 2px 0 8px; }
.ticket ol { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; counter-reset: n; }
.ticket li { counter-increment: n; font-size: 13.5px; font-weight: 500; padding: 4px 9px 4px 6px; border-radius: 999px; border: 1.5px solid rgba(26, 18, 16, .3); display: flex; align-items: center; gap: 5px; transition: all .25s; }
.ticket li::before { content: counter(n); width: 18px; height: 18px; border-radius: 50%; background: rgba(26, 18, 16, .12); display: grid; place-items: center; font-family: var(--f-mono); font-size: 10.5px; }
.ticket li.is-next { background: var(--yellow); border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); font-weight: 700; scale: 1.06; }
.ticket li.is-done { opacity: .5; text-decoration: line-through; }
.ticket li.is-done::before { content: "✓"; background: var(--green); color: #fff; }
.bench { position: relative; flex: 1; min-height: 120px; display: grid; place-items: center; }
.bench::after { content: ""; position: absolute; left: 12%; right: 12%; bottom: 14%; height: 16px; border-radius: 50%; background: rgba(0, 0, 0, .35); filter: blur(8px); }
.stack { position: relative; width: min(74%, 300px); aspect-ratio: 2 / 1; z-index: 1; }
.stack .layer { position: absolute; inset: 0; pointer-events: none; transition: transform .45s cubic-bezier(.3, 1.5, .5, 1), opacity .2s; }
.stack .layer > img, .stack .layer > svg, .stk__l > img, .stk__l > svg { width: 100%; height: 100%; display: block; object-fit: contain; overflow: visible; }
.stk { position: relative; width: 100%; aspect-ratio: 2 / 1; }
.stk__l { position: absolute; inset: 0; transform: translateY(var(--y)); }
.g-stack.is-squash { animation: squash .5s var(--spring); }
@keyframes squash { 30% { transform: scale(1.06, .88); } }
.stamp-ok { position: absolute; z-index: 3; top: 8%; left: 50%; translate: -50% 0; rotate: -7deg; border: 4px solid var(--yellow); color: var(--yellow); font-family: var(--f-display); text-transform: uppercase; font-size: clamp(24px, 7.5vw, 34px); padding: 4px 14px 6px; border-radius: 10px; white-space: nowrap; opacity: 0; scale: 2.2; pointer-events: none; background: rgba(110, 8, 12, .55); }
.stamp-ok.is-on { opacity: 1; scale: 1; transition: opacity .15s, scale .35s var(--spring); }
.flash { position: absolute; z-index: 4; bottom: 4%; left: 0; right: 0; text-align: center; font-family: var(--f-display); text-transform: uppercase; font-size: 22px; color: #fff; text-shadow: 0 2px 0 var(--red-3); opacity: 0; pointer-events: none; }
.flash.is-on { animation: flash .9s ease-out; }
@keyframes flash { 0% { opacity: 0; translate: 0 10px; } 20% { opacity: 1; translate: 0 0; } 100% { opacity: 0; translate: 0 -22px; } }
.belt { position: relative; height: 122px; margin: 0 -16px; background: repeating-linear-gradient(90deg, #2A1E1A 0 26px, #33251F 26px 52px); border-top: 5px solid var(--yellow); border-bottom: 5px solid var(--yellow); overflow: hidden; flex: none; }
.tile { position: absolute; top: 9px; left: 0; width: 96px; height: 94px; border-radius: 14px; background: var(--cream); color: var(--ink); border: 2.5px solid var(--ink); box-shadow: 0 5px 0 rgba(0, 0, 0, .45); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 4px 4px 6px; will-change: transform; overflow: hidden; }
.tile img { position: absolute; top: 2px; left: 4px; width: 88px; height: 44px; object-fit: contain; pointer-events: none; }
.tile i { position: absolute; top: 12px; width: 44px; height: 26px; border-radius: 50%; background: var(--c, #ccc); border: 2px solid rgba(0, 0, 0, .2); }
.tile span { position: relative; font-size: 11.5px; font-weight: 600; line-height: 1.1; text-align: center; max-height: 2.3em; overflow: hidden; }
.tile:active { scale: .94; }
.tile.is-ok { background: var(--green); animation: pop .3s forwards; }
.tile.is-no { background: #FF8A8A; animation: shake .3s; }
@keyframes pop { to { scale: 1.2; opacity: 0; } }
@keyframes shake { 25% { rotate: -6deg; } 75% { rotate: 6deg; } }
.g.is-shake { animation: gshake .3s; }
@keyframes gshake { 25% { translate: -6px 0; } 75% { translate: 6px 0; } }

/* ---- livello 3: la consegna ---- */
.sc--path { padding-bottom: 0; }
.prog { position: relative; height: 12px; margin: 14px 18px 12px; border-radius: 8px; background: rgba(0, 0, 0, .35); }
.prog i { position: absolute; inset: 0; border-radius: 8px; background: var(--yellow); transform-origin: left; transform: scaleX(0); }
.prog span { position: absolute; top: 50%; translate: -50% -50%; font-size: 20px; }
.prog span:nth-of-type(1) { left: 0; } .prog span:nth-of-type(2) { left: 100%; }
.road { position: relative; flex: 1; min-height: 0; margin: 0 -16px; background: #6F675D; overflow: hidden; border-top: 5px solid var(--yellow); }
.road__lanes { position: absolute; inset: -72px 0 0; background:
  linear-gradient(90deg, transparent calc(33.33% - 2px), rgba(255, 255, 255, .35) calc(33.33% - 2px) calc(33.33% + 2px), transparent calc(33.33% + 2px) calc(66.66% - 2px), rgba(255, 255, 255, .35) calc(66.66% - 2px) calc(66.66% + 2px), transparent calc(66.66% + 2px)),
  radial-gradient(ellipse 20px 10px at 20px 12px, #8C8377 60%, transparent 62%) 0 0 / 40px 24px,
  radial-gradient(ellipse 20px 10px at 0 0, #7E766A 60%, transparent 62%) 0 0 / 40px 24px, #6F675D; }
.road.is-run .road__lanes { animation: roadMove .5s linear infinite; }
@keyframes roadMove { to { transform: translateY(72px); } }
.runner { position: absolute; left: 0; bottom: 70px; width: 33.333%; height: 70px; display: grid; place-items: center; transition: transform .14s ease-out; z-index: 3; }
.runner .tray { width: 76%; max-width: 132px; background: #E9D7AE; border: 3px solid var(--ink); border-radius: 12px; padding: 6px 4px 2px; box-shadow: 0 8px 0 rgba(0, 0, 0, .35); }
.runner.is-hit .tray { animation: blink .18s steps(2) 5; }
@keyframes blink { 50% { opacity: .2; } }
.ob { position: absolute; left: 0; top: 0; width: 33.333%; height: 56px; display: grid; place-items: center; font-size: 42px; line-height: 1; will-change: transform; z-index: 2; pointer-events: none; filter: drop-shadow(0 5px 0 rgba(0, 0, 0, .3)); }
.ob--bonus { font-size: 32px; }
.ob--table { font-size: 64px; width: 100%; }
.road__tap { position: absolute; top: 0; bottom: 0; width: 50%; z-index: 4; }
.road__tap--l { left: 0; } .road__tap--r { right: 0; }
.road__tap::after { position: absolute; bottom: 14px; font-size: 26px; opacity: .55; color: #fff; }
.road__tap--l::after { content: "◀"; left: 16px; } .road__tap--r::after { content: "▶"; right: 16px; }
.road__help { position: absolute; z-index: 5; left: 16px; right: 16px; top: 22%; text-align: center; background: var(--ink); color: var(--cream); padding: 14px 16px; border-radius: 16px; border: 2px solid var(--yellow); font-weight: 600; pointer-events: none; transition: opacity .4s; }
.road__help.is-off { opacity: 0; }
.g__lives { letter-spacing: 2px; }

/* ---- fine ---- */
.sc--end { align-items: center; justify-content: center; text-align: center; gap: 10px; overflow-y: auto; }
.end__art { width: min(70%, 260px); }
.sc--end h2 { font-size: clamp(40px, 12vw, 60px); color: var(--yellow); rotate: -3deg; text-shadow: .04em .05em 0 var(--red-3); }
.sc--end > p { max-width: 32ch; }
.end__score { display: flex; gap: 12px; margin-top: 6px; }
.end__score div { background: var(--ink); border-radius: 16px; padding: 10px 22px 12px; min-width: 120px; }
.end__score span { display: block; font-family: var(--f-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }
.end__score b { font-family: var(--f-display); font-weight: 400; font-size: 44px; line-height: 1; }
.end__rank { font-family: var(--f-hand); font-size: 26px; color: var(--yellow); }
.end__btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.gbtn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 20px; border-radius: 999px; font-weight: 600; text-decoration: none; background: var(--cream); color: var(--ink); border: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.gbtn--yellow { background: var(--yellow); flex: 1 1 100%; font-family: var(--f-display); font-weight: 400; text-transform: uppercase; font-size: 22px; }
.gbtn--line { background: transparent; color: var(--cream); border-color: rgba(247, 235, 211, .7); box-shadow: none; }
.gbtn:active { translate: 2px 2px; box-shadow: 2px 2px 0 var(--ink); }
.toast { position: absolute; z-index: 9; left: 50%; bottom: 24px; translate: -50% 0; background: var(--ink); color: var(--cream); padding: 10px 16px; border-radius: 999px; font-size: 14px; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { .door, .siren, .sc { animation: none; } }
@media (max-height: 620px) { .ticket h2 { font-size: 24px; margin-bottom: 4px; } .belt { height: 108px; } .tile { height: 84px; top: 6px; } h1 { font-size: 34px; } }
