* { box-sizing: border-box; }

:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --success: #159447;
    --danger: #dc3545;
    --border: #e5e7eb;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, #eef2ff, var(--bg));
}

.app {
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
    padding: 38px 0 24px;
}

.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(30px, 5vw, 48px); line-height: 1.05; }
h2 { font-size: 26px; margin-bottom: 22px; }
.subtitle { color: var(--muted); font-size: 17px; }

.badge {
    display: grid;
    place-items: center;
    width: 82px;
    height: 82px;
    flex: 0 0 auto;
    border-radius: 24px;
    background: var(--primary);
    color: #fff;
    font-size: 46px;
    font-weight: 800;
    box-shadow: 0 15px 35px rgba(79, 70, 229, .25);
}

.panel {
    padding: 30px;
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 24px;
    background: rgba(255,255,255,.92);
    box-shadow: 0 18px 50px rgba(31, 41, 55, .08);
}

.settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 20px;
    margin-bottom: 24px;
    align-items: start;
}

.setting-item--full {
    grid-column: 1 / -1;
}

label span,
.field-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.field-hint {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.field-meta {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
}

/* Multi-select dropdown for tables */
.multi-select {
    position: relative;
}

.multi-select-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 54px;
    padding: 0 16px;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
    font-size: 17px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: border-color .15s;
}

.multi-select-toggle:hover,
.multi-select.is-open .multi-select-toggle {
    border-color: var(--primary);
}

.multi-select-toggle .chevron {
    color: var(--muted);
    font-size: 14px;
    transition: transform .15s;
}

.multi-select.is-open .chevron {
    transform: rotate(180deg);
}

.multi-select-dropdown {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 16px 40px rgba(31, 41, 55, .12);
}

.multi-select-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.link-btn {
    border: 0;
    background: none;
    padding: 0;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}

.link-btn:hover {
    text-decoration: underline;
}

.table-chips {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.table-chip {
    height: 44px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    transition: .15s;
}

.table-chip:hover {
    border-color: #c7d2fe;
    background: #eef2ff;
}

.table-chip.is-selected {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

select, input {
    width: 100%;
    height: 54px;
    padding: 0 16px;
    border: 2px solid var(--border);
    border-radius: 14px;
    outline: none;
    background: #fff;
    color: var(--text);
    font-size: 17px;
}

select:focus, input:focus { border-color: var(--primary); }

.primary-btn {
    min-height: 54px;
    padding: 0 24px;
    border: 0;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-size: 17px;
    font-weight: 800;
    transition: .2s;
}

.primary-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.primary-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

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

.stats > div, .result-grid > div {
    padding: 15px;
    border-radius: 16px;
    background: #f8fafc;
}

.stats span, .result-grid span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 13px;
}

.stats strong, .result-grid strong { font-size: 21px; }

.progress-bar {
    height: 9px;
    margin: 20px 0 30px;
    overflow: hidden;
    border-radius: 99px;
    background: #e5e7eb;
}

#progressFill {
    width: 0;
    height: 100%;
    background: var(--primary);
    transition: width .25s;
}

.question-card {
    text-align: center;
    padding: 25px 10px 10px;
}

.question {
    margin-bottom: 30px;
    font-size: clamp(52px, 10vw, 88px);
    font-weight: 900;
    letter-spacing: -.04em;
}

#answerForm {
    display: flex;
    max-width: 520px;
    margin: auto;
    gap: 12px;
}

#answer { text-align: center; font-size: 24px; font-weight: 700; }

.feedback {
    min-height: 28px;
    margin: 17px 0 0;
    font-size: 17px;
    font-weight: 800;
}

.feedback.correct { color: var(--success); }
.feedback.wrong { color: var(--danger); }

.result-panel { text-align: center; }
.result-icon { font-size: 64px; margin-bottom: 10px; }
.result-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 28px 0;
    text-align: left;
}

.mistakes-block {
    margin: 0 0 28px;
    text-align: left;
    border: 1px solid #fecaca;
    border-radius: 16px;
    background: #fef2f2;
    overflow: hidden;
}

.mistakes-title {
    margin: 0;
    padding: 14px 18px;
    border-bottom: 1px solid #fecaca;
    color: var(--danger);
    font-size: 16px;
    font-weight: 800;
}

.mistakes-list {
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: 280px;
    overflow-y: auto;
}

.mistake-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    border-bottom: 1px solid #fee2e2;
    font-size: 16px;
}

.mistake-item:last-child {
    border-bottom: 0;
}

.mistake-expr {
    font-weight: 800;
    letter-spacing: -.02em;
}

.mistake-answers {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    font-weight: 700;
}

.mistake-user {
    color: var(--danger);
    text-decoration: line-through;
}

.mistake-arrow {
    color: var(--muted);
    font-weight: 600;
}

.mistake-correct {
    color: var(--success);
}

.hidden { display: none !important; }

footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 4px 0;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 680px) {
    .app { padding-top: 24px; }
    .hero { align-items: flex-start; }
    .badge { width: 60px; height: 60px; border-radius: 18px; font-size: 34px; }
    .panel { padding: 20px; border-radius: 20px; }
    .settings {
        grid-template-columns: 1fr;
    }
    .setting-item--full {
        grid-column: 1;
    }
    .stats, .result-grid { grid-template-columns: 1fr 1fr; }
    #answerForm { flex-direction: column; }
    .primary-btn { width: 100%; }
    .question { font-size: 56px; }
    footer { flex-direction: column; }
    .table-chips { grid-template-columns: repeat(5, 1fr); }
}
