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

/* The UA rule is only [hidden]{display:none} (specificity 0,1,0), which any
   id-based display rule below (e.g. #login{display:grid}) would override —
   leaving the login screen on top of the signed-in page. Keep this first. */
[hidden] { display: none !important; }

:root {
  --bg:      #0f1117;
  --surface: #1a1d27;
  --surface-elev: #232636;
  --border:  #2e3147;
  --accent:  #4f8ef7;
  --accent-rehearsal: #3ab07a;
  --text:    #e0e2f0;
  --muted:   #7a7f9a;
  --ok:      #3ab07a;
  --fail:    #e05a5a;
  --pending: #d4a24a;
  --mono:    'JetBrains Mono', 'Fira Mono', ui-monospace, monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

code, pre { font-family: var(--mono); }

/* ── Rehearsal banner ──────────────────────────────────────────────────── */
/* On every rehearsal screen, so a screenshot of the practice page can never
   pass for the real exam. */
.rehearsal-banner {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent-rehearsal);
  color: #07130d;
  text-align: center;
  font-size: .9rem;
  padding: .55rem 1rem;
}
.rehearsal-banner strong { letter-spacing: .04em; }

.boot-status { color: var(--muted); text-align: center; padding: 4rem 1rem; }

/* ── Login, sign-up and the other full-page cards ─────────────────────── */
#login, .front {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 2rem;
}
body:has(.rehearsal-banner:not([hidden])) .front { min-height: calc(100vh - 2.6rem); }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-card.wide { max-width: 520px; }
.login-card h1 { font-size: 1.4rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.login-card .subtitle { color: var(--muted); margin: .3rem 0 1.5rem; font-size: .9rem; }

form label {
  display: block;
  margin-bottom: 1rem;
  font-size: .85rem;
  color: var(--muted);
}

form input {
  display: block;
  width: 100%;
  margin-top: .3rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .55rem .7rem;
  font-family: inherit;
  font-size: .95rem;
}
form input:focus { outline: none; border-color: var(--accent); }

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: .6rem 1.2rem;
  border-radius: 5px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: default; }

button.link {
  background: none;
  color: var(--muted);
  padding: 0;
  font-weight: normal;
  font-size: .85rem;
  text-decoration: underline;
}
button.link:hover { color: var(--text); }

.error {
  color: var(--fail);
  font-size: .85rem;
  margin-top: .8rem;
  min-height: 1.2em;
}

/* ── Main page ─────────────────────────────────────────────────────────── */
#main { max-width: 900px; margin: 0 auto; padding: 2rem; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}
header h1 { font-size: 1.4rem; display: flex; align-items: center; gap: .6rem; }

.badge {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .1em;
  padding: .2rem .6rem;
  border-radius: 4px;
  color: var(--accent);
  background: rgba(79, 142, 247, 0.13);
}
.badge.rehearsal { color: var(--accent-rehearsal); background: rgba(58, 176, 122, 0.13); }

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .9rem;
  color: var(--muted);
}
#student-label { color: var(--text); font-weight: 600; }

/* ── Exam countdown ────────────────────────────────────────────────────── */
.exam-clock {
  display: inline-flex;
  align-items: baseline;
  gap: .45rem;
  padding: .25rem .65rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
}
.clock-label {
  font-size: .7rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.clock-time {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.exam-clock.pending .clock-time  { color: var(--muted); }
.exam-clock.warn {
  border-color: var(--pending);
  background: rgba(212, 162, 74, 0.12);
}
.exam-clock.warn .clock-time,
.exam-clock.warn .clock-label { color: var(--pending); }
.exam-clock.critical {
  border-color: var(--fail);
  background: rgba(224, 90, 90, 0.14);
}
.exam-clock.critical .clock-time,
.exam-clock.critical .clock-label { color: var(--fail); }

.intro {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 1.5rem;
}
.intro-warnings {
  list-style: none;
  margin: 0 0 1.5rem;
  display: grid;
  gap: .6rem;
}
.intro-warnings li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn, #d8a13a);
  border-radius: 6px;
  padding: .7rem .9rem;
  font-size: .9rem;
  color: var(--text);
  line-height: 1.5;
}
.intro-warnings code {
  background: var(--surface-elev);
  border: 1px solid var(--border);
  padding: .1rem .4rem;
  border-radius: 3px;
  font-size: .85em;
}

.intro code {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: .1rem .4rem;
  border-radius: 3px;
  font-size: .85em;
  color: var(--text);
}

/* ── Task cards ────────────────────────────────────────────────────────── */
.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.task-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  cursor: pointer;
  user-select: none;
}
.task-title { flex: 1; }
.task-title h2 { font-size: 1.05rem; display: flex; align-items: center; gap: .6rem; }

.status-chip {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: .2rem .55rem;
  border-radius: 12px;
  white-space: nowrap;
}
.status-chip.none { color: var(--muted); background: var(--surface-elev); }
.status-chip.pending { color: var(--pending); background: rgba(212, 162, 74, 0.13); }
.status-chip.grading { color: var(--accent); background: rgba(79, 142, 247, 0.13); }
.status-chip.pass { color: var(--ok); background: rgba(58, 176, 122, 0.13); }
.status-chip.fail { color: var(--fail); background: rgba(224, 90, 90, 0.13); }
.status-chip.exhausted { color: var(--fail); background: rgba(224, 90, 90, 0.13); }

.tries {
  font-size: .8rem;
  color: var(--muted);
  margin-left: .5rem;
}

.task-body {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.task-body[hidden] { display: none; }

/* Rendered markdown */
.markdown h1 { font-size: 1.15rem; margin-bottom: .6rem; }
.markdown h2 { font-size: 1rem; margin: 1rem 0 .4rem; }
.markdown h3 { font-size: .95rem; margin: .8rem 0 .3rem; color: var(--muted); }
.markdown p, .markdown ul, .markdown ol { margin: .5rem 0; font-size: .9rem; }
.markdown ul, .markdown ol { padding-left: 1.5rem; }
.markdown code {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: .1rem .35rem;
  border-radius: 3px;
  font-size: .85em;
}
.markdown pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .8rem 1rem;
  overflow-x: auto;
  font-size: .82rem;
  margin: .6rem 0;
}
.markdown pre code { background: none; border: none; padding: 0; }
.markdown table {
  border-collapse: collapse;
  margin: .6rem 0;
  font-size: .85rem;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: .3rem .7rem;
  text-align: left;
}
.markdown th { background: var(--surface-elev); font-weight: 600; }

.footer {
  color: var(--muted);
  font-size: .8rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Submission history ─────────────────────────────────────────────────── */
.history {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.history h3 {
  font-size: .95rem;
  margin-bottom: .75rem;
  color: var(--text);
}
.muted { color: var(--muted); font-size: .875rem; }

.attempt {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: .5rem;
  overflow: hidden;
}
.attempt-head {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .8rem;
  cursor: pointer;
  background: var(--surface);
  user-select: none;
}
.attempt-head:hover { background: var(--surface-elev); }
.attempt-n { font-weight: 600; font-size: .875rem; }
.attempt-time { color: var(--muted); font-size: .8rem; }
.attempt-sha {
  color: var(--muted);
  font-size: .75rem;
  background: var(--surface-elev);
  padding: .1rem .35rem;
  border-radius: 3px;
}
.attempt-toggle { margin-left: auto; color: var(--muted); }
.attempt-body { padding: .8rem; background: var(--bg); }

.group-list { list-style: none; margin-bottom: .75rem; font-size: .875rem; }
.group-list li { padding: .15rem 0; color: var(--muted); }
.group-list strong { color: var(--text); }

.all-pass { color: var(--ok); font-size: .875rem; }

.failure {
  border-left: 3px solid var(--fail);
  background: var(--surface);
  border-radius: 4px;
  padding: .6rem .8rem;
  margin-bottom: .6rem;
}
.failure-title { font-size: .875rem; font-weight: 600; margin-bottom: .5rem; }
.failure-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.failure-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: .2rem .75rem .2rem 0;
  vertical-align: top;
  white-space: nowrap;
  width: 1%;
}
.failure-table td { padding: .2rem 0; vertical-align: top; }
.failure-table code {
  background: var(--surface-elev);
  border: 1px solid var(--border);
  padding: .1rem .35rem;
  border-radius: 3px;
  font-size: .95em;
  white-space: pre-wrap;
  word-break: break-word;
}
.failure-table td.got code { border-color: var(--fail); }
.failure-table .or { color: var(--muted); }
.failure-note { color: var(--muted); font-size: .8rem; margin-top: .4rem; }

/* ── Task list (home) → per-task page ───────────────────────────────────── */
.task-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .12s ease, background .12s ease;
}
.task-link:hover {
  border-color: var(--accent);
  background: var(--surface-elev);
}
.task-link .task-header { cursor: pointer; }
.task-chevron {
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  margin-left: .25rem;
}
.task-link:hover .task-chevron { color: var(--accent); }

.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: .875rem;
  margin-bottom: 1.25rem;
}
.back-link:hover { color: var(--accent); }

.task-page-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
}
.task-page-header h2 {
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .6rem;
}
.task-page-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.build-failure { border-left-color: var(--pending); }
.build-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .6rem .8rem;
  font-size: .8rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
}

/* ── Task levels ─────────────────────────────────────────────────────────── */
/* Bronze/silver/gold. Colour alone does not carry the meaning — the level is
   spelled out in the badge text, so this still reads correctly in greyscale
   and to anyone who cannot separate the three hues. */
.level {
  flex: none;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .16rem .45rem;
  border-radius: 3px;
  border: 1px solid transparent;
}
.level-bronze { color: #b0763c; background: rgba(176, 118, 60, 0.13); border-color: rgba(176, 118, 60, 0.35); }
.level-silver { color: #8e9aa6; background: rgba(142, 154, 166, 0.15); border-color: rgba(142, 154, 166, 0.38); }
.level-gold   { color: #c9a227; background: rgba(201, 162, 39, 0.14); border-color: rgba(201, 162, 39, 0.38); }

.locked-note {
  margin-top: 1rem;
  color: var(--muted);
  font-size: .85rem;
}

/* ── Notices ─────────────────────────────────────────────────────────────── */
/* A push that produced no result. Students never open GitLab, so this is the
   only place they learn why nothing happened. */
.notice {
  border-left: 3px solid var(--border);
  border-radius: 4px;
  padding: .7rem .9rem;
  margin: 0 0 1.1rem;
  font-size: .88rem;
  line-height: 1.5;
  background: var(--surface-elev);
  color: var(--text);
}
.notice strong { display: block; margin-bottom: .15rem; }
.notice-blocked { border-left-color: var(--fail); background: rgba(224, 90, 90, 0.10); }
.notice-error   { border-left-color: var(--pending); background: rgba(212, 162, 74, 0.10); }

/* ── Rehearsal sign-up ─────────────────────────────────────────────────── */
fieldset.levels { border: none; margin-bottom: 1rem; }
fieldset.levels legend { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.level-option {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  margin-bottom: .5rem;
  padding: .65rem .8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.level-option:has(input:checked) { border-color: var(--accent-rehearsal); background: rgba(58, 176, 122, 0.08); }
.level-option input { width: auto; margin-top: .3rem; accent-color: var(--accent-rehearsal); }
.level-body { display: flex; flex-direction: column; font-size: .9rem; }
.level-body strong { font-size: 1rem; }
.level-body span { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin-top: .5rem; }
.switch { margin-top: 1.2rem; font-size: .85rem; color: var(--muted); }

dl.credentials {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .4rem 1.2rem;
  margin: 1.2rem 0 1.5rem;
  padding: 1rem 1.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
dl.credentials dt { color: var(--muted); font-size: .85rem; align-self: center; }
dl.credentials dd { font-family: var(--mono); font-size: 1.4rem; letter-spacing: .08em; }

/* ── Rehearsal setup ───────────────────────────────────────────────────── */
#setup { max-width: 900px; margin: 0 auto; padding: 2rem; }
.setup-student { color: var(--text); font-weight: 600; }
ol.steps { list-style: none; counter-reset: step; display: grid; gap: 1rem; margin-top: 1.2rem; }
ol.steps > li {
  counter-increment: step;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.2rem 1.1rem 3.4rem;
}
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 1.1rem;
  top: 1.05rem;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--accent-rehearsal);
  background: rgba(58, 176, 122, 0.13);
}
ol.steps h3 { font-size: 1rem; margin-bottom: .3rem; }
ol.steps p { color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
ol.steps p strong { color: var(--text); }
pre.cmd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .8rem 1rem;
  font-size: .82rem;
  overflow-x: auto;
  white-space: pre;
  margin-bottom: .4rem;
  user-select: all;
}
a.button {
  display: inline-block;
  background: var(--accent);
  color: white;
  text-decoration: none;
  padding: .55rem 1.1rem;
  border-radius: 5px;
  font-weight: 600;
  font-size: .95rem;
}
a.button:hover { filter: brightness(1.1); }
#start-btn { background: var(--accent-rehearsal); }

@media (max-width: 600px) {
  #main, #setup { padding: 1rem; }
  header { flex-wrap: wrap; gap: .6rem; }
  ol.steps > li { padding-left: 1.2rem; padding-top: 2.8rem; }
}

/* ── Quiz ──────────────────────────────────────────────────────────────── */
.quiz-question {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.quiz-question.wrong { border-color: var(--fail); }
.quiz-question.right { border-color: var(--ok); }
.quiz-question-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: .4rem;
}
.quiz-question-head .verdict.wrong { color: var(--fail); }
.quiz-question-head .verdict.right { color: var(--ok); }
.quiz-alternative {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  margin: .35rem 0;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  font-size: .9rem;
}
/* Not the full-width text-field look that `form input` gives everything. */
.quiz-alternative input {
  flex: none;
  width: auto;
  margin: .2rem 0 0;
  padding: 0;
  accent-color: var(--accent);
}
.quiz-alternative:has(input:checked) { border-color: var(--accent); }
.quiz-alternative p { margin: 0; }
.quiz-hint { font-size: .8rem; color: var(--muted); margin: .2rem 0 .4rem; }
.quiz-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
