/* ============================================================
   Matematyczna Przygoda — "Vivid Edu" Design System
   Universal (kids → teens → adults), maximum animations.
   ============================================================ */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@500;600;700&display=swap');

/* ---------- Tokens — "Academic Edu" palette (teal · indigo · amber) ---------- */
:root {
    /* Core brand */
    --c-teal: #0F766E;
    --c-teal-dark: #115E59;
    --c-teal-light: #14B8A6;
    --c-indigo: #3730A3;
    --c-indigo-dark: #312E81;
    --c-indigo-light: #6366F1;
    --c-amber: #D97706;
    --c-amber-dark: #B45309;
    --c-amber-light: #F59E0B;
    --c-sky: #0369A1;
    --c-sky-dark: #075985;
    --c-emerald: #059669;
    --c-emerald-dark: #047857;
    --c-slate: #334155;
    --c-slate-dark: #1E293B;

    /* Per-operation accents (cohesive cool→warm) */
    --op-add: #059669;
    --op-add-dark: #047857;
    --op-sub: #0369A1;
    --op-sub-dark: #075985;
    --op-mul: #D97706;
    --op-mul-dark: #B45309;
    --op-div: #3730A3;
    --op-div-dark: #312E81;

    /* Surfaces */
    --surface: rgba(255, 255, 255, 0.94);
    --surface-strong: rgba(255, 255, 255, 0.99);
    --surface-soft: rgba(255, 255, 255, 0.85);
    --surface-muted: rgba(241, 245, 249, 0.78);
    --border: rgba(15, 118, 110, 0.16);
    --border-strong: rgba(15, 23, 42, 0.10);

    /* Ink */
    --ink: #0F172A;
    --ink-soft: #1E293B;
    --ink-muted: #475569;
    --ink-faint: #64748B;

    /* States */
    --good: #059669;
    --good-dark: #047857;
    --bad: #DC2626;
    --bad-dark: #991B1B;
    --gold: #D97706;

    /* Effects (more restrained, less rainbow) */
    --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
    --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.14);
    --shadow-xl: 0 28px 72px rgba(15, 23, 42, 0.20);
    --shadow-glow-primary: 0 0 0 3px rgba(15, 118, 110, 0.18), 0 14px 32px rgba(15, 118, 110, 0.22);
    --shadow-glow-good: 0 0 0 3px rgba(5, 150, 105, 0.22), 0 14px 32px rgba(5, 150, 105, 0.28);
    --shadow-glow-bad: 0 0 0 3px rgba(220, 38, 38, 0.22), 0 14px 32px rgba(220, 38, 38, 0.28);

    /* Backwards-compat aliases (so existing rules referring to violet/pink still work) */
    --c-violet: var(--c-teal);
    --c-violet-dark: var(--c-teal-dark);
    --c-pink: var(--c-indigo);
    --c-pink-dark: var(--c-indigo-dark);
    --c-cyan: var(--c-sky);
    --c-cyan-dark: var(--c-sky-dark);
    --shadow-glow-violet: var(--shadow-glow-primary);

    /* Radii — slightly less round, more "designed" */
    --r-xl: clamp(20px, 2.4vw, 26px);
    --r-lg: clamp(14px, 1.6vw, 20px);
    --r-md: 12px;
    --r-sm: 10px;
    --r-pill: 999px;

    /* Fonts — modern, scientific, no novelty */
    --f-display: "Space Grotesk", "Inter", system-ui, sans-serif;
    --f-head: "Space Grotesk", "Inter", system-ui, sans-serif;
    --f-body: "Inter", system-ui, sans-serif;
    --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

    /* Motion */
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Reset & base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

html {
    height: 100%;
    height: 100dvh;
}

body {
    font-family: var(--f-body);
    color: var(--ink);
    background:
        radial-gradient(circle at 20% 20%, rgba(15, 118, 110, 0.08), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(55, 48, 163, 0.07), transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(217, 119, 6, 0.04), transparent 50%),
        #F1F5F9;
    min-height: 100%;
    min-height: 100dvh;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    /* Desktop: lock to viewport for an "app" feel.
       Small screens override below to allow natural scrolling. */
    overflow: hidden;
    height: 100%;
    height: 100dvh;
}

/* Subtle blueprint dot grid */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(15, 23, 42, 0.08) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.55;
}

button,
input,
select {
    font-family: inherit;
}

/* ============================================================
   ANIMATED MESH-GRADIENT BACKGROUND
   ============================================================ */
.bg-stage {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.mesh-blob {
    position: absolute;
    width: 55vmax;
    height: 55vmax;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.30;
    mix-blend-mode: multiply;
    will-change: transform;
}

.mesh-blob.b1 {
    background: radial-gradient(circle, var(--c-teal), transparent 65%);
    top: -25vmax;
    left: -20vmax;
    animation: blobDrift1 28s ease-in-out infinite;
}

.mesh-blob.b2 {
    background: radial-gradient(circle, var(--c-indigo), transparent 65%);
    top: -10vmax;
    right: -25vmax;
    animation: blobDrift2 32s ease-in-out infinite;
}

.mesh-blob.b3 {
    background: radial-gradient(circle, var(--c-amber), transparent 65%);
    bottom: -25vmax;
    left: 10vmax;
    animation: blobDrift3 30s ease-in-out infinite;
    opacity: 0.20;
}

.mesh-blob.b4 {
    background: radial-gradient(circle, var(--c-sky), transparent 65%);
    bottom: -20vmax;
    right: -15vmax;
    animation: blobDrift4 26s ease-in-out infinite;
}

.mesh-blob.b5 {
    background: radial-gradient(circle, var(--c-emerald), transparent 65%);
    top: 20vmax;
    left: 30vmax;
    width: 35vmax;
    height: 35vmax;
    animation: blobDrift5 22s ease-in-out infinite;
    opacity: 0.18;
}

@keyframes blobDrift1 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(15vw, 8vw, 0) scale(1.15); }
}

@keyframes blobDrift2 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(-12vw, 10vw, 0) scale(1.10); }
}

@keyframes blobDrift3 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(8vw, -10vw, 0) scale(1.20); }
}

@keyframes blobDrift4 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(-10vw, -8vw, 0) scale(1.10); }
}

@keyframes blobDrift5 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50% { transform: translate3d(-20vw, -15vw, 0) scale(0.85); }
}

/* Floating math symbols across the page */
.math-bg {
    position: fixed;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.math-bg span {
    position: absolute;
    font-family: var(--f-display);
    font-weight: 700;
    color: rgba(255, 255, 255, 0.55);
    text-shadow: 0 4px 16px rgba(124, 58, 237, 0.25);
    user-select: none;
    will-change: transform, opacity;
    animation: floatSymbol linear infinite;
}

@keyframes floatSymbol {
    0% {
        transform: translate3d(0, 0, 0) rotate(var(--rot, 0deg));
        opacity: 0;
    }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% {
        transform: translate3d(var(--dx, 30vw), var(--dy, -100vh), 0) rotate(calc(var(--rot, 0deg) + 360deg));
        opacity: 0;
    }
}

/* Particle dots layer (rendered by JS) */
.particles {
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.particle-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.7);
    animation: dotTwinkle 3s ease-in-out infinite;
}

@keyframes dotTwinkle {
    0%, 100% { transform: scale(0.8); opacity: 0.3; }
    50% { transform: scale(1.3); opacity: 1; }
}

/* ============================================================
   LAYOUT
   ============================================================ */
.layout-wrapper {
    position: relative;
    z-index: 5;
    height: 100%;
    width: 100%;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: clamp(8px, 1.6vw, 22px);
    overflow: hidden;
}

.game-container {
    position: relative;
    width: min(100%, 1280px);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    flex: 1;
    flex-direction: column;
    display: none;
    overflow: hidden;
    animation: screenIn 0.55s var(--ease-smooth) both;
}

.screen.is-active {
    display: flex;
}

@keyframes screenIn {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================================
   PANEL CARDS (glass)
   ============================================================ */
.panel-card {
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: clamp(18px, 2.2vw, 28px);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.panel-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.5) 0%, transparent 45%, transparent 100%);
    pointer-events: none;
    border-radius: inherit;
}

/* ============================================================
   PROFILE TOPNAV (desktop) — pływająca nawigacja w prawym górnym rogu
   ============================================================ */
.profile-topnav {
    /* Sticky wewnątrz profile-main — automatycznie wyrównane do paneli pod spodem
       (ten sam padding profile-main, ten sam scrollbar gutter) */
    position: sticky;
    top: 0;
    z-index: 11;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255,255,255,0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 16px;
    padding: 6px 6px 6px 18px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
    flex-shrink: 0;
    /* Margin tylko dolny — dystans od następnego panelu w siatce profile-main */
    margin-bottom: 0;
}

/* Brand area — logo + tytuł aplikacji po lewej */
.ptn-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ptn-brand-icon {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(15, 118, 110, 0.25));
}

.ptn-brand-text {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: clamp(14px, 1.15vw, 16px);
    color: var(--c-teal-dark);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Actions area — kontener na przyciski po prawej */
.ptn-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Fullscreen button - subtelnie wydzielony lewym borderem */
.ptn-btn-fs {
    margin-left: 6px;
    padding-left: 14px !important;
    border-left: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 8px 10px 10px 8px !important;
}

/* Węższe desktopy — kompaktowy brand (sam ikon) */
@media (min-width: 761px) and (max-width: 1100px) {
    .ptn-brand-text { display: none; }
    .ptn-btn { padding: 8px 11px; font-size: 12px; }
    .ptn-icon { font-size: 15px; }
}

.ptn-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease;
    white-space: nowrap;
    color: var(--ink-muted);
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 13px;
}

.ptn-btn:hover {
    background: rgba(15, 118, 110, 0.10);
    color: var(--c-teal-dark);
    transform: translateY(-1px);
}

.ptn-btn:active {
    transform: scale(0.96);
}

.ptn-icon {
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.ptn-lbl {
    letter-spacing: 0.1px;
}

/* ============================================================
   WELCOME HERO — split layout: avatar | identity+stats | CTA+links
   ============================================================ */
.welcome-hero {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: clamp(20px, 2.5vw, 36px);
    background: linear-gradient(135deg,
        rgba(15, 118, 110, 0.13) 0%,
        rgba(55, 48, 163, 0.10) 50%,
        rgba(245, 158, 11, 0.07) 100%);
    border: 1.5px solid rgba(15, 118, 110, 0.25);
    border-radius: var(--r-lg);
    padding: clamp(20px, 2.2vw, 32px) clamp(22px, 2.6vw, 38px);
    box-shadow: 0 12px 36px rgba(15, 118, 110, 0.14), 0 2px 8px rgba(55,48,163,0.08);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Shimmer overlay */
.welcome-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg,
        transparent 40%,
        rgba(255,255,255,0.18) 50%,
        transparent 60%);
    background-size: 200% 100%;
    animation: shimmer 5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.welcome-hero[style*="display:none"],
.welcome-hero[style*="display: none"] {
    display: none !important;
}

/* LEFT: Avatar */
.wh-left {
    position: relative;
    z-index: 1;
}

.wh-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.wh-avatar {
    width: clamp(72px, 7vw, 100px);
    height: clamp(72px, 7vw, 100px);
    border-radius: 22px;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-indigo) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(40px, 4.4vw, 60px);
    box-shadow: 0 14px 32px rgba(15, 118, 110, 0.40);
    animation: avatarBob 5s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

.wh-avatar-ring {
    position: absolute;
    inset: -5px;
    border-radius: 26px;
    border: 2px solid rgba(15, 118, 110, 0.32);
    animation: ringPulse 3s ease-in-out infinite;
    pointer-events: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

@keyframes ringPulse {
    0%, 100% { transform: scale(1); opacity: 0.55; }
    50% { transform: scale(1.08); opacity: 1; }
}

/* ===== STAN POŁĄCZENIA — 3 stany ringa wokół awatara ===== */

/* OFFLINE / lokalnie — szary, subtelnie pulsujący */
body.is-mode-local .wh-avatar-ring {
    border-color: rgba(148, 163, 184, 0.45);
    box-shadow: 0 0 0 0 rgba(148, 163, 184, 0);
}

/* ANONYMOUS online — bursztynowy, lekka aura */
body.is-mode-anon .wh-avatar-ring {
    border-color: rgba(245, 158, 11, 0.55);
    box-shadow: 0 0 16px 2px rgba(245, 158, 11, 0.20);
    animation: ringPulseAnon 2.4s ease-in-out infinite;
}

@keyframes ringPulseAnon {
    0%, 100% { transform: scale(1);    opacity: 0.65; box-shadow: 0 0 14px 1px rgba(245, 158, 11, 0.18); }
    50%      { transform: scale(1.08); opacity: 1;    box-shadow: 0 0 20px 4px rgba(245, 158, 11, 0.32); }
}

/* PERSISTENT online — zielona aura z "świeceniem" jak status online */
body.is-mode-online .wh-avatar-ring {
    border-color: rgba(16, 185, 129, 0.70);
    box-shadow: 0 0 22px 3px rgba(16, 185, 129, 0.35);
    animation: ringPulseOnline 2s ease-in-out infinite;
}

@keyframes ringPulseOnline {
    0%, 100% { transform: scale(1);    opacity: 0.85; box-shadow: 0 0 18px 2px rgba(16, 185, 129, 0.30); }
    50%      { transform: scale(1.10); opacity: 1;    box-shadow: 0 0 28px 6px rgba(16, 185, 129, 0.50); }
}

/* ===== MODE PILL — klikalny wskaźnik trybu gry pod imieniem ===== */
.wh-mode-pill {
    /* width:100% żeby wyrównać szerokość ze stats-mini pod spodem */
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 0 0 12px;
    padding: 8px 14px 8px 12px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 14px;
    cursor: pointer;
    font-family: var(--f-display);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.wh-mode-pill:hover {
    background: rgba(255, 255, 255, 0.85);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.10);
}

.wh-mode-pill:active {
    transform: scale(0.97);
}

/* Kropka wewnątrz pilla — zsynchronizowana ze stanem ringa */
.wh-mode-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8; /* domyślnie szary */
    flex-shrink: 0;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.wh-mode-text {
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.1px;
}

.wh-mode-action {
    color: var(--c-teal-dark);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding-left: 10px;
    border-left: 1px solid rgba(15, 23, 42, 0.12);
    /* Push do prawej krawędzi pilla */
    margin-left: auto;
    flex-shrink: 0;
}

/* Pill — stany */
body.is-mode-local .wh-mode-pill {
    border-color: rgba(148, 163, 184, 0.30);
}
body.is-mode-local .wh-mode-dot {
    background: #94a3b8;
}

body.is-mode-anon .wh-mode-pill {
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(254, 243, 199, 0.55);
}
body.is-mode-anon .wh-mode-dot {
    background: #F59E0B;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.55);
}

body.is-mode-online .wh-mode-pill {
    border-color: rgba(16, 185, 129, 0.40);
    background: rgba(209, 250, 229, 0.55);
}
body.is-mode-online .wh-mode-dot {
    background: #10B981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.65);
    animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
    50%      { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
}

/* CENTER: Identity + stats */
.wh-center {
    min-width: 0;
    position: relative;
    z-index: 1;
}

.wh-kicker {
    font-family: var(--f-head);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.8px;
    font-size: 10px;
    color: var(--c-teal-dark);
    display: block;
    margin-bottom: 4px;
    opacity: 0.85;
}

.wh-name {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: clamp(22px, 2.4vw, 32px);
    margin: 0 0 4px;
    color: var(--ink);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.wh-meta {
    margin: 0 0 14px;
    color: var(--ink-muted);
    font-weight: 500;
    font-size: 13px;
}

/* Stats mini-row */
.wh-stats-mini {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0;
    background: rgba(255,255,255,0.65);
    border: 1px solid rgba(15,118,110,0.18);
    border-radius: 14px;
    padding: 10px 8px;
    backdrop-filter: blur(8px);
}

.wh-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 18px;
    flex: 1;
}

.wh-stat-divider {
    width: 1px;
    height: 30px;
    background: rgba(15, 118, 110, 0.20);
}

.wh-stat-val {
    font-family: var(--f-display);
    font-weight: 800;
    font-size: clamp(20px, 2vw, 26px);
    color: var(--c-teal-dark);
    line-height: 1;
    letter-spacing: -0.01em;
}

.wh-stat-lbl {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--ink-faint);
    margin-top: 4px;
}

/* RIGHT: Big CTA + secondary links */
.wh-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    position: relative;
    z-index: 1;
}

.wh-play-btn {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: clamp(15px, 1.3vw, 18px);
    color: white;
    border: none;
    border-radius: 16px;
    padding: 16px 32px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    box-shadow: 0 12px 30px rgba(15, 118, 110, 0.42);
    transition: transform 0.22s var(--ease-spring), box-shadow 0.22s ease, filter 0.18s;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: 0.2px;
}

.wh-play-btn::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.22), transparent 55%);
    pointer-events: none;
}

.wh-play-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 18px 40px rgba(15, 118, 110, 0.50);
    filter: brightness(1.08);
}

.wh-play-btn:active {
    transform: scale(0.96);
}

.wh-play-icon {
    font-size: 14px;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(255,255,255,0.22);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.wh-play-text {
    font-weight: 600;
}

.wh-play-text strong {
    font-weight: 800;
}

.wh-links {
    display: flex;
    gap: 2px;
    justify-content: center;
}

/* ============================================================
   PROFILE TOP ROW — welcome-hero (1.4fr) + fact widget (1fr)
   ============================================================ */
.profile-top {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: clamp(14px, 1.6vw, 20px);
    align-items: stretch;
    flex-shrink: 0;
}

/* W profile-top welcome-hero powinno wypełnić swoją kolumnę */
.profile-top > .welcome-hero {
    width: 100%;
    min-width: 0;
}

/* ============================================================
   FACT WIDGET — elegancki side widget z ciekawostkami matematycznymi
   ============================================================ */
.profile-fact-widget {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: clamp(20px, 2vw, 28px) clamp(20px, 2.2vw, 28px);
    border-radius: var(--r-lg);
    background: linear-gradient(135deg,
        rgba(245, 158, 11, 0.14) 0%,
        rgba(217, 119, 6, 0.10) 50%,
        rgba(194, 65, 12, 0.08) 100%);
    border: 1.5px solid rgba(245, 158, 11, 0.30);
    box-shadow: 0 12px 36px rgba(245, 158, 11, 0.14), 0 2px 8px rgba(194, 65, 12, 0.06);
    flex-shrink: 0;
    min-width: 0;
}

/* Decorative floating math symbols */
.pfw-decoration {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    opacity: 0.10;
}

.pfw-decoration-symbol {
    position: absolute;
    font-family: var(--f-head);
    font-weight: 800;
    color: #C2410C;
    user-select: none;
    line-height: 1;
}

.pfw-d1 { top: 10%;  left:  8%; font-size: 38px; transform: rotate(-12deg); animation: pfwFloat 8s ease-in-out infinite; }
.pfw-d2 { top: 60%;  left: 75%; font-size: 52px; transform: rotate(15deg);  animation: pfwFloat 10s ease-in-out infinite reverse; }
.pfw-d3 { top: 70%;  left:  6%; font-size: 30px; transform: rotate(-8deg);  animation: pfwFloat 12s ease-in-out infinite; }
.pfw-d4 { top:  8%;  left: 78%; font-size: 36px; transform: rotate(20deg);  animation: pfwFloat 9s ease-in-out infinite reverse; }

@keyframes pfwFloat {
    0%, 100% { transform: translate(0, 0) rotate(var(--rot, 0deg)); }
    50%      { transform: translate(4px, -6px) rotate(var(--rot, 0deg)); }
}

.pfw-head {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.pfw-icon {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
    animation: pfwGlow 2.5s ease-in-out infinite;
}

@keyframes pfwGlow {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(245, 158, 11, 0)); }
    50%      { transform: scale(1.1); filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.5)); }
}

.pfw-kicker {
    flex: 1;
    font-family: var(--f-head);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    font-size: 11px;
    color: #C2410C;
}

.pfw-next-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid rgba(194, 65, 12, 0.20);
    background: rgba(255, 255, 255, 0.65);
    color: #C2410C;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s var(--ease-spring), background 0.18s ease;
    flex-shrink: 0;
}

.pfw-next-btn:hover {
    background: white;
    transform: rotate(180deg);
}

.pfw-next-btn:active {
    transform: rotate(180deg) scale(0.92);
}

.pfw-text {
    margin: 0;
    flex: 1;
    font-family: var(--f-display);
    font-size: clamp(14px, 1.2vw, 16px);
    line-height: 1.5;
    color: var(--ink);
    font-weight: 500;
    position: relative;
    z-index: 1;
    animation: pfwTextIn 0.5s ease-out;
}

@keyframes pfwTextIn {
    0%   { opacity: 0; transform: translateY(6px); }
    100% { opacity: 1; transform: translateY(0); }
}

.pfw-progress {
    height: 3px;
    border-radius: 999px;
    background: rgba(194, 65, 12, 0.12);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.pfw-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #F59E0B, #C2410C);
    border-radius: 999px;
    transition: width 0.1s linear;
}

/* Recent footer (motywacyjny element po usunięciu starego pd-fact) */
.pd-recent-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(55, 48, 163, 0.05));
    border: 1px solid rgba(15, 118, 110, 0.15);
    border-radius: 12px;
    margin-top: auto;
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 13px;
    color: var(--c-teal-dark);
}

.pd-recent-footer-icon {
    font-size: 18px;
    line-height: 1;
}

.pd-recent-footer-text {
    flex: 1;
}

/* ============================================================
   PROFILE DASHBOARD — wypełnia pustą przestrzeń (dla returning user)
   ============================================================ */
.profile-dashboard {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: clamp(14px, 1.6vw, 20px);
    align-items: stretch;
    flex-shrink: 0;
}

.pd-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pd-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.pd-card-title {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: clamp(15px, 1.3vw, 18px);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.01em;
}

.pd-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    color: white;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.30);
}

.pd-tabs {
    display: inline-flex;
    background: rgba(15, 23, 42, 0.05);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.pd-tab {
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 12px;
    color: var(--ink-muted);
    transition: background 0.18s ease, color 0.18s ease;
}

.pd-tab:hover {
    color: var(--c-teal-dark);
}

.pd-tab.active {
    background: white;
    color: var(--c-teal-dark);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

/* Leaderboard list */
.pd-leaderboard-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pd-leaderboard-list li {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.6);
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 12px;
    transition: background 0.18s ease, transform 0.18s ease;
}

.pd-leaderboard-list li:hover {
    background: rgba(15, 118, 110, 0.05);
    transform: translateX(2px);
}

.pd-leaderboard-list li.top-empty {
    display: block;
    text-align: center;
    color: var(--ink-faint);
    font-style: italic;
    padding: 24px 12px;
    grid-template-columns: none;
}

.pd-leaderboard-list .top-rank {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: 14px;
    color: var(--c-teal-dark);
    min-width: 28px;
    text-align: center;
}

.pd-leaderboard-list li:nth-child(1) .top-rank { color: #F59E0B; }
.pd-leaderboard-list li:nth-child(2) .top-rank { color: #94A3B8; }
.pd-leaderboard-list li:nth-child(3) .top-rank { color: #C2410C; }

.pd-leaderboard-list .top-avatar {
    font-size: 24px;
    line-height: 1;
}

.pd-leaderboard-list .top-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-family: var(--f-display);
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
}

.pd-leaderboard-list .top-meta {
    font-weight: 500;
    font-size: 11px;
    color: var(--ink-faint);
    text-transform: none;
    letter-spacing: 0;
}

.pd-leaderboard-list .top-score {
    font-family: var(--f-display);
    font-weight: 800;
    font-size: 18px;
    color: var(--c-teal-dark);
}

/* Side card: recent + fact */
.pd-side {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.pd-recent-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.pd-recent-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: rgba(255,255,255,0.6);
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 12px;
}

.pd-recent-val {
    font-family: var(--f-display);
    font-weight: 800;
    font-size: clamp(18px, 1.8vw, 24px);
    color: var(--c-teal-dark);
    line-height: 1;
}

.pd-recent-text {
    font-size: clamp(12px, 1vw, 14px);
    text-align: center;
}

.pd-recent-lbl {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--ink-faint);
}

/* Fact card */
.pd-fact {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.10), rgba(194, 65, 12, 0.06));
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 14px;
    margin-top: auto;
}

.pd-fact-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.pd-fact-content {
    flex: 1;
    min-width: 0;
}

.pd-fact-kicker {
    display: block;
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #C2410C;
    margin-bottom: 4px;
}

.pd-fact-text {
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--ink);
    font-weight: 500;
}

/* ============================================================
   PROFILE START CTA — duży przycisk Start dla nowych użytkowników
   ============================================================ */
.profile-start-cta {
    display: flex;
    justify-content: center;
    padding: clamp(8px, 1vw, 14px);
    flex-shrink: 0;
}

.psc-btn {
    font-family: var(--f-display);
    font-weight: 800;
    font-size: clamp(16px, 1.4vw, 20px);
    color: white;
    border: none;
    border-radius: 16px;
    padding: 16px 48px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    box-shadow: 0 12px 32px rgba(15, 118, 110, 0.40);
    transition: transform 0.22s var(--ease-spring), box-shadow 0.22s ease, filter 0.18s;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.3px;
}

.psc-btn::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.22), transparent 55%);
    pointer-events: none;
}

.psc-btn:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 20px 44px rgba(15, 118, 110, 0.52);
    filter: brightness(1.08);
}

.psc-btn:active {
    transform: scale(0.96);
}

.psc-icon {
    font-size: 14px;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255,255,255,0.22);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ============================================================
   STAN WYŚWIETLANIA: returning user vs nowy gracz
   ============================================================ */
/* Gdy mamy znanego gracza — pokaż profile-top + dashboard, ukryj formularz/hero/start-cta */
body.has-returning-user .hero-panel,
body.has-returning-user .profile-grid,
body.has-returning-user .profile-start-cta {
    display: none !important;
}

body.has-returning-user .profile-top {
    display: grid !important;
}

body.has-returning-user .profile-dashboard {
    display: grid !important;
}

/* Dla nowego gracza — ukryj profile-top + dashboard, pokaż wszystko inne */
.profile-top { display: none; }
.profile-dashboard { display: none; }

/* ============================================================
   MOBILE TAB BAR — stała dolna nawigacja, widoczna tylko ≤760px
   ============================================================ */
/* Tab bar ukryty na ekranach setup i game — tam nie jest potrzebny */
#screen-setup.is-active ~ .mobile-tab-bar,
#screen-game.is-active ~ .mobile-tab-bar {
    display: none !important;
}

.mobile-tab-bar {
    display: none; /* pokazana tylko na mobile */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 110;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(15, 23, 42, 0.09);
    box-shadow: 0 -6px 28px rgba(15, 23, 42, 0.09);
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    align-items: stretch;
}

.mtb-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 4px 2px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 0;
    transition: background 0.18s ease;
    position: relative;
    min-width: 0;
}

.mtb-tab:active {
    background: rgba(15, 118, 110, 0.06);
}

.mtb-icon {
    font-size: 20px;
    line-height: 1;
    transition: transform 0.22s var(--ease-spring);
}

.mtb-tab:active .mtb-icon {
    transform: scale(0.88);
}

.mtb-lbl {
    font-family: var(--f-display);
    font-size: 10px;
    font-weight: 600;
    color: var(--ink-muted);
    letter-spacing: 0.1px;
}

/* Play tab — highlighted */
.mtb-play {
    position: relative;
}

.mtb-play::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(15, 118, 110, 0.35);
    z-index: -1;
    transition: box-shadow 0.2s ease, transform 0.2s var(--ease-spring);
}

.mtb-play:active::before {
    transform: translateX(-50%) scale(0.92);
}

.mtb-play .mtb-icon {
    color: white;
    position: relative;
    z-index: 1;
    font-size: 16px;
    margin-top: 2px;
}

.mtb-play .mtb-lbl {
    color: var(--c-teal-dark);
    font-weight: 700;
}

/* Ukryj stare elementy — zastąpione przez nowe */
.btn-container-bottom,
.btn-hamburger,
.btn-nav-extra,
.nav-drawer {
    display: none !important;
}

/* Przycisk "Zakończ grę" widoczny podczas rozgrywki */
body.game-active #screen-game .btn-container-bottom {
    display: flex !important;
}

/* ============================================================
   HERO (profile screen)
   ============================================================ */
.fullscreen-btn {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 10;
    background: var(--surface);
    border: 1px solid var(--border);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 22px;
    cursor: pointer;
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s var(--ease-spring), box-shadow 0.25s ease;
}

.fullscreen-btn:hover {
    transform: scale(1.08) rotate(8deg);
    box-shadow: var(--shadow-md);
}

.profile-main,
.setup-main,
.game-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: clamp(8px, 1.4vw, 18px) clamp(8px, 1.6vw, 22px);
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 1.6vw, 20px);
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 118, 110, 0.4) transparent;
}

/* Children of these scrollable flex columns must NOT shrink — otherwise on
   short viewports cards get squeezed and clipped (e.g. mission-strip chips
   getting cut off by .panel-card { overflow: hidden }). Container has
   overflow-y:auto so it scrolls naturally instead. */
.profile-main > *,
.setup-main > *,
.game-main > * {
    flex-shrink: 0;
}

.profile-main::-webkit-scrollbar,
.setup-main::-webkit-scrollbar,
.game-main::-webkit-scrollbar {
    width: 8px;
}

.profile-main::-webkit-scrollbar-thumb,
.setup-main::-webkit-scrollbar-thumb,
.game-main::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.4);
    border-radius: 8px;
}

.hero-panel {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: clamp(20px, 3vw, 38px);
    align-items: center;
    min-height: clamp(220px, 28vh, 320px);
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(245, 243, 255, 0.92) 50%,
        rgba(254, 243, 232, 0.92) 100%);
    transition: min-height 0.3s ease;
}

.hero-copy {
    position: relative;
    z-index: 2;
}

.hero-topline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--f-head);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    font-size: 11px;
    color: var(--c-teal-dark);
    background: rgba(15, 118, 110, 0.10);
    border: 1px solid rgba(15, 118, 110, 0.20);
    padding: 6px 14px;
    border-radius: var(--r-pill);
    margin-bottom: 14px;
}

.hero-topline::before {
    content: "▲";
    font-size: 11px;
    color: var(--c-amber);
}

.hero-copy h1 {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: clamp(30px, 4.6vw, 52px);
    line-height: 1.05;
    margin: 0 0 12px;
    letter-spacing: -0.025em;
    background: linear-gradient(120deg, var(--c-teal-dark) 0%, var(--c-indigo) 60%, var(--c-amber) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 12s ease-in-out infinite;
    background-size: 200% 200%;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.hero-subtitle {
    font-size: clamp(15px, 1.3vw, 18px);
    color: var(--ink-muted);
    line-height: 1.55;
    margin: 0 0 16px;
    font-weight: 500;
    max-width: 50ch;
}

#quote-box {
    background: rgba(15, 118, 110, 0.06);
    border-radius: var(--r-md);
    padding: 12px 16px;
    border-left: 3px solid var(--c-teal);
    display: inline-block;
    min-width: 240px;
}

#quote-display {
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 17px;
    color: var(--ink-soft);
    animation: quoteFade 0.7s var(--ease-smooth);
}

@keyframes quoteFade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Hero math scene with parallax */
.hero-math-scene {
    position: relative;
    height: 100%;
    min-height: 220px;
    transform-style: preserve-3d;
    perspective: 800px;
}

.math-core {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(70px, 10vw, 120px);
    filter: drop-shadow(0 12px 24px rgba(15, 118, 110, 0.30));
    animation: coreFloat 8s ease-in-out infinite;
    z-index: 2;
}

@keyframes coreFloat {
    0%, 100% { transform: translate(-50%, -50%) rotate(-4deg); }
    50% { transform: translate(-50%, -54%) rotate(4deg); }
}

.math-token {
    position: absolute;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--f-mono);
    font-weight: 700;
    font-size: 24px;
    color: white;
    box-shadow: var(--shadow-md);
    animation: tokenFloat 6s ease-in-out infinite;
}

.token-plus {
    background: var(--c-emerald);
    top: 8%;
    left: 8%;
    animation-delay: 0s;
    --rot: -6deg;
    transform: rotate(var(--rot));
}

.token-minus {
    background: var(--c-sky);
    top: 8%;
    right: 8%;
    animation-delay: 1.5s;
    --rot: 6deg;
    transform: rotate(var(--rot));
}

.token-mul {
    background: var(--c-amber);
    bottom: 8%;
    left: 6%;
    animation-delay: 3s;
    --rot: 4deg;
    transform: rotate(var(--rot));
}

.token-div {
    background: var(--c-indigo);
    bottom: 8%;
    right: 6%;
    animation-delay: 4.5s;
    --rot: -4deg;
    transform: rotate(var(--rot));
}

@keyframes tokenFloat {
    0%, 100% { transform: rotate(var(--rot, 0deg)) translateY(0); }
    50% { transform: rotate(calc(var(--rot, 0deg) + 6deg)) translateY(-12px); }
}

.math-formula {
    position: absolute;
    background: white;
    padding: 5px 12px;
    border-radius: 8px;
    font-family: var(--f-mono);
    font-weight: 600;
    font-size: 13px;
    color: var(--c-teal-dark);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(15, 118, 110, 0.20);
    animation: formulaPop 5s ease-in-out infinite;
}

.formula-a { top: 38%; left: 0%; animation-delay: 0.5s; }
.formula-b { top: 22%; right: 0%; animation-delay: 1.5s; color: var(--c-indigo); border-color: rgba(55, 48, 163, 0.20); }
.formula-c { bottom: 30%; left: -2%; animation-delay: 2.5s; color: var(--c-emerald-dark); border-color: rgba(5, 150, 105, 0.20); }
.formula-d { bottom: 18%; right: -2%; animation-delay: 3.5s; color: var(--c-amber-dark); border-color: rgba(217, 119, 6, 0.20); }

@keyframes formulaPop {
    0%, 100% { transform: scale(1) translateY(0); opacity: 0.95; }
    50% { transform: scale(1.05) translateY(-6px); opacity: 1; }
}

/* ============================================================
   PROFILE FORM
   ============================================================ */
.profile-grid {
    display: grid;
    /* Równe kolumny — spójność z dashboard po zalogowaniu */
    grid-template-columns: 1fr 1fr;
    gap: clamp(14px, 1.6vw, 20px);
    align-items: stretch;
}

.profile-form-card,
.avatar-panel {
    height: 100%;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.settings-label {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: clamp(15px, 1.3vw, 18px);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.label-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    color: white;
    font-size: 15px;
    box-shadow: 0 3px 10px rgba(15, 118, 110, 0.30);
}

.helper-text {
    font-size: 12px;
    color: var(--ink-faint);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.input-name {
    width: 100%;
    background: var(--surface-strong);
    border: 2px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 14px 18px;
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    font-family: var(--f-display);
    outline: none;
    transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.input-name:focus {
    border-color: var(--c-violet);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.16);
    transform: translateY(-1px);
}

.form-helper-text {
    margin: 12px 2px 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--ink-muted);
    font-weight: 500;
}

.form-helper-text strong {
    color: var(--c-teal-dark);
    font-weight: 700;
}

.input-name::placeholder {
    color: var(--ink-faint);
    font-weight: 500;
}

/* ---------- Avatar grid: 5 kolumn × N rzedow + scroll, 100 emoji ---------- */
.avatar-search-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.avatar-search {
    flex: 1;
    background: white;
    border: 1.5px solid var(--border-strong);
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: var(--f-display);
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}

.avatar-search:focus {
    border-color: var(--c-teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.avatar-current {
    font-size: 36px;
    width: 56px;
    height: 56px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(15,118,110,0.10), rgba(55,48,163,0.08));
    border: 1.5px solid rgba(15, 118, 110, 0.25);
    flex-shrink: 0;
    line-height: 1;
}

/* Avatar-panel jako flex column zeby siatka mogla sie prawidlowo
   skurczyc do dostepnej przestrzeni i scrollowac WEWNATRZ. */
.avatar-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.avatar-grid {
    display: grid;
    /* auto-fill: tyle kolumn ile sie zmiesci, min 64px, max 1fr */
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    width: 100%;
    /* Większy zakres widocznych awatarów — mniej scrollowania, lepsze użycie ekranu */
    max-height: clamp(320px, 56vh, 560px);
    min-height: 0;
    overflow-y: auto;
    padding: 4px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 118, 110, 0.4) transparent;
    flex: 1 1 auto;
}

.avatar-grid::-webkit-scrollbar { width: 6px; }
.avatar-grid::-webkit-scrollbar-thumb {
    background: rgba(15, 118, 110, 0.35);
    border-radius: 6px;
}

.avatar-category-header {
    grid-column: 1 / -1;
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--c-teal-dark);
    padding: 8px 4px 4px;
    border-bottom: 1px dashed rgba(15, 23, 42, 0.10);
    margin-top: 4px;
}

.avatar-category-header:first-child {
    margin-top: 0;
}

.avatar-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--ink-faint);
    font-size: 13px;
    font-weight: 500;
    padding: 24px 12px;
}

.avatar-option {
    aspect-ratio: 1;
    background: var(--surface-strong);
    border: 1.5px solid var(--border-strong);
    border-radius: 12px;
    /* Skaluje sie z rozmiarem komorki - emoji wypelnia ~55-65% kwadratu. */
    font-size: clamp(30px, 4.6vmin, 64px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s var(--ease-spring), border-color 0.2s ease, box-shadow 0.25s ease;
    position: relative;
    line-height: 1;
}

.avatar-option:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--c-teal);
}

.avatar-option:active {
    transform: scale(0.94);
}

.avatar-option.selected {
    border-color: var(--c-teal);
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.10), rgba(55, 48, 163, 0.08));
    box-shadow: var(--shadow-glow-primary);
    transform: scale(1.06);
    animation: avatarSelect 0.55s var(--ease-spring);
}

/* ============================================================
   QUICK TOP 3 (mini-leaderboard inside profile-form-card)
   ============================================================ */
.quick-tops {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed rgba(15, 23, 42, 0.10);
}

.quick-tops-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.quick-tops-title {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 13px;
    color: var(--c-teal-dark);
    letter-spacing: 0.2px;
}

.quick-tops-hint {
    font-size: 11px;
    color: var(--ink-faint);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.quick-tops-tabs {
    display: inline-flex;
    gap: 4px;
    background: rgba(15, 23, 42, 0.05);
    padding: 3px;
    border-radius: 999px;
}

.qt-tab {
    background: transparent;
    border: none;
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 11px;
    color: var(--ink-muted);
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.qt-tab:hover { background: rgba(15, 118, 110, 0.08); }

.qt-tab.active {
    background: white;
    color: var(--c-teal-dark);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.10);
}

/* Leaderboard controls */
#modal-leaderboard .modal-card {
    max-width: min(980px, calc(100vw - 32px));
}

.lb-subtitle {
    margin: 8px 0 0;
    color: rgba(255, 255, 255, 0.82);
    font-weight: 650;
    font-size: 13px;
}

.lb-controls {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    position: relative;
    z-index: 1;
}

.lb-control-group {
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.10);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.lb-control-label {
    width: 100%;
    color: rgba(255, 255, 255, 0.76);
    font-family: var(--f-head);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
}

.lb-tabs,
.lb-filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.lb-tab,
.lb-filter {
    min-width: 0;
    min-height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.20);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.11);
    color: rgba(255, 255, 255, 0.94);
    cursor: pointer;
    font-family: var(--f-display);
    font-size: 13px;
    font-weight: 750;
    line-height: 1;
    white-space: nowrap;
    transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.15s var(--ease-spring);
}

.lb-tab {
    flex: 0 1 128px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 14px;
}

.lb-filter {
    flex: 0 1 118px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 13px;
}

.lb-tab-ico,
.lb-filter-ico {
    flex: 0 0 auto;
    font-size: 17px;
    line-height: 1;
}

.lb-tab-txt,
.lb-filter span:last-child {
    display: inline-block;
    min-width: 0;
    text-align: center;
}

.lb-tab:hover,
.lb-filter:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.34);
}

.lb-tab:active,
.lb-filter:active {
    transform: scale(0.98);
}

.lb-tab.active,
.lb-filter.active {
    background: #fff;
    border-color: #fff;
    color: var(--c-teal-dark);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
}

@media (min-width: 760px) {
    .lb-controls {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

@media (min-width: 1060px) {
    .lb-controls {
        grid-template-columns: minmax(0, 1fr);
    }

    .lb-tab {
        flex-basis: 136px;
    }

    .lb-filter {
        flex-basis: 128px;
    }
}

@media (max-width: 520px) {
    #modal-leaderboard .modal-card {
        max-width: calc(100vw - 24px);
    }

    .lb-subtitle {
        font-size: 12px;
    }

    .lb-control-group {
        padding: 8px;
        border-radius: 14px;
    }

    .lb-tabs,
    .lb-filters {
        gap: 7px;
    }

    .lb-tab {
        flex: 1 1 calc(33.333% - 7px);
        min-height: 48px;
        border-radius: 14px;
        flex-direction: column;
        gap: 4px;
        padding: 8px 5px;
        font-size: 11.5px;
    }

    .lb-filter {
        flex: 1 1 calc(50% - 7px);
        min-height: 42px;
        border-radius: 12px;
        padding: 8px 6px;
        font-size: 12px;
    }

    .lb-tab-ico,
    .lb-filter-ico {
        font-size: 16px;
    }
}

@media (max-width: 340px) {
    .lb-tab,
    .lb-filter {
        font-size: 11px;
    }
}

/* Generic is-hidden — uzywane przez welcomeChange itd. */
.is-hidden { display: none !important; }
.welcome-back.is-hidden { display: none !important; }

/* Top list retry button (gdy fetch zwisnie) */
.top-retry-btn {
    background: var(--c-teal);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 4px 12px;
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.top-retry-btn:hover {
    background: var(--c-teal-dark);
    transform: scale(1.05);
}

.top-retry-btn:active {
    transform: scale(0.95);
}

/* Rankings sub-tabs (Szkoły / Klasy / Miasta) wewnątrz modal-body */
.lb-rankings-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    background: rgba(15, 23, 42, 0.04);
    padding: 4px;
    border-radius: 999px;
    width: max-content;
}

.lb-rsubtab {
    background: transparent;
    border: none;
    color: var(--ink-muted);
    padding: 6px 14px;
    border-radius: 999px;
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.lb-rsubtab:hover { background: rgba(15, 118, 110, 0.08); }

.lb-rsubtab.active {
    background: white;
    color: var(--c-teal-dark);
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10);
}

/* Aggregate ranking entries (top szkół/klas/miast) */
.aggregate-list .agg-entry {
    cursor: default;
}

.aggregate-list .agg-mine {
    border-color: var(--c-amber);
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.08), white);
}

.aggregate-list .agg-you {
    margin-left: 8px;
    background: var(--c-amber);
    color: white;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.aggregate-list .agg-extra {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--ink-faint);
}

.aggregate-list .agg-extra span {
    font-weight: 600;
}

/* Edit profile form row (klasa + nr w dzienniku obok siebie) */
.ep-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.school-request-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1.5px solid rgba(15, 118, 110, 0.18);
    border-radius: 10px;
    background: rgba(15, 118, 110, 0.045);
}

.school-request-head {
    display: grid;
    gap: 2px;
    color: var(--ink);
}

.school-request-head strong {
    font-family: var(--f-head);
    font-size: 15px;
}

.school-request-head span {
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
}

.school-request-grid,
.admin-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 10px;
}

.admin-modal-card {
    max-width: 760px;
}

.admin-section {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1.5px solid rgba(15, 118, 110, 0.14);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.72);
}

.admin-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.admin-section-head h3 {
    margin: 0;
    color: var(--ink);
    font-family: var(--f-head);
    font-size: 18px;
}

.admin-list {
    display: grid;
    gap: 10px;
}

.admin-empty {
    padding: 14px;
    border-radius: 10px;
    background: rgba(15, 118, 110, 0.06);
    color: var(--ink-muted);
    font-weight: 700;
    text-align: center;
}

.admin-request {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: white;
}

.admin-request-title {
    margin: 0 0 4px;
    color: var(--ink);
    font-weight: 800;
}

.admin-request-meta {
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 650;
    line-height: 1.35;
}

.admin-request-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-small {
    border: 1.5px solid rgba(15, 118, 110, 0.25);
    background: white;
    color: var(--c-teal-dark);
    border-radius: 10px;
    padding: 8px 12px;
    font-family: var(--f-display);
    font-weight: 800;
    cursor: pointer;
}

@media (max-width: 520px) {
    .ep-row { flex-direction: column; gap: 12px; }
    .ep-row .acc-field { flex: 1 1 auto !important; width: 100%; }
    .school-request-grid,
    .admin-form-grid,
    .admin-request {
        grid-template-columns: 1fr;
    }
    .admin-request-actions {
        justify-content: stretch;
    }
    .admin-request-actions .btn-small {
        flex: 1 1 auto;
    }
}

.top-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.top-list li {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 8px 12px;
    background: linear-gradient(90deg, rgba(15, 118, 110, 0.05), rgba(55, 48, 163, 0.04));
    border-radius: 10px;
    font-size: 13px;
    border-left: 3px solid var(--c-teal);
    animation: topRowIn 0.35s var(--ease-spring) both;
}

.top-list li:nth-child(1) { border-left-color: #D97706; }   /* gold */
.top-list li:nth-child(2) { border-left-color: #94A3B8; }   /* silver */
.top-list li:nth-child(3) { border-left-color: #B45309; }   /* bronze */
.top-list li:nth-child(2) { animation-delay: 0.05s; }
.top-list li:nth-child(3) { animation-delay: 0.10s; }

@keyframes topRowIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

.top-list .top-rank {
    font-family: var(--f-mono);
    font-weight: 700;
    font-size: 14px;
    color: var(--c-teal-dark);
    text-align: center;
}

.top-list .top-name {
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-list .top-name .top-avatar {
    margin-right: 6px;
    font-size: 16px;
}

.top-list .top-meta {
    font-size: 10px;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-left: 6px;
    font-weight: 600;
}

.top-list .top-score {
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    font-weight: 700;
    font-size: 15px;
    color: var(--c-teal);
}

.top-list .top-empty {
    display: block;
    text-align: center;
    color: var(--ink-faint);
    font-size: 12px;
    padding: 12px;
    border-left: none;
    background: rgba(15, 23, 42, 0.03);
    font-weight: 500;
}

/* ============================================================
   PROFILE EXTRAS (math fact + tips row, full width below grid)
   ============================================================ */
.profile-extras {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: clamp(12px, 1.4vw, 18px);
}

.extra-card {
    display: flex;
    flex-direction: column;
}

.fact-text {
    font-family: var(--f-display);
    font-weight: 500;
    font-size: 16px;
    color: var(--ink);
    line-height: 1.55;
    margin: 0;
    padding: 4px 0;
    animation: factFade 0.6s var(--ease-smooth);
}

.fact-text::before {
    content: "“";
    font-size: 28px;
    color: var(--c-teal);
    font-family: serif;
    line-height: 0;
    vertical-align: -8px;
    margin-right: 4px;
    font-weight: 700;
}

.fact-text::after {
    content: "”";
    font-size: 28px;
    color: var(--c-teal);
    font-family: serif;
    line-height: 0;
    vertical-align: -10px;
    margin-left: 2px;
    font-weight: 700;
}

@keyframes factFade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.tips-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    counter-reset: tip;
}

.tips-list li {
    counter-increment: tip;
    display: grid;
    grid-template-columns: 26px 1fr;
    gap: 10px;
    align-items: center;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ink-muted);
}

.tips-list li::before {
    content: counter(tip);
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--c-teal), var(--c-indigo));
    color: white;
    font-family: var(--f-mono);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tips-list li strong {
    color: var(--ink);
    font-weight: 700;
}

/* ---------- Responsive: profile-extras stacks below 880px ---------- */
@media (max-width: 880px) {
    .profile-extras {
        grid-template-columns: 1fr;
    }
}

@keyframes avatarSelect {
    0% { transform: scale(1); }
    50% { transform: scale(1.20) rotate(-6deg); }
    100% { transform: scale(1.10) rotate(0); }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-container-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    padding: clamp(10px, 1.4vw, 16px);
    flex-shrink: 0;
}

.btn-big {
    font-family: var(--f-display);
    font-weight: 600;
    font-size: clamp(14px, 1.2vw, 16px);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 13px 26px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
    box-shadow: 0 8px 22px rgba(15, 118, 110, 0.30);
    transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease, filter 0.2s ease;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.2px;
}

.btn-big::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 50%);
    pointer-events: none;
}

.btn-big:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(15, 118, 110, 0.40);
    filter: brightness(1.06);
}

.btn-big:active {
    transform: translateY(0) scale(0.98);
}

.btn-secondary {
    background: white;
    color: var(--c-teal-dark);
    border: 1.5px solid rgba(15, 118, 110, 0.30);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    box-shadow: var(--shadow-md);
    background: rgba(15, 118, 110, 0.04);
    border-color: var(--c-teal);
}

/* ---- Hamburger button — ukryty na desktopie ---- */
.btn-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 12px;
    flex-shrink: 0;
}

/* ---- Nav drawer (mobile slide-up) ---- */
.nav-drawer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
}

.nav-drawer.is-open {
    pointer-events: auto;
}

.nav-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.nav-drawer.is-open .nav-drawer-backdrop {
    opacity: 1;
}

.nav-drawer-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
    transform: translateY(110%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.nav-drawer.is-open .nav-drawer-panel {
    transform: translateY(0);
}

.nav-drawer-panel .btn-big {
    font-size: 15px;
    padding: 14px 20px;
    text-align: left;
}

.btn-danger {
    background: linear-gradient(135deg, var(--bad), var(--bad-dark));
    box-shadow: 0 8px 22px rgba(220, 38, 38, 0.30);
}

.btn-danger:hover {
    box-shadow: 0 14px 32px rgba(220, 38, 38, 0.40);
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--c-teal);
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: 10px;
    transition: background 0.2s ease;
}

.link-btn:hover {
    background: rgba(15, 118, 110, 0.08);
}

/* ============================================================
   SETUP SCREEN
   ============================================================ */
.player-summary {
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0.95) 0%,
        rgba(245, 243, 255, 0.92) 100%);
}

.player-badge {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.player-id {
    display: flex;
    align-items: center;
    gap: 16px;
}

.player-avatar {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-indigo) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    box-shadow: 0 8px 22px rgba(15, 118, 110, 0.30);
    animation: avatarBob 5s ease-in-out infinite;
}

@keyframes avatarBob {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50% { transform: translateY(-5px) rotate(3deg); }
}

.player-name-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.section-kicker {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--c-teal-dark);
}

.player-name-wrap h2 {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: clamp(22px, 2.4vw, 30px);
    margin: 0;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.player-name-wrap p {
    margin: 0;
    color: var(--ink-muted);
    font-weight: 600;
    font-size: 14px;
}

.mission-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.info-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    border-radius: var(--r-md);
    padding: 10px 14px;
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid;
}

.chip-goal { border-color: var(--c-emerald); }
.chip-reward { border-color: var(--c-amber); }
.chip-speed { border-color: var(--c-sky); }

.chip-icon {
    font-size: 18px;
}

.setup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(12px, 1.6vw, 20px);
}

.control-card {
    display: flex;
    flex-direction: column;
}

.wide-card {
    grid-column: 1 / -1;
}

/* Difficulty buttons */
.diff-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.btn-diff {
    border: 2px solid transparent;
    background: white;
    border-radius: var(--r-md);
    padding: 14px 10px;
    cursor: pointer;
    font-family: var(--f-display);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s var(--ease-spring), box-shadow 0.25s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn-diff::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--diff-c1, var(--c-violet)), var(--diff-c2, var(--c-pink)));
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.btn-diff > * {
    position: relative;
    z-index: 1;
}

.btn-diff.beginner { --diff-c1: var(--c-emerald); --diff-c2: var(--c-cyan); }
.btn-diff.explorer { --diff-c1: var(--c-amber); --diff-c2: var(--c-pink); }
.btn-diff.legend { --diff-c1: var(--c-violet); --diff-c2: var(--c-pink); }

.btn-diff:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.btn-diff.active {
    transform: translateY(-2px);
    border-color: transparent;
    color: white;
    box-shadow: 0 14px 32px rgba(124, 58, 237, 0.32);
}

.btn-diff.active::before {
    opacity: 1;
}

.btn-diff.active strong {
    color: white;
}

.btn-diff.active small {
    color: rgba(255, 255, 255, 0.85);
}

.diff-icon {
    font-size: 26px;
    line-height: 1;
}

.btn-diff strong {
    font-weight: 700;
    font-size: 14px;
}

.btn-diff small {
    color: var(--ink-faint);
    font-weight: 600;
    font-size: 12px;
}

/* Time select */
.select-control {
    width: 100%;
    background: white;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    font-family: var(--f-display);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237C3AED' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.select-control:focus {
    outline: none;
    border-color: var(--c-violet);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.16);
}

/* Mode (mission) buttons */
.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

/* mode-cell: kontener wrappujacy btn-mode + ikonka info "?" */
.mode-cell {
    position: relative;
    display: flex;
}

.mode-cell .btn-mode {
    flex: 1 1 auto;
    width: 100%;
}

.mode-info-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    border: 1.5px solid rgba(255, 255, 255, 0.45);
    color: white;
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.2s var(--ease-spring), background 0.2s ease, border-color 0.2s ease;
    z-index: 2;
    line-height: 1;
    padding: 0;
}

.mode-info-btn:hover {
    background: rgba(255, 255, 255, 0.40);
    border-color: white;
    transform: scale(1.10);
}

.mode-info-btn:active {
    transform: scale(0.95);
}

/* Lesson modal — sekcje */
.lesson-section {
    margin-bottom: 16px;
    padding: 12px 14px;
    background: rgba(15, 118, 110, 0.04);
    border-left: 3px solid var(--c-teal);
    border-radius: 10px;
}

.lesson-section h3 {
    margin: 0 0 8px;
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 15px;
    color: var(--c-teal-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.lesson-section h3 .lesson-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--c-teal);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.lesson-section p {
    margin: 0 0 6px;
    color: var(--ink-muted);
    font-size: 13.5px;
    line-height: 1.55;
    font-weight: 500;
}

.lesson-section p:last-child { margin-bottom: 0; }

.lesson-section strong {
    color: var(--ink);
    font-weight: 700;
}

.lesson-eq {
    font-family: var(--f-mono);
    font-feature-settings: 'tnum';
    font-weight: 700;
    background: white;
    border: 1px solid var(--border-strong);
    color: var(--c-teal-dark);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 13px;
    margin: 0 2px;
}

.lesson-examples {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.lesson-example {
    background: white;
    border: 1px solid var(--border-strong);
    padding: 8px 10px;
    border-radius: 8px;
    text-align: center;
    font-family: var(--f-mono);
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
}

.lesson-example small {
    display: block;
    color: var(--ink-faint);
    font-family: var(--f-body);
    font-size: 11px;
    font-weight: 600;
    margin-top: 2px;
    letter-spacing: 0.3px;
}

.lesson-tip {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.08), rgba(217, 119, 6, 0.04));
    border-left-color: var(--c-amber);
}

.lesson-tip h3 .lesson-icon {
    background: var(--c-amber);
}

.lesson-tip h3 {
    color: var(--c-amber-dark);
}

.lesson-warn {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.06), rgba(220, 38, 38, 0.02));
    border-left-color: var(--bad);
}

.lesson-warn h3 .lesson-icon {
    background: var(--bad);
}

.lesson-warn h3 {
    color: var(--bad-dark);
}

/* Lesson modal-header: gradient zalezny od misji (set przez JS) */
#lesson-header.theme-add { background: linear-gradient(135deg, #10B981 0%, #047857 100%); }
#lesson-header.theme-sub { background: linear-gradient(135deg, #0EA5E9 0%, #075985 100%); }
#lesson-header.theme-mul { background: linear-gradient(135deg, #F59E0B 0%, #B45309 100%); }
#lesson-header.theme-div { background: linear-gradient(135deg, #6366F1 0%, #312E81 100%); }
#lesson-header.theme-mix { background: linear-gradient(135deg, #0F766E 0%, #3730A3 50%, #C2410C 100%); }

.btn-mode {
    border: none;
    border-radius: var(--r-lg);
    padding: 18px 18px;
    cursor: pointer;
    font-family: var(--f-display);
    color: white;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
    transition: transform 0.3s var(--ease-spring), box-shadow 0.3s ease, filter 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn-mode::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 55%);
    pointer-events: none;
}

.btn-mode:hover {
    transform: translateY(-5px) rotate(-0.4deg);
    box-shadow: 0 22px 44px rgba(15, 23, 42, 0.28);
    filter: brightness(1.06);
}

.btn-mode:active {
    transform: translateY(-1px) scale(0.98);
}

.bg-add { background: linear-gradient(135deg, #10B981 0%, #047857 100%); }
.bg-sub { background: linear-gradient(135deg, #0EA5E9 0%, #075985 100%); }
.bg-mul { background: linear-gradient(135deg, #F59E0B 0%, #B45309 100%); }
.bg-div { background: linear-gradient(135deg, #6366F1 0%, #312E81 100%); }
.bg-mix {
    background: linear-gradient(135deg, #0F766E 0%, #3730A3 50%, #C2410C 100%);
    background-size: 200% 200%;
    animation: gradientShift 10s ease-in-out infinite;
}

.mode-title {
    font-weight: 700;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.mode-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    backdrop-filter: blur(8px);
}

.mode-subtitle {
    font-weight: 500;
    font-size: 13px;
    opacity: 0.92;
    color: rgba(255, 255, 255, 0.95);
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
.game-main {
    gap: clamp(10px, 1.2vw, 16px);
}

.game-hud {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(10px, 1.2vw, 16px);
}

.hud-card {
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: clamp(12px, 1.4vw, 18px);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    overflow: hidden;
}

.hud-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.4), transparent 50%);
    pointer-events: none;
    border-radius: inherit;
}

.hud-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--c-teal-dark);
}

.hud-card > div:nth-of-type(1) {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: clamp(20px, 2.2vw, 28px);
    color: var(--ink);
    line-height: 1.1;
}

#game-score,
#game-timer {
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    letter-spacing: -0.02em;
}

.hud-secondary {
    display: flex;
    justify-content: space-between;
    color: var(--ink-faint);
    font-weight: 700;
    font-size: 12px;
    gap: 8px;
}

#game-timer.is-urgent {
    color: var(--bad);
    animation: timerPulse 1s ease-in-out infinite;
}

.audio-dot {
    font-size: 14px;
    opacity: 0.45;
    transition: opacity 0.3s ease, transform 0.3s var(--ease-spring);
    cursor: help;
}

.audio-dot.audio-good {
    opacity: 1;
    color: var(--good);
    animation: audioPing 0.6s ease;
}

.audio-dot.audio-bad {
    opacity: 1;
    color: var(--bad);
    animation: audioPing 0.6s ease;
}

@keyframes audioPing {
    0% { transform: scale(1); }
    40% { transform: scale(1.6); }
    100% { transform: scale(1); }
}

@keyframes timerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.10); }
}

#game-score {
    transition: transform 0.3s var(--ease-spring);
}

#game-score.bump {
    animation: scoreBump 0.55s var(--ease-spring);
}

@keyframes scoreBump {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.20); }
}

/* Game board */
.game-board {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    gap: clamp(12px, 1.4vw, 18px);
    flex: 1;
    min-height: 0;
}

.stage-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 1.4vw, 16px);
    background: linear-gradient(160deg,
        rgba(255, 255, 255, 0.96),
        rgba(245, 243, 255, 0.92));
    text-align: center;
    position: relative;
}

.rewards-shelf {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-height: 36px;
    width: 100%;
    max-width: 360px;
}

.shelf-icon {
    font-size: 24px;
    filter: drop-shadow(0 4px 8px rgba(245, 158, 11, 0.4));
    animation: rewardPop 0.65s var(--ease-spring);
}

.shelf-icon.special {
    background: linear-gradient(135deg, var(--c-amber), var(--c-pink));
    color: white;
    padding: 4px 14px;
    border-radius: var(--r-pill);
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 14px;
}

@keyframes rewardPop {
    0% { transform: scale(0) rotate(-30deg); opacity: 0; }
    60% { transform: scale(1.4) rotate(8deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Avatar with power rings */
.avatar-wrapper {
    position: relative;
    width: clamp(160px, 22vw, 220px);
    height: clamp(160px, 22vw, 220px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.power-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    animation: ringRotate 30s linear infinite;
}

@keyframes ringRotate {
    from { transform: rotate(-90deg); }
    to { transform: rotate(270deg); }
}

.ring-bg {
    fill: none;
    stroke: rgba(124, 58, 237, 0.10);
    stroke-width: 6;
}

.ring-progress {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.55s var(--ease-smooth);
}

.r1-prog {
    stroke: url(#ring-grad-1);
    stroke-dasharray: 377;
    stroke-dashoffset: 377;
    filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
}

.r2-prog {
    stroke: url(#ring-grad-2);
    stroke-dasharray: 471;
    stroke-dashoffset: 471;
    filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.5));
}

.r3-prog {
    stroke: url(#ring-grad-3);
    stroke-dasharray: 565;
    stroke-dashoffset: 565;
    filter: drop-shadow(0 0 10px rgba(236, 72, 153, 0.6));
}

.main-avatar {
    font-size: clamp(70px, 8vw, 96px);
    filter: drop-shadow(0 12px 24px rgba(124, 58, 237, 0.4));
    animation: avatarIdle 4s ease-in-out infinite;
    z-index: 2;
    transition: transform 0.3s var(--ease-spring);
    will-change: transform;
}

@keyframes avatarIdle {
    0%, 100% { transform: translateY(0) rotate(-3deg); }
    50% { transform: translateY(-8px) rotate(3deg); }
}

.main-avatar.celebrate {
    animation: avatarCelebrate 0.8s var(--ease-spring);
}

@keyframes avatarCelebrate {
    0% { transform: translateY(0) scale(1) rotate(0); }
    35% { transform: translateY(-30px) scale(1.20) rotate(-12deg); }
    70% { transform: translateY(-10px) scale(1.10) rotate(12deg); }
    100% { transform: translateY(0) scale(1) rotate(0); }
}

.main-avatar.shake {
    animation: avatarShake 0.55s ease-in-out;
}

@keyframes avatarShake {
    0%, 100% { transform: translateX(0) rotate(0); }
    20% { transform: translateX(-12px) rotate(-6deg); }
    40% { transform: translateX(12px) rotate(6deg); }
    60% { transform: translateX(-8px) rotate(-4deg); }
    80% { transform: translateX(8px) rotate(4deg); }
}

/* Question box */
.question-box {
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    font-weight: 700;
    font-size: clamp(34px, 4.8vw, 58px);
    color: var(--ink);
    background: white;
    padding: clamp(14px, 2vw, 22px) clamp(22px, 3vw, 38px);
    border-radius: var(--r-lg);
    border: 2px solid transparent;
    background-image:
        linear-gradient(white, white),
        linear-gradient(135deg, var(--c-teal), var(--c-indigo), var(--c-amber));
    background-origin: border-box;
    background-clip: padding-box, border-box;
    box-shadow: var(--shadow-lg);
    letter-spacing: 0;
    line-height: 1.1;
    animation: questionIn 0.5s var(--ease-spring);
    will-change: transform, opacity;
}

.question-box.question-out {
    animation: questionOut 0.3s ease-in forwards;
}

@keyframes questionIn {
    0% { transform: translateY(20px) scale(0.85); opacity: 0; }
    60% { transform: translateY(-4px) scale(1.05); opacity: 1; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes questionOut {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-30px) scale(0.85); opacity: 0; }
}

.progress-meta {
    display: flex;
    justify-content: center;
    width: 100%;
}

.progress-pill {
    background: rgba(15, 118, 110, 0.08);
    color: var(--c-teal-dark);
    padding: 8px 18px;
    border-radius: var(--r-pill);
    font-weight: 700;
    font-size: 13px;
    border: 1.5px solid rgba(15, 118, 110, 0.25);
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
    text-align: center;
    max-width: 100%;
}

.progress-pill.quote-show {
    animation: quotePop 0.45s var(--ease-spring);
}

.progress-pill.quote-good {
    background: linear-gradient(135deg, var(--c-teal), var(--c-emerald-dark));
    color: white;
    border-color: transparent;
    box-shadow: 0 6px 16px rgba(15, 118, 110, 0.32);
}

.progress-pill.quote-bad {
    background: linear-gradient(135deg, var(--c-amber), var(--c-amber-dark));
    color: white;
    border-color: transparent;
    box-shadow: 0 6px 16px rgba(217, 119, 6, 0.32);
}

@keyframes quotePop {
    0%   { transform: scale(0.78) translateY(6px); opacity: 0; }
    60%  { transform: scale(1.08) translateY(-2px); opacity: 1; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Answers card */
.answers-card {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.4vw, 16px);
}

.answers-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    flex-wrap: wrap;
}

.answers-title h3 {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: clamp(18px, 1.8vw, 22px);
    margin: 0;
    color: var(--ink);
}

.answers-title p {
    margin: 4px 0 0;
    color: var(--ink-faint);
    font-weight: 600;
    font-size: 13px;
}

.combo-badge {
    background: linear-gradient(135deg, var(--c-amber) 0%, var(--c-amber-dark) 100%);
    color: white;
    padding: 8px 16px;
    border-radius: var(--r-pill);
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.35);
    opacity: 0;
    transform: scale(0.6);
    transition: transform 0.4s var(--ease-spring), opacity 0.3s ease;
    letter-spacing: 0.3px;
}

.combo-badge.visible {
    opacity: 1;
    transform: scale(1);
    animation: comboPulse 1.8s ease-in-out infinite;
}

@keyframes comboPulse {
    0%, 100% { box-shadow: 0 6px 18px rgba(217, 119, 6, 0.35); transform: scale(1); }
    50% { box-shadow: 0 12px 28px rgba(217, 119, 6, 0.50); transform: scale(1.05); }
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(10px, 1.2vw, 14px);
    flex: 1;
    min-height: 0;
}

.btn-option {
    background: white;
    border: 1.5px solid var(--border-strong);
    border-radius: 14px;
    padding: clamp(14px, 1.8vw, 20px);
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    font-weight: 700;
    font-size: clamp(26px, 3.4vw, 40px);
    color: var(--ink);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s var(--ease-spring), box-shadow 0.25s ease, background 0.3s ease, border-color 0.3s ease;
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.btn-option::before {
    content: "";
    position: absolute;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(15, 118, 110, 0.12);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.5s var(--ease-smooth), height 0.5s var(--ease-smooth);
    pointer-events: none;
}

.btn-option:hover {
    transform: translateY(-2px);
    border-color: var(--c-teal);
    box-shadow: var(--shadow-md);
}

.btn-option:hover::before {
    width: 220%;
    height: 220%;
}

.btn-option:active {
    transform: scale(0.97);
}

.btn-option.correct {
    background: linear-gradient(135deg, var(--good), var(--good-dark));
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-glow-good);
    animation: correctPulse 0.7s var(--ease-spring);
}

.btn-option.wrong {
    background: linear-gradient(135deg, var(--bad), var(--bad-dark));
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-glow-bad);
    animation: wrongShake 0.55s ease;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.10); }
    100% { transform: scale(1); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

.btn-option:disabled {
    cursor: not-allowed;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(7, 17, 31, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: overlayIn 0.3s ease both;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    background: white;
    border-radius: var(--r-xl);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.45s var(--ease-spring) both;
    min-height: 0;
}

/* Header MUST keep its content size (so tab bar never gets clipped),
   body MUST be the flexible scrollable region. */
.modal-card > .modal-header {
    flex: 0 0 auto;
}
.modal-card > .modal-footer {
    flex: 0 0 auto;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 50%, var(--c-indigo) 100%);
    color: white;
    padding: 22px 26px;
    padding-right: 64px; /* leave room for close button */
    position: relative;
    overflow: hidden;
}

/* Close button (X) — top-right of modal header */
.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    color: white;
    font-size: 24px;
    line-height: 1;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.2s ease, transform 0.2s var(--ease-spring), border-color 0.2s ease;
    z-index: 10;
    padding: 0;
    font-family: var(--f-display);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.32);
    border-color: rgba(255, 255, 255, 0.55);
    transform: scale(1.10) rotate(90deg);
}

.modal-close:active {
    transform: scale(0.94) rotate(90deg);
}

.modal-header::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.25), transparent 50%);
    pointer-events: none;
}

.modal-header h2 {
    font-family: var(--f-head);
    font-weight: 800;
    margin: 0;
    font-size: 28px;
    letter-spacing: -0.01em;
    position: relative;
    z-index: 1;
}

#archive-badge {
    display: none;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    padding: 4px 12px;
    border-radius: var(--r-pill);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 8px;
    width: max-content;
    backdrop-filter: blur(6px);
    position: relative;
    z-index: 1;
}

.modal-body {
    padding: 22px 26px;
    overflow-y: auto;
    /* CRITICAL: flex:1 + min-height:0 are needed for the body to actually
       scroll INTERNALLY when content exceeds available space. Without this,
       the body content pushes the modal-header out of the visible area
       (clipping the tab bar). */
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 16px 22px;
    background: rgba(245, 247, 255, 0.85);
    border-top: 1px solid var(--border-strong);
}

.modal-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.alert-icon {
    font-size: 56px;
    text-align: center;
    margin-bottom: 8px;
    filter: drop-shadow(0 8px 20px rgba(124, 58, 237, 0.35));
    animation: alertIconPop 0.55s var(--ease-spring);
}

@keyframes alertIconPop {
    0% { transform: scale(0) rotate(-30deg); }
    70% { transform: scale(1.18) rotate(8deg); }
    100% { transform: scale(1) rotate(0); }
}

.alert-copy {
    text-align: center;
    color: var(--ink-muted);
    line-height: 1.55;
    font-weight: 600;
    margin: 0;
}

/* ============================================================
   MODAL HOWTO — instrukcje gry
   ============================================================ */
.howto-section {
    margin-bottom: 18px;
}

.howto-section:last-child {
    margin-bottom: 0;
}

.howto-section h3 {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 17px;
    color: var(--c-teal-dark);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.howto-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--c-teal), var(--c-indigo));
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(15, 118, 110, 0.25);
}

.howto-section p {
    margin: 0;
    color: var(--ink-muted);
    font-size: 14px;
    line-height: 1.55;
    font-weight: 500;
}

.howto-section p strong {
    color: var(--ink);
    font-weight: 700;
}

.howto-modes,
.howto-levels,
.howto-rewards,
.howto-tips {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Modes — colored pill + text */
.howto-modes li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.03);
    border-radius: 10px;
}

.howto-pill {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.15);
}

.howto-modes li > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.howto-modes strong {
    font-family: var(--f-display);
    font-weight: 700;
    color: var(--ink);
    font-size: 14px;
}

.howto-modes span {
    font-size: 13px;
    color: var(--ink-muted);
    font-weight: 500;
}

/* Levels */
.howto-levels li {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 10px;
    padding: 10px 14px;
    background: rgba(15, 23, 42, 0.03);
    border-left: 3px solid var(--c-teal);
    border-radius: 8px;
}

.howto-levels strong {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
}

.howto-range {
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    font-weight: 700;
    font-size: 13px;
    color: var(--c-teal-dark);
    background: rgba(15, 118, 110, 0.10);
    padding: 2px 8px;
    border-radius: 6px;
}

.howto-levels em {
    grid-column: 1 / -1;
    font-style: normal;
    font-size: 13px;
    color: var(--ink-muted);
    font-weight: 500;
}

/* Rewards & Tips */
.howto-rewards li,
.howto-tips li {
    padding: 8px 12px 8px 32px;
    position: relative;
    font-size: 13px;
    color: var(--ink-muted);
    line-height: 1.5;
    font-weight: 500;
}

.howto-rewards li::before {
    content: "▸";
    position: absolute;
    left: 12px;
    top: 8px;
    color: var(--c-teal);
    font-weight: 700;
}

.howto-tips li::before {
    content: "💡";
    position: absolute;
    left: 8px;
    top: 8px;
    font-size: 14px;
}

.howto-rewards strong,
.howto-tips strong {
    color: var(--ink);
    font-weight: 700;
}

/* ============================================================
   CLOUD STATUS PILL — inline w hero-topline (nie absolute!)
   ============================================================ */
.hero-topline-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.hero-topline-row .hero-topline {
    margin-bottom: 0;
}

/* Mobile: hero-topline-row wycentruj i pill pod kicker'em (a nie z boku) */
@media (max-width: 760px) {
    .hero-topline-row {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }
    .hero-topline-row .hero-topline {
        margin: 0;
    }
}

.cloud-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(15, 23, 42, 0.08);
    padding: 6px 12px;
    border-radius: var(--r-pill);
    font-family: var(--f-display);
    font-weight: 600;
    font-size: 12px;
    color: var(--ink-muted);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cloud-status-pill:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.cloud-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-faint);
    flex-shrink: 0;
}

.cloud-status-pill.is-online .cloud-dot {
    background: var(--good);
    box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5);
    animation: cloudPulse 2s ease-in-out infinite;
}

.cloud-status-pill.is-online {
    color: var(--c-teal-dark);
    border-color: rgba(15, 118, 110, 0.25);
}

.cloud-status-pill.is-offline .cloud-dot {
    background: var(--ink-faint);
}

.cloud-status-pill.is-error .cloud-dot {
    background: var(--bad);
}

@keyframes cloudPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.5); }
    50%      { box-shadow: 0 0 0 5px rgba(5, 150, 105, 0); }
}

@media (max-width: 520px) {
    .cloud-status-pill {
        font-size: 11px;
        padding: 5px 10px;
        max-width: 160px;
    }
}

/* ============================================================
   MODAL ACCOUNT (logowanie / rejestracja)
   ============================================================ */
.acc-tab {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Hint pod formularzem — link do drugiego tabu */
.acc-tab-switch-hint {
    margin: 6px 0 0;
    text-align: center;
    font-size: 13px;
    color: var(--ink-muted);
    font-weight: 500;
}

.acc-tab-link {
    background: none;
    border: none;
    color: var(--c-teal-dark);
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    margin-left: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.acc-tab-link:hover {
    background: rgba(15, 118, 110, 0.10);
    color: var(--c-teal);
}

.acc-info {
    background: rgba(15, 118, 110, 0.06);
    border-left: 3px solid var(--c-teal);
    padding: 10px 14px;
    border-radius: 8px;
    margin: 0;
    font-size: 13px;
    color: var(--ink-muted);
    line-height: 1.5;
    font-weight: 500;
}

.acc-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.acc-label {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    letter-spacing: 0.2px;
}

.acc-field input,
.acc-field select {
    width: 100%;
    background: white;
    border: 1.5px solid var(--border-strong);
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 16px;          /* iOS no auto-zoom */
    font-family: var(--f-display);
    font-weight: 600;
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.acc-field select {
    min-height: 47px;
    cursor: pointer;
}

.acc-field input:focus,
.acc-field select:focus {
    border-color: var(--c-teal);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.acc-hint {
    font-size: 11px;
    color: var(--ink-faint);
    font-weight: 600;
}

.acc-hint.is-good { color: var(--good-dark); }
.acc-hint.is-bad  { color: var(--bad-dark); }

.acc-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.acc-status {
    font-family: var(--f-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-muted);
    margin-top: 4px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.04);
    display: none;
}

.acc-status.is-shown { display: block; }
.acc-status.is-good { background: rgba(5, 150, 105, 0.10); color: var(--good-dark); }
.acc-status.is-bad  { background: rgba(220, 38, 38, 0.10); color: var(--bad-dark); }
.acc-status.is-info { background: rgba(15, 118, 110, 0.08); color: var(--c-teal-dark); }

/* ============================================================
   ACCOUNT MODAL — 3 widoki (online / anon / local)
   ============================================================ */
.acc-view {
    flex-direction: column;
    gap: 16px;
}

.acc-section-title {
    font-family: var(--f-head);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-size: 11px;
    color: var(--ink-faint);
    margin: 6px 0 -4px;
}

.acc-section-danger {
    color: var(--bad-dark);
}

/* ===== VIEW: ONLINE (z trwałym kontem) ===== */
.acc-online-card {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 18px 18px 18px 16px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.10), rgba(15, 118, 110, 0.08));
    border: 1.5px solid rgba(16, 185, 129, 0.30);
    border-radius: 16px;
}

.acc-online-avatar {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--c-teal), var(--c-indigo));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: 0 8px 18px rgba(16, 185, 129, 0.25);
    flex-shrink: 0;
}

.acc-online-info {
    flex: 1;
    min-width: 0;
}

.acc-avatar-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ep-avatar-picker {
    margin-bottom: 2px;
}

.acc-avatar-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 8px;
    max-height: 168px;
    overflow: auto;
    padding: 8px;
    border: 1.5px solid rgba(15, 23, 42, 0.10);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.70);
}

.acc-avatar-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 1.5px solid rgba(15, 23, 42, 0.12);
    border-radius: 10px;
    background: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.acc-avatar-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(59, 130, 246, 0.45);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.acc-avatar-btn.is-selected {
    border-color: var(--c-indigo);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(16, 185, 129, 0.12));
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

.acc-online-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--f-head);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 10px;
    color: #047857;
    margin-bottom: 4px;
}

.acc-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10B981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    animation: dotPulse 2s ease-in-out infinite;
}

.acc-online-name {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: 22px;
    margin: 0 0 2px;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.acc-online-desc {
    margin: 0;
    color: var(--ink-muted);
    font-size: 13px;
    font-weight: 500;
}

.acc-profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.acc-pi-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    min-width: 0;
}

.acc-pi-icon {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.acc-pi-lbl {
    font-size: 11px;
    color: var(--ink-faint);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.acc-pi-val {
    flex: 1;
    text-align: right;
    font-weight: 700;
    color: var(--ink);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.acc-pi-val.is-empty {
    color: var(--ink-faint);
    font-weight: 500;
    font-style: italic;
}

.acc-edit-profile-btn {
    align-self: stretch;
}

/* Logout zone */
.acc-logout-zone {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px dashed rgba(15, 23, 42, 0.10);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.acc-logout-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.acc-logout-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1.5px solid rgba(220, 38, 38, 0.20);
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
    font-family: var(--f-display);
    color: var(--ink);
    width: 100%;
}

.acc-logout-btn:hover {
    background: rgba(220, 38, 38, 0.04);
    border-color: rgba(220, 38, 38, 0.40);
    transform: translateY(-1px);
}

.acc-logout-icon {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}

.acc-logout-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.acc-logout-text strong {
    font-weight: 700;
    color: var(--bad-dark);
    font-size: 14px;
}

.acc-logout-text small {
    color: var(--ink-muted);
    font-size: 12px;
    font-weight: 500;
}

.acc-logout-confirm {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: rgba(220, 38, 38, 0.06);
    border: 1.5px solid rgba(220, 38, 38, 0.30);
    border-radius: 12px;
}

.acc-logout-confirm-msg {
    font-weight: 600;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.4;
}

.acc-logout-confirm-actions {
    display: flex;
    gap: 8px;
}

.acc-logout-confirm-actions .btn-big {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
}

/* ===== VIEW: ANON (anonimowo online) ===== */
.acc-anon-banner {
    display: flex;
    gap: 14px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.10), rgba(217, 119, 6, 0.06));
    border: 1.5px solid rgba(245, 158, 11, 0.30);
    border-radius: 14px;
    align-items: flex-start;
}

.acc-anon-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #F59E0B;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
    flex-shrink: 0;
    margin-top: 5px;
    animation: dotPulse 2.4s ease-in-out infinite;
}

.acc-anon-banner-text h3 {
    margin: 0 0 4px;
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 16px;
    color: #B45309;
}

.acc-anon-banner-text p {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ink-muted);
}

.acc-benefits {
    padding: 14px 16px;
    background: rgba(15, 118, 110, 0.04);
    border: 1px solid rgba(15, 118, 110, 0.15);
    border-radius: 12px;
}

.acc-benefits-title {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 13px;
    color: var(--c-teal-dark);
    margin-bottom: 8px;
}

.acc-benefits-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.acc-benefits-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--ink);
    font-weight: 500;
}

.acc-benefit-icon {
    font-size: 16px;
    flex-shrink: 0;
}

/* ===== VIEW: LOCAL (offline) ===== */
.acc-local-banner {
    display: flex;
    gap: 14px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(148, 163, 184, 0.10), rgba(100, 116, 139, 0.06));
    border: 1.5px solid rgba(148, 163, 184, 0.30);
    border-radius: 14px;
    align-items: flex-start;
}

.acc-local-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

.acc-local-banner-text h3 {
    margin: 0 0 4px;
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
}

.acc-local-banner-text p {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--ink-muted);
}

.acc-info-card {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.acc-info-card-title {
    font-family: var(--f-head);
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    margin-bottom: 8px;
}

.acc-info-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.acc-info-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--ink-muted);
    font-weight: 500;
}

.acc-info-icon {
    font-size: 16px;
    flex-shrink: 0;
}

/* ===== TOAST — komunikat po akcji wewnątrz modalu ===== */
.acc-toast {
    margin-top: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 13px;
    text-align: center;
    background: rgba(15, 23, 42, 0.06);
    color: var(--ink);
    animation: accToastIn 0.3s ease-out;
}

.acc-toast.is-good {
    background: rgba(5, 150, 105, 0.10);
    color: var(--good-dark);
    border: 1px solid rgba(5, 150, 105, 0.25);
}

.acc-toast.is-bad {
    background: rgba(220, 38, 38, 0.10);
    color: var(--bad-dark);
    border: 1px solid rgba(220, 38, 38, 0.25);
}

@keyframes accToastIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Mobile — uproszczenia */
@media (max-width: 520px) {
    .acc-profile-grid { grid-template-columns: 1fr; }
    .acc-online-card { padding: 14px; gap: 12px; }
    .acc-online-avatar { width: 52px; height: 52px; font-size: 30px; border-radius: 12px; }
    .acc-online-name { font-size: 18px; }
    .acc-logout-confirm-actions { flex-direction: column; }
}

/* ============================================================
   LEGACY — stary acc-logged-in (zachowane dla kompatybilności)
   ============================================================ */
.acc-logged-in {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.acc-logged-head {
    font-family: var(--f-head);
    font-size: 16px;
    font-weight: 700;
    color: var(--good-dark);
}

.acc-logged-desc {
    margin: 0;
    color: var(--ink-muted);
    font-size: 13px;
    line-height: 1.5;
    font-weight: 500;
}

.acc-logged-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    align-items: stretch;
}

.acc-logout-global {
    background: transparent;
    border: 1px dashed rgba(220, 38, 38, 0.40);
    color: var(--bad-dark);
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.acc-logout-global:hover {
    background: rgba(220, 38, 38, 0.06);
    border-color: var(--bad);
}

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
.settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.settings-row .btn-big {
    flex-shrink: 0;
}

.settings-status {
    font-family: var(--f-mono);
    font-size: 13px;
    color: var(--ink-muted);
    font-weight: 600;
    flex: 1;
    min-width: 180px;
}

.settings-status.is-good {
    color: var(--good-dark);
}

.settings-status.is-bad {
    color: var(--bad-dark);
}

.settings-diag {
    margin-top: 12px;
    background: rgba(15, 23, 42, 0.04);
    border-radius: 10px;
    padding: 10px 14px;
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-faint);
    line-height: 1.6;
    display: none;
    white-space: pre-wrap;
    word-break: break-word;
}

.settings-diag.is-shown {
    display: block;
}

.ios-hint {
    margin-top: 12px;
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.08), rgba(15, 118, 110, 0.06));
    border-left: 3px solid var(--c-amber);
    border-radius: 10px;
    font-size: 13px;
    color: var(--ink);
    line-height: 1.5;
}

.ios-hint strong {
    color: var(--c-amber-dark);
}

.ios-hint ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.ios-hint li {
    margin-bottom: 4px;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 6px;
    margin-top: 14px;
    background: rgba(255, 255, 255, 0.18);
    padding: 4px;
    border-radius: var(--r-pill);
    width: max-content;
    backdrop-filter: blur(8px);
    position: relative;
    z-index: 1;
}

.tab-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: var(--r-pill);
    font-family: var(--f-display);
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.25s ease, transform 0.2s ease;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.20);
}

.tab-btn.active {
    background: white;
    color: var(--c-teal-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.20);
    font-weight: 700;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: white;
    border: 2px solid var(--border-strong);
    padding: 16px;
    border-radius: var(--r-md);
    text-align: center;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card span {
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--ink-faint);
    display: block;
    margin-bottom: 6px;
}

.stat-card b {
    font-family: var(--f-head);
    font-weight: 800;
    font-size: 32px;
    color: var(--ink);
    line-height: 1;
}

.stat-primary {
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(55, 48, 163, 0.08));
    border-color: rgba(15, 118, 110, 0.22);
}

.stat-primary b {
    background: linear-gradient(135deg, var(--c-teal-dark), var(--c-indigo));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.10), rgba(6, 182, 212, 0.10));
    border-color: rgba(16, 185, 129, 0.25);
}

.stat-success b { color: var(--good-dark); }

.stat-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.10), rgba(245, 158, 11, 0.10));
    border-color: rgba(239, 68, 68, 0.25);
}

.stat-danger b { color: var(--bad-dark); }

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: white;
    border-radius: var(--r-md);
    padding: 12px 14px;
    border-left: 4px solid;
    box-shadow: var(--shadow-sm);
}

.history-item.h-good {
    border-color: var(--good);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.06), white);
}

.history-item.h-bad {
    border-color: var(--bad);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.06), white);
}

.history-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.history-top strong {
    font-family: var(--f-display);
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
}

.history-meta {
    font-size: 12px;
    color: var(--ink-faint);
    font-weight: 700;
}

.extreme-section h4 {
    margin: 0 0 8px;
    font-family: var(--f-head);
    font-weight: 800;
    font-size: 16px;
    color: var(--ink);
}

.extreme-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Leaderboard */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-entry {
    background: white;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-md);
    padding: 12px 14px;
    cursor: pointer;
    text-align: left;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s var(--ease-spring), box-shadow 0.2s ease, border-color 0.2s ease;
    width: 100%;
    font-family: var(--f-body);
}

.leaderboard-entry:hover {
    transform: translateY(-2px);
    border-color: var(--c-violet);
    box-shadow: var(--shadow-md);
}

.leaderboard-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.leaderboard-player {
    display: flex;
    align-items: center;
    gap: 12px;
}

.leaderboard-rank {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--c-teal), var(--c-indigo));
    color: white;
    font-family: var(--f-mono);
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(15, 118, 110, 0.30);
}

.leaderboard-name {
    font-family: var(--f-display);
    font-weight: 700;
    color: var(--ink);
    font-size: 16px;
}

.leaderboard-meta {
    font-size: 12px;
    color: var(--ink-faint);
    font-weight: 600;
}

.leaderboard-score {
    font-family: var(--f-mono);
    font-feature-settings: "tnum";
    font-weight: 700;
    font-size: 22px;
    color: var(--c-teal-dark);
}

.muted-empty {
    text-align: center;
    color: var(--ink-faint);
    font-weight: 600;
    padding: 24px 12px;
}

/* ============================================================
   CONFETTI & EFFECTS
   ============================================================ */
.confetti-burst {
    position: fixed;
    pointer-events: none;
    z-index: 999;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    animation: confettiFall 1.4s ease-out forwards;
    will-change: transform, opacity;
}

@keyframes confettiFall {
    0% {
        transform: translate(0, 0) rotate(0);
        opacity: 1;
    }
    100% {
        transform: translate(var(--cx, 0), var(--cy, 0)) rotate(var(--cr, 720deg));
        opacity: 0;
    }
}

.screen-shake {
    animation: screenShake 0.5s ease;
}

@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

.flash-good,
.flash-bad {
    position: fixed;
    inset: 0;
    z-index: 950;
    pointer-events: none;
    opacity: 0;
    animation: flashFade 0.55s ease forwards;
}

.flash-good {
    background: radial-gradient(circle at center, rgba(16, 185, 129, 0.40), transparent 60%);
}

.flash-bad {
    background: radial-gradient(circle at center, rgba(239, 68, 68, 0.40), transparent 60%);
}

@keyframes flashFade {
    0% { opacity: 0; }
    20% { opacity: 1; }
    100% { opacity: 0; }
}

/* ============================================================
   RESPONSIVE — comprehensive breakpoints
   Breakpoints: 1200 (small desktop), 980 (tablet landscape),
                760 (tablet portrait), 520 (phone), 380 (phone-sm)
   ============================================================ */

/* ---------- Small desktop: ensure mode grid stays usable ---------- */
@media (max-width: 1200px) {
    .mode-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

/* ---------- Tablet landscape: hero stacks, game board still 2-col ---------- */
@media (max-width: 980px) {
    .hero-panel {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 16px;
        min-height: auto;
    }
    .hero-copy {
        text-align: center;
    }
    .hero-topline {
        margin: 0 auto 12px;
    }
    #quote-box {
        margin: 0 auto;
    }
    .hero-math-scene {
        height: 200px;
        min-height: 200px;
    }
    .setup-grid {
        grid-template-columns: 1fr;
    }
    .game-hud {
        grid-template-columns: 1fr 1fr;
    }
    .game-hud .hud-card:first-child {
        grid-column: 1 / -1;
    }
}

/* ---------- Profile grid: stack from narrower screens ---------- */
@media (max-width: 880px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }
}

/* ---------- Tablet portrait & smaller: switch to scrollable body ---------- */
@media (max-width: 760px) {
    /* Allow natural document scroll on small screens — fixes iOS keyboard
       issues, fixes "input below container" perception, lets users see whole UI. */
    html, body {
        overflow: visible !important;
        height: auto !important;
        min-height: 100dvh;
    }
    .layout-wrapper {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        padding: 8px;
    }
    .game-container {
        height: auto;
        min-height: calc(100dvh - 16px);
        overflow: visible;
    }
    .screen {
        overflow: visible;
        flex: 0 0 auto;
    }
    .profile-main,
    .setup-main,
    .game-main {
        flex: 0 0 auto;
        overflow: visible;
        padding: 6px 4px;
    }
    .game-board {
        grid-template-columns: 1fr;
    }
    .game-hud {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .game-hud .hud-card {
        padding: 10px;
    }
    .game-hud .hud-card:first-child { grid-column: auto; }
    .game-hud .hud-card > div:nth-of-type(1) {
        font-size: 18px;
    }
    .hud-secondary {
        font-size: 11px;
    }
    .hero-math-scene {
        height: 160px;
        min-height: 160px;
    }
    .hero-copy h1 {
        font-size: clamp(28px, 6vw, 40px);
    }
    .player-badge {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .player-badge .link-btn {
        align-self: flex-start;
    }
    .panel-card {
        padding: 16px;
    }
    .avatar-wrapper {
        width: 180px;
        height: 180px;
    }
    .modal-card {
        max-width: 100%;
        max-height: calc(100dvh - 24px);
        margin: 12px 0;
    }
}

/* ============================================================
   MOBILE OVERRIDES dla nowych komponentów (≤760px)
   ============================================================ */
@media (max-width: 760px) {
    /* Ukryj desktop topnav, pokaż mobilny tab bar */
    .profile-topnav { display: none !important; }
    .mobile-tab-bar { display: flex !important; }

    /* Dodaj odstęp na dole dla floating tab bara (z marginesem) */
    .profile-main,
    .setup-main {
        padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* ========== WELCOME HERO MOBILE — pionowy stack (force) ========== */
    .welcome-hero {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 14px !important;
        padding: 20px 18px 18px !important;
        text-align: center !important;
    }

    .wh-left {
        display: flex !important;
        justify-content: center !important;
        margin: 0 auto;
    }

    .wh-avatar {
        width: 72px !important;
        height: 72px !important;
        font-size: 40px !important;
        border-radius: 18px !important;
    }

    .wh-avatar-ring {
        border-radius: 22px !important;
    }

    .wh-center {
        text-align: center !important;
        width: 100%;
    }

    .wh-kicker {
        font-size: 10px !important;
        margin-bottom: 4px;
    }

    .wh-name {
        font-size: 22px !important;
        margin-bottom: 4px;
    }

    .wh-meta {
        font-size: 12px !important;
        margin: 0 0 14px !important;
    }

    .wh-stats-mini {
        display: flex !important;
        width: 100% !important;
        justify-content: space-around !important;
        padding: 12px 4px !important;
    }

    .wh-stat {
        padding: 0 8px !important;
        flex: 1;
    }

    .wh-stat-val {
        font-size: 20px !important;
    }

    .wh-stat-lbl {
        font-size: 9px !important;
    }

    .wh-right {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100%;
    }

    .wh-play-btn {
        font-size: 17px !important;
        padding: 16px 24px !important;
        justify-content: center !important;
        width: 100%;
    }

    .wh-links {
        justify-content: center !important;
        gap: 8px !important;
    }

    /* ========== TOP ROW MOBILE — single column ========== */
    body.has-returning-user .profile-top {
        grid-template-columns: 1fr !important;
    }

    /* Fact widget na mobile — kompaktowy */
    .profile-fact-widget {
        padding: 16px 18px !important;
        gap: 10px !important;
    }
    .pfw-text {
        font-size: 13px !important;
        line-height: 1.45;
    }
    .pfw-decoration-symbol {
        font-size: 28px !important;
    }
    .pfw-d2 { font-size: 38px !important; }

    /* ========== DASHBOARD MOBILE — single column ========== */
    body.has-returning-user .profile-dashboard {
        grid-template-columns: 1fr !important;
    }

    .pd-card { padding: 16px; }
    .pd-card-title { font-size: 15px; }

    .pd-leaderboard-list li {
        padding: 8px 10px;
        gap: 8px;
    }
    .pd-leaderboard-list .top-avatar { font-size: 20px; }
    .pd-leaderboard-list .top-name { font-size: 13px; }
    .pd-leaderboard-list .top-score { font-size: 16px; }

    /* Start CTA — ukryty na mobile, jego rolę pełni "Graj" w tab barze */
    .profile-start-cta {
        display: none !important;
    }

    /* ========== FLOATING PILL TAB BAR — modern, oddalony od krawędzi ========== */
    .mobile-tab-bar {
        position: fixed !important;
        bottom: max(14px, env(safe-area-inset-bottom, 14px)) !important;
        left: 12px !important;
        right: 12px !important;
        border-radius: 24px !important;
        padding: 6px !important;
        background: rgba(255,255,255,0.92) !important;
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow:
            0 18px 48px rgba(15, 23, 42, 0.18),
            0 4px 12px rgba(15, 23, 42, 0.06) !important;
        gap: 2px;
    }

    .mtb-tab {
        padding: 10px 4px 8px !important;
        border-radius: 18px !important;
        min-height: 56px;
        gap: 4px !important;
    }

    .mtb-tab:active {
        background: rgba(15, 118, 110, 0.10);
    }

    .mtb-icon {
        font-size: 22px !important;
    }

    .mtb-lbl {
        font-size: 10px !important;
    }

    /* Play tab — most prominent (większy kolorowy kafelek) */
    .mtb-play {
        background: linear-gradient(135deg, var(--c-teal) 0%, var(--c-teal-dark) 100%);
        box-shadow: 0 6px 18px rgba(15, 118, 110, 0.40);
    }
    .mtb-play::before {
        display: none !important; /* nie potrzebujemy tła pod ikoną — całe tło zakładki jest kolorowe */
    }
    .mtb-play .mtb-icon {
        color: white !important;
        font-size: 22px !important;
        margin-top: 0 !important;
    }
    .mtb-play .mtb-lbl {
        color: white !important;
        font-weight: 700 !important;
    }
    .mtb-play:active {
        background: linear-gradient(135deg, var(--c-teal-dark) 0%, var(--c-teal) 100%);
        transform: scale(0.97);
    }
}

/* ---------- Phone ---------- */
@media (max-width: 520px) {
    .hero-copy h1 {
        font-size: 32px;
    }
    .hero-subtitle {
        font-size: 14px;
    }
    .hero-math-scene {
        height: 140px;
        min-height: 140px;
    }
    .math-core {
        font-size: 80px;
    }
    .math-token {
        width: 44px;
        height: 44px;
        font-size: 22px;
        border-radius: 14px;
    }
    .math-formula {
        font-size: 11px;
        padding: 4px 10px;
    }
    /* Form & avatar */
    .input-name {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
        padding: 12px 14px;
    }
    .avatar-grid {
        gap: 8px;
    }
    .avatar-option {
        font-size: 24px;
        border-radius: 12px;
    }
    .player-avatar {
        width: 60px;
        height: 60px;
        font-size: 32px;
        border-radius: 16px;
    }
    .player-name-wrap h2 {
        font-size: 22px;
    }
    /* Setup */
    .diff-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    .btn-diff {
        padding: 10px 6px;
    }
    .btn-diff strong {
        font-size: 12px;
    }
    .btn-diff small {
        font-size: 11px;
    }
    .diff-icon {
        font-size: 22px;
    }
    .mode-grid {
        grid-template-columns: 1fr;
    }
    .btn-mode {
        padding: 14px;
    }
    .mode-title {
        font-size: 16px;
    }
    .mode-subtitle {
        font-size: 12px;
    }
    .select-control {
        font-size: 16px; /* prevents iOS auto-zoom */
    }
    /* Game */
    .game-hud {
        grid-template-columns: 1fr 1fr;
    }
    .game-hud .hud-card:nth-child(3) {
        grid-column: 1 / -1;
    }
    .question-box {
        font-size: clamp(28px, 7vw, 38px);
        padding: 12px 18px;
    }
    .avatar-wrapper {
        width: 150px;
        height: 150px;
    }
    .main-avatar {
        font-size: 60px;
    }
    .options-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .btn-option {
        font-size: clamp(24px, 6vw, 32px);
        min-height: 64px;
        padding: 12px;
    }
    .answers-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    .answers-title h3 {
        font-size: 18px;
    }
    /* Modal & buttons */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .stat-card {
        padding: 12px 10px;
    }
    .stat-card b {
        font-size: 26px;
    }
    .modal-header {
        padding: 18px 18px;
    }
    .modal-header h2 {
        font-size: 22px;
    }
    .modal-body {
        padding: 16px 18px;
    }
    .modal-footer {
        padding: 12px 14px;
    }
    .btn-big {
        font-size: 14px;
        padding: 12px 18px;
    }
    /* Stały pasek na dole z głównym przyciskiem + hamburgerem */
    .btn-container-bottom {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08);
    }
    .btn-container-bottom .btn-big:first-child {
        flex: 1;
    }
    /* Ukryj dodatkowe przyciski na mobile — dostępne przez hamburger */
    .btn-nav-extra {
        display: none !important;
    }
    /* Pokaż hamburger na mobile */
    .btn-hamburger {
        display: flex;
    }
    /* Pokaż szufladę nawigacyjną */
    .nav-drawer {
        display: block;
    }
    /* Dodaj odstęp na dole ekranu dla stałego paska */
    .profile-main,
    .setup-main {
        padding-bottom: 80px;
    }
    /* Tab bar — full width, larger hit area */
    .tab-bar {
        width: 100%;
        gap: 4px;
    }
    .tab-btn {
        flex: 1;
        padding: 10px 8px;
        font-size: 13px;
        text-align: center;
        min-height: 40px;
    }
    .mission-strip {
        grid-template-columns: 1fr;
    }
    .info-chip {
        font-size: 12px;
    }
}

/* ---------- Tiny phones (≤380px) ---------- */
@media (max-width: 380px) {
    .avatar-grid {
        grid-template-columns: repeat(3, 1fr); /* 3x5 — also balanced for 15 */
    }
    .hero-math-scene {
        display: none;
    }
    .game-hud {
        grid-template-columns: 1fr;
    }
    .game-hud .hud-card:nth-child(3) {
        grid-column: auto;
    }
    .options-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   COMPACT SIZING: ekrany krotsze niz ~900px wys. — kompresja
   paddingow/gapow/font-size'ow zeby calosc setup/profile miescila
   sie w viewport bez scrolla. Tablet/mobile dostaja swoje rules
   ponizej (body scrolls naturally tam).
   ============================================================ */
@media (min-width: 760px) and (max-height: 900px) {
    .layout-wrapper { padding: 8px 14px; }
    .profile-main, .setup-main, .game-main {
        gap: 12px;
        padding: 8px 12px;
    }
    .panel-card { padding: 16px 20px; border-radius: 18px; }
    .section-title-row { margin-bottom: 10px; }

    /* Hero compact */
    .hero-panel { min-height: 180px; gap: 18px; }
    .hero-copy h1 { font-size: clamp(26px, 3.4vw, 38px); margin-bottom: 8px; }
    .hero-subtitle { font-size: 14px; margin-bottom: 10px; }
    #quote-box { padding: 8px 12px; min-width: 200px; }
    #quote-display { font-size: 14px; }
    .hero-math-scene { min-height: 160px; }
    .math-core { font-size: clamp(56px, 7vw, 90px); }
    .math-token { width: 42px; height: 42px; font-size: 20px; border-radius: 10px; }
    .math-formula { font-size: 11px; padding: 4px 10px; }

    /* Profile form */
    .input-name { padding: 10px 14px; font-size: 16px; }
    .avatar-grid {
        gap: 6px;
        max-height: clamp(180px, 32vh, 300px);
    }
    .avatar-option { font-size: clamp(28px, 4.2vmin, 52px); border-radius: 10px; }
    .avatar-search { padding: 7px 12px; font-size: 13px; }
    .avatar-current { width: 48px; height: 48px; font-size: 30px; border-radius: 12px; }

    /* Player summary */
    .player-avatar { width: 56px; height: 56px; font-size: 30px; border-radius: 14px; }
    .player-name-wrap h2 { font-size: 22px; }
    .player-name-wrap p { font-size: 13px; }
    .info-chip { padding: 8px 12px; font-size: 12px; }
    .mission-strip { margin-top: 10px; gap: 8px; }

    /* Setup grid */
    .setup-grid { gap: 12px; }

    /* Difficulty */
    .diff-grid { gap: 6px; }
    .btn-diff { padding: 9px 6px; }
    .diff-icon { font-size: 20px; }
    .btn-diff strong { font-size: 12px; }
    .btn-diff small { font-size: 11px; }

    /* Time */
    .select-control { padding: 11px 14px; font-size: 14px; }

    /* Mode buttons */
    .mode-grid { gap: 8px; }
    .btn-mode { padding: 12px 14px; }
    .mode-title { font-size: 15px; }
    .mode-icon { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
    .mode-subtitle { font-size: 12px; }

    /* Bottom buttons */
    .btn-container-bottom { padding: 6px 10px; gap: 8px; }
    .btn-big { padding: 10px 22px; font-size: 14px; }
    .fullscreen-btn { width: 36px; height: 36px; font-size: 18px; top: 8px; right: 12px; }

    /* Section labels */
    .settings-label { font-size: 14px; }
    .label-badge { width: 26px; height: 26px; font-size: 13px; border-radius: 7px; }
    .helper-text { font-size: 11px; }
}

/* Even shorter viewports (laptops 720-800px tall) */
@media (min-width: 760px) and (max-height: 760px) {
    .panel-card { padding: 12px 16px; border-radius: 16px; }
    .profile-main, .setup-main, .game-main { gap: 8px; padding: 6px 10px; }
    .hero-panel { min-height: 140px; }
    .hero-math-scene { min-height: 130px; display: block; }
    .math-token { width: 36px; height: 36px; font-size: 17px; }
    .player-avatar { width: 48px; height: 48px; font-size: 26px; border-radius: 12px; }
    .player-name-wrap h2 { font-size: 19px; }
    .info-chip { padding: 6px 10px; font-size: 11px; }
    .mission-strip { margin-top: 8px; }
    .btn-diff { padding: 7px 4px; }
    .diff-icon { font-size: 17px; }
    .btn-mode { padding: 10px 12px; }
    .mode-title { font-size: 14px; gap: 6px; }
    .mode-icon { width: 24px; height: 24px; font-size: 13px; }
    .mode-subtitle { font-size: 11px; line-height: 1.3; }
    .btn-big { padding: 9px 18px; font-size: 13px; }
    .btn-container-bottom { padding: 4px 8px; }
    .section-title-row { margin-bottom: 8px; }
    .input-name { font-size: 15px; padding: 9px 12px; }
    .select-control { font-size: 13px; padding: 9px 12px; }
}

/* ============================================================
   GAME-ACTIVE: kompaktowy, viewport-locked layout dla mobile
   ============================================================ */
@media (max-width: 760px) {
    /* Override the "body scrolls" rule when game is in progress —
       the game screen stays inside 100dvh and elements are sized
       to fit without scrolling. */
    body.game-active,
    body.game-active html {
        overflow: hidden !important;
        height: 100dvh !important;
    }
    body.game-active .layout-wrapper {
        height: 100dvh;
        overflow: hidden;
        padding: 4px;
    }
    body.game-active .game-container {
        height: 100%;
        max-height: 100dvh;
        overflow: hidden;
    }
    body.game-active #screen-game.is-active {
        height: 100%;
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }
    body.game-active .game-main {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 4px;
    }

    /* Compact HUD: 3 metrics in single tight row, no big labels */
    body.game-active .game-hud {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
        flex: 0 0 auto;
    }
    body.game-active .game-hud .hud-card {
        padding: 6px 8px;
        gap: 0;
    }
    body.game-active .game-hud .hud-card:first-child,
    body.game-active .game-hud .hud-card:nth-child(3) {
        grid-column: auto;
    }
    body.game-active .game-hud .hud-label {
        font-size: 9px;
        letter-spacing: 1px;
    }
    body.game-active .game-hud .hud-card > div:nth-of-type(1) {
        font-size: 16px;
        line-height: 1.1;
    }
    body.game-active .game-hud .hud-secondary {
        display: none;
    }

    /* Compact stage: tight padding, smaller avatar, no progress pill */
    body.game-active .game-board {
        flex: 1 1 auto;
        min-height: 0;
        gap: 8px;
        display: flex;
        flex-direction: column;
    }
    body.game-active .stage-card {
        padding: 10px;
        gap: 6px;
        flex: 0 0 auto;
    }
    body.game-active .rewards-shelf {
        min-height: 0;
        max-height: 28px;
        overflow: hidden;
    }
    body.game-active .avatar-wrapper {
        width: 110px;
        height: 110px;
    }
    body.game-active .main-avatar {
        font-size: 50px;
    }
    body.game-active .question-box {
        font-size: clamp(26px, 7vw, 36px);
        padding: 10px 18px;
    }
    body.game-active .progress-meta {
        display: flex;
        margin-top: 0;
    }
    body.game-active .progress-pill {
        font-size: 11px;
        padding: 5px 12px;
    }

    /* Compact answers card: minimal header */
    body.game-active .answers-card {
        flex: 1 1 auto;
        min-height: 0;
        padding: 10px;
        gap: 8px;
        display: flex;
        flex-direction: column;
    }
    body.game-active .answers-title {
        display: none;
    }
    body.game-active .answers-header {
        flex: 0 0 auto;
        justify-content: flex-end;
        gap: 0;
        min-height: 28px;
    }
    body.game-active #combo-badge {
        font-size: 12px;
        padding: 5px 12px;
    }
    body.game-active .options-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px;
        flex: 1 1 auto;
        min-height: 0;
    }
    body.game-active .btn-option {
        font-size: clamp(22px, 5.6vw, 30px);
        min-height: 0;
        padding: 8px;
    }
    body.game-active .btn-container-bottom {
        position: static;
        padding: 4px;
        gap: 6px;
        flex: 0 0 auto;
    }
    body.game-active .btn-container-bottom .btn-big {
        padding: 9px 18px;
        font-size: 13px;
    }
}

/* On very tall phones, give the question a bit more room */
@media (max-width: 520px) and (min-height: 750px) {
    body.game-active .avatar-wrapper {
        width: 130px;
        height: 130px;
    }
    body.game-active .main-avatar {
        font-size: 60px;
    }
}

/* On short phones (<700px) hide the avatar entirely to save space */
@media (max-width: 760px) and (max-height: 700px) {
    body.game-active .avatar-wrapper {
        display: none;
    }
}

/* ---------- Touch / no-hover devices: kill parallax artifacts ---------- */
@media (hover: none) {
    .hero-math-scene {
        transform: none !important;
    }
    .hero-math-scene .math-token,
    .hero-math-scene .math-formula {
        transform: none !important;
    }
    /* Disable hover-only effects */
    .btn-mode:hover,
    .btn-option:hover,
    .panel-card:hover {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001s !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.05s !important;
    }
}
