:root {
  --bg: #ffffff;
  --fg: #16181d;
  --muted: #646b7a;
  --border: #dfe3ea;
  --panel: #f7f8fa;
  --accent: #1f4fd8;
  --ok: #17795e;
  --warn: #9a5b00;
  --danger: #b3261e;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .4rem; }
h4 { font-size: .85rem; margin: 1rem 0 .25rem; color: var(--muted); font-family: ui-monospace, monospace; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
.warn { color: var(--warn); }

/* !important is load-bearing here, not laziness. `hidden` is a boolean
   attribute with one unambiguous meaning, but any id-based layout rule below
   (#screen-test sets display:flex) outranks a class+attribute selector on
   specificity. Without this, an element is `hidden === true` in the DOM and
   still painted - every screen renders stacked on top of the others. */
[hidden] { display: none !important; }

/* --- cards (code entry, instructions, done) ----------------------------- */

.card {
  max-width: 54rem;
  margin: 3rem auto;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card.narrow { max-width: 34rem; }

.prose {
  white-space: pre-wrap;
  font: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0 0 1rem;
  overflow-x: auto;
}

/* --- controls ----------------------------------------------------------- */

button {
  font: inherit;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.large { padding: .75rem 1.5rem; font-size: 1rem; }

input[type="text"], #code-input, #submit-confirm {
  font: inherit;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
}
#code-input {
  font-family: ui-monospace, monospace;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: .75rem;
}

textarea {
  font: inherit;
  width: 100%;
  padding: .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.field { margin: 1.25rem 0; }
.field label {
  display: block;
  margin-bottom: .35rem;
  font-weight: 500;
}

.start-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* --- test chrome -------------------------------------------------------- */

#screen-test { display: flex; flex-direction: column; height: 100vh; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.bar.footer { border-bottom: none; border-top: 1px solid var(--border); }

.sections { display: flex; gap: .35rem; flex-wrap: wrap; }
.sections button { padding: .35rem .7rem; font-size: .85rem; background: transparent; border-color: transparent; }
.sections button.active { background: #fff; border-color: var(--border); font-weight: 600; }

.bar-right { display: flex; align-items: center; gap: 1rem; }

.timer {
  font-family: ui-monospace, monospace;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  padding: .15rem .5rem;
  border-radius: var(--radius);
}
.timer.warn { color: var(--warn); background: #fff6e5; }
.timer.critical { color: #fff; background: var(--danger); }

/* The save indicator is never allowed to be invisible or ambiguous: a
   candidate must always be able to tell whether their work is safe. */
.save-state { font-size: .85rem; color: var(--ok); }
.save-state.unsaved, .save-state.saving { color: var(--muted); }
.save-state.retrying,
.save-state.conflict,
.save-state.expired {
  color: #fff;
  background: var(--danger);
  padding: .2rem .5rem;
  border-radius: var(--radius);
  font-weight: 600;
}

/* --- scenario panel ------------------------------------------------------
   Slides in over the section rather than replacing it, so a candidate can
   check a constraint and dismiss it without losing their place or their
   cursor position in a half-written answer. */

.scenario-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(38rem, 92vw);
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .08);
  overflow-y: auto;
  z-index: 40;
}
.scenario-inner { padding: 1.5rem; }
.scenario-inner h2 { margin-top: 0; }
.scenario-inner pre { max-height: none; }

#scenario-toggle.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#section-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  max-width: 62rem;
  width: 100%;
  margin: 0 auto;
}

.section-header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.requirements { margin: .25rem 0 1rem; padding-left: 1.2rem; }
.requirements li { margin: .2rem 0; }

.starter { font: 12.5px/1.5 ui-monospace, monospace; max-height: 15rem; overflow: auto; }

/* --- Section 2 live results --------------------------------------------- */

.prompt-controls { display: flex; align-items: center; gap: 1rem; margin: .5rem 0 1rem; }
.prompt-results { display: grid; gap: .75rem; }

.reply {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.reply.error { border-left-color: var(--danger); }
.reply-message { font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.reply-message::before { content: "Customer: "; font-weight: 600; }
.reply-text { white-space: pre-wrap; }
.reply-error { color: var(--danger); font-size: .9rem; }

/* --- editor ------------------------------------------------------------- */

.editor-mount { height: 26rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.code-editor {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  tab-size: 4;
  resize: none;
}

/* --- dialog ------------------------------------------------------------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 30rem;
  width: 90%;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog label { display: block; margin: 1rem 0 .35rem; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }

#submission-summary { margin-top: 1.5rem; }
#submission-summary pre { max-height: 14rem; overflow: auto; }

/* --- comprehension probe -------------------------------------------------- */

#probe-dialog { max-width: 40rem; }

.probe-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.probe-head h2 { margin: 0; }

.probe-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--muted);
}
.probe-timer.urgent { color: var(--danger); }

.probe-option {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .4rem;
  cursor: pointer;
}
.probe-option:hover { background: var(--panel); }
.probe-option input { margin-top: .2rem; }

.probe-question { font-weight: 600; margin: 1rem 0 .75rem; }
#probe-written { width: 100%; font: inherit; padding: .5rem;
                 border: 1px solid var(--border); border-radius: var(--radius); }

#probe-fieldset { border: none; padding: 0; margin: 0; min-width: 0; }
#probe-fieldset legend { padding: 0; }

/* Shown while probe questions are generated. Clicking Next used to look
   broken for a second or two. */
.probe-loading {
  position: fixed;
  left: 50%;
  bottom: 5rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--fg);
  color: #fff;
  padding: .6rem 1rem;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 40;
}
.spinner {
  width: .9rem; height: .9rem;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#probe-paste-notice { margin: .4rem 0 0; }

/* --- brand ---------------------------------------------------------------
   Hidden by its own onerror if the file is missing, so a missing asset never
   leaves a broken-image icon on a candidate's first screen. */
.brand { max-width: 190px; height: auto; display: block; margin-bottom: 1.25rem; }
.brand-small { max-width: 108px; margin: 0 .9rem 0 0; }
