/* =====================================================================
   Fiszki — styl minimalistyczny w duchu iOS, jasny i ciemny motyw.
   ===================================================================== */

:root {
    color-scheme: light dark;

    --bg: #F2F2F7;
    --surface: #FFFFFF;
    --fill: #EEEEF3;          /* pola, przyciski wtórne */
    --text: #1C1C1E;
    --text-2: #6E6E73;
    --text-3: #AEAEB2;
    --line: rgba(60, 60, 67, .14);

    --accent: #4F46E5;
    --accent-press: #4338CA;
    --accent-soft: #ECEBFF;
    --on-accent: #FFFFFF;

    --green: #1F9D55;
    --green-bg: #E6F6EC;
    --green-line: #34C759;
    --amber: #B25E00;
    --amber-bg: #FFF3DF;
    --amber-line: #FF9F0A;
    --red: #D70015;
    --red-bg: #FFEBEA;
    --red-line: #FF3B30;

    --topbar: #4F46E5;
    --on-topbar: #FFFFFF;

    --radius: 16px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* wykresy statystyk — kolory sprawdzone pod kątem daltonizmu (jasny i ciemny motyw) */
    --s-learn: #6250d6; --s-test: #eb6834;
    --t1: #86b6ef; --t2: #3987e5; --t3: #184f95;                     /* Podstawowy → Średni → Pro */
    --h0: #EEEEF3; --h1: #cde2fb; --h2: #86b6ef; --h3: #3987e5; --h4: #1c5cab;   /* kalendarz */
    --grid: rgba(60, 60, 67, .10);
    --seg-active: #FFFFFF;
    --title-font: var(--font);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --surface: #1C1C1E;
        --fill: #2C2C2E;
        --text: #F5F5F7;
        --text-2: #98989F;
        --text-3: #636366;
        --line: rgba(255, 255, 255, .12);

        --accent: #7D7BFF;
        --accent-press: #6A67F5;
        --accent-soft: rgba(125, 123, 255, .18);

        --green: #30D158;
        --green-bg: rgba(48, 209, 88, .15);
        --green-line: #30D158;
        --amber: #FFB340;
        --amber-bg: rgba(255, 159, 10, .15);
        --amber-line: #FF9F0A;
        --red: #FF6961;
        --red-bg: rgba(255, 69, 58, .16);
        --red-line: #FF453A;
        --s-learn: #9085e9; --s-test: #d95926;
        --t1: #184f95; --t2: #3987e5; --t3: #86b6ef;
        --h0: #2C2C2E; --h1: #184f95; --h2: #256abf; --h3: #3987e5; --h4: #86b6ef;
        --grid: rgba(255, 255, 255, .09);

        --topbar: #1C1C1E;
        --shadow: none;
        --seg-active: #636366;
    }
}

/* ===================================================================== motywy specjalne
   Przełącznik w górnej belce ustawia <html data-theme="…"> (app.js: applyTheme).
   Selektor :root[data-theme] ma wyższą specyficzność niż :root z bloku dark,
   więc motyw nadpisuje kolory niezależnie od trybu systemu. */

/* Halloween — zawsze nocny: fiolet, dyniowy pomarańcz, „glutowa” zieleń */
:root[data-theme="halloween"] {
    color-scheme: dark;
    --bg: #140E1A; --surface: #211829; --fill: #2E2338;
    --text: #F6EEE3; --text-2: #BBA9C6; --text-3: #6E5C7A; --line: rgba(255, 214, 170, .12);
    --accent: #FF7A1A; --accent-press: #E8650A; --accent-soft: rgba(255, 122, 26, .18); --on-accent: #1A0F05;
    --green: #8BE04E; --green-bg: rgba(139, 224, 78, .14); --green-line: #7ED348;
    --amber: #FFB340; --amber-bg: rgba(255, 159, 10, .16); --amber-line: #FF9F0A;
    --red: #FF6B6B; --red-bg: rgba(255, 80, 80, .16); --red-line: #FF4D4D;
    --topbar: #2A1638; --on-topbar: #FFE7CC;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    --s-learn: #9085e9; --s-test: #d95926;
    --t1: #184f95; --t2: #3987e5; --t3: #86b6ef;
    --h0: #2E2338; --h1: #184f95; --h2: #256abf; --h3: #3987e5; --h4: #86b6ef;
    --grid: rgba(255, 255, 255, .09);
    --seg-active: #4A3A57;
    --toast-bg: #3A2650; --toast-fg: #FFE7CC; --toast-line: rgba(255, 122, 26, .5);
}
:root[data-theme="halloween"] body {
    background:
        radial-gradient(1100px 520px at 50% -12%, rgba(255, 122, 26, .13), transparent 70%),
        radial-gradient(800px 600px at 110% 110%, rgba(139, 92, 246, .12), transparent 70%),
        var(--bg);
    background-attachment: fixed;
}
:root[data-theme="halloween"] .brand::before { content: "🎃 "; }
:root[data-theme="halloween"] .brand::after { content: " 🦇"; }
:root[data-theme="halloween"] .large-title { color: var(--accent); }

/* Modern Elegant — jasny: grafit, granat, ciepła biel; ciemny: grafit i szampańskie złoto */
:root[data-theme="elegant"] {
    color-scheme: light;
    --bg: #F4F3F0; --surface: #FFFFFF; --fill: #ECEAE5;
    --text: #17181B; --text-2: #6B6A66; --text-3: #A9A7A1; --line: rgba(23, 24, 27, .10);
    --accent: #1F3A5F; --accent-press: #172C48; --accent-soft: #E3E8EF; --on-accent: #FFFFFF;
    --green: #2E7D5B; --green-bg: #E5F1EB; --green-line: #3FA37A;
    --topbar: #17181B; --on-topbar: #F1E9DA;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px rgba(23, 24, 27, .06);
    --radius: 14px; --radius-sm: 10px;
    --seg-active: #FFFFFF;
    --title-font: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
    --brand-color: #C9A96E;
    --toast-bg: #17181B; --toast-fg: #F1E9DA; --toast-line: rgba(201, 169, 110, .45);
}
@media (prefers-color-scheme: dark) {
    :root[data-theme="elegant"] {
        color-scheme: dark;
        --bg: #0D0E11; --surface: #17181C; --fill: #23252B;
        --text: #ECEAE6; --text-2: #A6A39C; --text-3: #5E5C57; --line: rgba(236, 234, 230, .10);
        --accent: #C9A96E; --accent-press: #B8955A; --accent-soft: rgba(201, 169, 110, .16); --on-accent: #17130A;
        --green: #5FBF93; --green-bg: rgba(95, 191, 147, .14); --green-line: #5FBF93;
        --red: #FF7B72; --red-bg: rgba(255, 123, 114, .15); --red-line: #FF6B61;
        --topbar: #0D0E11; --on-topbar: #ECEAE6;
        --shadow: none;
        --s-learn: #9085e9; --s-test: #d95926;
        --t1: #184f95; --t2: #3987e5; --t3: #86b6ef;
        --h0: #23252B; --h1: #184f95; --h2: #256abf; --h3: #3987e5; --h4: #86b6ef;
        --grid: rgba(255, 255, 255, .08);
        --seg-active: #33353C;
        --toast-bg: #23252B; --toast-fg: #ECEAE6;
    }
}
:root[data-theme="elegant"] .brand {
    color: var(--brand-color); font-family: var(--title-font); font-weight: 600;
    letter-spacing: .22em; text-transform: uppercase; font-size: .98rem;
}
:root[data-theme="elegant"] .large-title,
:root[data-theme="elegant"] .auth h1,
:root[data-theme="elegant"] .result h1,
:root[data-theme="elegant"] .flash-prompt,
:root[data-theme="elegant"] .detail-head h2,
:root[data-theme="elegant"] .st-card h3,
:root[data-theme="elegant"] .level-tile .num { font-family: var(--title-font); font-weight: 600; letter-spacing: 0; }
:root[data-theme="elegant"] .topbar { border-bottom: 1px solid rgba(201, 169, 110, .35); }

/* ---------------------------------------------------------------- baza */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.35;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; min-height: 100dvh; }
body.no-scroll { overflow: hidden; }

h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

.muted { color: var(--text-2); }
.caption { color: var(--text-2); font-size: .82rem; }

/* ------------------------------------------------------------- górny pasek */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 92px 1fr 92px;
    align-items: center;
    gap: 8px;
    padding: calc(6px + var(--safe-top)) calc(12px + var(--safe-right)) 6px calc(12px + var(--safe-left));
    background: var(--topbar);
    color: var(--on-topbar);
}
.brand { grid-column: 2; text-align: center; font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; line-height: 44px; }
#btnProgress { grid-column: 1; }
.icon-btn {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border: 0; border-radius: 12px;
    background: transparent; color: inherit;
}
.icon-btn:active { background: rgba(255, 255, 255, .16); }
.icon-btn.plain { color: var(--text-2); background: var(--fill); width: 32px; height: 32px; border-radius: 50%; }
.icon-btn.plain svg { width: 16px; height: 16px; stroke-width: 2.6; }
.topbar-right { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 4px; }
.theme-btn { font-size: 1.25rem; line-height: 1; }
.theme-btn svg { width: 22px; height: 22px; }

.avatar {
    display: inline-grid; place-items: center; flex: none;
    border-radius: 50%; overflow: hidden;
    background: rgba(255, 255, 255, .22); line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 32px; height: 32px; font-size: 1.2rem; }
.avatar.lg { width: 64px; height: 64px; font-size: 2.1rem; background: var(--fill); }

/* ------------------------------------------------------------------ układ */
#app {
    max-width: 760px;
    margin: 0 auto;
    padding: 18px calc(16px + var(--safe-right)) calc(40px + var(--safe-bottom)) calc(16px + var(--safe-left));
}
.loader { display: grid; place-items: center; padding: 70px 0; }
.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--line); border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.stack { display: grid; gap: 10px; }

/* --------------------------------------------------------------- przyciski */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 50px; padding: 0 20px;
    border: 0; border-radius: var(--radius-sm);
    font-size: 1.02rem; font-weight: 600;
    transition: background .15s, transform .05s, opacity .15s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-press); }
.btn.tinted { background: var(--accent-soft); color: var(--accent); }
.btn.gray { background: var(--fill); color: var(--text); }
.btn.plain { background: transparent; color: var(--accent); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.danger-fill { background: var(--red-line); color: #fff; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: .9rem; border-radius: 10px; }
.btn[disabled] { opacity: .35; pointer-events: none; }

/* --------------------------------------------------- formularze (grupowane) */
.group {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.field {
    display: flex; flex-direction: column; gap: 2px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
}
.field:last-child { border-bottom: 0; }
.field > span { font-size: .78rem; color: var(--text-2); font-weight: 500; }
.field input, .field select {
    border: 0; outline: 0; background: transparent;
    font-size: 17px;                 /* ≥16px: iOS nie przybliża przy wpisywaniu */
    padding: 4px 0; width: 100%;
}
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; min-height: 50px; }
.field.inline > span { font-size: 1rem; color: var(--text); font-weight: 400; }
.field .switch { width: 51px; padding: 0; }

.switch {
    appearance: none; -webkit-appearance: none;
    width: 51px; height: 31px; flex: none;
    border-radius: 31px; background: var(--fill);
    position: relative; transition: background .2s; margin: 0;
}
.switch::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 27px; height: 27px; border-radius: 50%;
    background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
    transition: transform .2s;
}
.switch:checked { background: #34C759; }
.switch:checked::after { transform: translateX(20px); }

.form-error { color: var(--red); font-size: .88rem; min-height: 1.2em; text-align: center; }
.form-error.ok { color: var(--green); }
.form-error code, .list-foot code, .sso-state code { font-size: .85em; }

/* Konto Delta Eternal i pliki na serwerze (panel administratora) */
.sso-state { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-radius: 14px;
    background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--text-2); }
.sso-state b { font-size: .98rem; }
.sso-state span { font-size: .82rem; color: var(--text-2); line-height: 1.4; overflow-wrap: anywhere; }
.sso-state.on { border-left-color: var(--green-line); }
.sso-state.warn { border-left-color: var(--amber-line); }
.junk-list { list-style: none; margin: 10px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.junk-list li { display: flex; flex-direction: column; gap: 2px; padding: 9px 14px; }
.junk-list li + li { border-top: 1px solid var(--line); }
.junk-list code { font-size: .86rem; font-weight: 600; overflow-wrap: anywhere; }
.junk-list span { font-size: .8rem; color: var(--text-2); line-height: 1.35; }
.form-ok { color: var(--green); }

/* ---------------------------------------------------------------- logowanie */
.auth {
    max-width: 400px; margin: 4vh auto 0;
    display: grid; gap: 14px; text-align: center;
}
.auth-logo { width: 76px; height: 76px; border-radius: 18px; margin: 0 auto 4px; box-shadow: var(--shadow); }
.auth h1 { font-size: 1.9rem; }
.auth .group { text-align: left; margin-top: 10px; }

/* ------------------------------------------------------------ ekran główny */
.large-title { font-size: 1.85rem; font-weight: 800; margin: 2px 0 14px; word-break: break-word; }

.summary { margin-bottom: 18px; }
.summary-text { display: flex; justify-content: space-between; font-size: .88rem; color: var(--text-2); margin-bottom: 7px; }
.summary-text b { color: var(--text); font-weight: 600; }
.bar { height: 6px; background: var(--fill); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .35s ease; }

.segmented {
    display: grid; grid-template-columns: 1fr 1fr;
    background: var(--fill); border-radius: 10px; padding: 2px;
    margin-bottom: 8px;
}
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented.four { grid-template-columns: repeat(4, 1fr); }
.segmented.four button { font-size: .8rem; padding: 0 2px; }
.segmented.five { grid-template-columns: repeat(5, 1fr); }
.segmented.five button { font-size: .78rem; padding: 0 1px; }
@media (max-width: 420px) { .segmented.five button { font-size: .7rem; } }
.segmented button {
    border: 0; background: transparent; border-radius: 8px;
    min-height: 36px; font-size: .92rem; font-weight: 600; color: var(--text);
}
.segmented button.active { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented button.active { background: var(--seg-active); }

.home .caption { margin: 0 2px 16px; }

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 10px;
}
.level-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    padding: 4px;
    border: 1.5px solid transparent;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform .08s;
}
.level-tile:active { transform: scale(.96); }
.level-tile .num { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
/* Poziom z nazwą nadaną przez administratora: nazwa zamiast numeru, maks. 2 linie. */
.level-tile .name {
    font-size: .74rem; font-weight: 700; line-height: 1.15; text-align: center;
    max-width: 100%; overflow: hidden; overflow-wrap: anywhere; hyphens: auto;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}

/* Zakładki zestawów poziomów: Podstawowe / Rozszerzone */
.tabs {
    display: flex; gap: 22px; margin: 0 2px 12px;
    border-bottom: 1px solid var(--line);
}
.tabs button {
    border: 0; background: none; padding: 8px 0 9px; margin-bottom: -1px;
    font-size: .98rem; font-weight: 600; color: var(--text-2);
    border-bottom: 2.5px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.level-tile .sub {
    font-size: .6rem; font-weight: 600; letter-spacing: -.01em;
    color: var(--text-2); max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.level-tile.yellow { background: var(--amber-bg); border-color: var(--amber-line); box-shadow: none; }
.level-tile.yellow .sub { color: var(--amber); }
.level-tile.green  { background: var(--green-bg); border-color: var(--green-line); box-shadow: none; }
.level-tile.green .sub { color: var(--green); }
.level-tile.green::after {
    content: ""; position: absolute; top: 7px; right: 7px;
    width: 8px; height: 8px; border-radius: 50%; background: var(--green-line);
}

.legend {
    display: flex; justify-content: center; gap: 18px; flex-wrap: wrap;
    margin-top: 18px; font-size: .8rem; color: var(--text-2);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--text-3); }
.dot.yellow { background: var(--amber-line); border-color: var(--amber-line); }
.dot.green  { background: var(--green-line); border-color: var(--green-line); }

.install-tip {
    display: flex; gap: 12px; align-items: flex-start;
    background: var(--accent-soft); color: var(--text);
    border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
    font-size: .88rem; line-height: 1.4;
}
.install-tip img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.install-tip .x { margin-left: auto; border: 0; background: transparent; color: var(--text-2); font-size: 1.3rem; line-height: 1; padding: 0 2px; }
.share-ico { display: inline-block; width: 15px; height: 15px; vertical-align: -2px; stroke-width: 2.4; color: var(--accent); }
.install-tip [data-install] { margin-top: 8px; }

/* --------------------------------------------------------- nauka / egzamin */
.nav-row {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
    margin: -6px 0 10px;
}
.nav-back {
    display: inline-flex; align-items: center; gap: 0;
    border: 0; background: transparent; color: var(--accent);
    font-size: 1rem; padding: 8px 6px 8px 0; min-height: 44px;
}
.nav-back svg { width: 24px; height: 24px; stroke-width: 2.6; }
.nav-back { justify-self: start; }
.nav-title { text-align: center; font-weight: 600; font-size: .98rem; white-space: nowrap; line-height: 1.2; }
.nav-title small { display: block; font-weight: 500; font-size: .74rem; color: var(--text-2); }
.chip {
    font-size: .72rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.yellow { background: var(--amber-bg); color: var(--amber); }
.chip.gray { background: var(--fill); color: var(--text-2); }

.play-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.play-progress .bar { flex: 1; }
.play-progress span { font-size: .8rem; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }

.flash {
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 26px 18px 20px;
    text-align: center;
    transition: background .2s, border-color .2s;
}
.flash.correct { background: var(--green-bg); border-color: var(--green-line); box-shadow: none; }
.flash.wrong   { background: var(--red-bg);   border-color: var(--red-line);   box-shadow: none; }

.flash-img { font-size: 3.6rem; line-height: 1; min-height: 0; }
.flash-img:empty { display: none; }
.flash-img img { max-height: 120px; max-width: 100%; border-radius: 12px; }
.flash-prompt { font-size: 2rem; font-weight: 700; margin: 10px 0 6px; word-break: break-word; }
.answer { display: grid; gap: 12px; margin-top: 18px; align-items: center; }

/* Kratki na litery słowa (playCard w app.js). Rozmiar --slot liczy JS z szerokości karty. */
.slots { position: relative; min-height: 64px; display: flex; align-items: center; justify-content: center; }
.slot-row { display: flex; justify-content: center; gap: var(--gap, 6px); --slot: 44px; }
.slot {
    width: var(--slot); height: calc(var(--slot) * 1.22);
    display: grid; place-items: center; flex: none;
    border-radius: calc(var(--slot) * .22);
    font-family: var(--mono); font-weight: 700; font-size: calc(var(--slot) * .6); line-height: 1;
    text-transform: lowercase;
}
.slot.given { color: var(--text-2); }                         /* litera z podpowiedzi */
.slot.sep { width: calc(var(--slot) * .45); }                  /* spacja w wyrażeniu */
.slot.blank {
    background: var(--fill); color: var(--accent);
    border: 2px solid transparent; border-bottom-color: var(--text-3);
    transition: border-color .12s, background .12s, box-shadow .12s;
}
/* kratka, do której trafi następna litera */
.slot.active { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
.slots:not(.focus) .slot.active { box-shadow: none; border-style: dashed; }
.slots.focus .slot.active::after {
    content: ""; width: 2px; height: 52%; border-radius: 1px; background: var(--accent);
    animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
.slot.pop { animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(1.25); } to { transform: none; } }
.flash.correct .slot.blank { color: var(--green); background: var(--surface); border-color: var(--green-line); }
.flash.wrong .slot.blank { background: var(--surface); border-color: var(--red-line); }
.flash.wrong .slot.filled { color: var(--green); }             /* trafiona litera */
.flash.wrong .slot.fixed { color: var(--red); }                /* poprawna litera w miejsce błędnej */

/* Pole pod kratkami: niewidoczne, ale klikalne — stuknięcie w kratki otwiera klawiaturę. */
.slots input {
    position: absolute; inset: 0; width: 100%; height: 100%;
    opacity: 0; border: 0; padding: 0; margin: 0; background: transparent;
    color: transparent; caret-color: transparent; font-size: 16px;   /* 16 px: iOS nie powiększa strony */
}

.feedback { min-height: 3.1em; margin-top: 14px; font-weight: 600; }
.feedback .ok { color: var(--green); }
.feedback .bad { color: var(--red); }
.feedback .warn { color: var(--amber); font-weight: 500; font-size: .92rem; }
.feedback .hint-next { display: block; margin-top: 8px; font-size: .86rem; font-weight: 500; color: var(--text-2); }
.feedback .tip { display: block; font-size: .86rem; font-weight: 500; color: var(--text-2); }
.btn.next { background: var(--red-line); color: #FFFFFF; }
.btn.next:active { filter: brightness(.92); }
.feedback .word { display: block; font-size: 1.55rem; font-weight: 700; color: var(--text); margin-top: 2px; }

@media (min-width: 600px) {
    /* iPad: większe kafelki — podpis trybu („Podstawowy") mieści się w całości */
    .level-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; }
    .level-tile .num { font-size: 1.6rem; }
    .level-tile .sub { font-size: .7rem; }
    .level-tile .name { font-size: .86rem; }
    .answer { grid-template-columns: 1fr auto; }
    .flash { padding: 34px 28px 24px; }
}
@media (max-height: 700px) {
    .flash { padding: 16px 14px 14px; }
    .flash-img { font-size: 2.6rem; }
    .flash-prompt { font-size: 1.7rem; margin-top: 6px; }
    .answer { margin-top: 12px; }
    .slots { min-height: 56px; }
}

/* --------------------------------------------------------------- wyniki */
.result {
    max-width: 440px; margin: 6vh auto 0; text-align: center;
    display: grid; gap: 8px;
}
.result-emoji { font-size: 3.6rem; }
.result h1 { font-size: 1.5rem; }
.result-score { font-size: 3.2rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.result-score.pass { color: var(--green); }
.result-score.fail { color: var(--amber); }
.result .stack { margin-top: 18px; }

/* --------------------------------------------------------- listy (iOS) */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list + .list, .list-title + .list { margin-top: 0; }
.list-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 20px 16px 7px; font-weight: 500; }
.list-title:first-child { margin-top: 4px; }
.list-foot { font-size: .8rem; color: var(--text-2); margin: 7px 16px 0; line-height: 1.4; }
.row {
    display: flex; align-items: center; gap: 12px;
    min-height: 54px; padding: 9px 14px;
    border-bottom: 1px solid var(--line);
}
.list > .row:last-child, .list > li:last-child > .row { border-bottom: 0; }
button.row { width: 100%; border-left: 0; border-right: 0; border-top: 0; background: transparent; text-align: left; }
button.row:active { background: var(--fill); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: .8rem; color: var(--text-2); display: block; margin-top: 1px; }
.row .end { color: var(--text-2); font-size: .9rem; font-variant-numeric: tabular-nums; }
.row .chev { color: var(--text-3); width: 16px; height: 16px; stroke-width: 2.6; }
.row .emoji { width: 32px; text-align: center; font-size: 1.35rem; flex: none; }

.badge {
    width: 34px; height: 34px; flex: none;
    display: grid; place-items: center;
    border-radius: 10px; font-weight: 700; font-size: .92rem;
    background: var(--fill); color: var(--text);
}
.badge.yellow { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }

/* --------------------------------------------------- panel administratora */
.admin-head { display: flex; align-items: center; justify-content: space-between; margin: -6px 0 12px; }
.admin-head h1 { font-size: 1.6rem; font-weight: 800; }
.admin-panel .segmented { margin-bottom: 16px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 2px 2px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.detail-head h2 { margin: 0; font-size: 1.4rem; min-width: 0; overflow-wrap: anywhere; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar select, .toolbar input {
    min-height: 40px; border: 0; border-radius: 10px; background: var(--fill);
    padding: 0 12px; font-size: 16px; outline: 0;
}
.toolbar input { flex: 1; min-width: 150px; }
.toolbar .btn { min-height: 40px; }
.row-actions { display: flex; gap: 6px; flex: none; }
.row-actions .btn { min-height: 34px; padding: 0 11px; font-size: .95rem; }
.empty { padding: 26px 16px; text-align: center; color: var(--text-2); font-size: .92rem; }

/* ------------------------------------------------------ arkusz od dołu */
.sheet { position: fixed; inset: 0; z-index: 60; }
/* Chowający się arkusz od razu przepuszcza stuknięcia (inaczej przez czas
   animacji niewidoczne tło „zjadało" szybkie stuknięcie w ekran pod spodem). */
.sheet:not(.open) { pointer-events: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .22s; }
.sheet-panel {
    position: absolute; left: 0; right: 0; bottom: 0;
    max-height: 90vh; max-height: 90dvh;
    display: flex; flex-direction: column;
    background: var(--bg);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    padding-bottom: var(--safe-bottom);
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: translateY(0); }
.sheet-grip { width: 36px; height: 5px; border-radius: 5px; background: var(--text-3); opacity: .5; margin: 7px auto 0; }
.sheet-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
}
.sheet-head h2 { font-size: 1.2rem; font-weight: 700; }
.sheet-body {
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding: 2px calc(16px + var(--safe-right)) 22px calc(16px + var(--safe-left));
}
@media (min-width: 700px) {
    .sheet-panel { left: 50%; right: auto; width: 560px; margin-left: -280px; bottom: 16px; border-radius: 16px; max-height: 84vh; }
}

.account { display: flex; align-items: center; gap: 14px; margin: 4px 2px 6px; }
.account b { font-size: 1.15rem; display: block; }
.avatar-picker { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; padding: 12px; }
.avatar-opt {
    aspect-ratio: 1 / 1; border: 0; border-radius: 50%;
    background: var(--fill); font-size: 1.4rem; line-height: 1;
    display: grid; place-items: center; padding: 0; min-width: 0;
}
.avatar-opt.sel { box-shadow: 0 0 0 2.5px var(--accent); background: var(--accent-soft); }
.file-row { position: relative; }
.file-row input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.version { text-align: center; font-size: .75rem; color: var(--text-3); margin-top: 18px; }

@media (max-width: 380px) {
    .avatar-picker { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    #app { padding-left: calc(12px + var(--safe-left)); padding-right: calc(12px + var(--safe-right)); }
    .level-grid { gap: 8px; }
}

/* ------------------------------------------------------- okno dialogowe */
.dialog { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); animation: fade .18s; }
.dialog-card {
    position: relative; width: min(320px, 100%);
    background: var(--surface); border-radius: 16px;
    text-align: center; overflow: hidden;
    animation: pop .2s cubic-bezier(.2, .8, .2, 1);
}
.dialog-card .dialog-body { padding: 20px 18px 16px; }
.dialog-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.dialog-card p { font-size: .92rem; color: var(--text-2); line-height: 1.4; }
.dialog-actions { display: flex; border-top: 1px solid var(--line); }
.dialog-actions button {
    flex: 1; min-height: 46px; border: 0; background: transparent;
    font-size: 1.02rem; color: var(--accent);
}
.dialog-actions button + button { border-left: 1px solid var(--line); }
.dialog-actions.column { flex-direction: column; }
.dialog-actions.column button + button { border-left: 0; border-top: 1px solid var(--line); }
.dialog-actions .strong { font-weight: 600; }
.dialog-actions .danger { color: var(--red-line); font-weight: 600; }
.dialog-actions button:active { background: var(--fill); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(1.08); } }

/* --------------------------------------------------------------- toast */
.toast {
    position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 90;
    transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
    background: var(--toast-bg, rgba(28, 28, 30, .92)); color: var(--toast-fg, #fff);
    box-shadow: 0 0 0 1px var(--toast-line, transparent);
    padding: 11px 18px; border-radius: 12px; font-size: .9rem; font-weight: 500;
    max-width: calc(100% - 32px); text-align: center;
    transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------- statystyki (panel administratora) */
.my-stats { margin: -2px 2px 14px; font-size: .86rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.my-stats b { color: var(--text); font-weight: 600; }
.my-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.my-tiles div { background: var(--fill); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.my-tiles span { font-size: .72rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.my-tiles b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.stats { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.stats > *, #stBody { min-width: 0; }
.st-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.st-picker { min-width: 0; display: flex; gap: 8px; overflow-x: auto; padding: 2px; scrollbar-width: none; max-width: 100%; }
.st-picker::-webkit-scrollbar { display: none; }
.st-picker button {
    flex: none; border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
    border-radius: 999px; padding: 4px 12px 4px 4px; font-size: .9rem; font-weight: 600;
    display: inline-flex; align-items: center; gap: 8px; min-height: 40px;
}
.st-picker button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.st-picker .avatar { width: 30px; height: 30px; font-size: 1rem; }
.st-picker .warn { width: 8px; height: 8px; border-radius: 50%; background: var(--amber-line); }
.st-range { display: inline-flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; }
.st-range button { border: 0; background: transparent; border-radius: 8px; padding: 7px 12px; font-size: .88rem; font-weight: 600; color: var(--text); }
.st-range button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.st-range button[aria-pressed="true"] { background: var(--seg-active); }
.st-alert { display: flex; gap: 10px; align-items: center; background: var(--amber-bg); border-radius: 12px; padding: 10px 14px; font-size: .9rem; }
.st-alert b { color: var(--amber); }
.st-kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.st-kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; align-content: start; }
.st-kpi .l { font-size: .7rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.st-kpi .v { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.st-kpi .v small { font-size: .78rem; color: var(--text-2); font-weight: 600; }
.st-kpi .d { font-size: .76rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.st-kpi .d.up { color: var(--green); } .st-kpi .d.down { color: var(--red); }
.st-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; }
.st-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 12px; min-width: 0; display: grid; gap: 8px; align-content: start; }
.st-card h3 { font-size: 1rem; }
.st-card .sub { font-size: .8rem; color: var(--text-2); margin-top: -4px; }
.st-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .78rem; color: var(--text-2); }
.st-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.st-legend i.dot { border-radius: 50%; }
.st-legend i.ring { background: transparent !important; border: 2px solid var(--text-2); border-radius: 50%; }
.st-chart { width: 100%; position: relative; }
/* wykresy: bez globalnego stylu ikon (obrys, brak wypełnienia, 22 px) — kolory nadają atrybuty */
.st-chart svg, .st-users svg { display: block; width: 100%; height: auto; overflow: visible; stroke: none; stroke-width: 1; fill: currentColor; }
.st-users svg { width: 140px; height: 28px; }
.st-chart text { fill: var(--text-2); font-size: 11px; font-family: var(--font); }
.st-chart .val { fill: var(--text); font-weight: 600; }
.st-chart .gl { stroke: var(--grid); stroke-width: 1; }
.st-chart .hit { fill: transparent; }
.st-empty { font-size: .86rem; color: var(--text-2); padding: 10px 0; }
.st-words { width: 100%; border-collapse: collapse; font-size: .88rem; }
.st-words th { text-align: left; font-size: .7rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.st-words td { padding: 7px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; vertical-align: middle; }
.st-words td small { color: var(--text-2); }
.st-words .wrong { font-family: var(--mono); color: var(--red); }
.st-words .acc { display: inline-block; width: 56px; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; vertical-align: middle; margin-right: 6px; }
.st-words .acc i { display: block; height: 100%; background: var(--green-line); }
.st-tablewrap { overflow-x: auto; }
.st-users { list-style: none; margin: 0; padding: 0; }
.st-users .avatar { width: 34px; height: 34px; font-size: 1.1rem; }
.st-users button { width: 100%; border: 0; background: transparent; color: var(--text); text-align: left;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.st-users li:last-child button { border-bottom: 0; }
.st-users .n { font-weight: 600; }
.st-users .s { display: block; font-size: .78rem; color: var(--text-2); }
.st-pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; margin-left: 4px; }
.st-pill.ok { background: var(--green-bg); color: var(--green); }
.st-pill.idle { background: var(--amber-bg); color: var(--amber); }
.st-tip { position: fixed; z-index: 90; pointer-events: none; background: var(--surface); color: var(--text);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .18), 0 0 0 1px var(--line); border-radius: 10px; padding: 8px 10px;
    font-size: .82rem; min-width: 140px; max-width: 240px; }
.st-tip b { display: block; margin-bottom: 2px; }
.st-tip .tr { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.st-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
@media (max-width: 860px) {
    .st-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .st-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 480px) { .st-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
