:root {
    --bg: #f2f7f7;
    --card: #ffffff;
    --ink: #16302f;
    --muted: #6b7f7e;
    --primary: #0d9488;
    --primary-d: #0f766e;
    --primary-l: #e3f4f2;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --yellow: #f59e0b;
    --yellow-bg: #fef3c7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --line: #dde5e5;
    --radius: 16px;
    --shadow: 0 6px 20px rgba(13, 42, 40, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }       /* atrybut hidden wygrywa z display: grid/flex */

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; }

/* iPhone: szybkie stuknięcia bez podwójnego powiększania, bez zaznaczania tekstu na przyciskach */
button { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    /* pod notchem / Dynamic Island (pasek stanu jest przezroczysty w aplikacji z ekranu początkowego) */
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
             10px calc(14px + env(safe-area-inset-left));
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow);
}
.brand { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; white-space: nowrap; }
/* numer wersji widoczny na każdym ekranie (także przy logowaniu i na telefonie) */
.version-pill {
    display: inline-block; vertical-align: 2px; margin-left: 4px;
    padding: 2px 7px; border-radius: 999px;
    background: rgba(255, 255, 255, .2); color: #fff;
    font-size: .68rem; font-weight: 700; letter-spacing: .2px;
    font-variant-numeric: tabular-nums;
}
@media (max-width: 360px) { .brand-emoji { display: none; } }   /* iPhone SE / mini: nazwa + wersja się mieszczą */
.icon-btn {
    background: rgba(255, 255, 255, .18);
    border: none;
    color: #fff;
    width: 42px; height: 42px;
    border-radius: 12px;
    font-size: 1.25rem;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .32); }
.avatar-mini { font-size: 1.35rem; line-height: 1; }
.avatar-mini img, .avatar-big img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ---------- Layout ---------- */
#app {
    max-width: 720px;
    margin: 0 auto;
    padding: 18px max(16px, env(safe-area-inset-right)) calc(60px + env(safe-area-inset-bottom))
             max(16px, env(safe-area-inset-left));
}
.loader { text-align: center; color: var(--muted); padding: 60px 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.muted { color: var(--muted); }
.section-title { font-size: 1.05rem; margin: 0 0 12px; color: var(--muted); font-weight: 700; }

/* ---------- Buttons / forms ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: 12px;
    padding: 12px 18px;
    font-size: 1rem; font-weight: 700;
    cursor: pointer;
    transition: transform .05s, background .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: .9rem; }

form label { display: block; margin: 12px 0; font-weight: 600; font-size: .95rem; }
form input[type="text"], form input:not([type]), form input[type="password"], form input[type="file"] {
    width: 100%;
    margin-top: 6px;
    padding: 12px 14px;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    font-size: 1.05rem;
    background: #fff;
}
form input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.checkbox input { width: auto; margin: 0; }
.form-error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; font-weight: 600; }
.login-card { max-width: 420px; margin: 30px auto; }
.login-card h1 { margin: 0 0 4px; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* ---------- Wybór działu ---------- */
.greeting { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.greeting h1 { margin: 0; font-size: 1.5rem; }
.avatar-big {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--card); box-shadow: var(--shadow);
    display: grid; place-items: center; font-size: 1.9rem;
}

.op-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; }
.op-card {
    background: #fff;
    border: 2px solid var(--line);
    border-radius: 18px;
    padding: 18px 14px;
    cursor: pointer;
    text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-family: inherit; color: inherit;
    transition: transform .06s, box-shadow .15s, border-color .15s;
}
.op-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--primary); }
.op-card.done { border-color: var(--green); background: var(--green-bg); }
.op-emoji { font-size: 2.6rem; line-height: 1.1; }
.op-label { font-size: 1.2rem; font-weight: 800; }
.op-desc { font-size: .85rem; color: var(--muted); }
.op-stat { font-size: .8rem; font-weight: 700; color: var(--muted); margin-top: 6px; }

/* ---------- Poziomy ---------- */
.mode-switch {
    display: flex; gap: 6px;
    background: #dfeceb; padding: 6px; border-radius: 14px;
    max-width: 340px;
}
.mode-btn {
    flex: 1; border: none; background: transparent; cursor: pointer;
    padding: 12px; border-radius: 10px; font-weight: 700; font-size: 1rem; color: var(--muted);
}
.mode-btn.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.mode-hint { color: var(--muted); margin: 10px 2px 14px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; color: var(--muted); font-size: .88rem; }
.legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; margin-right: 4px; border: 1px solid var(--line); }
.dot.white { background: #fff; }
.dot.yellow { background: var(--yellow); }
.dot.green { background: var(--green); }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.level-tile {
    aspect-ratio: 1 / 1;
    min-width: 0;
    border-radius: 14px;
    border: 2px solid var(--line);
    background: #fff;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-family: inherit; color: inherit;
    position: relative;
    overflow: hidden;
    padding: 4px;
    text-align: center;
    transition: transform .06s, box-shadow .15s;
}
.level-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.level-tile .lvl-short { font-weight: 800; font-size: 1.15rem; white-space: nowrap; }
.level-tile .lvl-tier {
    font-size: .58rem; font-weight: 700; margin-top: 2px;
    text-transform: uppercase; letter-spacing: .2px; opacity: .7;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.level-tile .lvl-score { font-size: .62rem; font-weight: 700; opacity: .75; }
.level-tile.yellow { background: var(--yellow-bg); border-color: var(--yellow); }
.level-tile.green { background: var(--green-bg); border-color: var(--green); }
.level-tile.green::after { content: "✓"; position: absolute; top: 4px; right: 7px; color: var(--green); font-size: .8rem; }

@media (max-width: 380px) {
    .level-grid { gap: 8px; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
    .level-tile .lvl-short { font-size: 1rem; }
    #app { padding-left: 12px; padding-right: 12px; }
}

/* ---------- Ćwiczenie ---------- */
.play-top .btn { white-space: nowrap; }
.play-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.play-meta { display: flex; align-items: center; gap: 10px; font-weight: 700; flex-wrap: wrap; justify-content: flex-end; }
.pill { background: var(--primary-l); color: var(--primary-d); padding: 4px 10px; border-radius: 999px; font-size: .82rem; }

.flash {
    background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
    padding: 26px 20px; text-align: center;
    transition: background .2s, box-shadow .2s;
}
.flash.correct { background: var(--green-bg); box-shadow: 0 0 0 4px var(--green) inset; }
.flash.wrong   { background: var(--red-bg);   box-shadow: 0 0 0 4px var(--red) inset; }

.timer-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-bottom: 18px; }
.timer-bar span { display: block; height: 100%; width: 100%; background: var(--primary); transition: background .2s; }
.timer-bar span.low { background: var(--red); }

.flash-task {
    font-size: clamp(2rem, 9vw, 3rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    margin: 10px 0 6px;
    word-break: break-word;
}

#answerForm { display: flex; gap: 8px; margin-top: 18px; }
#answerInput {
    flex: 1; padding: 14px; font-size: 1.5rem; font-weight: 700; text-align: center;
    border: 2px solid var(--line); border-radius: 12px; min-width: 0;
}
#answerInput:focus { outline: none; border-color: var(--primary); }

.feedback { min-height: 3.6em; margin-top: 14px; font-weight: 800; font-size: 1.15rem; }
.feedback .ok { color: var(--green); }
.feedback .bad { color: var(--red); }
.feedback .correct-word { display: block; font-size: 1.7rem; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Klawiatura dotykowa (iPhone) ---------- */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 14px auto 0;
    max-width: 420px;
}
.keypad button {
    min-height: 58px;
    border: none;
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow);
    color: var(--ink);
    font: 700 1.6rem/1 system-ui, -apple-system, sans-serif;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: transform .05s, background .1s;
}
.keypad button:active { transform: scale(.96); background: var(--primary-l); }
.keypad .key-alt { background: #dfeceb; color: var(--muted); }
.keypad .key-ok { background: var(--primary); color: #fff; }
.keypad .key-ok:active { background: var(--primary-d); }
#answerInput[readonly] { caret-color: transparent; cursor: default; }

@media (max-height: 700px) {                        /* iPhone SE i mniejsze */
    .keypad button { min-height: 48px; font-size: 1.4rem; }
    .flash { padding: 18px 16px; }
    .flash-task { margin: 4px 0; }
}

/* ---------- Wynik ---------- */
.result-card { max-width: 460px; margin: 24px auto; text-align: center; }
.result-emoji { font-size: 4rem; }
.result-score { font-size: 3rem; font-weight: 900; margin: 6px 0; }
.result-score.pass { color: var(--green); }
.result-score.fail { color: var(--yellow); }
.result-card .btn { margin-top: 14px; }

/* ---------- Panel boczny ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(13, 42, 40, .45); }
.drawer-panel {
    position: absolute; top: 0; bottom: 0; left: 0;
    width: min(440px, 92vw);
    background: var(--bg);
    box-shadow: var(--shadow);
    padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom))
             calc(18px + env(safe-area-inset-left));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.drawer-close { float: right; border: none; background: transparent; font-size: 1.3rem; cursor: pointer; color: var(--muted); }
.drawer h2 { margin: 4px 0 14px; }
.drawer-op {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    margin: 18px 0 8px; font-size: 1rem;
}
.drawer-op .muted { font-size: .82rem; font-weight: 600; }
.drawer-op .btn { margin-left: auto; }

.prog-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.prog-row {
    display: flex; align-items: center; gap: 10px;
    background: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow);
}
.prog-badge {
    min-width: 44px; height: 34px; padding: 0 6px; border-radius: 10px;
    display: grid; place-items: center; font-weight: 800; font-size: .85rem;
    border: 2px solid var(--line); white-space: nowrap;
}
.prog-badge.yellow { background: var(--yellow-bg); border-color: var(--yellow); }
.prog-badge.green { background: var(--green-bg); border-color: var(--green); }
.prog-info { flex: 1; min-width: 0; }
.prog-info .t { font-weight: 700; display: block; }
.prog-info .s { font-size: .82rem; color: var(--muted); }
.prog-score { font-weight: 800; }

.tier-chip { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--primary-l); color: var(--primary-d); font-weight: 700; }
.tier-legend { margin: 0; padding-left: 18px; font-size: .9rem; line-height: 1.6; }

.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.avatar-opt { font-size: 1.7rem; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.avatar-opt.sel { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-l); }

.section-block { background: #fff; border-radius: 12px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.section-block h3 { margin: 0 0 10px; font-size: 1rem; }

/* ---------- Panel administratora ---------- */
.admin-panel .play-top { margin-bottom: 14px; }
.small-note { font-size: .85rem; margin: 8px 0 0; }
.adm-user { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.adm-user:last-child { border-bottom: none; }
.adm-bulk { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red-bg); }
.adm-row { flex-wrap: wrap; }
.adm-actions { display: flex; gap: 6px; margin-left: auto; }
.adm-actions .btn { padding: 6px 10px; font-size: .95rem; line-height: 1; }
.adm-actions .btn[disabled] { opacity: .35; cursor: not-allowed; }
.hidden { display: none !important; }
