:root {
  --back: rgb(31, 33, 35);
  --surface: rgb(39, 42, 45);
  --card: rgb(36, 39, 42);
  --answ: rgb(33, 36, 38);
  --border: rgb(58, 62, 67);
  --sele: rgb(16, 85, 51);
  --accent: rgb(38, 132, 86);
  --accent-soft: rgba(38, 132, 86, 0.16);
  --err-bg: rgba(185, 56, 67, 0.24);
  --err-border: rgb(206, 86, 97);
  --warn: rgb(229, 192, 123);
  --font: rgb(206, 210, 214);
  --bright: #eef2f5;
  --muted: rgb(150, 156, 162);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--back);
  color: var(--font);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
  touch-action: manipulation;
}

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 14px 48px;
}

.hidden {
  display: none !important;
}

/* Шапка */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-slot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.auth-user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  min-height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  color: var(--bright);
}

.auth-user-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-sync-dot {
  font-size: 12px;
  color: #7be0a7;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 180;
  background: rgba(12, 14, 16, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  width: 100%;
  max-width: 390px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--bright);
}

.modal-close {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--font);
  font-size: 15px;
  cursor: pointer;
}

.modal-desc {
  margin: 0 0 16px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}

.oauth-btn:hover {
  border-color: #7c858e;
  background: rgb(49, 53, 57);
}

.oauth-btn-ya {
  background: #232629;
  border-color: rgba(252, 63, 29, 0.55);
}

.oauth-btn-ya:hover {
  border-color: #fc3f1d;
  background: #2d2626;
}

.oauth-btn-vk {
  background: #232629;
  border-color: rgba(0, 119, 255, 0.55);
}

.oauth-btn-vk:hover {
  border-color: #0077ff;
  background: #222933;
}

.brand-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--bright);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.brand-logo span {
  color: #56c28a;
}

.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px;
  gap: 3px;
}

.seg button,
.seg .seg-link {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
}

.seg button.active,
.seg .seg-link.active {
  background: var(--sele);
  color: #fff;
}

.seg button:hover:not(.active),
.seg .seg-link:hover:not(.active) {
  color: var(--bright);
}

.banner {
  margin-bottom: 12px;
  padding: 10px 13px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--font);
  font-size: 14px;
}

.banner.is-err {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: #ffd7db;
}

/* Выбор экзамена */
.train-hero {
  margin: 0 0 10px;
}

.train-h1 {
  margin: 0 0 3px;
  font-size: 20px;
  font-weight: 700;
  color: var(--bright);
  line-height: 1.25;
}

.train-lead {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.exam-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.exam-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.exam-filter {
  flex: 1 1 200px;
  background: var(--surface);
  color: var(--bright);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 16px;
}

.exam-select {
  flex: 2 1 320px;
  width: 100%;
  background: var(--surface);
  color: var(--bright);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 16px;
  font-weight: 600;
}

.exam-filter:focus,
.exam-select:focus,
.mini-select:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

/* Кнопки */
.btn {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  min-height: 44px;
  background: var(--surface);
  color: var(--font);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color 0.12s, background-color 0.12s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--sele);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #156d42;
}

.btn-err {
  border-color: var(--err-border);
  color: #f1a7ae;
}

.btn-star {
  border-color: rgba(229, 192, 123, 0.5);
  color: var(--warn);
}

.btn-sm {
  padding: 6px 10px;
  min-height: 36px;
  font-size: 13px;
}

.btn-icon {
  min-width: 40px;
  padding: 6px 10px;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--bright);
}

/* Статистика экзамена */
.summary-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.summary-stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-ok {
  color: #7be0a7;
  font-weight: 600;
}

.stat-err {
  color: #f1969f;
  font-weight: 600;
}

.stat-star {
  color: var(--warn);
  font-weight: 600;
}

/* Сетка тем */
.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 9px;
}

.theme-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 13px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.12s;
}

.theme-card:hover {
  border-color: var(--accent);
}

.theme-card:active {
  background: var(--surface);
}

.theme-card.is-done {
  border-color: rgba(38, 132, 86, 0.7);
}

.theme-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.theme-num {
  font-size: 12px;
  font-weight: 700;
  color: #9ad8b6;
  background: var(--answ);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
  flex: 0 0 auto;
}

.theme-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--bright);
  flex: 1;
}

.theme-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.prog-track {
  height: 6px;
  background: var(--answ);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

.prog-topic {
  margin-bottom: 10px;
}

.prog-ok {
  background: var(--accent);
  height: 100%;
  transition: width 0.25s;
}

.prog-err {
  background: var(--err-border);
  height: 100%;
  transition: width 0.25s;
}

.empty-msg {
  padding: 16px;
  color: var(--muted);
  font-size: 15px;
}

/* Шапка темы */
.study-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.study-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.study-title-wrap {
  min-width: 0;
}

.study-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.study-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.study-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.toggles label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--font);
  user-select: none;
  min-height: 28px;
}

.toggles input[type="checkbox"] {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
}

.mini-select {
  background: var(--surface);
  color: var(--bright);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 14px;
}

.btn-gear {
  display: none;
}

/* Карточка вопроса */
.q-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 15px;
}

.q-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.q-pills {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}

.pill-repeat {
  border-color: var(--err-border);
  color: #f1a7ae;
  background: var(--err-bg);
}

.pill-ok {
  border-color: var(--accent);
  color: #9ad8b6;
  background: var(--accent-soft);
}

.pill-timer {
  font-size: 14px;
  font-weight: 700;
  color: #9ad8b6;
}

.star-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 10px;
  min-height: 34px;
  font-size: 13px;
  cursor: pointer;
  flex: 0 0 auto;
}

.star-btn.active {
  border-color: var(--warn);
  color: var(--warn);
  background: rgba(229, 192, 123, 0.12);
}

.q-text {
  font-size: 19px;
  font-weight: 500;
  color: var(--bright);
  margin: 4px 0 14px;
  line-height: 1.44;
  white-space: pre-line;
}

/* Картинки */
.img-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 13px;
}

.img-thumb {
  max-width: 100%;
  max-height: 220px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: zoom-in;
  object-fit: contain;
}

/* Ответы */
.ans-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.ans-btn {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 12px;
  min-height: 52px;
  background: var(--answ);
  color: var(--font);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
  line-height: 1.38;
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}

.ans-btn:hover:not(.locked) {
  border-color: var(--accent);
  background: var(--surface);
  color: #fff;
}

.ans-btn:active:not(.locked) {
  transform: scale(0.99);
}

.ans-key {
  min-width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 0 0 auto;
  margin-top: 1px;
}

.ans-btn.is-right {
  background: var(--sele);
  border-color: #36b575;
  color: #fff;
}

.ans-btn.is-right .ans-key {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.ans-btn.is-wrong {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: #ffd7db;
}

.ans-btn.is-wrong .ans-key {
  background: rgba(206, 86, 97, 0.3);
  border-color: var(--err-border);
  color: #fff;
}

/* Подсказка */
.hint-box {
  margin-top: 12px;
  padding: 12px 13px;
  background: rgb(29, 34, 32);
  border: 1px solid rgba(38, 132, 86, 0.55);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  font-size: 14.5px;
  color: #dce6df;
}

.hint-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7be0a7;
  margin-bottom: 5px;
}

.hint-text {
  white-space: pre-line;
}

.requeue-note {
  margin-top: 8px;
  font-size: 12.5px;
  color: #f1a7ae;
}

/* Навигация */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.nav-left {
  display: flex;
  gap: 8px;
}

.key-hint {
  opacity: 0.72;
  font-size: 12px;
  font-weight: 500;
}

.hotkeys-bar {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--bright);
}

.swipe-hint {
  display: none;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 10px;
}

/* Конспект / Список */
.list-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.list-q {
  font-size: 16px;
  font-weight: 500;
  color: var(--bright);
  white-space: pre-line;
}

.list-ans {
  padding: 7px 9px;
  border-radius: 6px;
  margin: 4px 0;
  font-size: 14.5px;
  background: var(--answ);
  display: flex;
  gap: 8px;
}

.list-ans.right {
  background: var(--sele);
  color: #fff;
  font-weight: 500;
}

.list-ans.masked {
  background: var(--answ);
  color: var(--font);
  font-weight: 400;
  cursor: pointer;
}

/* Экран итогов */
.done-box {
  text-align: center;
  padding: 12px 4px;
}

.done-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--bright);
  margin: 0 0 8px;
}

.done-title.pass {
  color: #7be0a7;
}

.done-title.fail {
  color: #f1969f;
}

.done-sub {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 15px;
}

.done-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Экзамен */
.exam-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.dot {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.dot.cur {
  border-color: #fff;
  color: #fff;
}

.dot.ok {
  background: var(--sele);
  border-color: var(--accent);
  color: #fff;
}

.dot.err {
  background: var(--err-bg);
  border-color: var(--err-border);
  color: #ffd7db;
}

.review-list {
  margin-top: 16px;
  text-align: left;
}

/* Информационный блок и быстрые ссылки под сеткой тем */
.train-about {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.train-about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.train-about h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--bright);
}

.quick-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.quick-cat {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  font-size: 12.5px;
  color: var(--font);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  transition: border-color 0.12s, color 0.12s;
}

.quick-cat:hover {
  border-color: var(--accent);
  color: #fff;
}

.train-about-note {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.train-about-note a {
  color: #7be0a7;
}

.faq-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 11px;
  margin-bottom: 7px;
}

.faq-item summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--bright);
}

.faq-item p {
  margin: 7px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(12, 14, 16, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox img {
  max-width: 100%;
  max-height: 92vh;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.lightbox-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* Мобильная адаптация под один большой палец */
@media (max-width: 680px) {
  .page {
    padding: 8px 10px 96px;
  }

  .topbar {
    padding-bottom: 8px;
    margin-bottom: 10px;
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .themes-grid {
    grid-template-columns: 1fr;
  }

  .train-h1 {
    font-size: 17.5px;
  }

  .train-about-grid {
    grid-template-columns: 1fr;
  }

  .study-sub {
    display: none;
  }

  .study-title {
    font-size: 14.5px;
  }

  .btn-gear {
    display: inline-flex;
  }

  .options-bar:not(.open) {
    display: none;
  }

  .q-card {
    padding: 12px;
    border-radius: 9px;
  }

  .q-text {
    font-size: 17px;
    margin: 2px 0 12px;
  }

  .ans-btn {
    font-size: 15px;
    padding: 12px 11px;
    min-height: 50px;
  }

  .key-hint,
  .hotkeys-bar {
    display: none;
  }

  .swipe-hint {
    display: block;
  }

  .nav-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
    background: rgba(26, 28, 30, 0.96);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    z-index: 50;
    display: grid;
    grid-template-columns: 48px 1fr 1fr 1.25fr;
    gap: 7px;
  }

  .nav-left {
    display: contents;
  }

  .nav-bar .btn {
    min-height: 48px;
    padding: 8px 6px;
    font-size: 13.5px;
  }
}
