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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #eef1f7;
    color: #333;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1rem 2rem;
}

/* Top bar */
.top-bar {
    width: 100%;
    max-width: 520px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    font-size: 0.9rem;
}
.back-link {
    color: #555;
    text-decoration: none;
}
.back-link:hover { color: #3b82f6; }
.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.user-name {
    font-weight: 600;
    color: #475569;
}
.logout-link {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.85rem;
}
.logout-link:hover { color: #ef4444; }

/* Legacy back (auth pages) */
.back {
    align-self: flex-start;
    padding: 1rem 0;
    font-size: 0.9rem;
}
.back a {
    color: #555;
    text-decoration: none;
}
.back a:hover { color: #3b82f6; }

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 520px;
}
.hidden { display: none !important; }

/* Start screen */
#screen-start h1 {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    color: #1e293b;
    text-align: center;
}
.intro {
    color: #64748b;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    text-align: center;
    line-height: 1.5;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* ─── Level grid ─── */
.level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
}

.level-card {
    background: #fff;
    border: 2px solid transparent;
    border-radius: 14px;
    padding: 1rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}
.level-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.1);
    border-color: #3b82f6;
}
.level-card:active {
    transform: scale(0.97);
}

.level-emoji-small {
    font-size: 1.8rem;
    line-height: 1.2;
}
.level-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e293b;
}
.level-desc {
    font-size: 0.8rem;
    color: #64748b;
}
.level-stats {
    font-size: 0.75rem;
    font-weight: 600;
    color: #3b82f6;
    background: #eff6ff;
    border-radius: 6px;
    padding: 0.15rem 0.5rem;
    margin-top: 0.2rem;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 10px;
    padding: 0.75rem 2rem;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: #3b82f6;
    color: #fff;
}
.btn-primary:hover { background: #2563eb; }

.btn-secondary {
    background: #e2e8f0;
    color: #334155;
}
.btn-secondary:hover { background: #cbd5e1; }

.btn-sm {
    font-size: 0.85rem;
    padding: 0.5rem 1.25rem;
}

.btn-full {
    width: 100%;
}

/* Progress bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #dde3ed;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}
.progress-fill {
    height: 100%;
    background: #3b82f6;
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.status-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 1.25rem;
    font-weight: 500;
}

/* Game card */
.card {
    background: #fff;
    border-radius: 16px;
    padding: 2rem 1.5rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
}

.level-emoji {
    font-size: 3rem;
    line-height: 1.1;
    margin-bottom: 0.25rem;
}

.problem-text {
    margin-bottom: 0.75rem;
}

.equation {
    font-size: 2rem;
    font-weight: 800;
    color: #1e293b;
    letter-spacing: 0.02em;
}

.qmark {
    color: #3b82f6;
}

#answer-form {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.input {
    flex: 1;
    border: 2px solid #dde3ed;
    border-radius: 10px;
    padding: 0.7rem 1rem;
    font-size: 1.05rem;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
.input:focus {
    border-color: #3b82f6;
}

.math-input {
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.03em;
}

/* Feedback */
.feedback {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    width: 100%;
    text-align: center;
    margin-top: 0.5rem;
}
.feedback.correct {
    background: #dcfce7;
    color: #166534;
}
.feedback.wrong {
    background: #fee2e2;
    color: #991b1b;
}

/* Results screen */
#screen-results h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: #1e293b;
    text-align: center;
}

.results-score {
    font-size: 3rem;
    font-weight: 800;
    color: #3b82f6;
    margin: 0.75rem 0 1.5rem;
}

.results-list {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1.5rem;
}

.result-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: #f8fafc;
}
.result-row.ok { background: #f0fdf4; }
.result-row.fail { background: #fef2f2; }

.result-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
}
.result-text {
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
}
.result-answer {
    color: #64748b;
    margin-left: auto;
    text-align: right;
}

/* ─── Auth pages ─── */
.auth-box {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    padding: 2rem 1.75rem;
    width: 100%;
    max-width: 380px;
    margin-top: 2rem;
}
.auth-box h1 {
    font-size: 1.5rem;
    color: #1e293b;
    margin-bottom: 0.4rem;
    text-align: center;
}
.auth-subtitle {
    color: #64748b;
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    text-align: center;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 0.3rem;
}

/* ─── Progress screen ─── */
#screen-progress h2 {
    font-size: 1.5rem;
    color: #1e293b;
    margin-bottom: 1rem;
}

.progress-overview {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.overview-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    min-width: 90px;
}
.overview-num {
    font-size: 1.5rem;
    font-weight: 800;
    color: #3b82f6;
}
.overview-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.15rem;
}

.progress-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}
.progress-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.prog-emoji {
    font-size: 1.1rem;
    flex-shrink: 0;
}
.prog-level {
    font-weight: 600;
    min-width: 100px;
    white-space: nowrap;
}
.pbar {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    min-width: 40px;
}
.pbar-fill {
    height: 100%;
    border-radius: 4px;
    background: #ef4444;
    transition: width 0.3s ease;
}
.pbar-fill.pbar-good { background: #22c55e; }
.pbar-fill.pbar-mid { background: #f59e0b; }
.pbar-fill.pbar-low { background: #ef4444; }
.prog-stats {
    font-size: 0.8rem;
    color: #94a3b8;
    min-width: 70px;
    text-align: right;
    white-space: nowrap;
}

/* ─── Add user modal ─── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-box {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 1.75rem;
    width: 100%;
    max-width: 340px;
}
.modal-box h2 {
    font-size: 1.2rem;
    color: #1e293b;
    margin-bottom: 1rem;
}
.modal-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.modal-buttons .btn {
    flex: 1;
}

/* ─── Responsive ─── */
@media (max-width: 400px) {
    .level-grid {
        grid-template-columns: 1fr;
    }
    .equation {
        font-size: 1.6rem;
    }
}
