/* === Инструмент "Тесты" === */

.main-content:has(.tests-page) { padding-top: 0; }

.tests-page {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.tests-page__inner {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 16px 0 60px;
}

.tests-toolbar__search {
  min-width: 0;
  width: 100%;
  max-width: 480px;
  justify-self: end;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-on-surface);
  font-size: 13px;
  padding: 6px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.tests-toolbar__search:focus {
  border-color: var(--color-primary);
}
.tests-toolbar__timer {
  justify-self: end;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 16px;
  color: var(--color-primary);
  padding: 4px 12px;
  background: var(--color-primary-light);
  border-radius: 999px;
  transition: background 0.2s, color 0.2s;
}
.tests-toolbar__timer--danger {
  color: #fff;
  background: #c62828;
  animation: tests-timer-pulse 1s ease-in-out infinite;
}
@keyframes tests-timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.tests-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tests-section__header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.tests-section__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-on-surface);
}
.tests-section__hint {
  font-size: 12px;
  color: var(--color-on-surface-secondary);
}

.tests-empty {
  padding: 24px;
  text-align: center;
  color: var(--color-on-surface-secondary);
  border: 1px dashed var(--color-border);
  border-radius: 14px;
  font-size: 14px;
}
.tests-empty--error {
  color: #c62828;
  border-color: color-mix(in srgb, #c62828 40%, var(--color-border));
  background: color-mix(in srgb, #c62828 6%, transparent);
}

.tests-tabs {
  margin-bottom: 4px;
}

/* --- Сетка категорий (встроенные тесты) --- */
.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.tests-card {
  position: relative;
  height: 110px;
  background-size: cover;
  background-position: center;
  border: 1px solid var(--color-border);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.tests-card:hover {
  transform: translateY(-2px);
  border-color: var(--color-primary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.tests-card__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--color-surface) 94%, transparent) 0%,
    color-mix(in srgb, var(--color-surface) 80%, transparent) 50%,
    color-mix(in srgb, var(--color-surface) 40%, transparent) 100%
  );
  pointer-events: none;
}
.tests-card__body {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  color: var(--color-on-surface);
}
.tests-card__title {
  font-size: 16px;
  font-weight: 700;
  text-shadow: 0 1px 2px color-mix(in srgb, var(--color-surface) 40%, transparent);
}
.tests-card__meta {
  font-size: 11px;
  color: var(--color-on-surface-secondary);
}
.tests-card__stats {
  font-size: 11px;
  color: var(--color-on-surface-secondary);
  margin-top: 2px;
}
.tests-card__trophy {
  color: var(--color-primary);
  font-weight: 600;
}
.tests-card__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  z-index: 1;
}
[data-theme="dark"] .tests-card__badge { color: #000; }

/* --- Список пользовательских тестов --- */
.tests-custom-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.tests-custom-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.tests-custom-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
}
.tests-custom-card--loading {
  opacity: 0.6;
  pointer-events: none;
}
.tests-custom-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.tests-custom-card__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-on-surface);
}
.tests-custom-card__badge {
  flex-shrink: 0;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.tests-custom-card__author,
.tests-custom-card__desc,
.tests-custom-card__stats {
  font-size: 12px;
  color: var(--color-on-surface-secondary);
}
.tests-custom-card__desc {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tests-custom-card__flags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.tests-custom-card__flag {
  display: inline-block;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--color-primary-light);
  color: var(--color-primary);
}
.tests-custom-card__flag--locked {
  background: color-mix(in srgb, #c62828 16%, transparent);
  color: #c62828;
}
.tests-custom-card--locked {
  opacity: 0.7;
  cursor: not-allowed;
}
.tests-custom-card--locked:hover {
  transform: none;
  border-color: var(--color-border);
}
.tests-custom-card:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.tests-custom-card__actions {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 2;
}
.tests-custom-card { position: relative; }
.tests-card-action {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  border: 1px solid var(--color-border);
  color: var(--color-on-surface-secondary);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tests-card-action:hover {
  background: var(--color-hover);
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.tests-card-action--danger:hover {
  color: #c62828;
  border-color: #c62828;
}
.tests-create-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.15s;
}
.tests-create-btn:hover { opacity: 0.9; }
[data-theme="dark"] .tests-create-btn { color: #000; }

/* --- Редактор пользовательских тестов --- */
.tests-editor-modal .tool-modal__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tests-editor__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tests-editor__field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-on-surface-secondary);
}
.tests-editor__field input[type="text"],
.tests-editor__field input[type="number"],
.tests-editor__field textarea {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--color-on-surface);
  font: inherit;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.tests-editor__field input:focus,
.tests-editor__field textarea:focus {
  border-color: var(--color-primary);
}
.tests-editor__field textarea { resize: vertical; min-height: 60px; }
.tests-editor__field--inline {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.tests-editor__field--inline label { margin: 0; }
.tests-editor__field--inline input[type="number"] {
  width: 120px;
}
.tests-editor__row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.tests-editor__checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--color-on-surface);
  cursor: pointer;
}
.tests-editor__checkbox input { accent-color: var(--color-primary); width: 18px; height: 18px; }
.tests-editor__themes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--color-border);
  padding-top: 14px;
}
.tests-editor__themes-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-on-surface);
}
.tests-editor__empty {
  padding: 16px;
  text-align: center;
  color: var(--color-on-surface-secondary);
  font-size: 13px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}
.tests-editor__empty--error { color: #c62828; }
.tests-editor__themes {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tests-editor__theme-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tests-editor__theme-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tests-editor__theme-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-on-surface);
}
.tests-editor__theme-mode {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.tests-editor__radio {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-on-surface);
  cursor: pointer;
}
.tests-editor__radio input { accent-color: var(--color-primary); }
.tests-editor__theme-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.tests-editor__theme-picked {
  font-size: 13px;
  color: var(--color-on-surface-secondary);
}
.tests-editor__theme-summary {
  font-size: 11px;
  color: var(--color-on-surface-secondary);
  border-top: 1px dashed var(--color-border);
  padding-top: 8px;
}
.tests-editor__own-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tests-editor__own-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  align-items: flex-start;
}
.tests-editor__own-text {
  flex: 1;
  font-size: 13px;
  color: var(--color-on-surface);
  line-height: 1.35;
}
.tests-editor__own-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.tests-editor__pick-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-on-surface);
  cursor: pointer;
  font: inherit;
  margin-bottom: 8px;
  width: 100%;
}
.tests-editor__pick-row:hover {
  border-color: var(--color-primary);
  background: var(--color-hover);
}
.tests-editor__pick-meta {
  font-size: 12px;
  color: var(--color-on-surface-secondary);
}
.tests-editor__qrow {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  cursor: pointer;
  margin-bottom: 8px;
  align-items: flex-start;
}
.tests-editor__qrow:hover { border-color: var(--color-primary); }
.tests-editor__qrow--checked {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
  border-color: var(--color-primary);
}
.tests-editor__qrow input { accent-color: var(--color-primary); margin-top: 3px; }
.tests-editor__qrow-text { flex: 1; font-size: 13px; color: var(--color-on-surface); line-height: 1.35; }
.tests-editor__qrow-right {
  margin-top: 4px;
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 600;
}

/* --- Стартовый экран теста --- */
.tests-intro {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 760px;
  padding: 20px 22px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
}
.tests-intro__title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-on-surface);
  margin: 0;
}
.tests-intro__subtitle {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-primary);
  margin: 6px 0 0;
}
.tests-intro__description {
  font-size: 14px;
  color: var(--color-on-surface);
  line-height: 1.5;
}
.tests-intro__author {
  font-size: 12px;
  color: var(--color-primary);
}
.tests-intro__meta {
  font-size: 14px;
  color: var(--color-on-surface);
  line-height: 1.6;
}
.tests-intro__best {
  color: var(--color-primary);
  font-weight: 700;
}
.tests-intro__list,
.tests-intro__themes {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--color-on-surface);
  line-height: 1.5;
}
.tests-intro__total {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-on-surface);
}
.tests-intro__notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
}
.tests-intro__notice--info {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  border: 1px solid var(--color-primary);
  color: var(--color-on-surface);
}
.tests-intro__notice--info svg {
  color: var(--color-primary);
  flex-shrink: 0;
}
.tests-intro__notice--warn {
  background: color-mix(in srgb, #ffb300 18%, transparent);
  border: 1px solid #ffb300;
  color: var(--color-on-surface);
}
.tests-intro__notice--warn svg {
  color: #c77700;
  flex-shrink: 0;
}
.tests-intro__stats {
  font-size: 13px;
  color: var(--color-primary);
}
.tests-intro__ready {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-on-surface);
  margin-top: 4px;
}
.tests-intro__loading {
  padding: 16px;
  text-align: center;
  color: var(--color-on-surface-secondary);
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  font-size: 13px;
}
.tests-intro__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.tests-intro__start {
  width: 100%;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--color-primary) 18%, transparent);
  border: 1px solid var(--color-primary);
  border-radius: 12px;
  color: var(--color-primary);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.tests-intro__start:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-primary) 28%, transparent);
  transform: translateY(-1px);
}
.tests-intro__start--disabled,
.tests-intro__start:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.tests-intro__warning {
  text-align: center;
  font-size: 12px;
  color: var(--color-primary);
}
.tests-intro__error {
  text-align: center;
  font-size: 12px;
  color: #c62828;
}

/* --- Сессия прохождения --- */
.tests-session {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 820px;
}
.tests-session__dots {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  padding: 4px 0 8px;
}
.tests-session__dot {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--color-primary) 35%, transparent);
  background: transparent;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.tests-session__dot--current {
  border-color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 16%, transparent);
  transform: scale(1.15);
}
.tests-session__dot--correct {
  background: #2e7d32;
  border-color: #2e7d32;
}
.tests-session__dot--wrong {
  background: #c62828;
  border-color: #c62828;
}
.tests-session__dot-connector {
  flex: 1;
  height: 1px;
  background: color-mix(in srgb, var(--color-primary) 30%, transparent);
  min-width: 4px;
}
.tests-session__dot-connector--done {
  background: color-mix(in srgb, var(--color-primary) 100%, transparent);
}
.tests-session__theme {
  font-size: 12px;
  color: var(--color-on-surface-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tests-session__question {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--color-on-surface);
}
.tests-session__image {
  max-width: 100%;
  max-height: 360px;
  border-radius: 14px;
  object-fit: contain;
  background: var(--color-surface);
}
.tests-session__answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.tests-session__answer {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  cursor: pointer;
  color: var(--color-on-surface);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.tests-session__answer:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-hover);
}
.tests-session__answer:disabled {
  cursor: default;
}
.tests-session__answer-letter {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 700;
  font-size: 12px;
}
.tests-session__answer-text {
  flex: 1;
}
.tests-session__answer--correct {
  border-color: #2e7d32;
  background: color-mix(in srgb, #4caf50 18%, transparent);
}
.tests-session__answer--correct .tests-session__answer-letter {
  background: #2e7d32;
  color: #fff;
}
.tests-session__answer--wrong {
  border-color: #c62828;
  background: color-mix(in srgb, #f44336 18%, transparent);
}
.tests-session__answer--wrong .tests-session__answer-letter {
  background: #c62828;
  color: #fff;
}

/* --- Экран результатов --- */
.tests-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 820px;
}
.tests-results__test-title {
  font-size: 14px;
  color: var(--color-on-surface-secondary);
}
.tests-results__score-row {
  display: flex;
  gap: 20px;
  padding: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  flex-wrap: wrap;
}
.tests-results__score {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 120px;
  padding: 12px 20px;
  background: var(--color-primary-light);
  border-radius: 14px;
}
.tests-results__score-value {
  font-size: 48px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}
.tests-results__score-max {
  font-size: 12px;
  color: var(--color-primary);
  opacity: 0.8;
  margin-top: 4px;
}
.tests-results__stats {
  flex: 1;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--color-on-surface);
}
.tests-results__stats span {
  color: var(--color-on-surface-secondary);
  margin-right: 6px;
}
.tests-results__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.tests-results__btn {
  padding: 10px 18px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-on-surface);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.tests-results__btn:hover {
  background: var(--color-hover);
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.tests-results__btn--primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.tests-results__btn--primary:hover {
  background: color-mix(in srgb, var(--color-primary) 85%, black);
  color: #fff;
}
[data-theme="dark"] .tests-results__btn--primary,
[data-theme="dark"] .tests-results__btn--primary:hover {
  color: #0a0a0a;
}

.tests-results__review {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.tests-results__review-item {
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.4;
}
.tests-results__review-item--correct {
  border-left: 4px solid #2e7d32;
}
.tests-results__review-item--wrong {
  border-left: 4px solid #c62828;
}
.tests-results__review-q {
  font-weight: 600;
  color: var(--color-on-surface);
}
.tests-results__review-theme {
  font-size: 11px;
  color: var(--color-on-surface-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.tests-results__review-a {
  color: var(--color-on-surface);
}
.tests-results__review-a span {
  color: var(--color-on-surface-secondary);
}
.tests-results__review-a--right {
  color: #2e7d32;
}

/* --- Таблица лидеров --- */
.tests-leaderboard {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  max-width: 640px;
}
.tests-leaderboard__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-on-surface);
}
.tests-leaderboard__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tests-leaderboard__table th,
.tests-leaderboard__table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-on-surface);
}
.tests-leaderboard__table th {
  font-weight: 600;
  color: var(--color-on-surface-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.tests-leaderboard__table tr:last-child td {
  border-bottom: none;
}
.tests-leaderboard__hint {
  font-size: 11px;
  color: var(--color-on-surface-secondary);
  font-style: italic;
}

