/* AI Tutor — Mobile-first адаптивный стиль */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --primary: #6c5ce7;
    --primary-hover: #5b4bd5;
    --primary-light: #e8e5ff;
    --text: #2d3436;
    --muted: #636e72;
    --border: #dfe6e9;
    --success: #00b894;
    --danger: #ff6b6b;
    --warning: #fdcb6e;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
}
html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* Container */
.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 12px;
}
@media (min-width: 768px) {
    .field select {
        border: 1.5px solid var(--border);
        border-radius: 8px;
        padding: 10px 12px;
        background: white;
        transition: border-color 0.2s;
    }
    .field select:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 3px var(--primary-light);
    }
}

/* Header */
header {
    text-align: center;
    padding: 16px 0 20px;
}
header h1 { font-size: 1.6rem; color: var(--primary); }
@media (min-width: 768px) { header h1 { font-size: 2rem; } }
.subtitle { color: var(--muted); font-size: 0.85rem; }
@media (min-width: 768px) { .subtitle { font-size: 0.95rem; } }

/* Controls */
.controls {
    background: var(--card);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}
@media (min-width: 768px) { .controls { padding: 20px; margin-bottom: 20px; } }

.row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
}
@media (min-width: 600px) {
    .row { flex-direction: row; flex-wrap: wrap; gap: 12px; }
}

.field { width: 100%; }
@media (min-width: 600px) { .field { flex: 1; min-width: 140px; } }

.field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.field select, .field input {
    width: 100%;
    padding: 10px 12px;
    font-size: 0.95rem;
}
.field select {
    background: white;
}
.field input {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.2s;
}
.field select:focus, .field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
@media (min-width: 600px) { .btn-primary { width: auto; padding: 12px 32px; } }

.btn-check {
    background: var(--success);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 36px;
}
.btn-check:hover { background: #00a381; }
.btn-check:disabled { opacity: 0.5; cursor: not-allowed; }

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 10px;
    cursor: pointer;
}
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }

/* Badge */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: 8px;
    white-space: nowrap;
}
.badge.cached { background: #dfe6e9; color: #636e72; }
.badge.fresh { background: #55efc4; color: #00b894; }

/* Loading */
#loading {
    text-align: center;
    padding: 40px 16px;
    color: var(--muted);
}
.spinner {
    width: 36px; height: 36px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Exercises card */
#exercises {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
@media (min-width: 768px) { #exercises { padding: 20px; margin-bottom: 20px; } }

.exercise-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}
/* exercise-header остаётся column на всех экранах */
.exercise-header h2 { font-size: 1.15rem; color: var(--text); }
.meta { font-size: 0.8rem; color: var(--muted); }

/* Exercise card */
.exercise-card {
    background: var(--bg);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 10px;
    border-left: 4px solid var(--primary);
    word-break: break-word;
    overflow-wrap: break-word;
    transition: border-color 0.3s;
}
@media (min-width: 768px) { .exercise-card { padding: 16px; margin-bottom: 12px; } }
.exercise-card.correct { border-left-color: var(--success); }
.exercise-card.wrong { border-left-color: var(--danger); }

.exercise-card .question {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
}
.exercise-card .options {
    margin: 8px 0;
    padding-left: 18px;
    list-style: none;
}
.exercise-card .options li {
    margin-bottom: 6px;
    padding: 4px 0;
    font-size: 0.92rem;
}
.exercise-card .options li label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}
.exercise-card .options li label:hover { background: var(--primary-light); }
.exercise-card .options li input[type="radio"] { width: 18px; height: 18px; cursor: pointer; }

/* Answer input */
.answer-input {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 8px;
    transition: border-color 0.2s;
}
.answer-input:focus { outline: none; border-color: var(--primary); }

/* Answer row (input + button) */
.answer-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-top: 8px;
}
.answer-row .answer-input { flex: 1; margin-top: 0; }

/* Result feedback */
.answer-result {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.88rem;
    margin-top: 8px;
    font-weight: 500;
    word-break: break-word;
}
.answer-result.correct {
    background: #e8f5e9;
    color: #2e7d32;
}
.answer-result.wrong {
    background: #ffebee;
    color: #c62828;
}

.exercise-card .explanation {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 6px;
    font-style: italic;
    line-height: 1.4;
}
.exercise-card .hint {
    font-size: 0.82rem;
    color: var(--primary);
    margin-top: 4px;
}

/* Score bar */
.score-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}
.score-fill {
    height: 8px;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.5s ease;
}

footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--muted);
    padding: 16px 0 24px;
}

/* Touch-friendly */
@media (max-width: 600px) {
    .field select, .field input, .btn-primary, .btn-check { min-height: 44px; }
}

.error-toast {
    background: var(--danger);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 12px;
    animation: fadeIn 0.3s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.hint-label {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--muted);
    display: block;
}

.task-topic {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 0.3rem;
}

.task-desc {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.5rem;
    line-height: 1.5;
}

.hidden { display: none !important; }

/* Topics Section */
.topics-section {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}
@media (min-width: 768px) { .topics-section { padding: 20px; margin-bottom: 20px; } }

.topics-header { margin-bottom: 12px; }
.topics-header h3 { font-size: 1rem; color: var(--text); }

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

.topic-group { margin-bottom: 4px; }
.topic-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

.topic-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 2px;
}
.topic-item:hover { background: var(--primary-light); }
.topic-item input[type="radio"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}
.topic-item input[type="radio"]:checked + .topic-name {
    font-weight: 700;
    color: var(--primary);
}
.topic-name {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.3;
}
.topic-progress {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    min-width: 80px;
}
.progress-bar {
    width: 50px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.5s ease;
}
.progress-text {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    min-width: 30px;
    text-align: right;
}

/* Убираем мобильный медиа-запрос — вёрстка как на ПК */

/* Theory button */
.theory-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
    line-height: 1;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    opacity: 0.6;
}
.topic-item:hover .theory-btn {
    opacity: 1;
    animation: theoryPulse 1.5s ease-in-out infinite;
}
@keyframes theoryPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* Theory Modal */
.theory-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    animation: fadeIn 0.2s;
}
.theory-modal-content {
    background: var(--card);
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    max-width: 600px;
    margin: 0 auto;
    overflow-y: auto;
    padding: 16px;
}
.theory-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}
.theory-modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    flex: 1;
    padding-right: 8px;
}
.theory-close-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
    line-height: 1;
}
.theory-close-btn:hover { color: var(--text); }
.theory-modal-body {
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text);
}
.theory-modal-body strong {
    color: var(--primary);
}

/* Theory tables */
.theory-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.88rem;
}
.theory-table th {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
    padding: 8px 10px;
    text-align: left;
    border: 1px solid var(--border);
}
.theory-table td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    vertical-align: top;
}
.theory-table tr:nth-child(even) td {
    background: #fafafa;
}
.theory-modal-body p {
    margin-bottom: 8px;
    line-height: 1.6;
}

/* Auth */
.btn-small {
    background: none;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-small:hover { background: var(--primary-light); }
#userBadge { font-size: 0.85rem; font-weight: 600; color: var(--primary); }

.auth-modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000; display: flex;
    align-items: center; justify-content: center;
}
.auth-modal-content {
    background: var(--card);
    border-radius: var(--radius);
    width: 100%; max-width: 400px;
    padding: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.auth-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.auth-modal-title { font-size: 1.1rem; font-weight: 700; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-field label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.auth-field input, .auth-field select {
    width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: 8px; font-size: 0.95rem;
}
.auth-error { color: var(--danger); font-size: 0.85rem; padding: 8px; background: #ffebee; border-radius: 6px; }
.auth-success { text-align: center; padding: 20px; font-size: 1rem; font-weight: 600; color: var(--success); }

.auth-tabs { display: flex; gap: 0; margin-bottom: 4px; }
.auth-tab {
    flex: 1; padding: 8px; border: 1px solid var(--border);
    background: var(--bg); cursor: pointer; font-size: 0.85rem; font-weight: 600;
    transition: all 0.2s;
}
.auth-tab:first-child { border-radius: 6px 0 0 6px; }
.auth-tab:last-child { border-radius: 0 6px 6px 0; }
.auth-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Profile */
.profile-body { font-size: 0.9rem; line-height: 1.6; }
.profile-info p { margin-bottom: 4px; }
.students-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.students-table th { background: var(--primary-light); padding: 6px 8px; text-align: left; border: 1px solid var(--border); }
.students-table td { padding: 6px 8px; border: 1px solid var(--border); }
.muted { color: var(--muted); font-style: italic; font-size: 0.85rem; }

.btn-edit {
    background: none; border: none; font-size: 0.8rem; cursor: pointer;
    color: var(--muted); padding: 2px 6px; border-radius: 4px;
    transition: all 0.2s;
}
.btn-edit:hover { background: var(--primary-light); color: var(--primary); }

.tariff-info { font-size: 0.9rem; }
.tariff-info ul { padding-left: 16px; margin: 4px 0; }
.tariff-info li { margin-bottom: 2px; }

.stat-card {
    background: var(--primary-light); padding: 8px 12px; border-radius: 8px;
    font-size: 0.82rem; min-width: 80px; text-align: center;
}
