:root {
    --bg: #f4f6ff;
    --card: #ffffff;
    --text: #1f2544;
    --muted: #6b7290;
    --primary: #4c6ef5;
    --primary-dark: #3b5bdb;
    --good: #2fb344;
    --bad: #e8590c;
    --gold: #fab005;
    --line: #dde2f5;
    --radius: 20px;
    --shadow: 0 6px 20px rgba(40, 55, 120, 0.12);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12152a;
        --card: #1c2140;
        --text: #eef1ff;
        --muted: #a3a9c9;
        --line: #2d3460;
        --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
main { max-width: 520px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.center { text-align: center; }
.big-emoji { font-size: 64px; line-height: 1; margin: 8px 0; }

/* Przyciski */
.btn {
    font: inherit; font-weight: 700; border: 0; border-radius: 14px; padding: 14px 22px; cursor: pointer;
    background: var(--line); color: var(--text); touch-action: manipulation;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.wide { width: 100%; margin-top: 12px; font-size: 22px; }
.btn:focus-visible, .key:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Nagłówek */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; }
.hello { font-size: 20px; }
.badges { display: flex; gap: 6px; }
.badge { background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 6px 12px; font-weight: 700; }

/* Pasek postępu */
.progress { margin-bottom: 14px; }
.progress-label { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.reward-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { height: 18px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill {
    height: 100%; width: 0; border-radius: 999px;
    background: linear-gradient(90deg, var(--gold), #ff922b);
    transition: width 0.5s cubic-bezier(.2, .8, .2, 1);
}
.progress-hint { color: var(--muted); font-size: 15px; margin-top: 6px; }

/* Zadanie */
.task { text-align: center; padding: 22px 16px; border: 4px solid transparent; transition: border-color .2s, background-color .2s; }
.task-text { font-size: clamp(40px, 13vw, 60px); font-weight: 800; letter-spacing: 1px; }
.answer {
    margin: 12px auto 6px; min-height: 70px; max-width: 260px; border-radius: 14px; background: var(--bg);
    font-size: 48px; font-weight: 800; color: var(--primary); display: flex; align-items: center; justify-content: center;
}
.answer.placeholder::after { content: "?"; color: var(--muted); opacity: .5; }
.feedback { min-height: 28px; font-weight: 700; font-size: 20px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback.hint { color: var(--muted); }
.task.good { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--card)); }
.task.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--card)); }
.task.shake { animation: shake .4s; }
@keyframes shake {
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* Klawiatura ekranowa */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.keypad.disabled .key { opacity: .45; pointer-events: none; }
.key {
    font: inherit; font-size: 30px; font-weight: 800; height: 68px; border: 0; border-radius: 16px; cursor: pointer;
    background: var(--card); color: var(--text); box-shadow: var(--shadow); touch-action: manipulation; user-select: none;
}
.key:active { transform: scale(.96); }
.key.muted { color: var(--muted); }
.small { font-size: 14px; }
.row.between { justify-content: space-between; margin-bottom: 10px; }
.row.spaced { margin-top: 10px; }
.key.go { background: var(--good); color: #fff; }
.today { text-align: center; color: var(--muted); font-size: 15px; margin-top: 16px; }

/* Nagroda */
.modal { position: fixed; inset: 0; background: rgba(10, 14, 40, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-box { max-width: 380px; width: 100%; position: relative; overflow: hidden; animation: pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.reward-big { font-size: 24px; font-weight: 800; color: var(--primary); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.confetti, .confetti::before, .confetti::after {
    position: absolute; inset: -40px 0 auto; height: 40px; pointer-events: none;
    background: radial-gradient(circle, var(--gold) 3px, transparent 4px) 0 0 / 34px 34px,
        radial-gradient(circle, var(--primary) 3px, transparent 4px) 17px 10px / 34px 34px,
        radial-gradient(circle, var(--good) 3px, transparent 4px) 8px 20px / 34px 34px;
    animation: fall 2.2s linear infinite;
}
.confetti::before { content: ""; animation-delay: .7s; }
.confetti::after { content: ""; animation-delay: 1.4s; }
@keyframes fall { to { transform: translateY(520px); } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Panel opiekuna */
body.admin main { max-width: 900px; }
body.admin h1 { font-size: 24px; margin: 6px 0 14px; }
body.admin h2 { font-size: 18px; margin: 0 0 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px; }
.tile span { color: var(--muted); font-size: 14px; display: block; }
.tile strong { font-size: 24px; }
.section { margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
td.ok { color: var(--good); font-weight: 700; }
td.no { color: var(--bad); font-weight: 700; }
.table-wrap { overflow-x: auto; }
label.field { display: block; margin-bottom: 10px; font-weight: 600; }
label.field input, label.field select {
    display: block; width: 100%; margin-top: 4px; font: inherit; padding: 10px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 4px 0 12px; }
.checks label { display: flex; gap: 6px; align-items: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.msg { min-height: 24px; font-weight: 600; margin: 8px 0; }
.msg.ok { color: var(--good); }
.msg.err { color: var(--bad); }
.link-box { word-break: break-all; background: var(--bg); padding: 10px; border-radius: 10px; font-family: ui-monospace, monospace; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row.between { justify-content: space-between; margin-bottom: 10px; }
.row.spaced { margin-top: 10px; }
