/* ==================== ПЕРЕМЕННЫЕ И БАЗА ==================== */
:root {
  --bg: #eef2f8;
  --card: #ffffff;
  --text: #1a2233;
  --muted: #6b7690;
  --primary: #4f6ef7;
  --primary-hover: #3d5ae0;
  --border: #dbe2ef;
  --ok: #1fa971;
  --err: #e5484d;
  --warn: #f0a600;
  --radius: 12px;
}

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 700; line-height: 1.2; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 18px; }
a { color: var(--primary); text-decoration: none; }

/* Утилиты */
.muted { color: var(--muted); font-size: 14px; }
.err { color: var(--err); font-size: 14px; font-weight: 500; }
.ok { color: var(--ok); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
[hidden] { display: none !important; }
.text-center { text-align: center; }

/* ==================== СЕТКА И КАРТОЧКИ ==================== */
.home {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 4px 15px rgba(0,0,0,.05);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.narrow { max-width: 440px; width: 100%; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ==================== ИНПУТЫ И КНОПКИ ==================== */
input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* Важно для iOS, чтобы не было зума */
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  outline: none;
  background: #fff;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

label.lbl { display: block; margin: 12px 0; font-size: 14px; color: #444; font-weight: 500; }

button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover { background: #f4f7ff; }
button:active { transform: scale(0.98); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: var(--primary-hover); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: #eef2f8; color: var(--text); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ==================== ШАПКА И ВКЛАДКИ ==================== */
.topbar {
  display: flex;
  align-items: center;
  padding: 15px 30px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 15px;
}

.brand { font-weight: 800; font-size: 18px; }
.tabs { display: flex; gap: 8px; margin-left: 20px; flex-wrap: wrap; }
.tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
#logout { margin-left: auto; }

main { padding: 30px; max-width: 1100px; margin: 0 auto; }

/* ==================== КОНСТРУКТОР ВОПРОСОВ ==================== */
.question {
  background: #fafbff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.qhead { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.qnum { font-weight: 700; color: var(--primary); white-space: nowrap; }
.qhead select { width: auto; max-width: 200px; padding: 8px; }
.qhead .del { margin-left: auto; color: var(--err); font-size: 18px; padding: 8px; }

.q-options .opt { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.opt input[type=radio], .opt input[type=checkbox] { width: 20px; height: 20px; flex: 0 0 auto; margin: 0; }
.opt input[type=text], .opt .opt-text { flex: 1; }

/* ==================== ТАБЛИЦЫ ==================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 15px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 600px; }
th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f8faff; color: #555; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
tr:hover td { background: #fafbff; }
tr:last-child td { border-bottom: none; }

/* ==================== БЕЙДЖИ ОЦЕНОК ==================== */
.badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-weight: 800; font-size: 14px; }
.g5 { background: #d9f5e8; color: #0d7f52; }
.g4 { background: #e3efff; color: #2a5bd7; }
.g3 { background: #fff3d6; color: #8a6100; }
.g2 { background: #ffe1e1; color: #b12424; }

/* ==================== МОДАЛЬНЫЕ ОКНА ==================== */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 25, 50, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 15px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  max-width: 850px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-head h2 { margin: 0; font-size: 22px; }

/* ==================== ЭКРАН УЧЕНИКА ==================== */
.screen { max-width: 800px; margin: 0 auto; padding: 20px; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }

.testbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 12px 20px; border-radius: 10px;
  margin-bottom: 15px; font-weight: 700; font-size: 15px;
  border: 1px solid var(--border); flex-wrap: wrap; gap: 10px;
}

.timer { color: var(--primary); font-variant-numeric: tabular-nums; font-size: 18px; }

/* Прогресс-бар */
.progress { margin-bottom: 20px; }
.progress-bar { height: 10px; background: #dde3ee; border-radius: 5px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.1); }
#progressFill { height: 100%; background: linear-gradient(90deg, #4f6ef7, #6f8cff); width: 0; transition: width 0.3s ease; }
.progress-text { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; font-weight: 700; }

/* Кнопки навигации (для телефона большие) */
.nav-buttons { display: flex; justify-content: space-between; margin-top: 20px; gap: 12px; }
.nav-buttons button { flex: 1; padding: 16px; font-size: 16px; border-radius: 10px; }

/* Вопросы ученику */
.qtext { font-size: 18px; font-weight: 700; margin: 15px 0 20px; line-height: 1.5; }
.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 15px 18px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: all 0.2s; font-size: 16px; background: #fff;
}
.option:hover { background: #f4f7ff; border-color: var(--primary); }
.option input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; margin-top: 2px; }

/* Лекция */
.lecture { white-space: pre-wrap; line-height: 1.6; font-size: 16px; background: #fafbff; padding: 20px; border-radius: 10px; border: 1px solid var(--border); }

/* Результаты */
.result-box { text-align: center; padding: 25px; background: #fafbff; border-radius: 12px; margin: 20px 0; border: 1px solid var(--border); }
.result-box .big { font-size: 48px; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: 10px; }
.result-box .grade { font-size: 32px; color: var(--ok); font-weight: 800; }

/* Бейджи (Достижения) */
.badge-icon { font-size: 48px; margin: 0 5px; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.15)); display: inline-block; animation: pop 0.4s ease-out; }
@keyframes pop { 0% { transform: scale(0); } 80% { transform: scale(1.1); } 100% { transform: scale(1); } }

/* ==================== LIVE РЕЖИМ ==================== */
#liveStats { background: #f8faff; padding: 20px; border-radius: 10px; border: 1px solid var(--border); margin-top: 15px; }
#liveStats h3 { color: var(--primary); }
.live-option { display: block; padding: 15px; border: 2px solid var(--border); border-radius: 10px; margin-bottom: 10px; cursor: pointer; font-size: 18px; transition: 0.2s; }
.live-option:hover { border-color: var(--primary); background: #f4f7ff; }
.live-option input { display: none; }
.live-option input:checked + span { color: var(--primary); font-weight: 800; }

/* ==================== АДАПТИВ ПОД ТЕЛЕФОНЫ ==================== */
@media (max-width: 768px) {
  main { padding: 15px; }
  .topbar { padding: 12px 15px; justify-content: center; }
  .brand { width: 100%; text-align: center; margin-bottom: 10px; }
  .tabs { margin-left: 0; width: 100%; justify-content: center; }
  #logout { margin-left: 0; width: 100%; margin-top: 10px; }
  
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  
  .modal-box { padding: 16px; border-radius: 12px; }
  
  /* Экран ученика */
  .screen { padding: 12px; justify-content: flex-start; padding-top: 20px; }
  .testbar { padding: 10px 15px; font-size: 14px; justify-content: center; text-align: center; }
  .timer { font-size: 16px; }
  
  .qtext { font-size: 17px; }
  .option { padding: 14px; font-size: 15px; }
  .nav-buttons button { padding: 14px; font-size: 15px; }
  
  .result-box .big { font-size: 40px; }
}

@media (max-width: 480px) {
  h1 { font-size: 20px; }
  h2 { font-size: 18px; }
  
  .qhead { flex-direction: column; align-items: stretch; }
  .qhead select { max-width: 100%; }
  .qhead .del { align-self: flex-end; margin-top: -40px; }
  
  .nav-buttons { flex-direction: column; }
  .nav-buttons button { width: 100%; }
}

/* ==================== ПЕЧАТЬ ==================== */
@media print {
  .topbar, .tabs, #logout, .toolbar, .modal, .nav-buttons, .btn-to-bank, button { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: none; padding: 0; margin: 0 0 20px 0; }
  .question { page-break-inside: avoid; border: none; border-bottom: 1px dashed #ccc; padding: 0 0 20px 0; background: #fff; }
  .q-options .opt { margin-bottom: 5px; }
}