:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2230;
  --muted: #6b7385;
  --border: #dfe3ec;
  --primary: #2f6fed;
  --primary-dark: #2259c7;
  --danger: #d93a3a;
  --warn-bg: #fff4d6;
  --warn-border: #f0c14b;
  --ok: #1f9d55;
}

* { box-sizing: border-box; }

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

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 6px 24px rgba(20, 30, 60, 0.06);
}

/* ---------- Setup ---------- */
.setup-card { max-width: 980px; margin: 40px auto; }
.setup-card h1 { margin: 0 0 4px; }
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin: 24px 0;
}
@media (max-width: 760px) {
  .setup-grid { grid-template-columns: 1fr; }
  .setup-card { margin: 16px; padding: 20px; }
}
h3 { margin: 18px 0 10px; font-size: 1rem; }
label { display: block; margin-bottom: 12px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
}
input[type="text"]:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }

.instructions { padding-left: 18px; margin: 0; font-size: 0.9rem; }
.instructions li { margin-bottom: 6px; }

.preview-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #10131a;
  border-radius: 12px;
  overflow: hidden;
}
.preview-wrap video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #8a93a8;
}
.mic-meter {
  height: 6px; background: var(--border); border-radius: 3px; margin: 10px 0; overflow: hidden;
}
#mic-level { height: 100%; width: 0; background: var(--ok); transition: width 80ms linear; }

.device-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.agree { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 0.95rem; margin: 8px 0 20px; }
.agree input { margin-top: 4px; }

.status { min-height: 1.4em; font-size: 0.9rem; margin: 8px 0 0; }
.status.error { color: var(--danger); }
.status.ok { color: var(--ok); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover:not(:disabled) { background: #f0f2f7; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; }

/* ---------- Exam ---------- */
.exam-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.exam-header-left, .exam-header-right { display: flex; align-items: center; gap: 12px; }
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--danger);
  animation: pulse 1.2s infinite;
}
.rec-label { color: var(--danger); font-weight: 700; font-size: 0.85rem; letter-spacing: 1px; }
@keyframes pulse { 50% { opacity: 0.3; } }

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.3rem; font-weight: 700;
  padding: 4px 12px; border-radius: 8px; background: #eef2fb;
}
.timer.low { background: #fde3e3; color: var(--danger); }
.violation-count { font-size: 0.9rem; color: var(--muted); }
.violation-count.has { color: var(--danger); font-weight: 700; }

.warning-banner {
  position: sticky; top: 61px; z-index: 9;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  font-weight: 600;
}
.warning-banner #warning-text { flex: 1; }

.questions { max-width: 820px; margin: 24px auto 140px; padding: 0 16px; }
.question {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 24px; margin-bottom: 16px;
}
.question h4 { margin: 0 0 12px; font-size: 1rem; }
.question .qnum { color: var(--primary); margin-right: 6px; }
.option {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 12px; margin: 6px 0;
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); cursor: pointer;
}
.option:hover { background: #f6f8fc; }
.option input { margin: 0; }
textarea { min-height: 120px; resize: vertical; }

.self-view {
  position: fixed; right: 20px; bottom: 20px;
  width: 140px; height: 140px; border-radius: 50%;
  object-fit: cover; transform: scaleX(-1);
  border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  background: #000; z-index: 20;
}

/* ---------- Done ---------- */
.done-card { max-width: 560px; margin: 80px auto; text-align: center; }
.progress { height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; margin: 24px 0 8px; }
#progress-bar { height: 100%; width: 0; background: var(--primary); transition: width 0.2s; }
.done-actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }

/* ---------- Dialog ---------- */
dialog { border: none; border-radius: 12px; padding: 24px; max-width: 420px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 15, 30, 0.5); }
dialog h3 { margin-top: 0; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* Make exam text unselectable to discourage copying */
#exam-screen .question h4, #exam-screen .option { user-select: none; }
