:root {
  /* 🚂 Корпоративные цвета РЖД */
  --primary: #E30613;          /* Основной красный РЖД */
  --primary-hover: #B8050F;    /* Тёмно-красный для ховера */
  --primary-light: #FFEAEA;    /* Светлый оттенок для фонов */
  --bg: #F7F8FA;               /* Светло-серый фон страницы */
  --card: #FFFFFF;             /* Фон карточек */
  --text: #2D2D2D;             /* Основной текст */
  --text-muted: #6B7280;       /* Второстепенный текст */
  --border: #E2E8F0;           /* Границы */
  --success: #16A34A;          /* Зелёный для верных ответов */
  --danger: #DC2626;           /* Красный для ошибок/таймера */
  --warning: #F59E0B;          /* Оранжевый для предупреждений */
  --radius: 12px;              /* Единый радиус скругления */
  --shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.08), 0 2px 8px -4px rgba(0, 0, 0, 0.05);
  --font-main: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 🖼 Фоновое изображение сайта */
body {
  font-family: var(--font-main);
  color: var(--text);
  line-height: 1.6;
  padding: 20px;
  -webkit-font-smoothing: antialiased;

  background-color: var(--bg); /* Фоллбэк, если картинка не загрузится */
  background-image: url('../images/bg.png'); /* Путь относительно папки assets/ */
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed; /* Фон остаётся на месте при скролле */
}

/* 🔲 Полупрозрачная подложка для читаемости */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  /* Белый оверлей 85%. Измените последнее значение (0.85) для прозрачности */
  background: rgba(255, 255, 255, 0.85);
  
  /* 💡 Опционально: лёгкий корпоративный оттенок РЖД */
  background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(227,6,19,0.05) 100%);
}

.container {
  max-width: 780px;
  margin: 40px auto;
  padding: 32px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.hidden { display: none !important; }
.text-center { text-align: center; }

/* 🎨 Стильный заголовок */
h2 {
  margin-bottom: 28px;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  position: relative;
  padding-bottom: 14px;
  letter-spacing: -0.01em;
}

h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 321px;
  height: 4px;
  background: var(--primary);
  border-radius: 2px;
  box-shadow: 0 2px 4px rgba(227, 6, 19, 0.3);
}

h3 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.95rem;
}

select, input[type="password"], input[type="text"] {
  width: 100%;
  padding: 13px 16px;
  margin-bottom: 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  transition: all 0.25s ease;
  background: #FAFAFA;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: #FFFFFF;
}

button {
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  padding: 14px 22px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  width: 100%;
  letter-spacing: 0.01em;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(227, 6, 19, 0.25);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

/* ⏱ Тест */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

#timer {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  background: #F8FAFC;
  border: 1.5px solid var(--border);
  min-width: 90px;
  text-align: center;
  transition: all 0.3s ease;
}

#timer.warning {
  color: var(--warning);
  background: #FFFBEB;
  border-color: #FCD34D;
}

#timer.danger {
  color: #FFFFFF;
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

#q-image {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
  margin-bottom: 20px;
  border-radius: 10px;
  background: #F8FAFC;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

#q-text {
  font-size: 1.2rem;
  margin-bottom: 24px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
}

#options {
  display: grid;
  gap: 14px;
}

.option-btn {
  background: #FFFFFF;
  color: var(--text);
  border: 2px solid var(--border);
  text-align: left;
  padding: 18px 20px;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
}

.option-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.option-btn::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 0;
  background: var(--primary);
  transition: height 0.2s ease;
}

.option-btn:hover:not(:disabled)::before {
  height: 60%;
}

/* 📊 Результаты и разбор */
.stats {
  display: flex;
  gap: 16px;
  margin: 28px 0;
  flex-wrap: wrap;
}

.stat-box {
  flex: 1;
  min-width: 130px;
  padding: 20px;
  background: #F8FAFC;
  border-radius: 12px;
  text-align: center;
  border: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.stat-box:hover { transform: translateY(-2px); }

.stat-box span {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 6px;
}

.stat-box.correct span { color: var(--success); }
.stat-box.incorrect span { color: var(--danger); }

.hint {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-style: italic;
  background: #F8FAFC;
  padding: 14px 18px;
  border-radius: 10px;
  border-left: 4px solid var(--warning);
  line-height: 1.5;
}

.review-item {
  margin-bottom: 32px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.review-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.review-img {
  max-width: 100%;
  max-height: 240px;
  margin-bottom: 16px;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.review-q {
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 1.1rem;
  color: var(--text);
}

.review-a {
  color: var(--primary);
  font-weight: 500;
  padding: 8px 14px;
  background: var(--primary-light);
  border-radius: 8px;
  display: inline-block;
  margin-top: 4px;
}

.btn-secondary {
  background: #6B7280;
  margin-top: 20px;
}

.btn-secondary:hover {
  background: #4B5563;
}

/* 📱 Адаптивность */
@media (max-width: 640px) {
  .container {
    margin: 16px auto;
    padding: 24px;
  }
  .header {
    flex-direction: column;
    align-items: stretch;
  }
  #timer {
    text-align: center;
    width: 100%;
  }
  h2 { font-size: 1.5rem; }
  .stats { flex-direction: column; }
}

.test-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.badge { background: #e2e8f0; padding: 4px 10px; border-radius: 6px; font-size: 0.85rem; font-weight: 500; }
.timer { background: #fef3c7; color: #92400e; font-family: monospace; font-size: 1.1rem; }
.topic-label { background: #dbeafe; color: #1e40af; padding: 6px 12px; border-radius: 6px; display: inline-block; margin-bottom: 16px; font-weight: 600; }

/* ==================== Альтернативные входы ==================== */
.alt-login-block {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px dashed var(--border, #e2e8f0);
}

.alt-login-divider {
    text-align: center;
    color: var(--muted, #64748b);
    font-size: 0.8rem;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.alt-login-divider span {
    background: var(--card, #fff);
    padding: 0 12px;
    position: relative;
    display: inline-block;
}

.alt-login-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.alt-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    background: #f8fafc;
    color: #475569;
}

.alt-login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.06);
}

.alt-login-btn .alt-icon {
    font-size: 1rem;
}

/* Преподаватель — синий акцент */
.teacher-btn {
    background: #eff6ff;
    color: #1e40af;
    border-color: #dbeafe;
}
.teacher-btn:hover {
    background: #dbeafe;
    color: #1e3a8a;
}

/* Администратор — нейтрально-тёмный */
.admin-btn {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}
.admin-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

@media (max-width: 480px) {
    .alt-login-buttons {
        flex-direction: column;
    }
    .alt-login-btn {
        justify-content: center;
    }
}

/* ==================== Тема вопроса ==================== */
.topic-label {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 6px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-left: 4px solid #2563eb;
}
.topic-label.hidden {
    display: none !important;
}

/* ==================== Альтернативные входы ==================== */
.alt-login-block {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px dashed var(--border, #e2e8f0);
}
.alt-login-divider {
    text-align: center;
    color: var(--muted, #64748b);
    font-size: 0.8rem;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.alt-login-divider span {
    background: var(--card, #fff);
    padding: 0 12px;
    position: relative;
    display: inline-block;
}
.alt-login-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}
.alt-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    background: #f8fafc;
    color: #475569;
}
.alt-login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.06);
}
.teacher-btn {
    background: #eff6ff;
    color: #1e40af;
    border-color: #dbeafe;
}
.teacher-btn:hover {
    background: #dbeafe;
    color: #1e3a8a;
}
.admin-btn {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}
.admin-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}
@media (max-width: 480px) {
    .alt-login-buttons { flex-direction: column; }
    .alt-login-btn { justify-content: center; }
}


/* ==================== Модальное окно студента ==================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-box {
    background: #fff;
    border-radius: 14px;
    width: 400px;
    max-width: 95vw;
    box-shadow: 0 20px 60px rgb(0 0 0 / 0.2);
    overflow: hidden;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover {
    color: #dc2626;
}
.modal-body {
    padding: 20px;
}
.modal-body select,
.modal-body input {
    width: 100%;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 1rem;
}
.modal-body .btn {
    width: 100%;
}

/* Кнопка "Студент" */
.student-btn {
    background: #f0fdf4;
    color: #166534;
    border-color: #bbf7d0;
}
.student-btn:hover {
    background: #dcfce7;
    color: #14532d;
}

.q-type-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: .8rem;
    font-weight: 600;
    margin-bottom: 10px;
}
.q-type-badge.single   { background: #dcfce7; color: #166534; }
.q-type-badge.multiple { background: #fef3c7; color: #92400e; }
.q-type-badge.open     { background: #f1f5f9; color: #475569; }
.q-type-badge.yesno    { background: #dcfce7; color: #166534; }
.q-type-badge.sequence { background: #fef3c7; color: #92400e; }
.q-type-badge.matching { background: #fef3c7; color: #92400e; }
.q-type-badge.numeric  { background: #f1f5f9; color: #475569; }
.q-type-badge.hidden   { display: none !important; }

/* Бейдж типа вопроса */
.q-type-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: .8rem;
    font-weight: 600;
    margin-bottom: 10px;
}
.q-type-badge.single   { background: #dcfce7; color: #166534; }
.q-type-badge.multiple { background: #fef3c7; color: #92400e; }
.q-type-badge.open     { background: #f1f5f9; color: #475569; }
.q-type-badge.yesno    { background: #dcfce7; color: #166534; }
.q-type-badge.sequence { background: #fef3c7; color: #92400e; }
.q-type-badge.matching { background: #fef3c7; color: #92400e; }
.q-type-badge.numeric  { background: #f1f5f9; color: #475569; }
.q-type-badge.hidden   { display: none !important; }

/* Метка темы */
.topic-label {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 6px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-left: 4px solid #2563eb;
}
.topic-label.hidden { display: none !important; }

/* Выделенный вариант ответа */
.option-btn.selected {
    background: #eff6ff !important;
    border-color: #2563eb !important;
}

/* =========================================================
   Логотип TestMaster
   ========================================================= */

.testmaster-logo {
    display: flex;
    justify-content: center;
    align-items: center;

    width: 100%;
    margin: 0 auto 24px;
}

.testmaster-logo img {
    display: block;

    width: auto;
    max-width: 100%;
    height: 62px;

    object-fit: contain;
}

@media (max-width: 600px) {

    .testmaster-logo {
        margin-bottom: 18px;
    }

    .testmaster-logo img {
        height: auto;
        width: 90%;
        max-width: 420px;
    }
}

/* =========================================================
   Студенческий интерфейс на телефонах
   ========================================================= */

html {
    -webkit-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

#q-text,
.option-btn,
.sequence-text,
.matching-row,
.review-q,
.review-a {
    overflow-wrap: anywhere;
}

#open-answer {
    resize: vertical;
}

@media (max-width: 640px) {
    body {
        padding:
            max(10px, env(safe-area-inset-top))
            max(10px, env(safe-area-inset-right))
            max(14px, env(safe-area-inset-bottom))
            max(10px, env(safe-area-inset-left));
        background-attachment: scroll;
    }

    .container {
        width: 100%;
        margin: 0 auto 12px;
        padding: 18px 16px;
        border-radius: 10px;
    }

    h2 {
        margin-bottom: 20px;
        padding-bottom: 11px;
        font-size: 1.4rem;
        line-height: 1.25;
    }

    h2::after {
        width: min(72%, 240px);
    }

    h3 {
        font-size: 1.15rem;
        line-height: 1.3;
    }

    select,
    input[type="password"],
    input[type="text"],
    textarea {
        min-height: 48px;
        font-size: 16px !important;
    }

    button,
    .alt-login-btn,
    .attempt-pill,
    .br {
        min-height: 44px;
    }

    .header {
        position: sticky;
        top: 0;
        z-index: 10;
        margin: -18px -16px 18px;
        padding: 14px 16px;
        background: rgba(255, 255, 255, .96);
        border-radius: 10px 10px 0 0;
        box-shadow: 0 4px 10px rgba(15, 23, 42, .06);
        backdrop-filter: blur(8px);
    }

    .header h3 {
        margin: 0;
        text-align: center;
    }

    #timer {
        width: auto;
        align-self: center;
        min-width: 124px;
        padding: 8px 14px;
        font-size: 1.2rem;
    }

    #q-text {
        margin-bottom: 18px;
        font-size: 1.08rem;
        line-height: 1.5;
    }

    #q-image {
        width: 100%;
        max-height: 42vh;
    }

    #options {
        gap: 10px;
    }

    .option-btn {
        min-height: 52px;
        padding: 14px 15px !important;
        margin-bottom: 4px !important;
        line-height: 1.4;
        touch-action: manipulation;
    }

    #numeric-answer {
        max-width: none !important;
    }

    .sequence-item {
        align-items: flex-start !important;
        flex-wrap: wrap;
    }

    .sequence-number {
        width: 26px !important;
        flex-basis: 26px !important;
    }

    .sequence-text {
        max-width: calc(100% - 42px) !important;
        flex: 1 1 calc(100% - 42px) !important;
    }

    .sequence-up,
    .sequence-down {
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        height: 44px !important;
        min-height: 44px !important;
        max-height: 44px !important;
        margin-left: 34px !important;
    }

    .sequence-down {
        margin-left: 0 !important;
    }

    .matching-row {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 8px !important;
    }

    .matching-select {
        min-height: 48px;
        font-size: 16px !important;
    }

    #control-buttons {
        flex-direction: column;
        gap: 8px !important;
    }

    #control-buttons button {
        margin-top: 0;
    }

    .modal-overlay {
        padding:
            max(10px, env(safe-area-inset-top))
            max(10px, env(safe-area-inset-right))
            max(10px, env(safe-area-inset-bottom))
            max(10px, env(safe-area-inset-left));
        align-items: flex-end;
    }

    .modal-box {
        width: 100%;
        max-width: none;
        max-height: calc(100dvh - 20px);
        overflow-y: auto;
        border-radius: 16px 16px 10px 10px;
    }

    .modal-close {
        min-height: 44px;
        min-width: 44px;
    }

    .stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .stat-box {
        min-width: 0;
        padding: 14px 10px;
    }
}

@media (max-width: 380px) {
    .container {
        padding-right: 13px;
        padding-left: 13px;
    }

    .header {
        margin-right: -13px;
        margin-left: -13px;
    }

    .alt-login-btn {
        flex-basis: 100% !important;
    }
}

@media (hover: none) {
    button:hover:not(:disabled),
    .option-btn:hover:not(:disabled),
    .alt-login-btn:hover,
    .stat-box:hover {
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
