:root {
  --bg: #0f1420;
  --panel: #171d2b;
  --panel-2: #1f2637;
  --border: #2a3244;
  --text: #e7ebf3;
  --muted: #8b93a7;
  --accent: #e75225;
  --accent-hover: #c4461f;
  --danger: #e3564a;
  --success: #37b26c;
}

body.tg-light {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #f0f1f5;
  --border: #e1e4ea;
  --text: #14171f;
  --muted: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 24px;
}

.hidden { display: none !important; }

.center-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 15px;
}

.screen { max-width: 480px; margin: 0 auto; padding: 20px 16px 90px; }
.screen h1 { font-size: 18px; margin: 0 0 16px; }

.stack { display: flex; flex-direction: column; gap: 8px; }

.exam-item-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 15px;
  cursor: pointer;
}
.exam-item-btn:active { background: var(--panel-2); }

.hint { color: var(--muted); font-size: 14px; }

.group-card {
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.group-card p { margin: 0; white-space: pre-wrap; }
.group-image, .q-image { cursor: zoom-in; }
.group-image { width: 100%; border-radius: 8px; margin-bottom: 8px; display: block; }

.question-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.q-number { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.q-text { font-size: 15px; margin-bottom: 10px; line-height: 1.45; white-space: pre-wrap; }
.q-image { width: 100%; border-radius: 8px; margin-bottom: 10px; display: block; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  overflow: auto;
  cursor: zoom-out;
}
.lightbox img {
  max-width: none;
  width: auto;
  height: auto;
  min-width: 100%;
  border-radius: 4px;
}

.option-list { display: flex; flex-direction: column; gap: 8px; }
.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}
.option-row:has(input:checked) { border-color: var(--accent); background: rgba(231,82,37,0.12); }
.option-row input { width: 18px; height: 18px; flex-shrink: 0; }

.option-image-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.option-image-label {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  display: block;
}
.option-image-label:has(input:checked) { border-color: var(--accent); }
.option-image-label img { width: 100%; height: 120px; object-fit: cover; display: block; cursor: zoom-in; }
.option-image-label input { position: absolute; top: 6px; left: 6px; width: 18px; height: 18px; }
.option-letter-badge {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 12px; padding: 2px 7px; border-radius: 6px;
}

.answer-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.primary-btn {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 448px;
  margin: 0 auto;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:active { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.6; }

.result-score { font-size: 28px; font-weight: 700; margin: 0 0 8px; }
#result-body p { font-size: 15px; margin: 4px 0; }

.countdown {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.section-gap { margin-top: 28px; }

.attempt-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.attempt-title { font-size: 14px; flex: 1; min-width: 0; }
.attempt-note { font-size: 12px; color: var(--muted); text-align: right; }

.secondary-btn {
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.secondary-btn:active { background: rgba(231,82,37,0.12); }

.review-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.review-card.correct { border-left-color: var(--success); }
.review-card.incorrect { border-left-color: var(--danger); }

.review-option {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 8px;
}
.review-option.is-correct { border-color: var(--success); color: var(--success); }
.review-option.is-wrong { border-color: var(--danger); color: var(--danger); }

.review-answer { font-size: 14px; margin-top: 6px; }

/* --- Exam-in-progress content protection (deters casual screenshotting/
   copying; not a real DRM — see app.js's tab-switch violation tracking
   for the actual anti-cheating enforcement) --- */
#exam-screen.locked-down {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#exam-screen.locked-down img {
  pointer-events: none;
  -webkit-user-drag: none;
}

.violation-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 24px;
}
.violation-overlay.hidden { display: none; }

.save-status {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  color: var(--hint, #8e8e93);
}
.save-status.error { color: var(--danger, #e5484d); }

.submit-box { border-color: var(--accent, #2ea6ff); }
.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent, #2ea6ff);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.violation-box {
  background: var(--panel, #1c1c1e);
  border: 1px solid var(--danger, #e5484d);
  border-radius: 16px;
  padding: 24px;
  max-width: 340px;
  text-align: center;
}
.violation-box h2 { color: var(--danger, #e5484d); margin: 0 0 12px; font-size: 18px; }
.violation-box p { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
.violation-box .count { font-weight: 700; font-size: 22px; }

/* --- Invisible-ish per-student watermark ---
   Faint, repeating text overlay carrying the student's Telegram id, shown
   only while an exam is in progress. Not meant to be legible at a glance —
   its purpose is that a leaked screenshot still carries enough of it to
   trace back to whoever took it, which is a real deterrent even though no
   CSS overlay can stop a screenshot from being taken in the first place. */
#exam-watermark {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  overflow: hidden;
  opacity: 0.06;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  transform: rotate(-25deg) scale(1.4);
  transform-origin: center;
}
#exam-watermark span {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  margin: 28px 18px;
  color: #000;
}
:root[data-theme="dark"] #exam-watermark span,
body.tg-dark #exam-watermark span {
  color: #fff;
}
