/* ============ Змінні та скидання ============ */
:root {
  --bg-1: #f8f2e6;
  --bg-2: #efe5d1;
  --card-bg: #fffdf8;
  --card-border: rgba(120, 90, 40, 0.16);
  --text: #1c1307;
  --text-dim: #1c1307;
  --accent: #d97706;
  --accent-2: #b45309;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 18px;
  /* Горизонтальні відступи сторінки — одна змінна, щоб меню могло
     розтягнутися від краю до краю на вузьких екранах */
  --pad-x: 20px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* hidden має завжди ховати елемент, навіть якщо в класу задано display: grid/flex */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* На вузьких екранах нічого не має вилазити за край */
  overflow-x: hidden;
}

/* Тапи по ігрових елементах не мають виділяти текст і викликати меню iOS */
button, select, input, textarea,
.cell, .nav-tab, .mode-btn, .btn, .fov-word, .scan-word,
.stroop-opt, .num-num, .sacc-dot {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.cell, .nav-tab, .mode-btn, .btn, .fov-word, .scan-word,
.stroop-opt, .num-num {
  user-select: none;
}

body {
  min-height: 100vh;   /* запасний варіант для старих браузерів */
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 15% -10%, rgba(251, 191, 36, 0.45) 0%, transparent 55%),
              radial-gradient(1000px 700px at 110% 110%, rgba(249, 115, 22, 0.28) 0%, transparent 50%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  overflow-x: hidden;
}

/* ============ Фоновий декор ============ */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.4;
}

.blob-1 { width: 420px; height: 420px; background: #fbbf24; top: -120px; left: -100px; }
.blob-2 { width: 380px; height: 380px; background: #f59e0b; bottom: -140px; right: -80px; animation-delay: -6s; }
.blob-3 { width: 260px; height: 260px; background: #f97316; top: 40%; left: 60%; opacity: 0.28; animation-delay: -12s; }


/* ============ Шапка ============ */
.header {
  padding-top: max(20px, env(safe-area-inset-top));
  padding-right: calc(var(--pad-x) + env(safe-area-inset-right));
  padding-bottom: 8px;
  padding-left: calc(var(--pad-x) + env(safe-area-inset-left));
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  /* Контейнер для @container ниже: реальная ширина шапки, а не окна —
     так правило срабатывает и при масштабе A+ (zoom), который media
     queries не видят */
  container-type: inline-size;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 18px rgba(217, 119, 6, 0.4);
  font-size: 1.1rem;
}

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: #241a0e;
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.35);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ============ Панель у шапці: розмір інтерфейсу ============ */
.header-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scale {
  display: flex;
  gap: 4px;
}

.scale button {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  color: #241a0e;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.scale button:hover {
  border-color: rgba(217, 119, 6, 0.45);
}

.scale button:disabled {
  opacity: 0.4;
  cursor: default;
}

.scale button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Перемикач мов: селект того ж розміру, що й кнопки A− / A+ */
.lang select {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #241a0e;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  height: 32px;
  padding: 0 8px;
  max-width: 150px;
  cursor: pointer;
}

.lang select:hover {
  border-color: rgba(217, 119, 6, 0.45);
}

.lang select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============ Навігація між вправами ============ */
.nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.nav-tab {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 10px 20px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
}

.nav-tab:hover {
  color: var(--text);
  border-color: rgba(217, 119, 6, 0.45);
}

.nav-tab.active {
  color: #fffdf8;
  background: linear-gradient(135deg, #3d2b18, #1f160b);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(31, 22, 11, 0.35);
}

/* ============ Основна частина ============ */
.main {
  max-width: 720px;
  margin: 0 auto;
  padding-top: 16px;
  padding-right: calc(var(--pad-x) + env(safe-area-inset-right));
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  padding-left: calc(var(--pad-x) + env(safe-area-inset-left));
  /* Контейнер для правил @container: ловить і вузький екран, і zoom A+ */
  container-type: inline-size;
}

.intro {
  text-align: center;
  margin-bottom: 24px;
}

.intro h1 {
  font-size: clamp(1.9rem, 6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 10px;
}

.subtitle {
  color: var(--text-dim);
  line-height: 1.6;
  max-width: 560px;
  margin: 0 auto 14px;
  font-size: 1rem;
}

.hints {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.hints li {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(120, 90, 40, 0.06);
  border: 1px solid rgba(120, 90, 40, 0.14);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ============ Картка вправи ============ */
.exercise-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 24px 60px rgba(90, 60, 20, 0.16);
}

/* Панель стану */
.stats-bar {
  /* Сітка, а не flex: колонки можуть стискатися вужче за текст,
     інакше на вузькому екрані (або при A+×1.5) рядок вилазить за картку */
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 8px;
  margin-bottom: 18px;
}

.stat {
  min-width: 0;
  text-align: center;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.12);
  border-radius: 14px;
  padding: 10px 6px;
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 4px;
  overflow-wrap: break-word;
}

.stat-value {
  overflow-wrap: break-word;
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-target {
  color: var(--text);
  font-size: 1.7rem;
}

/* Ігрове поле (вправа 1) */
.grid-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(6px, 1.6vw, 12px);
  width: min(100%, 460px);
  aspect-ratio: 1;
}

.cell {
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #ffffff, #fbf6ea);
  border: 1px solid rgba(120, 90, 40, 0.18);
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}

.cell:hover {
  transform: translateY(-2px);
  border-color: rgba(217, 119, 6, 0.55);
  box-shadow: 0 6px 18px rgba(217, 119, 6, 0.25);
}

.cell:active {
  transform: scale(0.96);
}

.cell.correct {
  background: linear-gradient(145deg, #10b981, #059669);
  border-color: rgba(16, 185, 129, 0.6);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  cursor: default;
  animation: pop 0.15s ease;
}

.cell.wrong {
  background: linear-gradient(145deg, #ef4444, #dc2626);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fff;
  animation: shake 0.25s ease;
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ============ Вправа 2: RSVP-читання ============ */
.rsvp-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  overflow: hidden;
}

.rsvp-word {
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  font-weight: 800;
  text-align: center;
  word-break: break-word;
  padding: 0 14px;
  max-width: 100%;
}

.rsvp-word.flash {
  animation: rsvpIn 0.12s ease;
}

/* Рядок піраміди: кілька слів, виділений центр */
.pyramid-line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.45em;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  font-weight: 700;
}

.pyramid-center {
  background: rgba(217, 119, 6, 0.22);
  border-radius: 8px;
  padding: 2px 8px;
  font-weight: 800;
  box-shadow: 0 0 0 1px rgba(217, 119, 6, 0.3);
}

@keyframes rsvpIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rsvp-hint {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* ============ Вправа 3: Сакади ============ */
.sacc-stage {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 24px 18px;
}

.sacc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: var(--sacc-width, 100%);
  margin: 0 auto;
}

.sacc-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(120, 90, 40, 0.18);
  border: 2px solid rgba(120, 90, 40, 0.3);
  transition: background 0.08s ease, transform 0.08s ease, border-color 0.08s ease, box-shadow 0.08s ease;
}

.sacc-dot.active {
  background: var(--accent);
  border-color: var(--accent-2);
  transform: scale(1.15);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.3);
}

/* Перемикач режимів */
.mode-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.mode-btn {
  flex: 0 0 auto;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 8px 20px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.mode-btn:hover {
  color: var(--text);
  border-color: rgba(217, 119, 6, 0.45);
}

.mode-btn.active {
  color: #fffdf8;
  background: linear-gradient(135deg, #3d2b18, #1f160b);
  border-color: transparent;
}

/* Вільне поле */
.sacc-field {
  position: relative;
  height: clamp(180px, 46vh, 260px);
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  overflow: hidden;
}

.sacc-field-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-2);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.3);
  transform: translate(-50%, -50%);
}

/* ============ Вправа 5: Указка-тренування ============ */
.pacer-stage {
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 16px 20px;
  font-size: clamp(1.1rem, 4vw, 1.3rem);
  line-height: 2;
  text-align: left;
}

.pacer-line {
  padding: 2px 10px;
  border-radius: 8px;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.pacer-line.active {
  background: rgba(217, 119, 6, 0.16);
  box-shadow: inset 0 -4px 0 rgba(217, 119, 6, 0.65); /* смуга-указка під рядком */
  font-weight: 700;
}

/* ============ Вправа 5: Сканування (читання по діагоналі) ============ */
.scan-wrap {
  position: relative;
  margin-bottom: 18px;
}

.scan-stage {
  max-height: 300px;
  overflow-y: auto;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 18px 20px;
  font-size: 1.25rem;
  line-height: 2.1;
  text-align: left;
  cursor: default;
}

.scan-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  font-size: 1.15rem;
  color: var(--text-dim);
  background: rgba(255, 253, 248, 0.85);
  z-index: 1;
  pointer-events: none;
}

.scan-word {
  cursor: pointer;
  border-radius: 6px;
  padding: 1px 2px;
  transition: background 0.12s ease;
}

.scan-word:hover {
  background: rgba(217, 119, 6, 0.14);
}

.scan-word.scan-hit {
  background: rgba(22, 163, 74, 0.28);
  font-weight: 700;
  cursor: default;
}

.scan-word.scan-miss {
  background: rgba(220, 38, 38, 0.24);
  animation: scanShake 0.3s ease;
}

@keyframes scanShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

/* ============ Вправа 6: Поле зору ============ */
.fov-target {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.fov-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.55em;
  flex-wrap: nowrap;
  min-height: 90px;
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 20px 14px;
}

.fov-word {
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, transform 0.12s ease;
}

.fov-word.center {
  font-weight: 800;
  background: rgba(217, 119, 6, 0.22);
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.35);
}

.fov-word.hit {
  background: rgba(22, 163, 74, 0.28);
}

.fov-word.miss {
  background: rgba(220, 38, 38, 0.24);
  animation: scanShake 0.3s ease;
}

/* Режим «Поле 2D»: слова навколо центру (3×3) */
.fov-stage.fov-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 12px;
  place-items: center;
  min-height: 220px;
  padding: 24px;
}

.fov-stage.fov-grid .fov-word {
  max-width: 100%;
  text-align: center;
  font-size: clamp(0.72rem, 3.4vw, 1.15rem);
  line-height: 1.25;
}

/* ============ Вправа 7: Числа навколо центру ============ */
.num-stage {
  position: relative;
  height: clamp(240px, 70vw, 340px);
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  overflow: hidden;
}

.num-fix {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent-2);
  user-select: none;
  pointer-events: none;
  line-height: 1;
}

.num-num {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.num-num:hover {
  border-color: rgba(217, 119, 6, 0.5);
}

.num-num.found {
  background: rgba(22, 163, 74, 0.25);
  border-color: var(--green);
  cursor: default;
  transform: translate(-50%, -50%) scale(0.9);
}

.num-num.miss {
  background: rgba(220, 38, 38, 0.22);
  animation: scanShake 0.3s ease;
}

/* ============ Вправа 8: Тест Струпа ============ */
.stroop-stage {
  text-align: center;
  margin-bottom: 18px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 28px 18px 22px;
}

.stroop-word {
  font-size: clamp(2.6rem, 10vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  min-height: 1.2em;
  /* заглавные рисует CSS: в разметке остаётся обычное слово,
     поэтому переключатель языков может его перевести */
  text-transform: uppercase;
}

.stroop-task {
  display: inline-block;
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  background: rgba(217, 119, 6, 0.12);
  border: 1px solid rgba(217, 119, 6, 0.3);
  padding: 6px 16px;
  border-radius: 999px;
}

.stroop-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.stroop-opt {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--card-bg);
  border: 2px solid;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.12s ease;
}

.stroop-opt:hover {
  transform: scale(1.04);
}

.stroop-opt.miss {
  background: rgba(220, 38, 38, 0.16);
  animation: scanShake 0.3s ease;
}

/* ============ Вправа 6 (прихована): Тест на розуміння ============ */
.test-wrap {
  position: relative;
  margin-bottom: 18px;
}

.test-stage {
  max-height: 260px;
  overflow-y: auto;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 14px;
  padding: 18px 20px;
  font-size: 1.2rem;
  line-height: 1.9;
  text-align: left;
}

/* Блок із питаннями */
.quiz {
  margin-bottom: 18px;
  text-align: left;
}

.quiz-q {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-opt {
  font-family: inherit;
  font-size: 1.05rem;
  text-align: left;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.quiz-opt:hover:not(:disabled) {
  border-color: rgba(217, 119, 6, 0.45);
}

.quiz-opt:disabled {
  cursor: default;
  opacity: 0.8;
}

.quiz-opt.correct {
  background: rgba(22, 163, 74, 0.16);
  border-color: var(--green);
  opacity: 1;
}

.quiz-opt.wrong {
  background: rgba(220, 38, 38, 0.14);
  border-color: var(--red);
  opacity: 1;
}

.quiz-feedback {
  font-size: 1.05rem;
  margin-bottom: 12px;
  font-weight: 600;
}

/* Регулятор швидкості */
.rsvp-controls {
  margin-bottom: 18px;
}

.wpm-label {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--text-dim);
  font-size: 1.05rem;
}

.wpm-label strong {
  color: var(--text);
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.wpm-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Блок із текстом */
.text-block {
  margin-bottom: 18px;
}

.text-block summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 10px;
  user-select: none;
}

.text-block textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
}

.text-block textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.18);
}

/* ============ Кнопки ============ */
.actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn {
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 14px 34px;
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  color: #fffdf8;
  background: linear-gradient(135deg, #3d2b18, #1f160b);
  box-shadow: 0 8px 24px rgba(31, 22, 11, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 10px 30px rgba(31, 22, 11, 0.5);
  transform: translateY(-1px);
}

.btn-ghost {
  color: var(--text-dim);
  background: rgba(120, 90, 40, 0.06);
  border: 1px solid rgba(120, 90, 40, 0.16);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(120, 90, 40, 0.1);
}

/* ============ Результат ============ */
.result {
  margin-top: 20px;
  text-align: center;
  padding: 24px 16px;
  border-radius: var(--radius);
  background: rgba(217, 119, 6, 0.08);
  border: 1px solid rgba(217, 119, 6, 0.28);
  animation: fadeUp 0.45s ease;
}

.result.fail {
  background: rgba(220, 38, 38, 0.07);
  border-color: rgba(220, 38, 38, 0.28);
}

.result-icon {
  font-size: 3rem;
  margin-bottom: 6px;
  animation: bounce 0.6s ease;
}

.result-status {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.result-score {
  font-size: 2.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin-bottom: 14px;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.r-stat {
  min-width: 96px;
  background: rgba(120, 90, 40, 0.05);
  border: 1px solid rgba(120, 90, 40, 0.14);
  border-radius: 12px;
  padding: 8px 12px;
}

.r-label {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.r-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-advice {
  font-size: 1rem;
  color: var(--text-dim);
  line-height: 1.55;
  max-width: 420px;
  margin: 0 auto 16px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ============ Підвал ============ */
.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 28px 0 8px;
}

/* ============ Адаптивність ============ */

/* Планшети й телефони: меню одним рядком із горизонтальним скролом,
   замість двох-трьох рядів кнопок */
@media (max-width: 640px) {
  .nav {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0 calc(-1 * var(--pad-x)) 18px;
    padding: 2px var(--pad-x) 8px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scroll-padding-inline: var(--pad-x);
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav-tab {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  /* Край меню, за яким є ще таби, плавно зникає (класи ставить app.js):
     інакше обрізаний таб виглядає білою плямою біля краю екрана */
  .nav.nav-more-right {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
  }

  .nav.nav-more-left {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 36px);
    mask-image: linear-gradient(to right, transparent, #000 36px);
  }

  .nav.nav-more-left.nav-more-right {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
  }
}

/* Телефони */
@media (max-width: 430px) {
  :root {
    --pad-x: 14px;
  }

  .header {
    padding-bottom: 6px;
  }

  .header-inner {
    row-gap: 8px;
  }

  .logo {
    font-size: 1.05rem;
    gap: 8px;
  }

  .logo-mark {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 0.95rem;
  }

  .badge {
    font-size: 0.78rem;
    padding: 5px 9px;
    margin-left: auto;
  }

  .header-tools {
    /* Бейдж і панель стають окремими елементами шапки: лого + бейдж
       у першому рядку, панель — у другому (інакше шапка на 3 ряди) */
    display: contents;
  }

  /* Панель — окремий рядок на всю ширину: мова зліва (по логотипу),
     кнопки розміру справа (по бейджу). Інакше рядок висить посередині */
  .toolbar {
    flex: 1 0 100%;
    /* flex-end + margin-right: auto у селекта: якщо при масштабі кнопки
       переносяться на другий рядок, вони лишаються притиснутими вправо */
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }

  .lang {
    flex: 0 1 auto;
    min-width: 0;
    margin-right: auto;
  }

  .scale button {
    width: 30px;
    height: 30px;
    font-size: 0.78rem;
  }

  /* Компактніше, щоб три режими Струпа вміщалися в один рядок */
  .mode-btn {
    padding: 8px 14px;
    font-size: 0.9rem;
  }

  /* 16px: інакше iOS сам збільшує сторінку при виборі мови.
     Ширина обмежена, щоб рядок не виглядав як поле пошуку */
  .lang select {
    height: 30px;
    font-size: 16px;
    padding: 0 6px;
    max-width: 190px;
  }

  .exercise-card {
    padding: 16px 12px;
    border-radius: 16px;
  }

  .intro h1 {
    font-size: clamp(1.6rem, 8vw, 2rem);
  }

  .stats-bar {
    gap: 6px;
  }

  .stat {
    padding: 8px 4px;
    border-radius: 12px;
  }

  .stat-label {
    font-size: 0.66rem;
    letter-spacing: 0.03em;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .stat-target {
    font-size: 1.45rem;
  }

  .grid {
    gap: 6px;
  }

  .cell {
    border-radius: 12px;
    font-size: clamp(1.5rem, 8vw, 2rem);
  }

  /* На тачі :hover залипає після натискання — прибираємо підйом */
  .cell:hover {
    transform: none;
    box-shadow: none;
  }

  .rsvp-stage {
    min-height: 140px;
  }

  .rsvp-word {
    font-size: clamp(2rem, 12vw, 3rem);
    padding: 0 10px;
    overflow-wrap: break-word;
  }

  .sacc-stage {
    padding: 18px 12px;
  }

  .scan-stage {
    max-height: 52dvh;
    padding: 14px;
    font-size: 1.15rem;
  }

  /* 16px: без автозуму iOS при фокусі */
  .text-block textarea {
    font-size: 16px;
  }

  .fov-stage {
    padding: 16px 10px;
  }

  .fov-stage.fov-grid {
    gap: 8px;
    padding: 16px 12px;
    min-height: 200px;
  }

  .num-num {
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
  }

  .num-fix {
    font-size: 1.9rem;
  }

  .stroop-stage {
    padding: 22px 12px 18px;
  }

  .stroop-word {
    font-size: clamp(2rem, 11vw, 3rem);
  }

  .stroop-task {
    font-size: 0.95rem;
    padding: 5px 12px;
  }

  .stroop-opt {
    padding: 10px 14px;
    font-size: 1rem;
  }

  .btn {
    flex: 1;
    max-width: 220px;
    padding: 13px 18px;
  }

  .actions {
    gap: 10px;
  }

  .result {
    padding: 20px 12px;
  }

  .result-score {
    font-size: 2.2rem;
  }

  .r-stat {
    min-width: 84px;
    padding: 6px 10px;
  }

  .r-label {
    font-size: 0.72rem;
  }
}

/* Дуже вузькі телефони (320–360 px) */
@media (max-width: 360px) {
  .grid {
    gap: 4px;
  }

  .cell {
    border-radius: 10px;
    font-size: clamp(1.35rem, 8.5vw, 1.8rem);
  }

  .nav-tab {
    padding: 8px 11px;
    font-size: 0.85rem;
  }

  .hints li {
    font-size: 0.8rem;
    padding: 5px 10px;
  }

  .stats-bar {
    gap: 4px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .stat-target {
    font-size: 1.3rem;
  }
}

/* Горизонтальна орієнтація: сцени й таблиця мають уміщатися по висоті */
@media (max-height: 560px) and (orientation: landscape) {
  .header {
    padding-top: max(8px, env(safe-area-inset-top));
  }

  .intro {
    margin-bottom: 16px;
  }

  .intro h1 {
    margin-bottom: 6px;
  }

  .grid {
    width: min(100%, 460px, 58vh);
  }

  .rsvp-stage {
    min-height: 110px;
  }

  .sacc-field {
    height: 150px;
  }

  .scan-stage {
    max-height: 46vh;
  }

  .num-stage {
    height: min(72vw, 240px);
  }

  .stroop-stage {
    padding: 18px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell, .result, .result-icon, .rsvp-word, .sacc-dot {
    animation: none !important;
    transition: none !important;
  }
}

/* ============ Очень узкая эффективная ширина ============
   Срабатывает на 320 px при масштабе A+×1.5 (контейнер ~185 px):
   media queries zoom не видят, а @container видит реальную ширину.
   Без этого шапка разваливается на 4–5 рядов, а подписи статистики
   рвутся по буквам. Блок стоит последним, чтобы перебивать media. */
@container (max-width: 220px) {
  .logo-text {
    display: none;
  }

  /* Селект делит рядок с кнопками A− / A+ и тянется по остатку */
  .lang {
    flex: 1 1 80px;
    min-width: 0;
  }

  .lang select {
    width: 100%;
    max-width: none;
  }

  .stat {
    padding: 6px 3px;
  }

  .stat-label {
    font-size: 0.5rem;
    letter-spacing: 0;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-target {
    font-size: 1.15rem;
  }
}
