:root {
  --bg: #0b0d12;
  --card: rgba(255, 255, 255, 0.03);
  --card-2: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
  --border-str: rgba(255, 255, 255, 0.14);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --faint: #6b7280;
  --purple: #8b5cf6;
  --cyan: #06b6d4;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  position: relative;
  overflow-x: hidden;
}

.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.25;
  z-index: 0;
  pointer-events: none;
}
.glow-a { width: 420px; height: 420px; background: var(--purple); top: -120px; left: -120px; }
.glow-b { width: 420px; height: 420px; background: var(--cyan); bottom: -140px; right: -120px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: rgba(7,9,19,0.6); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(6,182,212,0.4); }

/* ---------- Login ---------- */
.login-wrap {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 410px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2.1rem;
  backdrop-filter: blur(14px);
  display: flex; flex-direction: column; gap: 0.45rem;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,0.6);
}
.brand { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.3rem; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 13px;
  display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 800; color: white;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  box-shadow: 0 8px 24px -8px rgba(139,92,246,0.6);
}
.brand h1 { font-size: 1.15rem; margin: 0; }
.brand p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }
.login-card label { font-size: 0.78rem; color: var(--muted); margin-top: 0.6rem; }
.login-card input {
  width: 100%; padding: 0.7rem 0.85rem; margin-top: 0.3rem;
  background: rgba(0,0,0,0.25); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 0.92rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-card input:focus {
  outline: none; border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.18);
}

.btn-primary {
  margin-top: 1.1rem; padding: 0.8rem 1rem;
  border: none; border-radius: 11px; cursor: pointer;
  font-size: 0.92rem; font-weight: 700; color: white;
  background: linear-gradient(135deg, var(--purple), var(--cyan));
  transition: transform .12s ease, box-shadow .15s ease, opacity .15s ease;
  box-shadow: 0 10px 28px -12px rgba(6,182,212,0.7);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.login-error { color: var(--red); font-size: 0.82rem; min-height: 1rem; margin: 0.6rem 0 0; }
.login-hint { color: var(--faint); font-size: 0.72rem; line-height: 1.5; margin-top: 0.8rem; }

/* ---------- Exam shell ---------- */
.exam-wrap {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto;
  padding: 1.6rem 1.5rem 4rem;
}
.exam-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem;
}
.exam-header h1 { margin: 0; font-size: 1.5rem; }
.exam-sub { margin: 0.25rem 0 0; color: var(--cyan); font-size: 0.85rem; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.session-chip {
  padding: 0.35rem 0.8rem; border-radius: 50px;
  background: rgba(139,92,246,0.14); border: 1px solid rgba(139,92,246,0.3);
  color: #ddd6fe; font-size: 0.78rem; font-weight: 600;
}
.btn-ghost {
  padding: 0.5rem 0.9rem; border-radius: 9px; cursor: pointer;
  background: var(--card-2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.82rem; font-weight: 600;
  transition: border-color .15s ease, background .15s ease;
}
.btn-ghost:hover { border-color: var(--purple); background: rgba(139,92,246,0.1); }
.btn-ghost:disabled { opacity: 0.5; cursor: default; }

/* ---------- Sticky command bar ---------- */
.exam-topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.2rem;
  padding: 0.85rem 1.1rem; margin-bottom: 1.3rem;
  background: rgba(13,16,24,0.82);
  border: 1px solid var(--border-str);
  border-radius: 14px;
  backdrop-filter: blur(16px);
  box-shadow: 0 14px 40px -20px rgba(0,0,0,0.7);
}
.timer {
  display: flex; flex-direction: column; min-width: 98px;
  padding-right: 1.1rem; border-right: 1px solid var(--border);
}
.timer-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--faint); }
.timer-value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
.timer.urgent .timer-value { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.progress-wrap { flex: 1; min-width: 160px; }
.progress-row {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--muted); margin-bottom: 0.4rem; font-weight: 600;
}
.progress-track { height: 8px; background: rgba(255,255,255,0.07); border-radius: 50px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--purple), var(--cyan));
  border-radius: 50px; transition: width .3s ease;
}
.btn-submit { margin: 0; white-space: nowrap; padding: 0.7rem 1.3rem; }

/* ---------- Meta / instructions ---------- */
.exam-meta {
  display: flex; flex-wrap: wrap; gap: 0.7rem; margin-bottom: 1.2rem;
}
.meta-cell {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.55rem 0.95rem; border-radius: 11px;
  background: var(--card); border: 1px solid var(--border);
}
.meta-cell span { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--faint); }
.meta-cell strong { font-size: 1rem; }

.instructions {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 13px; padding: 1rem 1.2rem; margin-bottom: 1.2rem;
}
.instructions h3 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--muted); }
.instructions ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: 0.85rem; line-height: 1.6; }

.status-box { padding: 0.9rem 1.1rem; border-radius: 11px; font-size: 0.88rem; margin-bottom: 1.2rem; display: none; }
.status-box.loading { background: rgba(6,182,212,0.1); color: #67e8f9; border: 1px solid rgba(6,182,212,0.25); }
.status-box.error { background: rgba(248,113,113,0.1); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }

/* ---------- Body: questions + palette ---------- */
.exam-body {
  display: grid;
  grid-template-columns: 1fr 232px;
  gap: 1.5rem; align-items: start;
}
.questions { display: flex; flex-direction: column; gap: 1.1rem; }

.q-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 15px; padding: 1.3rem 1.4rem;
  scroll-margin-top: 90px;
  transition: border-color .25s ease, box-shadow .25s ease, background .25s ease;
}
.q-card.q-focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(6,182,212,0.18); }
.q-card.graded.right { border-left: 3px solid var(--green); }
.q-card.graded.wrong { border-left: 3px solid var(--red); }
.q-card.graded.blank { border-left: 3px solid var(--faint); }

.q-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; }
.q-num {
  display: grid; place-items: center;
  min-width: 30px; height: 30px; padding: 0 0.4rem; border-radius: 8px;
  background: rgba(139,92,246,0.16); border: 1px solid rgba(139,92,246,0.3);
  color: #ddd6fe; font-size: 0.85rem; font-weight: 800;
}
.q-type {
  font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 0.2rem 0.5rem; border-radius: 6px; color: var(--cyan);
  background: rgba(6,182,212,0.1); border: 1px solid rgba(6,182,212,0.25); font-weight: 700;
}
.q-flag { margin-left: auto; font-size: 0.68rem; font-weight: 700; color: var(--faint); }
.q-flag.done { color: var(--green); }
.q-flag.right { color: var(--green); }
.q-flag.wrong { color: var(--red); }
.q-flag.blank { color: var(--faint); }

.q-statement { font-size: 1rem; line-height: 1.65; white-space: pre-wrap; }
.q-image { max-width: 100%; margin-top: 0.9rem; border-radius: 10px; border: 1px solid var(--border); }

/* ---------- Options (answerable) ---------- */
.options { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
.option {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 0.9rem; border-radius: 11px; cursor: pointer;
  background: rgba(255,255,255,0.02); border: 1px solid var(--border);
  transition: border-color .15s ease, background .15s ease;
}
.option:hover { border-color: var(--border-str); background: rgba(255,255,255,0.04); }
.option.selected { border-color: var(--purple); background: rgba(139,92,246,0.12); }
.option input[type="radio"] { accent-color: var(--purple); width: 17px; height: 17px; flex-shrink: 0; cursor: pointer; }
.option input:disabled { cursor: default; }
.opt-key {
  display: grid; place-items: center; width: 24px; height: 24px; flex-shrink: 0;
  border-radius: 6px; background: rgba(255,255,255,0.06);
  font-size: 0.78rem; font-weight: 800; color: var(--muted);
}
.option.selected .opt-key { background: rgba(139,92,246,0.3); color: #ede9fe; }
.opt-text { font-size: 0.92rem; line-height: 1.45; }

.numeric-wrap { margin-top: 1rem; }
.numeric-label { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.35rem; }
.numeric-input {
  width: 100%; max-width: 320px; padding: 0.65rem 0.85rem;
  background: rgba(0,0,0,0.25); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 0.95rem;
}
.numeric-input:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(139,92,246,0.18); }

/* ---------- Palette ---------- */
.palette {
  position: sticky; top: 92px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 15px; padding: 1.1rem;
}
.palette-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 0.8rem; font-weight: 700; }
.palette-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; }
.pal-btn {
  aspect-ratio: 1; border-radius: 8px; cursor: pointer;
  background: rgba(255,255,255,0.04); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.78rem; font-weight: 700;
  transition: all .12s ease;
}
.pal-btn:hover { border-color: var(--purple); color: var(--text); }
.pal-btn.answered { background: rgba(139,92,246,0.25); border-color: var(--purple); color: #ede9fe; }
.pal-btn.pal-right { background: rgba(16,185,129,0.25); border-color: var(--green); color: #d1fae5; }
.pal-btn.pal-wrong { background: rgba(248,113,113,0.22); border-color: var(--red); color: #fecaca; }
.pal-btn.pal-blank { background: rgba(255,255,255,0.03); border-color: var(--border); color: var(--faint); }

.palette-legend { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.9rem; font-size: 0.72rem; color: var(--muted); }
.palette-legend span { display: flex; align-items: center; gap: 0.45rem; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-answered { background: var(--purple); }
.dot-unanswered { background: rgba(255,255,255,0.1); border: 1px solid var(--border); }
.dot-right { background: var(--green); }
.dot-wrong { background: var(--red); }
.dot-blank { background: var(--faint); }
.palette-submit { width: 100%; margin-top: 1rem; }

.empty { color: var(--faint); font-style: italic; }

/* ---------- Result overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: rgba(5,7,12,0.72); backdrop-filter: blur(6px);
}
.result-card {
  width: 100%; max-width: 440px; text-align: center;
  background: #12151e; border: 1px solid var(--border-str);
  border-radius: 20px; padding: 2.2rem 2rem;
  box-shadow: 0 40px 100px -30px rgba(0,0,0,0.8);
}
.result-card h2 { margin: 1rem 0 0.3rem; font-size: 1.3rem; }
.result-sub { color: var(--muted); font-size: 0.88rem; margin: 0.2rem 0 0; }

.result-emblem {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-size: 2rem;
  background: rgba(16,185,129,0.15); color: var(--green); border: 2px solid rgba(16,185,129,0.4);
}
.result-ring {
  width: 128px; height: 128px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--cyan)) calc(var(--pct) * 1%), rgba(255,255,255,0.07) 0);
}
.result-ring.great { --ring-color: var(--green); }
.result-ring.ok { --ring-color: var(--cyan); }
.result-ring.low { --ring-color: var(--amber); }
.result-ring-inner {
  width: 100px; height: 100px; border-radius: 50%; background: #12151e;
  display: grid; place-items: center; align-content: center;
}
.result-ring-inner strong { font-size: 1.8rem; font-weight: 800; }
.result-ring-inner span { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--faint); }

.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin: 1.3rem 0; }
.result-stats .rs {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.7rem; border-radius: 11px; background: var(--card); border: 1px solid var(--border);
}
.result-stats .rs span { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--faint); }
.result-stats .rs strong { font-size: 1.05rem; }

.breakdown { margin: 0.4rem 0 1.3rem; text-align: left; }
.breakdown-legend { display: flex; gap: 1rem; font-size: 0.7rem; color: var(--muted); margin-bottom: 0.6rem; }
.breakdown-legend span { display: flex; align-items: center; gap: 0.4rem; }
.breakdown-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 0.3rem; }
.bd-cell {
  aspect-ratio: 1; display: grid; place-items: center;
  border-radius: 6px; font-size: 0.66rem; font-weight: 700;
}
.bd-cell.right { background: rgba(16,185,129,0.22); color: #d1fae5; }
.bd-cell.wrong { background: rgba(248,113,113,0.2); color: #fecaca; }
.bd-cell.blank { background: rgba(255,255,255,0.05); color: var(--faint); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .exam-body { grid-template-columns: 1fr; }
  .palette { position: static; order: -1; }
  .palette-grid { grid-template-columns: repeat(10, 1fr); }
  .palette-submit { display: none; }
  .exam-topbar { flex-wrap: wrap; gap: 0.8rem; }
  .btn-submit { flex: 1; }
}
