/* ═══════════════════════════════════════════════════════════════════
   ТРЕНАЖЕРИ · ЗІН-ДИЗАЙН-СИСТЕМА (trainers/shared/trainer.css)
   Сторінки тренажерів підключають ds/tokens.css + ds/base.css + ds/components.css
   (html.ui-z, тема — data-theme, як у застосунку) і цей файл — лише для того,
   чого в компонентах немає. Правила ті самі, що й у ds/*.css (scripts/check_ds.js):
   усе під .ui-z, лише класи, кольори — тільки токени, без !important.
   Помаранчевий — ЛИШЕ головна дія (Почати / Далі / Продовжити).
   ═══════════════════════════════════════════════════════════════════ */

/* ---------- Каркас ---------- */
.ui-z body { margin: 0; }
html.ui-z { scroll-padding-top: 76px; }
.ui-z .app-container {
    box-sizing: border-box; max-width: 640px; margin: 0 auto;
    padding: 0 calc(var(--gutter) + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(var(--gutter) + env(safe-area-inset-left));
}
.ui-z .main-content { display: block; }
.ui-z .screen { display: none; }
.ui-z .screen.active { display: flex; flex-direction: column; gap: var(--s-4); animation: tr-in var(--dur) var(--ease); }
@keyframes tr-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Шапка (як .z-testbar у тесті застосунку) ---------- */
.ui-z .tr-bar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: var(--s-2);
    box-sizing: border-box; min-height: 60px; margin: 0 calc(-1 * var(--gutter)) var(--s-3);
    padding: calc(8px + env(safe-area-inset-top)) var(--gutter) 8px;
    background: var(--paper); border-bottom: var(--bw-s) solid var(--hairline);
}
.ui-z .tr-back { text-decoration: none; }
.ui-z .tr-bar__title { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ui-z .trainer-title {
    margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
    font-size: 15px; line-height: 1.2; font-weight: var(--fw-black); color: var(--ink);
}
.ui-z .tr-bar__sub { font-size: 12px; line-height: 1.25; font-weight: var(--fw-strong); color: var(--muted); }
.ui-z .tr-streak { flex: none; min-height: 32px; padding: 3px 10px; font-weight: var(--fw-black); }
.ui-z .tr-streak svg { width: 16px; height: 16px; }

/* ---------- Прогрес раунду ---------- */
.ui-z .progress-container { display: flex; align-items: center; gap: var(--s-3); margin: 0 0 var(--s-4); }
.ui-z .progress-container .z-progress { flex: 1; }
.ui-z .progress-text {
    flex: none; font-size: var(--fs-small); font-weight: var(--fw-strong); color: var(--muted);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------- Старт ---------- */
.ui-z .welcome-screen { display: flex; flex-direction: column; gap: var(--s-4); }
.ui-z .welcome-title { margin: 0; font-size: var(--fs-h1); line-height: 1.15; font-weight: var(--fw-black); letter-spacing: -.01em; color: var(--ink); }
.ui-z .welcome-description { margin: 0; font-size: var(--fs-body); line-height: 1.5; color: var(--ink-2); }
.ui-z .formula-preview { display: grid; gap: var(--s-2); }
.ui-z .theory-card {
    box-sizing: border-box; padding: 12px 14px;
    border: var(--bw-s) solid var(--line); border-radius: var(--r-md); background: var(--surface-2);
}
.ui-z .formula-main { font-size: 16px; line-height: 1.5; font-weight: var(--fw-strong); color: var(--ink); overflow-x: auto; overflow-y: hidden; padding-block: 4px; }
.ui-z .formula-note { margin-top: 4px; font-size: var(--fs-small); line-height: 1.45; color: var(--muted); }

/* ---------- Питання ---------- */
.ui-z .question-container { display: flex; flex-direction: column; gap: var(--s-3); }
.ui-z .difficulty-indicator { display: flex; align-items: center; gap: 6px; }
.ui-z .difficulty-indicator::before {
    content: 'Складність'; margin-right: 4px;
    font-size: var(--fs-eyebrow); font-weight: var(--fw-black); letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.ui-z .difficulty-dot {
    box-sizing: border-box; width: 12px; height: 12px;
    border: var(--bw-s) solid var(--line); border-radius: 50%; background: var(--surface);
}
.ui-z .difficulty-dot.active { background: var(--sage); }
.ui-z .question-card {
    box-sizing: border-box; padding: var(--s-4) var(--s-4) var(--s-5);
    border: var(--bw) solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-s);
}
.ui-z .question-number {
    margin: 0 0 var(--s-2); font-size: var(--fs-eyebrow); line-height: 1.3; font-weight: var(--fw-black);
    letter-spacing: .12em; text-transform: uppercase; color: var(--sage-ink);
}
.ui-z .question-text { font-size: 17px; line-height: 1.5; font-weight: var(--fw-strong); color: var(--ink); overflow-wrap: anywhere; }
.ui-z .question-text:focus { outline: none; }
.ui-z .question-text:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: var(--r-xs); }
.ui-z .question-text .katex { font-size: 1.12em; }
.ui-z .question-figure {
    display: flex; justify-content: center; margin-top: var(--s-3); padding: var(--s-3);
    border: var(--bw-s) solid var(--hairline); border-radius: var(--r-md); background: var(--figure-bg); color: var(--figure-ink);
}
.ui-z .question-figure:empty { display: none; }
.ui-z .question-figure svg { max-width: 100%; height: auto; max-height: 260px; }

/* Варіанти — .z-option з ds/components.css; тут лише сітка й KaTeX */
.ui-z .answers-container { display: grid; gap: var(--s-3); }
.ui-z .answers-container .z-option__text { font-size: 16px; }
.ui-z .answers-container .z-option__text .katex { font-size: 1.15em; }

/* Відгук після відповіді: колір + іконка + текст (не лише колір) */
.ui-z .feedback-container {
    display: none; box-sizing: border-box; padding: 12px 14px;
    border: var(--bw-s) solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--sh-s);
}
.ui-z .feedback-container.show { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s-3); align-items: start; }
.ui-z .feedback-container.correct { background: var(--sage-tint); }
.ui-z .feedback-container.incorrect { background: var(--red-tint); }
.ui-z .feedback-icon { grid-row: span 2; display: inline-flex; padding-top: 1px; }
.ui-z .feedback-icon svg { width: 24px; height: 24px; stroke-width: 2.6; }
.ui-z .feedback-container.correct .feedback-icon { color: var(--sage-ink); }
.ui-z .feedback-container.incorrect .feedback-icon { color: var(--red-ink); }
.ui-z .feedback-text { font-size: var(--fs-body); font-weight: var(--fw-black); color: var(--ink); }
.ui-z .feedback-explanation { font-size: var(--fs-body); line-height: 1.5; color: var(--ink-2); overflow-wrap: anywhere; }
.ui-z .feedback-explanation:empty { display: none; }

.ui-z .help-panel { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ui-z .btn-next { margin-top: var(--s-2); }

/* ---------- Результат ---------- */
.ui-z .results-content {
    display: flex; flex-direction: column; gap: var(--s-4); box-sizing: border-box; padding: var(--s-5) var(--s-4);
    border: var(--bw) solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-s);
}
.ui-z .results-title { margin: 0; font-size: var(--fs-h1); line-height: 1.15; font-weight: var(--fw-black); color: var(--ink); }
.ui-z .results-title:focus { outline: none; }
.ui-z .results-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-2); }
.ui-z .results-stats .stat-card {
    display: flex; flex-direction: column; gap: 2px; box-sizing: border-box; min-width: 0; padding: 10px 8px;
    border: var(--bw-s) solid var(--line); border-radius: var(--r-md); background: var(--surface-2);
}
.ui-z .results-stats .stat-card:first-child { background: var(--sage-tint); }
/* Три плитки в ряд — Onest 900 з табличними цифрами (не Unbounded: широкий, у третині ширини телефона він дрібнішав до 18px).
   Розмір — від ширини плитки (cqi): «100%» (найширше реальне значення) = 2,9em, тож 34cqi завжди влазить; не більше 26px.
   Без підтримки container queries (iOS 15) — 20px, на вужчих за 360px — 18px (нижче). */
.ui-z .results-stats .stat-card { container-type: inline-size; }
.ui-z .results-stats .stat-value {
    order: 2; font-family: var(--font-ui); font-size: 20px; font-size: min(26px, 34cqi); line-height: 1.05; font-weight: var(--fw-black);
    letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ui-z .results-stats .stat-label {
    order: 1; max-width: 100%; overflow-wrap: anywhere;
    font-size: var(--fs-eyebrow); line-height: 1.3; font-weight: var(--fw-black);
    letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.ui-z .ai-feedback {
    display: flex; gap: var(--s-3); align-items: flex-start; padding: 12px 14px;
    border: var(--bw-s) solid var(--line); border-radius: var(--r-md); background: var(--brand-tint);
}
.ui-z .ai-icon { flex: none; display: inline-flex; color: var(--brand-ink); }
.ui-z .ai-icon svg { width: 22px; height: 22px; }
.ui-z .ai-text { font-size: var(--fs-body); line-height: 1.5; color: var(--ink); }
.ui-z .weak-topics h3 {
    margin: 0 0 var(--s-2); font-size: var(--fs-eyebrow); line-height: 1.3; font-weight: var(--fw-black);
    letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.ui-z .weak-list { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ui-z .weak-tag {
    display: inline-flex; align-items: center; padding: 4px 10px;
    border: var(--bw-s) solid var(--line); border-radius: var(--r-pill);
    background: var(--red-tint); color: var(--red-ink); font-size: var(--fs-small); font-weight: var(--fw-strong);
}
.ui-z .results-actions { display: flex; flex-direction: column; gap: var(--s-3); }

/* ---------- Правила ---------- */
.ui-z .formulas-content { display: flex; flex-direction: column; gap: var(--s-4); }
.ui-z .formulas-content h2 { margin: 0; font-size: var(--fs-h1); line-height: 1.15; font-weight: var(--fw-black); color: var(--ink); }
.ui-z .formula-category { display: flex; flex-direction: column; gap: var(--s-2); }
.ui-z .formula-category h3 {
    margin: 0; font-size: var(--fs-eyebrow); line-height: 1.3; font-weight: var(--fw-black);
    letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}

/* ---------- Вікно «Правило» (role=dialog) ---------- */
.ui-z .ai-modal.hidden { display: none; }
.ui-z .ai-modal {
    position: fixed; inset: 0; z-index: var(--z-modal);
    display: flex; align-items: flex-end; justify-content: center;
    padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom)); background: var(--scrim);
}
@media (min-width: 600px) { .ui-z .ai-modal { align-items: center; } }
.ui-z .ai-modal-content {
    box-sizing: border-box; width: 100%; max-width: 560px; max-height: 80vh; overflow: auto;
    border: var(--bw) solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-l);
}
.ui-z .ai-modal-header {
    position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
    padding: 10px 10px 10px 16px; background: var(--surface); border-bottom: var(--bw-s) solid var(--hairline);
}
.ui-z .ai-modal-title { display: flex; align-items: center; gap: var(--s-2); margin: 0; font-size: var(--fs-h3); font-weight: var(--fw-black); color: var(--ink); }
.ui-z .ai-modal-title svg { width: 20px; height: 20px; color: var(--sage-ink); }
.ui-z .ai-modal-body { padding: var(--s-4); }
.ui-z .ai-loading { display: none; align-items: center; gap: var(--s-2); color: var(--muted); }
.ui-z .ai-loading-spinner {
    width: 18px; height: 18px; border: var(--bw-s) solid var(--hairline); border-top-color: var(--sage); border-radius: 50%;
    animation: tr-spin .8s linear infinite;
}
@keyframes tr-spin { to { transform: rotate(360deg); } }
.ui-z .ai-response { font-size: var(--fs-body); line-height: 1.55; color: var(--ink); }
.ui-z .tr-rule { padding: 10px 0; border-bottom: var(--bw-s) solid var(--hairline); }
.ui-z .tr-rule:last-child { border-bottom: 0; }
.ui-z .tr-rule__formula { margin: 0; font-size: 16px; line-height: 1.5; font-weight: var(--fw-strong); overflow-x: auto; overflow-y: hidden; padding-block: 4px; }
.ui-z .tr-rule__name { margin: 2px 0 0; font-size: var(--fs-small); color: var(--muted); }

/* ---------- Підпис збереження (sync.js + engine.showSaveNote) ---------- */
.ui-z .zin-save-note { margin: 0; text-align: center; font-size: var(--fs-small); line-height: 1.45; color: var(--muted); }

/* ---------- Реакції на відповідь ---------- */
.ui-z .animate-shake { animation: tr-shake .35s; }
@keyframes tr-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.ui-z .animate-pulse { animation: tr-pulse .4s; }
@keyframes tr-pulse { 50% { transform: scale(1.02); } }

@media (prefers-reduced-motion: reduce) {
    .ui-z .screen.active,
    .ui-z .animate-shake,
    .ui-z .animate-pulse,
    .ui-z .ai-loading-spinner { animation: none; }
}

/* ---------- Вузькі екрани ---------- */
@media (max-width: 359px) {
    .ui-z .question-text { font-size: 17px; }
    .ui-z .results-stats .stat-value { font-size: 18px; font-size: min(26px, 34cqi); }   /* без cqi — 18px, щоб «100%» влізло в 58px на 320 */
    .ui-z .results-stats .stat-label { letter-spacing: 0; }   /* «ТОЧНІСТЬ» 56,7px в один рядок (з .04em — 60px, ламалося на «ТОЧНІСТ/Ь») */
    .ui-z .difficulty-indicator::before { content: none; }
}
