:root {
  color-scheme: light dark;
  --bg: #0b0e13;
  --surface: #141922;
  --surface-strong: #10151e;
  --text: #eef2f7;
  --muted: #9aa5b5;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --border: rgba(255, 255, 255, 0.08);
  --border-btn: rgba(255, 255, 255, 0.25);
  --shadow: 0 18px 40px rgba(5, 10, 18, 0.5);
  --radius: 16px;
  --answer-color: #c7d2fe;  /* indigo-200: bright on dark background */
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #eef4f6;
  --surface: #ffffff;
  --surface-strong: #dde8ec;
  --text: #0f1218;
  --muted: #354050;
  --accent: #2a97aa;
  --accent-strong: #1a7d8e;
  --border: rgba(15, 25, 45, 0.14);
  --border-btn: rgba(15, 25, 45, 0.18);
  --shadow: 0 3px 14px rgba(15, 25, 45, 0.10), 0 1px 4px rgba(15, 25, 45, 0.06);
  --answer-color: #1a6b78;
}

/* Запрещаем скролл на уровне html/body — прокрутка только внутри панелей */
html {
  height: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

/* Скрываем скроллбары везде, сохраняя функциональность прокрутки */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; -ms-overflow-style: none; }

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.14), transparent 55%), var(--bg);
  color: var(--text);
  font-weight: 400;
}

body[data-theme="light"] {
  background: linear-gradient(180deg, #d8edf1 0%, #eef4f6 55%);
}

body[data-theme="light"] .btn.primary {
  box-shadow: 0 8px 24px rgba(26, 125, 142, 0.38);
}

body[data-theme="light"] .btn.play {
  background: rgba(42, 151, 170, 0.13);
  border: 1px solid rgba(42, 151, 170, 0.35);
}

/* Приложение занимает весь экран, flex-колонка */
.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 8px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  overflow: hidden;
}

/* ── App bar ── */
.app-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  min-height: 36px;
  flex-shrink: 0;
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 25px;
  cursor: pointer;
  color: var(--text);
  line-height: 1;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:active { background: var(--surface-strong); }

/* ── Gate logo (shown only on start screen) ── */
.gate-logo {
  width: 114px !important;
  height: 114px !important;
  max-width: 40vw !important;
  max-height: 40vw !important;
  object-fit: contain;
  margin-top: -5px;
  margin-bottom: -5px;
}

/* ── Progress bar ── */
.progress {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  font-size: 22px;
  font-weight: 400;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 6px;
  flex-shrink: 0;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
  /* Занимает всё оставшееся место в flex-колонке */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#gate {
  display: flex;
  align-items: flex-start;
}

.gate-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  text-align: center;
  padding-bottom: 12px;
}

#gateLead:empty,
#startHint:empty {
  display: none;
}

.panel h1,
.panel h2 {
  margin: 0 0 10px;
  font-family: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 22px;
  font-weight: 400;
}

#gate h1 {
  margin: 0;
  display: block;
  width: 100%;
  text-align: center;
}

.block-intro {
  margin-top: 8px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
}

.block-title {
  font-size: 27px;
  font-weight: 400;
  color: var(--text);
  text-align: center;
}

.block-desc {
  font-size: 24px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 4px;
  text-align: center;
  display: block;
  width: 100%;
}

.block-spacer {
  height: 0.5em;
}

.lead {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.6;
}

#gate .lead {
  margin: 0;
}

.hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

/* ── Trainer ── */
#trainer {
  display: flex;
  align-items: stretch;
}

.trainer-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: center;
  align-items: stretch;
}

.phrase {
  font-size: 28px;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
}

.answer {
  font-size: 27px;
  color: var(--answer-color);
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
  white-space: pre-line;
}

/* ── Cultural note ── */
.cultural-note {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 6px 12px;
  border-left: 2px solid var(--border);
  margin: 0 auto;
  max-width: 90%;
  text-align: left;
}

#trainer .phrase,
#trainer .answer,
#trainer .grades {
  margin: 0;
}

#trainer .answer {
  margin-top: 0;
}

#trainer .btn {
  margin-bottom: 0;
}

/* ── Buttons ── */
.btn {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 400;
  cursor: pointer;
  background: var(--surface-strong);
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  margin-bottom: 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.35);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn.play {
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* ── Grade buttons (horizontal row, 3 cols) ── */
.grades {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 4px;
}

.grade {
  border-radius: 12px;
  border: 1.5px solid transparent;
  padding: 13px 6px;
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.2;
}

.grade:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.grade.hard {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.40);
}

.grade.good {
  background: rgba(245, 158, 11, 0.10);
  border-color: rgba(245, 158, 11, 0.40);
}

.grade.easy {
  background: rgba(34, 197, 94, 0.10);
  border-color: rgba(34, 197, 94, 0.40);
}

/* ── 2-col grades (stage 2 & 4) ── */
.grades.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ── 1-col grades (stage 4 "Далее") ── */
.grades.one-col {
  grid-template-columns: 1fr;
}

.btn:not(:disabled):hover,
.grade:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(5, 10, 20, 0.25);
}

.hidden {
  display: none;
}

@media (max-width: 600px) {
  .app {
    padding: 12px 14px 12px;
  }

  .panel h1,
  .panel h2 {
    font-size: 20px;
  }

  .progress {
    font-size: 18px;
  }

  .phrase,
  .answer {
    font-size: 26px;
  }

  /* grades stay 3-col on mobile — horizontal layout intentional */
}

/* ── Gate screen: 1.5× fonts ── */
#gate h1    { font-size: 33px; }
#gate .lead { font-size: 24px; }
#gate .hint { font-size: 18px; }
#gate .btn  { font-size: 24px; }

/* ── Dialog screen ────────────────────────────────── */
.dlg-stack {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px 16px 16px;
  overflow: hidden;
}

/* Dialog list */
#dlgList { flex: 1; overflow-y: auto; min-height: 0; }
.dlg-list { display: flex; flex-direction: column; gap: 8px; }
.dlg-list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}
.dlg-list-item:active { background: var(--surface-strong); }
.dlg-list-icon { font-size: 1.56rem; flex-shrink: 0; }
.dlg-list-meta { flex: 1; min-width: 0; }
.dlg-list-title { font-size: 1.08rem; font-weight: 600; }
.dlg-list-sub   { font-size: 0.94rem; color: var(--muted); margin-top: 2px; }
.dlg-list-arrow { color: var(--muted); font-size: 1.32rem; }

/* Dialog player */
#dlgPlayer { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#dlgTitle { flex-shrink: 0; }
.dlg-bubbles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
}
.dlg-bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 1.05rem;
  line-height: 1.4;
  cursor: pointer;
  transition: opacity 0.2s;
}
.dlg-bubble.other {
  align-self: flex-start;
  margin-left: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.dlg-bubble.user {
  align-self: flex-end;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.38);
  color: var(--text);
}
.dlg-bubble.active { opacity: 1; box-shadow: 0 0 0 2px var(--accent); }
.dlg-bubble.dimmed { opacity: 0.45; }
.dlg-bubble-role { font-size: 0.8rem; color: var(--muted); margin-bottom: 2px; }
.dlg-bubble-sr { font-weight: 500; }
.dlg-bubble-ru { font-size: 0.92rem; color: var(--muted); margin-top: 3px; display: none; }
.dlg-bubble.ru-shown .dlg-bubble-ru { display: block; }

.dlg-controls {
  padding-top: 10px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.dlg-controls .btn { flex: 1; }

.lvl-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}
