:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #5d6677;
  --line: #dfe3ea;
  --accent: #1a5fd1;
  --accent-text: #ffffff;
  --me: #1a5fd1;
  --me-text: #ffffff;
  --ok: #1a7f45;
  --ok-bg: #e6f4ec;
  --gap-bg: #eef0f3;
  --warn: #9a4d00;
  --check-bg: #fff4cc;
  --check-chip: #ffd666;
  --check-text: #3d2a00;
  --mark: #fff1b8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1c2029;
    --text: #e8ebf1;
    --muted: #a3abba;
    --line: #2e3442;
    --accent: #5b9dff;
    --accent-text: #0b1220;
    --me: #2f6fd6;
    --me-text: #ffffff;
    --ok: #5fd08f;
    --ok-bg: #173325;
    --gap-bg: #252a35;
    --warn: #ffb35c;
    --check-bg: #3a2f10;
    --check-chip: #e0b84a;
    --check-text: #2a1d00;
    --mark: #5a4a12;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 760px; margin: 0 auto;
  background: var(--bg);
}

/* шапка */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 1.375rem; font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 0.875rem; color: var(--muted); }
.lang { display: inline-flex; flex-shrink: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button {
  border: 0; background: transparent; padding: 6px 12px; min-height: 44px; font-size: 0.9375rem;
}
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.link-btn {
  border: 0; background: transparent; color: var(--accent); padding: 6px 4px; min-height: 44px;
  font-size: 0.9375rem; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn.small { font-size: 0.875rem; min-height: 44px; min-width: 44px; }

/* тема и карта */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; align-items: center;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.topic { flex: 1 1 100%; min-width: 0; }
.toolbar-row { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
@media (min-width: 700px) {
  .topic { flex: 1 1 auto; }
  .toolbar-row { flex: 0 0 auto; }
}
/* Название темы целиком, с переносом строк: однострочный select обрезает
   длинные названия, поэтому он прозрачный и лежит поверх (нажатие открывает
   обычный список выбора). */
.topic { position: relative; display: block; }
.topic select {
  position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 1rem; /* ≥ 16px: iOS не увеличивает страницу */
}
.topic-face {
  display: block; position: relative; min-height: 44px; padding: 10px 36px 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 0.9375rem; line-height: 1.3;
  overflow-wrap: anywhere;
}
.topic-face::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
}
.topic-face:empty::before { content: "\00a0"; }
.topic select:focus-visible + .topic-face { outline: 3px solid var(--accent); outline-offset: 2px; }
.topic select:disabled { cursor: default; }
.topic select:disabled + .topic-face { opacity: .7; }
.map-btn {
  flex-shrink: 0; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--surface); color: var(--accent);
  font-size: 0.9375rem; font-weight: 600; display: inline-flex; gap: 6px; align-items: center;
}
.map-count {
  font-size: 0.875rem; background: var(--accent); color: var(--accent-text);
  border-radius: 999px; padding: 1px 8px;
}
.map-count:empty { display: none; }

/* чат */
.chat {
  flex: 1; overflow-y: auto; padding: 14px 16px 8px;
  display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
.row { display: flex; }
.row-me { justify-content: flex-end; }
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.row-dos .bubble { border-top-left-radius: 4px; }
.row-me .bubble {
  background: var(--me); color: var(--me-text); border-color: transparent; border-top-right-radius: 4px;
}
.who { font-size: 0.875rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.row-me .who { color: #ffffff; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.why-btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 4px 14px; font-size: 0.875rem; min-height: 44px; min-width: 44px; color: var(--accent);
}
.why-btn[aria-expanded="true"] { background: var(--gap-bg); }
.why-btn.strong { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.why-box {
  margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--gap-bg);
  font-size: 0.9375rem;
}
.why-box p { margin: 0 0 6px; }
.why-box p:last-child { margin-bottom: 0; }
.quote { font-style: italic; }
.muted { color: var(--muted); }
.heard { margin: 0 0 6px; padding-left: 18px; }
mark { background: var(--mark); color: inherit; border-radius: 4px; padding: 0 3px; }
.guard { font-size: 0.875rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
.guard-hit { color: var(--warn); font-weight: 600; }
.system { align-self: center; font-size: 0.875rem; color: var(--warn); text-align: center; }

.typing { display: inline-flex; gap: 4px; padding: 14px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .7; } }

/* ввод */
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 140px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-size: 1.0625rem; line-height: 1.35;
}
.composer button {
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 1rem;
}
.composer button:disabled { opacity: .5; cursor: default; }
.footnote {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 2px 12px;
  padding: 2px 16px calc(6px + env(safe-area-inset-bottom)); background: var(--surface);
  font-size: 0.875rem; line-height: 1.35; color: var(--muted);
}
#mode-note { flex: 1 1 200px; min-width: 0; }

/* листы: карта и «о проекте» */
.sheet {
  position: fixed; inset: 0; background: rgba(10, 14, 22, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 10;
}
.sheet[hidden] { display: none; }
.sheet-body {
  width: 100%; max-width: 760px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 16px 16px 24px;
}
@media (min-width: 800px) {
  .sheet { align-items: center; }
  .sheet-body { border-radius: 18px; max-width: 640px; }
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  position: sticky; top: -16px; background: var(--surface); padding: 4px 0 8px; margin-top: -4px;
}
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet h3 { font-size: 1rem; margin: 16px 0 6px; }
.sheet p { margin: 0 0 8px; }

.map-progress { font-weight: 600; margin-bottom: 6px; }
.bar { height: 10px; border-radius: 999px; background: var(--gap-bg); overflow: hidden; margin-bottom: 12px; }
.bar-fill { height: 100%; background: var(--ok); border-radius: 999px; transition: width .3s; }
.ideas { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.idea { border-radius: 12px; padding: 10px 12px; border: 1px solid var(--line); }
.idea.covered { background: var(--ok-bg); border-color: transparent; }
.idea.missing { background: var(--gap-bg); border-color: transparent; }
.idea-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.idea-id { font-weight: 700; font-size: 0.875rem; }
.chip { font-size: 0.875rem; border-radius: 999px; padding: 1px 10px; }
.covered .chip { background: var(--ok); color: var(--surface); }
.missing .chip { background: var(--line); color: var(--text); }
.idea-text { font-weight: 500; }
.idea-q { font-style: italic; }
.idea .label { font-size: 0.875rem; margin-bottom: 2px; }
.sheet-body { font-size: 1rem; }
.checks { padding-left: 22px; margin: 0; }
.checks li { margin-bottom: 6px; }
.locked { margin-top: 12px; font-size: 0.875rem; }
.about p { color: var(--text); }
.foot-actions { display: flex; gap: 12px; flex-shrink: 0; margin-left: auto; }
.finish-btn { margin-top: 12px; }

/* «Скопировать карту»: текст карты в буфер обмена, на сервер не уходит */
.copy-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin: 0 0 12px; }
.copy-btn { font-weight: 600; min-height: 44px; padding: 6px 16px; }
.copy-status:empty { display: none; }
.sheet .copy-status { margin: 0; color: var(--ok); font-weight: 600; }
.copy-fallback {
  width: 100%; min-height: 140px; padding: 8px 10px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--line); background: var(--bg); font-size: 0.9375rem;
}
.copy-buffer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; }

/* первая строка чата */
.intro {
  align-self: center; margin: 0; padding: 4px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 0.875rem; font-weight: 600;
  text-align: center;
}
.small { font-size: 0.875rem; }
.typing { align-items: center; }
.dots { display: inline-flex; gap: 4px; }
.typing-text.slow { font-size: 0.875rem; color: var(--muted); margin-left: 6px; }
.link-btn:disabled, .lang button:disabled, .why-btn:disabled { opacity: .55; cursor: default; }
select:disabled { opacity: .7; }

/* «проверь» на карте */
.idea.check { background: var(--check-bg); border-color: transparent; }
.check .chip { background: var(--check-chip); color: var(--check-text); font-weight: 600; }
.check-text { font-weight: 500; }
.check-line { margin-bottom: 4px; }
.map-checks { font-size: 0.875rem; font-weight: 600; margin: -4px 0 8px; }

/* мини-контрольная Доса */
.quiz {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--gap-bg); font-size: 0.9375rem;
}
.sheet .quiz { margin: 0 0 12px; }
.quiz-title, .sheet .quiz-title { margin: 0 0 4px; font-size: 1rem; }
.quiz p { margin: 0 0 6px; }
.quiz-list { margin: 0 0 6px; padding-left: 20px; }
.quiz-item { margin-bottom: 8px; }
.quiz-q { font-weight: 500; }
.quiz-a { font-style: italic; border-left: 3px solid var(--accent); padding-left: 8px; }
.quiz-unknown .quiz-a { border-left-color: var(--muted); }

/* проверочные вопросы с ответом */
.check-item { margin-bottom: 14px; }
.check-q { font-weight: 500; margin-bottom: 6px; }
.check-form { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.check-form textarea {
  width: 100%; resize: vertical; min-height: 64px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 1rem;
}
.check-result { padding: 10px 12px; border-radius: 10px; background: var(--gap-bg); }
.check-result p { margin: 0 0 6px; }
.check-result.check { background: var(--check-bg); }
.check-result:focus { outline: none; }
.check-result:focus-visible { outline: 3px solid var(--accent); }

/* низкий и широкий экран (телефон боком): шапка и панель темы компактнее;
   узкий и низкий (увеличение 200 %) сюда не попадает — там нужны переносы */
@media (max-height: 500px) and (min-width: 500px) {
  .top { padding: 4px 16px; }
  .brand-name { font-size: 1.125rem; }
  .brand-sub { display: none; }
  .toolbar { padding: 4px 16px; flex-wrap: nowrap; }
  .topic { flex: 1 1 auto; }
  .toolbar-row { flex: 0 0 auto; }
  .topic select, .map-btn { min-height: 44px; padding-top: 4px; padding-bottom: 4px; }
  .topic-face { min-height: 44px; padding-top: 6px; padding-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .composer { padding: 6px 16px; }
}

/* доступность: размер текста, озвучка, цели нажатия не меньше 44 px */
.top { flex-wrap: wrap; }
.top .brand { flex: 1 1 170px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-left: auto; }
.scale-btn {
  min-height: 44px; min-width: 44px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; font-weight: 700; font-size: 0.9375rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.scale-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.scale-val { font-size: 0.875rem; font-weight: 600; }
.speak-btn[aria-pressed="true"] { background: var(--gap-bg); }
html[data-no-voice] .speak-btn { display: none; }
.idea .speak-btn { margin-top: 6px; }
.bubble-actions:empty { display: none; }
/* узкий экран или сильное увеличение (браузер 175–200 %, A+): переносы вместо прокрутки вбок */
.toolbar-row, .foot-actions, .top-actions { flex-wrap: wrap; }
.map-btn { max-width: 100%; flex-wrap: wrap; text-align: left; }
.foot-actions { column-gap: 12px; row-gap: 0; justify-content: flex-end; flex-shrink: 1; min-width: 0; }
.top-actions { flex-shrink: 1; min-width: 0; justify-content: flex-end; }
.composer { flex-wrap: wrap; }
.composer textarea { flex-basis: 140px; }
.composer button { flex: 0 1 auto; max-width: 100%; }
.sheet-head { flex-wrap: wrap; }
.sheet-head h2 { min-width: 0; overflow-wrap: anywhere; }
/* узко и низко (телефон с увеличением 200 %): шапка и панель занимают весь
   экран, поэтому страница прокручивается целиком, а не только чат */
@media (max-height: 500px) and (max-width: 499.98px) {
  .app { height: auto; min-height: 100vh; min-height: 100dvh; }
  .chat { flex: 1 0 auto; overflow-y: visible; min-height: 200px; }
}

/* значки «О проекте» и «Отправить» — только в компактной шапке */
.about-icon, .send-icon { display: none; }
#send { display: inline-flex; align-items: center; justify-content: center; }

/* компактная шапка: A+ от 130 % или окно ниже 700 px (data-compact ставит
   app.js). Подзаголовок скрыт, тема — одна строка с «…» (полные названия
   в списке выбора), «О проекте» и «Отправить» — значки, имя кнопки остаётся
   текстом для озвучки. Цели нажатия по-прежнему не меньше 44 px. */
html[data-compact] .brand-sub { display: none; }
html[data-compact] .top { padding: 4px 12px; gap: 4px 8px; }
html[data-compact] .top .brand { flex: 0 1 auto; }
html[data-compact] .brand-name { font-size: 1.0625rem; }
html[data-compact] .top-actions { gap: 6px; }
html[data-compact] .scale-btn { padding: 4px 8px; }
html[data-compact] .lang button { padding: 4px 10px; font-size: 0.875rem; }
html[data-compact] .toolbar { padding: 6px 12px; gap: 6px; }
html[data-compact] .toolbar-row { flex-wrap: nowrap; }
html[data-compact] .topic-face {
  min-height: 44px; padding-top: 6px; padding-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
html[data-compact] .map-btn { min-height: 44px; padding: 4px 10px; min-width: 0; flex-shrink: 1; overflow-wrap: anywhere; }
html[data-compact] .about-btn {
  flex-shrink: 0; min-width: 44px; padding: 0; border: 1px solid var(--accent); border-radius: 999px;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
html[data-compact] .about-icon {
  display: inline; font: italic 700 1.125rem/1 Georgia, "Times New Roman", serif;
}
html[data-compact] .about-text, html[data-compact] .send-text {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
html[data-compact] .send-icon { display: block; width: 1.25rem; height: 1.25rem; }
html[data-compact] .composer { padding: 6px 12px; flex-wrap: nowrap; }
html[data-compact] .composer textarea { flex: 1 1 auto; }
html[data-compact] .composer button { min-width: 48px; padding: 0 12px; flex: 0 0 auto; }
html[data-compact] .chat { padding-top: 10px; }
