:root {
    --bg-main: #F5F7FA;
    --bg-dark: #111827;
    --bg-card: #FFFFFF;
    
    --text-dark: #1F1F1F;
    --text-light: #F9FAFB;
    --text-grey: #6B7280;
    
    --primary-blue: #0095DA;
    --secondary-blue: #00649D;
    --success-green: #10B981;
    --error-red: #EF4444;

    /* Shadows & Borders */
    --shadow-brand: 0 10px 30px -10px rgba(0, 149, 218, 0.15);
    
    --border-subtle: 1px solid rgba(0, 0, 0, 0.05);
    --border-dark: 1px solid rgba(255, 255, 255, 0.1);
    
    --radius-card: 20px;
    --container-width: 800px;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: var(--bg-dark);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

.nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-weight: 800;
    font-size: 1.2rem;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}
.logo span { color: var(--primary-blue); }

.stats-bar {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    display: flex;
    gap: 15px;
}

/* Main Layout */
.app-container {
    flex: 1;
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Selection Screen */
.selection-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
}

.subject-card {
    background: var(--bg-card);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}

.subject-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 149, 218, 0.15);
    border-color: rgba(0, 149, 218, 0.3);
}

.mix-card {
    border: 1px solid rgba(0, 149, 218, 0.35);
    background: linear-gradient(to right, rgba(0, 149, 218, 0.06), var(--bg-card));
}

.subject-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-dark);
}

.subject-count {
    background: rgba(0, 149, 218, 0.1);
    color: var(--primary-blue);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
}

/* Quiz Card */
.quiz-card {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-brand);
    padding: 40px;
    width: 100%;
    position: relative;
    overflow: hidden;
    animation: fadeIn 0.4s ease-out;
}

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

.quiz-header {
    margin-bottom: 24px;
    border-bottom: 2px solid #F3F4F6;
    padding-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.subject-badge {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    font-weight: 800;
    color: var(--text-grey);
}

.question-text {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 32px;
    color: var(--text-dark);
}

/* Answers */
.answers-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.answer-item {
    padding: 16px 20px;
    border: 2px solid #E5E7EB;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-weight: 500;
    position: relative;
}

.answer-item:hover {
    border-color: var(--primary-blue);
    background-color: rgba(0, 149, 218, 0.02);
}

.answer-item.selected {
    border-color: var(--primary-blue);
    background-color: rgba(0, 149, 218, 0.05);
}

.answer-item.correct {
    border-color: var(--success-green);
    background-color: rgba(16, 185, 129, 0.1);
    color: #065F46;
}

.answer-item.incorrect {
    border-color: var(--error-red);
    background-color: rgba(239, 68, 68, 0.1);
    color: #991B1B;
}

/* Checkbox/Radio Styling */
.answer-input {
    margin-top: 4px;
    accent-color: var(--primary-blue);
    transform: scale(1.2);
}

/* Matching specific */
.matching-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.matching-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: center;
    padding: 12px;
    background: #F9FAFB;
    border-radius: 8px;
}

.matching-left {
    font-weight: 600;
}

.matching-select {
    padding: 10px;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    font-family: inherit;
    width: 100%;
}

.matching-select.correct { border-color: var(--success-green); background: rgba(16, 185, 129, 0.1); }
.matching-select.incorrect { border-color: var(--error-red); background: rgba(239, 68, 68, 0.1); }

/* Gapfill Styles */
.gapfill-container {
    background: #F9FAFB;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid #E5E7EB;
}

.gapfill-info {
    font-size: 0.85rem;
    color: var(--text-grey);
    margin-bottom: 20px;
    font-style: italic;
    padding-bottom: 12px;
    border-bottom: 1px dashed #E5E7EB;
}

.gapfill-text-display {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-dark);
}

.correct-gap {
    background-color: rgba(16, 185, 129, 0.15);
    color: #065F46;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 800;
    border-bottom: 2px solid var(--success-green);
    animation: highlight 0.5s ease-out;
}

.correct-label {
    background-color: rgba(16, 185, 129, 0.15);
    color: #065F46;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: bold;
    display: inline-block;
    vertical-align: middle;
}

@keyframes highlight {
    from { background-color: var(--success-green); color: white; }
    to { background-color: rgba(16, 185, 129, 0.15); color: #065F46; }
}


/* Controls */
.controls {
    margin-top: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 2px solid #F3F4F6;
    padding-top: 24px;
}

.btn {
    display: inline-flex;
    padding: 12px 28px;
    border-radius: 10px;
    font-weight: 700;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    font-size: 1rem;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary-blue);
    color: white;
}
.btn-primary:hover {
    background-color: var(--secondary-blue);
    box-shadow: 0 4px 15px rgba(0, 149, 218, 0.3);
}

.btn-outline {
    background: transparent;
    border: 2px solid #E5E7EB;
    color: var(--text-grey);
}
.btn-outline:hover {
    border-color: var(--text-dark);
    color: var(--text-dark);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Feedback Section */
.feedback-box {
    margin-top: 24px;
    padding: 20px;
    border-radius: 12px;
    display: none;
}
.feedback-box.visible { display: block; animation: fadeIn 0.3s; }

.feedback-success { background: rgba(16, 185, 129, 0.1); color: #065F46; border: 1px solid var(--success-green); }
.feedback-error { background: rgba(239, 68, 68, 0.1); color: #991B1B; border: 1px solid var(--error-red); }

.hint-box {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(0,0,0,0.05);
    font-size: 0.95rem;
    font-style: italic;
    color: var(--text-dark);
}
.hint-label { font-weight: 800; font-style: normal; margin-right: 5px; opacity: 0.7; }

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 6px;
    background: #E5E7EB;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1001;
}
.progress-bar {
    height: 100%;
    background: var(--primary-blue);
    width: 0%;
    transition: width 0.3s ease;
}

.back-btn {
    margin-bottom: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-grey);
    font-weight: 600;
    cursor: pointer;
}
.back-btn:hover { color: var(--primary-blue); }

.hidden { display: none !important; }

@media (max-width: 768px) {
    .matching-pair { grid-template-columns: 1fr; gap: 8px; }
    .controls { flex-direction: column; gap: 16px; }
    .btn { width: 100%; justify-content: center; }
}

/* Browse Mode Styles */
.browse-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 24px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}
.browse-filter {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-grey);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.browse-filter select {
    padding: 10px 12px;
    border: 2px solid #E5E7EB;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    background: #fff;
    min-width: 240px;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}
.browse-filter select:focus { outline: none; border-color: var(--primary-blue); }
.browse-count {
    margin-left: auto;
    align-self: center;
    font-weight: 700;
    color: var(--primary-blue);
    background: rgba(0, 149, 218, 0.1);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    white-space: nowrap;
}
@media (max-width: 768px) {
    .browse-filters { flex-direction: column; align-items: stretch; }
    .browse-filter select { min-width: 0; width: 100%; }
    .browse-count { margin-left: 0; align-self: flex-start; }
}

.browse-subject-header {
    margin: 40px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-blue);
    color: var(--primary-blue);
    font-size: 1.5rem;
    font-weight: 800;
}

.browse-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.05);
}

.browse-question {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text-dark);
}

.browse-answer-row {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.95rem;
    color: var(--text-grey);
}

.browse-answer-row.is-correct {
    color: #065F46;
    font-weight: 600;
}

.browse-marker {
    min-width: 24px;
}

.browse-hint {
    margin-top: 16px;
    padding: 12px;
    background: #F3F4F6;
    border-radius: 8px;
    font-size: 0.9rem;
    font-style: italic;
    color: var(--text-dark);
}

.browse-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px;
    background: #F9FAFB;
    border-bottom: 1px solid #E5E7EB;
}
.browse-pair:last-child { border-bottom: none; }
.browse-pair span:last-child { font-weight: 700; color: var(--primary-blue); }

/* ===== A11y / utils ===== */
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid rgba(0, 149, 218, 0.5); outline-offset: 2px; }

/* Touch feedback: press na :active, hover-lift tylko na urządzeniach z hoverem */
.subject-card:active, .btn:active { transform: scale(0.98); }
.answer-item:active { transform: scale(0.99); }
@media (hover: none) {
    .subject-card:hover { transform: none; box-shadow: 0 4px 6px rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.05); }
    .answer-item:hover { border-color: #E5E7EB; background-color: transparent; }
    .btn-primary:hover { background-color: var(--primary-blue); box-shadow: none; }
    .btn-outline:hover { border-color: #E5E7EB; color: var(--text-grey); }
}

.matching-correct-label { color: #059669; font-weight: 700; font-size: 0.9rem; margin-top: 4px; }

/* ===== Karta wznawiania ===== */
.resume-card {
    border: 2px solid var(--primary-blue);
    background: linear-gradient(to right, rgba(0, 149, 218, 0.10), var(--bg-card));
}
.resume-sub { margin: -12px 0 8px; font-size: 0.85rem; color: var(--text-grey); font-weight: 600; }

/* ===== Ekran wyniku ===== */
.result-card { text-align: center; }
.result-emoji { font-size: 4rem; line-height: 1; margin-bottom: 4px; }
.result-score { font-size: 3rem; font-weight: 800; color: var(--primary-blue); line-height: 1.1; }
.result-pct { font-size: 1.05rem; font-weight: 700; color: var(--text-grey); margin-top: 4px; }
.result-sub { color: var(--text-grey); margin-top: 6px; font-weight: 600; }
.result-tally { display: flex; justify-content: center; gap: 18px; margin: 22px 0; font-weight: 800; font-size: 1.05rem; }
.result-tally .ok { color: var(--success-green); }
.result-tally .bad { color: var(--error-red); }
.result-actions { display: flex; flex-direction: column; gap: 12px; }
.result-actions .btn { width: 100%; justify-content: center; }
.result-review { margin-top: 28px; text-align: left; }
.result-review h4 { margin-bottom: 14px; color: var(--text-dark); font-size: 1.05rem; }

/* ===== Modal (custom confirm) ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(17, 24, 39, 0.55);
    display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 2000;
}
.modal-box {
    background: var(--bg-card); border-radius: 16px; padding: 28px 24px;
    max-width: 380px; width: 100%; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.2s ease-out;
}
.modal-msg { font-weight: 600; margin-bottom: 22px; color: var(--text-dark); line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; }
.modal-actions .btn { flex: 1; width: auto; justify-content: center; }

/* ===== Mikrointerakcje ===== */
@keyframes shakeX {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-7px); }
    40%, 60% { transform: translateX(7px); }
}
.answers-container.shake { animation: shakeX 0.4s ease; }
@keyframes pulseScale {
    0% { transform: scale(1); }
    50% { transform: scale(1.015); }
    100% { transform: scale(1); }
}
.feedback-box.pulse { animation: pulseScale 0.35s ease; }
@media (prefers-reduced-motion: reduce) {
    .answers-container.shake, .feedback-box.pulse { animation: none; }
    .subject-card, .btn, .answer-item { transition: none; }
}

/* ===== Mobile (≤768px): ergonomia kciuka + sticky akcje ===== */
@media (max-width: 768px) {
    .quiz-card { padding: 24px 20px; overflow: visible; }
    .result-card { padding: 28px 20px; }
    .subject-card, .browse-card { padding: 20px; }
    .question-text { font-size: 1.15rem; margin-bottom: 24px; }

    .answer-item { padding: 18px 16px; min-height: 56px; align-items: center; }
    .answer-input { transform: scale(1.4); }

    .answers-container { padding-bottom: 4px; }
    .quiz-card .controls {
        position: sticky; bottom: 0; z-index: 5;
        flex-direction: row; gap: 12px;
        margin: 24px -20px -24px; padding: 16px 20px;
        background: var(--bg-card); border-top: 1px solid #F0F0F0;
        border-bottom-left-radius: var(--radius-card);
        border-bottom-right-radius: var(--radius-card);
    }
    .quiz-card .controls .btn { width: auto; flex: 1; justify-content: center; padding: 14px 16px; }
}

/* ===== Dashboard hero ===== */
.dash-hero {
    background: linear-gradient(135deg, #0095DA, #00649D);
    color: #fff; border-radius: 16px; padding: 20px 22px; margin-bottom: 8px;
    box-shadow: 0 10px 30px -12px rgba(0, 149, 218, 0.5);
}
.dash-hero-top { display: flex; justify-content: space-between; align-items: center; }
.dash-hero-title { font-weight: 800; font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.dash-hero-pct { font-weight: 800; font-size: 1.4rem; }
.dash-progress { height: 8px; background: rgba(255, 255, 255, 0.25); border-radius: 99px; overflow: hidden; margin: 12px 0 10px; }
.dash-progress-bar { height: 100%; background: #fff; border-radius: 99px; transition: width 0.6s ease; }
.dash-hero-sub { font-size: 0.82rem; font-weight: 600; opacity: 0.92; }

/* ===== Subject card: postęp ===== */
.subject-card { flex-direction: column; align-items: stretch; gap: 12px; }
.subject-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.subject-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.best-pill { background: rgba(16, 185, 129, 0.12); color: #059669; font-weight: 800; font-size: 0.78rem; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.card-progress { height: 6px; background: #E9EDF1; border-radius: 99px; overflow: hidden; }
.card-progress-bar { height: 100%; background: linear-gradient(90deg, #0095DA, #10B981); border-radius: 99px; }

/* ===== Badge'y A/B/C/D ===== */
.answer-input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.answer-letter {
    flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.9rem; background: #EEF2F6; color: var(--text-grey);
    border: 1.5px solid #E2E8F0; transition: var(--transition);
}
.answer-text { flex: 1; }
.answer-item.selected .answer-letter { background: var(--primary-blue); color: #fff; border-color: var(--primary-blue); }
.answer-item.correct .answer-letter { background: var(--success-green); color: #fff; border-color: var(--success-green); }
.answer-item.incorrect .answer-letter { background: var(--error-red); color: #fff; border-color: var(--error-red); }

/* ===== Ring wyniku ===== */
.result-ring { display: block; margin: 8px auto 4px; }
.result-ring .ring-prog { transition: stroke-dashoffset 0.9s ease; }
.result-ring .ring-num { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 800; font-size: 1.6rem; fill: var(--text-dark); }
.result-ring .ring-pct { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; font-size: 0.95rem; fill: var(--text-grey); }
@media (prefers-reduced-motion: reduce) { .result-ring .ring-prog { transition: none; } }

/* ===== Przełącznik motywu w navbarze ===== */
.nav-right { display: flex; align-items: center; gap: 14px; }
.theme-toggle {
    background: rgba(255, 255, 255, 0.12); border: none; color: #fff;
    width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
    font-size: 1.1rem; line-height: 1; display: flex; align-items: center; justify-content: center;
    transition: var(--transition); flex-shrink: 0;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.22); }
.theme-toggle:active { transform: scale(0.92); }

/* ===== Dark mode (auto wg systemu + ręczny przełącznik .theme-dark) ===== */
.theme-dark {
    --bg-main: #0f172a; --bg-card: #1e293b; --text-dark: #e5e7eb; --text-grey: #94a3b8;
    --bg-dark: #0b1220; --ring-track: #334155;
}
.theme-dark .subject-card, .theme-dark .browse-card, .theme-dark .modal-box { border-color: rgba(255, 255, 255, 0.08); }
.theme-dark .answer-item { border-color: #334155; }
.theme-dark .answer-letter { background: #0f172a; border-color: #334155; }
.theme-dark .quiz-header, .theme-dark .hint-box { border-color: #334155; }
.theme-dark .quiz-card .controls { background: var(--bg-card); border-top-color: #334155; }
.theme-dark .gapfill-container, .theme-dark .matching-pair, .theme-dark .browse-hint { background: #0f172a; border-color: #334155; }
.theme-dark .gapfill-info { border-bottom-color: #334155; }
.theme-dark select { background: #1e293b; color: var(--text-dark); border-color: #334155; }
.theme-dark .progress-container { background: #334155; }
.theme-dark .subject-count { background: rgba(0, 149, 218, 0.22); }
.theme-dark .card-progress { background: #334155; }
.theme-dark .answer-item.correct { color: #6ee7b7; }
.theme-dark .answer-item.incorrect { color: #fca5a5; }
.theme-dark .feedback-success { color: #6ee7b7; }
.theme-dark .feedback-error { color: #fca5a5; }
.theme-dark .result-tally .ok { color: #6ee7b7; }
.theme-dark .result-tally .bad { color: #fca5a5; }
.theme-dark .correct-gap { color: #6ee7b7; }
.theme-dark .best-pill { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
