:root {
  --ink: #fff8ec;
  --muted: #b9b2e0;
  --night: #160f38;
  --night2: #2a1c63;
  --gold: #ffcf3f;
  --good: #3ee08f;
  --bad: #ff5d73;
  --card: #241a57;
  --font: 'Baloo 2', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font); color: var(--ink);
  background: radial-gradient(120% 80% at 50% 0%, var(--night2) 0%, var(--night) 60%, #0b0722 100%) fixed;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
  overscroll-behavior: none;
}
.sky {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .7;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 42%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 46% 12%, #ffe9a8 50%, transparent 51%),
    radial-gradient(1px 1px at 64% 30%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 82% 16%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 52%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 8% 70%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 36% 84%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 74% 76%, #c7d8ff 50%, transparent 51%);
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { to { opacity: .35; } }
#app { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; }
sup { font-size: .55em; vertical-align: super; line-height: 0; margin-left: .03em; }

/* przyciski ogólne */
.go, .ghost {
  font-size: 1.35rem; font-weight: 800; padding: .7em 1.4em; border-radius: 18px; min-height: 64px;
}
.go { background: var(--gold); color: #2a1c00; box-shadow: 0 6px 0 #b8860b; }
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8860b; }
.ghost { background: rgba(255,255,255,.1); box-shadow: inset 0 0 0 2px rgba(255,255,255,.18); }
.ghost:active { background: rgba(255,255,255,.2); }

/* ---------- wieża ---------- */
.home { max-width: 720px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 20px 32px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.top h1 { margin: 0; font-size: clamp(2rem, 6vw, 3rem); line-height: 1; letter-spacing: -.01em;
  background: linear-gradient(180deg, #fff 30%, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hello { margin: 6px 0 0; color: var(--muted); font-size: 1.2rem; }
.total { font-size: 2rem; font-weight: 800; color: var(--gold); white-space: nowrap; text-shadow: 0 0 18px rgba(255,207,63,.5); }
.total small { font-size: 1rem; color: var(--muted); margin-left: 4px; }

.tower { display: flex; flex-direction: column; align-items: center; padding-top: 10px; }
.floor {
  --c: hsl(var(--h) 75% 52%);
  width: min(100%, 560px); display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 12px;
  padding: 14px 18px; margin-top: -2px; min-height: 92px; text-align: left;
  background: linear-gradient(180deg, hsl(var(--h) 80% 60%), hsl(var(--h) 70% 44%));
  border-radius: 10px; box-shadow: inset 0 -6px 0 hsl(var(--h) 70% 34%), inset 0 2px 0 hsl(var(--h) 90% 75%);
  position: relative; transition: transform .15s;
}
.floor::before { /* „cegły” */
  content: ''; position: absolute; inset: 0; border-radius: 10px; pointer-events: none; opacity: .06;
  background: repeating-linear-gradient(90deg, transparent 0 58px, #000 58px 60px);
}
.floor:active { transform: scale(.97); }
.flabel {
  font-size: 2.2rem; font-weight: 800; text-align: center; line-height: 1;
  background: rgba(0,0,0,.2); border-radius: 14px; padding: 12px 4px; text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.fname b { display: block; font-size: 1.45rem; line-height: 1.1; }
.fname small { font-size: 1.05rem; opacity: .85; }
.fstars { font-size: 1.7rem; letter-spacing: 2px; }
.fstars span { color: rgba(0,0,0,.28); }
.fstars span.on { color: var(--gold); text-shadow: 0 0 10px rgba(255,207,63,.8), 0 2px 0 rgba(0,0,0,.3); }
.floor.locked { filter: grayscale(.85) brightness(.55); }
.floor.locked .fstars { font-size: 1.5rem; }
.floor.roof {
  width: min(86%, 470px); border-radius: 26px 26px 10px 10px; min-height: 104px;
  background: linear-gradient(180deg, #ffd95c, #e39b12);
  box-shadow: inset 0 -6px 0 #a76a00, 0 0 40px rgba(255,190,60,.35); color: #2a1300;
}
.floor.roof .flabel { font-size: 2.8rem; background: rgba(0,0,0,.12); }
.floor.roof .fstars span.on { color: #fff; }
.floor.roof::after { /* blanki */
  content: ''; position: absolute; left: 10%; right: 10%; top: -18px; height: 20px;
  background: repeating-linear-gradient(90deg, #ffd95c 0 26px, transparent 26px 46px); border-radius: 4px 4px 0 0;
}
.floor.roof.locked::after { background: repeating-linear-gradient(90deg, #555 0 26px, transparent 26px 46px); }
.ground { width: min(100%, 640px); height: 22px; border-radius: 0 0 40% 40%; background: linear-gradient(#3f8a4a, #24552c); margin-top: -2px; }
.nope { animation: shake .4s; }

.extras { display: flex; justify-content: center; margin: 26px 0 10px; }
.blitz {
  display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; text-align: left;
  padding: 14px 26px; border-radius: 20px; min-width: min(100%, 420px);
  background: linear-gradient(135deg, #ffe066, #ff9f1c); color: #2b1500; box-shadow: 0 6px 0 #b4600a;
}
.blitz span { grid-row: span 2; font-size: 2.6rem; }
.blitz b { font-size: 1.5rem; line-height: 1; }
.blitz small { font-size: 1.05rem; opacity: .8; }
.blitz.locked { filter: grayscale(1) brightness(.6); }
.foot { display: flex; justify-content: center; gap: 12px; margin-top: 18px; }
.foot .ghost { font-size: 1.05rem; min-height: 52px; padding: .5em 1.1em; }

/* ---------- karty: intro / wynik / rodzic ---------- */
.intro, .result, .parent-view { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.intro.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(10,6,30,.82); backdrop-filter: blur(4px); overflow: auto; }
.card {
  width: min(100%, 600px); background: var(--card); border-radius: 28px; padding: 28px 30px 30px; text-align: center;
  box-shadow: 0 0 0 3px hsl(var(--h, 260) 70% 55% / .7), 0 24px 60px rgba(0,0,0,.45);
  animation: pop .35s cubic-bezier(.2,1.4,.5,1);
}
.card.wide { width: min(100%, 760px); text-align: left; }
.card h2 { margin: 0 0 8px; font-size: 2.3rem; line-height: 1.1; }
.kicker { margin: 0; text-transform: uppercase; letter-spacing: .14em; font-weight: 800; color: hsl(var(--h) 85% 70%); }
.lesson { font-size: 1.35rem; line-height: 1.45; }
.lesson p { margin: .6em 0; }
.lesson .big, .big { font-size: 2.1rem; display: inline-block; margin: .1em 0; }
.lesson .grid, .lesson .cube { margin: 10px auto; }
.trap { color: #ffb3bf; font-weight: 700; }
.order { display: inline-block; text-align: left; font-size: 1.4rem; margin: 6px 0; padding-left: 1.6em; }
.order li { margin: 2px 0; }
.card .go { margin-top: 14px; width: 100%; }
.card .back { margin-top: 12px; width: 100%; }
.dragon-big { font-size: 5rem; margin: 0; line-height: 1.1; animation: float 2.4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px) rotate(-4deg); } }

/* ---------- gra ---------- */
.play { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding: max(12px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.bar { display: flex; align-items: center; gap: 14px; }
.icon { width: 54px; height: 54px; border-radius: 16px; font-size: 1.6rem; font-weight: 800; background: rgba(255,255,255,.1); flex: none; }
.progress { flex: 1; height: 20px; border-radius: 10px; background: rgba(255,255,255,.12); overflow: hidden; }
.progress b { display: block; height: 100%; width: 0; border-radius: 10px; background: linear-gradient(90deg, hsl(var(--h) 80% 55%), hsl(var(--h) 90% 70%)); transition: width .4s; }
.streak { min-width: 64px; font-size: 1.5rem; font-weight: 800; color: #ffb347; text-align: center; }
.bossbar { flex: 1; display: flex; align-items: center; gap: 12px; }
.dragon { font-size: 2.6rem; display: inline-block; }
.dragon.ouch { animation: ouch .5s; }
@keyframes ouch { 20% { transform: translateX(-8px) rotate(-12deg) scale(.9); filter: brightness(2) saturate(0); } 60% { transform: translateX(6px) rotate(8deg); } }
.hp { flex: 1; height: 22px; border-radius: 11px; background: rgba(255,255,255,.12); overflow: hidden; box-shadow: inset 0 0 0 2px rgba(255,255,255,.1); }
.hp b { display: block; height: 100%; background: linear-gradient(90deg, #ff3d3d, #ff9f1c); transition: width .4s; }
.hearts { font-size: 1.5rem; white-space: nowrap; }
.hearts .lost { opacity: .5; }
.blitzbar { flex: 1; display: flex; justify-content: space-between; font-size: 1.9rem; font-weight: 800; }
.timer.hurry { color: var(--bad); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

.qa { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 16px 0; min-height: 0; }
.visual:empty { display: none; }
.visual { margin-bottom: 14px; }
.prompt { font-size: clamp(2.6rem, 8vw, 4.6rem); font-weight: 800; line-height: 1.15; }
.qa.has-visual .prompt { font-size: clamp(1.8rem, 5vw, 2.8rem); }
.prompt .slotline { margin-top: 10px; }
.slot {
  display: inline-block; min-width: 2.2em; padding: 0 .25em; border-radius: 16px; vertical-align: baseline;
  background: rgba(255,255,255,.1); box-shadow: inset 0 -4px 0 rgba(255,255,255,.18); color: var(--gold);
}
.qa.has-visual .slot { font-size: 1.5em; }
.slot.empty { animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { box-shadow: inset 0 -4px 0 var(--gold); } }
.qa.good .slot { background: var(--good); color: #062b17; }
.qa.wrong .slot { background: var(--bad); color: #fff; animation: shake .4s; }
.qa.wrong .slot.shown { background: rgba(62,224,143,.25); color: var(--good); animation: none; }
.again { display: block; font-size: 1rem; letter-spacing: .12em; text-transform: uppercase; color: #ffb347; margin-bottom: 4px; }
.praise { min-height: 2.6rem; font-size: 2rem; font-weight: 800; color: var(--good); }
.qa.good .praise { animation: pop .4s cubic-bezier(.2,1.6,.5,1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

/* klawiatura */
.input { width: 100%; max-width: 520px; margin: 0 auto; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button, .choices button {
  font-size: 2.3rem; font-weight: 800; min-height: 78px; border-radius: 20px;
  background: linear-gradient(180deg, #4b3a9c, #3a2c80); box-shadow: 0 6px 0 #22185a; transition: transform .05s;
}
.keypad button.pressed, .keypad button:active, .choices button:active { transform: translateY(4px); box-shadow: 0 2px 0 #22185a; }
.keypad .ok { background: linear-gradient(180deg, #46e79a, #22b56d); box-shadow: 0 6px 0 #137042; color: #052414; }
.keypad .del { background: linear-gradient(180deg, #6a5bb0, #554592); font-size: 2rem; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.choices.cmp { grid-template-columns: repeat(3, 1fr); }
.choices.cmp button { font-size: 3.4rem; min-height: 100px; }
.choices button.right { background: var(--good); color: #062b17; box-shadow: 0 6px 0 #137042; }
.choices button.bad { background: var(--bad); box-shadow: 0 6px 0 #9b2234; animation: shake .4s; }

/* kwadrat z kafelków */
.grid { --cell: clamp(26px, calc(min(46vw, 34vh) / var(--n)), 58px); display: grid; grid-template-columns: repeat(var(--n), var(--cell)); gap: 4px; justify-content: center; }
.grid i { width: var(--cell); height: var(--cell); border-radius: 6px; background: linear-gradient(135deg, #7ef0c0, #22b58a); box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); animation: tile .35s both cubic-bezier(.2,1.5,.5,1); }
.grid.small { --cell: clamp(12px, calc(150px / var(--n)), 26px); gap: 3px; }
@keyframes tile { from { transform: scale(0); opacity: 0; } }

/* sześcian z klocków */
.cube { width: clamp(150px, 30vh, 280px); height: auto; display: block; overflow: visible; }
.cube.small { width: 130px; margin: 6px auto; }
.cube g { animation: drop .4s both cubic-bezier(.2,1.3,.5,1); }
.cube polygon { stroke: #13235a; stroke-width: 1; stroke-linejoin: round; }
.cube .t { fill: #9fd0ff; } .cube .r { fill: #4f8fe8; } .cube .l { fill: #3466c2; }
@keyframes drop { from { transform: translateY(-30px); opacity: 0; } }

/* arkusz z wyjaśnieniem */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(10,6,30,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-in {
  width: min(100%, 680px); background: #fff8ec; color: #24184f; border-radius: 28px 28px 0 0; padding: 24px 26px max(24px, env(safe-area-inset-bottom));
  text-align: center; animation: up .3s cubic-bezier(.2,1.2,.5,1); max-height: 90vh; overflow: auto;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-title { font-size: 1.5rem; margin: 0 0 8px; }
.sheet-title b { color: #138a4f; font-size: 1.8rem; }
.sheet-explain { font-size: 1.45rem; line-height: 1.5; margin: 8px 0 16px; }
.sheet-explain .trap { color: #c8243e; }
.sheet .grid i { background: linear-gradient(135deg, #5ad6a4, #1c9a74); }
.sheet .next { width: 100%; font-size: 1.5rem; font-weight: 800; min-height: 70px; border-radius: 20px; background: #4b3a9c; color: #fff; box-shadow: 0 6px 0 #22185a; }

/* wyniki */
.result h2 { font-size: 2.6rem; }
.result p { font-size: 1.35rem; margin: .4em 0; }
.bigstars { font-size: 4.6rem; letter-spacing: 8px; margin: 4px 0 10px; }
.bigstars span { color: rgba(255,255,255,.15); display: inline-block; }
.bigstars span.on { color: var(--gold); text-shadow: 0 0 24px rgba(255,207,63,.9); animation: starpop .5s both cubic-bezier(.2,1.8,.5,1); }
@keyframes starpop { from { transform: scale(0) rotate(-90deg); } }
.bigscore { font-size: 4rem; font-weight: 800; color: var(--gold); display: block; line-height: 1; }
.btns { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 18px; }
.btns button { flex: 1 1 180px; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti span { position: absolute; top: -40px; font-size: 1.8rem; font-weight: 800; animation: fall var(--d) ease-in both; }
@keyframes fall { to { transform: translate(var(--x), 110vh) rotate(540deg); } }

/* rodzic */
.parent-view h3 { margin: 22px 0 2px; font-size: 1.4rem; }
.muted { color: var(--muted); margin: 4px 0 12px; font-size: 1.05rem; }
.parent-view table { width: 100%; border-collapse: collapse; font-size: 1.1rem; }
.parent-view th, .parent-view td { padding: 8px 6px; border-bottom: 1px solid rgba(255,255,255,.1); text-align: left; }
.parent-view td:nth-child(2) { color: var(--gold); }
.mistakes { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.mistakes li { display: flex; gap: 12px; align-items: baseline; background: rgba(255,255,255,.06); padding: 8px 12px; border-radius: 12px; font-size: 1.15rem; }
.mistakes li span { flex: 1; }
.mistakes li em { font-style: normal; color: var(--good); font-weight: 800; }
.mistakes li small { color: var(--muted); }
.parent-view .btns button { font-size: 1.1rem; }

/* tablet w poziomie: pytanie po lewej, klawiatura po prawej */
@media (orientation: landscape) and (min-width: 820px) {
  .play { display: grid; grid-template-columns: 1fr minmax(360px, 440px); grid-template-rows: auto 1fr; column-gap: 32px; }
  .bar { grid-column: 1 / -1; }
  .qa { grid-column: 1; }
  .input { grid-column: 2; align-self: center; }
  .keypad button { min-height: 84px; }
}
@media (max-height: 640px) and (orientation: landscape) {
  .keypad button { min-height: 58px; font-size: 1.9rem; }
  .keypad { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
