/* ============================================
   QTest дизайн жүйесі
   Палитра: аспан көгі (сенім, білім) + күн алтыны (жетістік, оқушы табысы)
   ============================================ */
:root {
    --ink: #142338;
    --ink-soft: #3C4A61;
    --sky: #0B93B0;
    --sky-dark: #076E85;
    --sky-tint: #E4F5F8;
    --sun: #F5AF19;
    --sun-tint: #FFF3D9;
    --success: #1F9D66;
    --success-tint: #DDF3E7;
    --danger: #E15554;
    --danger-tint: #FCE4E4;
    --paper: #F5F7FA;
    --card: #FFFFFF;
    --border: #E3E8EF;
    --muted: #64748B;

    --font-display: 'Unbounded', 'Manrope', sans-serif;
    --font-body: 'Manrope', -apple-system, "Segoe UI", sans-serif;

    --shadow-sm: 0 1px 2px rgba(20, 35, 56, 0.06);
    --shadow-md: 0 8px 24px rgba(20, 35, 56, 0.08);
    --shadow-lift: 0 12px 28px rgba(11, 147, 176, 0.18);
    --radius: 14px;
    --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--ink);
}
h1 { font-size: clamp(28px, 4vw, 38px); margin: 0 0 12px; }
h2 { font-size: 22px; margin: 32px 0 14px; }
h3 { font-size: 17px; margin: 0; }

a { color: var(--sky-dark); }

::selection { background: var(--sun-tint); color: var(--ink); }

:focus-visible {
    outline: 2px solid var(--sky);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------- Header ---------- */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 32px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.logo {
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 800;
    color: var(--ink);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.02em;
}
.logo::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: conic-gradient(from 180deg, var(--sun), var(--sky), var(--sun));
    box-shadow: 0 0 0 3px var(--sky-tint);
}

.site-header nav { display: flex; align-items: center; gap: 18px; }
.site-header nav a {
    text-decoration: none;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 14px;
    transition: color .18s var(--ease);
}
.site-header nav a:hover { color: var(--sky-dark); }
.user-name { color: var(--muted); font-size: 13px; font-weight: 500; }

.container { max-width: 960px; margin: 0 auto; padding: 40px 20px 64px; animation: fadeInUp .5s var(--ease) both; }
.container:has(.form-page) {
    min-height: calc(100vh - 62px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 24px;
    padding-bottom: 24px;
}

/* ---------- Hero ---------- */
.hero {
    position: relative;
    text-align: center;
    padding: 72px 24px;
    border-radius: 24px;
    background:
        radial-gradient(120% 140% at 15% -10%, var(--sky-tint) 0%, transparent 55%),
        radial-gradient(100% 120% at 90% 0%, var(--sun-tint) 0%, transparent 50%),
        var(--card);
    border: 1px solid var(--border);
    overflow: hidden;
}
.hero::before {
    content: "";
    position: absolute;
    top: -60px;
    right: -60px;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--sun) 0deg, transparent 60deg, transparent 300deg, var(--sun) 360deg);
    opacity: .35;
    filter: blur(1px);
    animation: spin 22s linear infinite;
}
.hero h1 { position: relative; }
.hero p { position: relative; color: var(--ink-soft); font-size: 18px; margin: 0 auto 28px; max-width: 520px; }
.hero-actions { position: relative; display: flex; gap: 12px; justify-content: center; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 11px 20px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 14.5px;
    transition: transform .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease), border-color .16s var(--ease);
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: #CBD5E1; }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--sky); color: #fff; border-color: var(--sky); }
.btn-primary:hover { background: var(--sky-dark); border-color: var(--sky-dark); box-shadow: var(--shadow-lift); }

.btn-link { background: none; border: none; color: var(--danger); cursor: pointer; text-decoration: underline; padding: 0; font-weight: 600; font-size: 13px; }
.btn-link:hover { opacity: .75; }

/* ---------- Forms ---------- */
.form-page { display: flex; flex-direction: column; align-items: center; text-align: center; animation: fadeInUp .5s var(--ease) both; }
.form-page h1 { margin-bottom: 6px; }
.form-page .card-form { text-align: left; }

.card-form {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 28px;
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: box-shadow .2s var(--ease);
}
.card-form:hover { box-shadow: var(--shadow-md); }

.card-form label { font-weight: 700; margin-top: 12px; font-size: 13.5px; color: var(--ink-soft); }

.card-form input,
.card-form select,
.card-form textarea {
    padding: 11px 12px;
    border: 1.5px solid var(--border);
    border-radius: 9px;
    font-size: 15px;
    width: 100%;
    font-family: var(--font-body);
    color: var(--ink);
    background: #fff;
    transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.card-form input:focus,
.card-form select:focus,
.card-form textarea:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 4px var(--sky-tint);
}
.card-form textarea { min-height: 90px; resize: vertical; }
.card-form button { margin-top: 20px; }

.radio-row { display: flex; gap: 22px; font-weight: 400; }
.radio-row label { font-weight: 600; margin: 0; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.radio-row input[type="radio"] { accent-color: var(--sky); width: 16px; height: 16px; }

.hint { color: var(--muted); font-size: 13.5px; }
.error {
    color: var(--danger);
    font-weight: 700;
    background: var(--danger-tint);
    border: 1px solid #F5C6C5;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    animation: shake .35s var(--ease);
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.autocomplete-results {
    border: 1px solid var(--border);
    border-radius: 9px;
    max-height: 180px;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}
.autocomplete-item { padding: 9px 12px; cursor: pointer; font-size: 14px; transition: background .12s; }
.autocomplete-item:hover { background: var(--sky-tint); }

/* ---------- Page layout ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }

/* ---------- Tables ---------- */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 16px 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; }
.data-table th { background: var(--sky-tint); color: var(--sky-dark); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.data-table tbody tr { transition: background .14s var(--ease); }
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--paper); color: var(--muted); }
.badge-green { background: var(--success-tint); color: var(--success); }
.badge-red { background: var(--danger-tint); color: var(--danger); }
.badge-sky { background: var(--sky-tint); color: var(--sky-dark); }

.my-directions { display: flex; gap: 8px; flex-wrap: wrap; }

.checkbox-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.checkbox-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all .16s var(--ease);
}
.checkbox-pill:has(input:checked) {
    background: var(--sky-tint);
    border-color: var(--sky);
    color: var(--sky-dark);
}
.checkbox-pill input { accent-color: var(--sky); width: 15px; height: 15px; }

/* ---------- Пән карточкалары (test.kz стиліндегі иконка-тор) ---------- */
.card-form:has(.subject-tile-grid) { max-width: 720px; }

.subject-tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 12px;
    margin-top: 8px;
}
.subject-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    aspect-ratio: 1 / 1;
    border-radius: 16px;
    cursor: pointer;
    padding: 10px 6px;
    text-align: center;
    background:
        radial-gradient(120% 140% at 20% 0%, rgba(255,255,255,0.14), transparent 60%),
        linear-gradient(155deg, var(--ink) 0%, var(--sky-dark) 100%);
    box-shadow: inset 0 0 0 2px transparent;
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.subject-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.subject-tile input { position: absolute; opacity: 0; pointer-events: none; }
.subject-tile:has(input:checked) {
    box-shadow: inset 0 0 0 3px var(--sun), var(--shadow-lift);
    transform: translateY(-3px);
}
.subject-tile-icon { font-size: 28px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.subject-tile-label {
    font-size: 11.5px;
    font-weight: 700;
    color: #fff;
    line-height: 1.25;
}

/* ---------- Stat cards ---------- */
.stats-cards { display: flex; gap: 16px; margin: 16px 0; }
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow-sm);
    transition: transform .18s var(--ease), box-shadow .18s var(--ease);
    animation: fadeInUp .45s var(--ease) both;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card:nth-child(2) { animation-delay: .06s; }
.stat-num { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--sky-dark); }
.stat-card span:last-child { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 4px; }

.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Question lists ---------- */
.question-list { padding-left: 0; margin: 0; }
.question-list li {
    margin-bottom: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    list-style: none;
    transition: box-shadow .16s var(--ease), transform .16s var(--ease);
}
.question-list li:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.topic-tag {
    display: inline-block;
    background: var(--sun-tint);
    color: #9A6B00;
    border-radius: 999px;
    padding: 3px 11px;
    font-size: 11.5px;
    font-weight: 700;
    margin-left: 8px;
}
.opts { color: var(--muted); font-size: 13.5px; margin-top: 8px; line-height: 1.6; }

.question-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    animation: fadeInUp .4s var(--ease) both;
    transition: box-shadow .16s var(--ease);
}
.question-card:hover { box-shadow: var(--shadow-sm); }
.question-card label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 14.5px;
    transition: background .14s var(--ease);
}
.question-card label:hover { background: var(--sky-tint); }
.question-card input[type="radio"] { accent-color: var(--sky); width: 17px; height: 17px; }

.result-card.is-correct { border-left: 4px solid var(--success); }
.result-card.is-wrong { border-left: 4px solid var(--danger); }

.opt-row { padding: 8px 10px; border-radius: 8px; margin: 5px 0; font-size: 14px; transition: transform .12s var(--ease); }
.opt-row.correct-answer { background: var(--success-tint); }
.opt-row.wrong-selected { background: var(--danger-tint); }
.opt-row.chosen-correct { background: var(--success-tint); font-weight: 700; }
.tag-correct, .tag-chosen {
    font-size: 10.5px;
    font-weight: 700;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(20, 35, 56, 0.08);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.topic-summary {
    background: var(--sun-tint);
    border: 1px solid #F3DFA6;
    border-radius: var(--radius);
    padding: 16px 18px;
    margin: 18px 0;
}
.topic-summary p { margin: 6px 0; }

.explanation-box {
    margin-top: 10px;
    background: var(--sky-tint);
    border: 1px dashed #9FD4E0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13.5px;
    color: var(--ink-soft);
    line-height: 1.55;
}

/* ---------- ИИ көмекші: төменнен ашылатын попап ---------- */
#ai-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 13px 20px;
    border-radius: 999px;
    border: none;
    background: var(--ink);
    color: #fff;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 14.5px;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(20, 35, 56, 0.28);
    transition: transform .18s var(--ease), opacity .18s var(--ease), box-shadow .18s var(--ease);
    animation: fabPulse 2.4s ease-in-out infinite;
}
#ai-fab:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 30px rgba(20, 35, 56, 0.34); }
#ai-fab.hidden-fab { opacity: 0; pointer-events: none; transform: translateY(10px); }
.ai-fab-icon { color: var(--sun); font-size: 16px; }

@keyframes fabPulse {
    0%, 100% { box-shadow: 0 10px 26px rgba(20, 35, 56, 0.28); }
    50% { box-shadow: 0 10px 26px rgba(11, 147, 176, 0.38); }
}

.ai-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    background: var(--card);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -12px 32px rgba(20, 35, 56, 0.16);
    max-width: 640px;
    margin: 0 auto;
    transform: translateY(105%);
    transition: transform .32s var(--ease);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}
.ai-panel.open { transform: translateY(0); }

.ai-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
}
#ai-panel-close {
    border: none;
    background: var(--paper);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--ink-soft);
    transition: background .14s var(--ease);
}
#ai-panel-close:hover { background: var(--sky-tint); }

.ai-panel-body { padding: 18px 20px 26px; overflow-y: auto; }
.ai-panel-body #ai-advice-text {
    margin-top: 14px;
    background: var(--sky-tint);
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 14.5px;
    white-space: pre-line;
    line-height: 1.6;
}

@media (max-width: 600px) {
    .ai-panel { border-radius: 16px 16px 0 0; max-height: 80vh; }
    #ai-fab { right: 16px; bottom: 16px; padding: 12px 16px; }
}

.site-footer { text-align: center; padding: 24px; color: var(--muted); font-size: 12.5px; }

/* ---------- Motion ---------- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    .site-header { flex-direction: column; gap: 10px; padding: 14px 18px; }
    .hero { padding: 48px 18px; }
    .options-grid { grid-template-columns: 1fr; }
    .stats-cards { flex-direction: column; }
}
