:root {
  --navy: #11131c; --navy2: #1b1f2e; --ink: #fff; --muted: #c3c6d6;
  --card: #fffdf7; --cardInk: #1b1f3b; --cardMuted: #5d6480;
  --red: #c8283b; --yellow: #ffd801; --ok: #2fd27a; --bad: #ff5a6e;
  --display: "Fredoka", "Rubik", system-ui, sans-serif; --body: "Rubik", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--navy); color: var(--ink); font-family: var(--body); overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.app { position: relative; max-width: min(560px, 56dvh); height: 100dvh; margin: 0 auto; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); background: var(--navy); }

/* HUD */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 56px; padding: 0 14px; font-weight: 700; }
.stage { font-family: var(--display); font-size: 17px; color: var(--muted); min-width: 90px; }
.scorebox { display: flex; align-items: center; gap: 10px; }
.score { font-family: var(--display); font-size: 26px; color: var(--yellow); font-variant-numeric: tabular-nums; }
.score.pop { animation: pop .35s ease; }
.mute { width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255,255,255,.1); display: grid; place-items: center; cursor: pointer; }
.mute svg { width: 24px; height: 24px; }
.mute .off, .mute.muted .on { display: none; }
.mute.muted .off { display: block; }
.timer { height: 10px; margin: 0 14px 8px; border-radius: 99px; background: rgba(255,255,255,.14); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #2fd27a, #ffc72c); transform-origin: left; border-radius: 99px; }
.timer.low i { background: linear-gradient(90deg, #ff5a6e, #ff8f5a); animation: blink .5s steps(2) infinite; }

/* Scena: ściana z majoliki na dwóch płótnach (kafle + efekty) */
.scene { position: relative; flex: 1; overflow: hidden; border-radius: 22px 22px 0 0; margin: 0 6px; touch-action: none; background: #0d0f17; }
.scene canvas.wall { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

.labels { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: space-between; padding: 0 10px; z-index: 3; }
.label { --hot: 0; display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 8px 14px; border: 0; border-radius: 99px; background: rgba(17, 19, 32, calc(.72 + var(--hot) * .28)); font-family: var(--display); font-weight: 600; font-size: 16px; cursor: pointer; transform: scale(calc(1 + var(--hot) * .14)); box-shadow: 0 0 calc(var(--hot) * 26px) rgba(255, 199, 44, calc(var(--hot) * .9)); transition: transform .12s, background .12s; }
.flag { display: inline-block; width: 30px; height: 18px; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1.5px rgba(255,255,255,.8); }
.flag svg { display: block; width: 100%; height: 100%; }

.deck { position: absolute; inset: 0; display: grid; place-items: center; z-index: 4; pointer-events: none; padding-bottom: 60px; }
.card { position: relative; pointer-events: auto; width: min(78%, 320px); min-height: 176px; padding: 26px 18px 22px; border-radius: 24px; background: var(--card); color: var(--cardInk); box-shadow: 0 14px 0 rgba(0,0,0,.18), 0 18px 40px rgba(0,0,0,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; cursor: grab; touch-action: none; }
/* Android (nagranie z testu 2026-10-01): od etapu 2 karta była widoczna TYLKO wtedy, gdy coś ją animowało (wjazd, ✓/✗, przeciąganie),
 * a nieruchoma znikała pod ścianą z płócien. Niewidoczna, ciągła animacja przezroczystości trzyma ją jako animowaną warstwę.
 * Klasy in/rise/shake/flipped podmieniają ją na chwilę własną animacją — po nich wraca sama. */
.card { animation: keepalive 1s linear infinite; }
@keyframes keepalive { from { opacity: 1; } to { opacity: .999; } }
/* osobna warstwa GPU tylko na czas przeciągania — stała warstwa na Androidzie potrafiła nie odmalować się po pokazaniu karty (pusta, dopóki jej nie ruszyć) */
.card.drag { will-change: transform; }
.card:active { cursor: grabbing; }
.card.in { animation: cardIn .32s cubic-bezier(.3,1.6,.5,1); }
.card.shake { animation: shake .4s ease; }
.card { transition: background-color .12s, box-shadow .12s; }
.card.ok { background: #dcfbe8; box-shadow: 0 0 0 5px var(--ok), 0 0 34px rgba(47, 210, 122, .75), 0 18px 40px rgba(0,0,0,.35); }
.card.bad { background: #ffe0e4; box-shadow: 0 0 0 5px var(--bad), 0 0 34px rgba(255, 90, 110, .75), 0 18px 40px rgba(0,0,0,.35); }
.card.ok .word { color: #0f6b3a; } .card.bad .word { color: #a3182b; }
.stamp { position: absolute; top: -22px; right: -14px; width: 64px; height: 64px; border-radius: 50%; display: none; place-items: center; font: 700 38px/1 var(--display); color: #fff; transform: rotate(-12deg); box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.card.ok .stamp, .card.bad .stamp { display: grid; animation: stamp .28s cubic-bezier(.2,1.8,.4,1); }
.card.ok .stamp { background: var(--ok); } .card.bad .stamp { background: var(--bad); }
@keyframes stamp { from { transform: scale(2.2) rotate(-30deg); opacity: 0; } }
/* rozmiar startowy; game.js zmniejsza go, aż najdłuższy wyraz zmieści się w karcie (łamanie tylko na spacjach) */
.word { width: 100%; font-family: var(--display); font-weight: 700; font-size: 44px; line-height: 1.05; overflow-wrap: normal; }
.gloss { font-size: 15px; font-weight: 500; color: var(--cardMuted); max-width: 26ch; }
.rush { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; display: none; transform: rotate(-90deg); }
.rush circle { fill: none; stroke: var(--red); stroke-width: 5; stroke-dasharray: 107; stroke-dashoffset: 0; }
.card.rushing .rush { display: block; }
.card.rushing .rush circle { animation: rushring var(--rush, 2.6s) linear forwards; }

.hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); margin: 0; text-align: center; font-weight: 700; font-size: 14px; color: #fff; z-index: 3; padding: 6px 14px; border-radius: 99px; background: rgba(13, 15, 23, .8); }
.feedback { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 16px); flex-wrap: wrap; justify-content: center; text-align: center; margin: 0; z-index: 6; padding: 10px 16px; border-radius: 16px; background: rgba(17, 19, 32, .92); font-family: var(--display); font-weight: 600; font-size: 18px; display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity .15s; pointer-events: none; }
.feedback.show { opacity: 1; }
.feedback .flag { width: 22px; height: 14px; }
.feedback.ok { background: rgba(21, 110, 64, .92); }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.bit { position: absolute; width: 12px; height: 12px; border-radius: 2px; }
.bit.star { width: 16px; height: 16px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); border-radius: 0; }

.twist { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(13, 15, 23, .55); text-align: center; padding: 20px; }
.twist b { font-family: var(--display); font-weight: 700; font-size: clamp(52px, 17vw, 84px); color: var(--yellow); text-shadow: 0 6px 0 var(--red); animation: slam .45s cubic-bezier(.2,1.8,.4,1); }
.twist span { font-weight: 700; font-size: 18px; max-width: 24ch; }

/* Przejście etapu: podpis pod złotą cyfrą z kafli */
.stagecap { position: absolute; left: 50%; top: 76%; margin: 0; z-index: 9; padding: 8px 18px; border-radius: 99px; background: rgba(13, 15, 23, .86); font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: 1px; text-transform: uppercase; white-space: nowrap; pointer-events: none; opacity: 0; transform: translate(-50%, 24px); transition: opacity .25s, transform .35s cubic-bezier(.3,1.5,.5,1); }
.stagecap.on { opacity: 1; transform: translate(-50%, 0); }

/* Nakładki */
.overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(13, 15, 23, .72); padding: 16px; }
.panel { width: min(100%, 420px); max-height: calc(100dvh - 40px); overflow: auto; background: var(--navy2); border-radius: 26px; padding: 22px 18px; box-shadow: 0 20px 50px rgba(0,0,0,.4); animation: cardIn .35s cubic-bezier(.3,1.5,.5,1); }
.panel h2 { font-family: var(--display); font-weight: 700; font-size: 28px; margin: 0 0 14px; text-align: center; }
.panel h3 { font-family: var(--display); font-weight: 600; font-size: 18px; margin: 16px 0 8px; color: var(--muted); }
.levels { display: grid; gap: 10px; }
.lvl { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 72px; padding: 12px 16px; border: 0; border-radius: 18px; background: rgba(255,255,255,.08); text-align: left; cursor: pointer; transition: transform .1s, background .15s; }
.lvl:hover, .lvl:focus-visible { background: rgba(255,255,255,.16); }
.lvl:active { transform: scale(.97); }
.lvl .code { font-family: var(--display); font-weight: 700; font-size: 20px; min-width: 70px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--yellow); color: var(--cardInk); }
.lvl.b1 .code { background: #ff9a3c; } .lvl.c1 .code { background: var(--red); color: #fff; }
.lvl .txt { display: flex; flex-direction: column; gap: 2px; }
.lvl .txt b { font-family: var(--display); font-size: 19px; }
.lvl .txt span { font-size: 14px; color: var(--muted); }
.sumline { text-align: center; margin: 4px 0; font-weight: 700; font-size: 17px; }
.sumline.bonus { color: var(--yellow); }
.mistakes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mistakes li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 14px; background: rgba(255,255,255,.07); }
.mistakes .pair { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 700; }
.mistakes .pair .flag { width: 20px; height: 12px; }
.mistakes .sep { color: var(--muted); }
.mistakes .say { display: flex; gap: 6px; flex-shrink: 0; }
.mistakes .say button { width: 44px; height: 44px; border: 0; border-radius: 12px; background: rgba(255,255,255,.12); display: grid; place-items: center; cursor: pointer; position: relative; }
.mistakes .say button .flag { position: absolute; right: 3px; bottom: 4px; width: 14px; height: 9px; }
.mistakes .say svg { width: 20px; height: 20px; }
.mistakes .none { justify-content: center; color: var(--muted); }
.voicehint { font-size: 13px; color: var(--muted); text-align: center; }
.cta { display: block; width: 100%; min-height: 56px; margin-top: 18px; border: 0; border-radius: 99px; background: var(--yellow); color: var(--cardInk); font-family: var(--display); font-weight: 700; font-size: 20px; cursor: pointer; box-shadow: 0 5px 0 #b89a00; }
.cta:active { transform: translateY(3px); box-shadow: 0 2px 0 #b89a00; }
button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

@keyframes pop { 50% { transform: scale(1.3); } }
@keyframes blink { 50% { opacity: .55; } }
@keyframes rain { to { background-position: -30px 60px; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes waves { to { background-position: 0 44px; } }
/* bez startu od pełnej przezroczystości: gdy animacja utknie na pierwszej klatce (Android), karta i tak jest widoczna */
@keyframes cardIn { from { transform: scale(.6) translateY(30px); opacity: .35; } }
@keyframes shake { 20% { transform: translateX(-14px) rotate(-3deg); } 40% { transform: translateX(12px) rotate(3deg); } 60% { transform: translateX(-8px); } 80% { transform: translateX(5px); } }
@keyframes rushring { to { stroke-dashoffset: 107; } }
@keyframes slam { from { transform: scale(2.4) rotate(-8deg); opacity: 0; } }

/* desktop: kolumna gry w proporcjach telefonu (ok. 9:16), żeby flagi z kafli wyglądały jak na telefonie */
@media (min-aspect-ratio: 9/14) { .scene { border-radius: 22px; margin-bottom: 10px; } }
@media (prefers-reduced-motion: reduce) {
  .timer.low i { animation: none; }
  .stagecap { transition: none; }
}

/* Fala combo: napis z bonusem (sama fala przejeżdża po kaflach na płótnie) */
.wavebadge { position: absolute; left: 50%; top: 9%; transform: translateX(-50%); margin: 0; z-index: 7; pointer-events: none; font-family: var(--display); font-weight: 700; font-size: 26px; color: #fff; white-space: nowrap; text-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 18px rgba(255,220,120,.9); opacity: 0; }
.wavebadge.on { animation: badge 1.6s ease-out; }
@keyframes badge { 0% { opacity: 0; transform: translateX(-50%) scale(2); } 15% { opacity: 1; transform: translateX(-50%) scale(1); } 75% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-16px); } }

/* PAIR!: stos karty i podglądu drugiej połówki pary */
.stack { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; pointer-events: none; }
.stack .card { pointer-events: auto; }
.peek { width: min(64%, 260px); padding: 12px 14px; border-radius: 18px; background: rgba(255, 253, 247, .88); color: var(--cardInk); text-align: center; box-shadow: 0 6px 0 rgba(0,0,0,.15); border: 2px dashed rgba(27, 31, 59, .25); animation: cardIn .3s ease-out; }
.peek .word { font-size: 30px; }
.card.rise { animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(70px) scale(.85); opacity: .7; } }
/* FLASH!: odwrócona karta — słowo znika, gracz decyduje z pamięci */
.card.flipped { animation: flip .28s ease-in-out; background: repeating-linear-gradient(45deg, #ffd801 0 12px, #ffe866 12px 24px); }
.card.flipped .word, .card.flipped .gloss { visibility: hidden; }
.card.flipped::after { content: "?"; position: absolute; inset: 0; display: grid; place-items: center; font: 700 64px/1 var(--display); color: #171c4e; }
.card.flipped.ok, .card.flipped.bad { background: var(--card); }
.card.flipped.ok .word, .card.flipped.bad .word { visibility: visible; }
.card.flipped.ok::after, .card.flipped.bad::after { content: none; }
@keyframes flip { 50% { transform: scaleX(0); } }

/* Podpisy stron tylko dla czytników ekranu i klawiatury (wizualnie stronę pokazują flagi; odpowiada się tapnięciem w połówkę ściany) */
.labels.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Pasek combo: 6 złotych kafli w ramce z fugi, znaczniki ×2 i ×3, medalion z bieżącym mnożnikiem */
.combobar { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 10px; border-radius: 99px; background: rgba(13, 15, 23, .86); box-shadow: 0 6px 18px rgba(0,0,0,.4); pointer-events: none; }
.combobar .slots { display: flex; align-items: center; gap: 4px; }
.combobar .slot { position: relative; width: 24px; height: 24px; border-radius: 6px; background: #2a2420; box-shadow: inset 0 2px 3px rgba(0,0,0,.6); }
.combobar .slot::after { content: ""; position: absolute; inset: 2px; border-radius: 4px; background: linear-gradient(135deg, #ffe866, #e8b400 55%, #b88c00); box-shadow: inset 1px 1px 0 rgba(255,255,255,.5), 0 0 10px rgba(255,216,1,.55); transform: scale(0); transition: transform .22s cubic-bezier(.3,1.7,.5,1); }
.combobar .slot.on::after { transform: scale(1); }
.combobar.full .slot.on::after { animation: shimmer 1.2s ease-in-out infinite; }
@keyframes shimmer { 50% { filter: brightness(1.35); } }
.combobar .mark { font: 700 12px var(--display); color: #8b8fa6; padding: 0 1px; transition: color .2s, transform .2s; }
.combobar .mark.hit { color: var(--yellow); transform: scale(1.2); }
/* medalion: ×1 szary, ×2 pomarańczowy pierścień, ×3 złoty krążek z poświatą */
.combobar .mult { display: grid; place-items: center; width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #2f3552, #171c2e 70%); border: 3px solid #4a4f68; font: 700 18px/1 var(--display); color: #a7abc0; font-variant-numeric: tabular-nums; transition: border-color .2s, color .2s, box-shadow .2s; }
.combobar .mult.x2 { border-color: #ff9a3c; color: #ffc27a; box-shadow: 0 0 12px rgba(255,154,60,.55); }
.combobar .mult.x3 { border-color: #fff1a8; background: radial-gradient(circle at 35% 30%, #fff1a8, #ffd801 45%, #c79a00); color: #171c4e; box-shadow: 0 0 18px rgba(255,216,1,.85); }
.combobar .mult.pop { animation: pop .4s ease; }
.shard { position: absolute; z-index: 3; width: 20px; height: 20px; border-radius: 4px; background: linear-gradient(135deg, #ffe866, #e8b400); pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .combobar.full .slot.on::after { animation: none; } }
