/* Exam workspace. Layout: rail (protocols) + board (topology over sequence) +
   optional tutor drawer. Reuses the palette from pages.css. */

.exam-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 0;
  min-height: calc(100vh - 64px);
  transition: grid-template-columns 0.18s ease;
}
.exam-shell.tutor-open {
  grid-template-columns: 236px minmax(0, 1fr) minmax(300px, 360px);
}

/* ---------------------------------------------------------------- rail */

.exam-rail {
  border-right: 1px solid var(--line-soft);
  background: var(--panel);
  padding: 18px 12px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
  position: sticky;
  top: 0;
}
.rail-head {
  display: grid;
  gap: 8px;
  padding: 0 6px 10px;
}
.rail-title {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted, #7f8ca6);
}
#protoSearch {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text, #e7edf9);
  font: inherit;
}
#protoSearch:focus-visible {
  outline: 2px solid var(--accent, #4ea1ff);
  outline-offset: 1px;
}
.proto-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}
.proto-list button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted, #9aa7c0);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.proto-list button:hover {
  background: var(--panel-2);
  color: var(--text, #e7edf9);
}
.proto-list button[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent, #4ea1ff) 16%, transparent);
  color: var(--text, #e7edf9);
}
.proto-list .count {
  font-size: 11px;
  color: var(--muted, #7f8ca6);
}
.proto-list .lock {
  font-size: 11px;
}
.rail-note {
  margin: 14px 6px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted, #7f8ca6);
}

/* ----------------------------------------------------------------- main */

.exam-main {
  min-width: 0;
  padding: 20px 22px 48px;
}
.exam-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted, #7f8ca6);
}
.exam-head h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}
#protoSub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted, #8d9bb5);
}
.scenario-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.scenario-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: transparent;
  color: var(--muted, #9aa7c0);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.scenario-tabs button span {
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}
.scenario-tabs button[aria-pressed="true"] {
  border-color: var(--accent, #4ea1ff);
  color: var(--text, #e7edf9);
  background: color-mix(in srgb, var(--accent, #4ea1ff) 14%, transparent);
}

/* --------------------------------------------- locked-exam interstitial */

.exam-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 9, 20, 0.72);
  backdrop-filter: blur(6px);
}
.exam-gate[hidden] {
  display: none;
}
.exam-gate-card {
  position: relative;
  width: min(460px, 100%);
  padding: 26px 24px 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 32, 58, 0.97), rgba(11, 20, 38, 0.97));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  display: grid;
  gap: 10px;
}
.gate-price {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  color: #ffc46b;
}
.exam-gate-card h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.35;
}
.gate-body {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted, #9aa7c0);
}
.gate-actions {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}
.gate-cta {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid #ef9c2c;
  border-radius: 10px;
  background: linear-gradient(135deg, #ffc46b, #ef9c2c);
  color: #1b1206;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.gate-cta:hover {
  filter: brightness(1.05);
}
.gate-cta:disabled {
  opacity: 0.7;
  cursor: progress;
}
.gate-later {
  padding: 9px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: transparent;
  color: var(--muted, #9aa7c0);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.gate-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted, #9aa7c0);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.gate-close:hover {
  background: var(--panel-2);
  color: var(--text, #e7edf9);
}

/* ------------------------------------------------------------- mission */

.workspace {
  padding-top: 18px;
  display: grid;
  gap: 14px;
}
/* `display: grid` above would otherwise beat the [hidden] attribute. */
.workspace[hidden],
.result[hidden] {
  display: none;
}
.mission {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.mission-text {
  min-width: 0;
  flex: 1 1 340px;
}
.mission-index {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--accent, #4ea1ff);
}
.mission h2 {
  margin: 2px 0 4px;
  font-size: 21px;
}
#missionDesc {
  margin: 0;
  color: var(--muted, #9aa7c0);
  font-size: 14px;
}
.context {
  flex: 0 1 460px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
}
.context summary {
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted, #9aa7c0);
}
.context p {
  margin: 8px 0 0;
  color: var(--text, #dfe7f5);
}
.context dl {
  margin: 10px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}
.context dt {
  color: var(--muted, #8d9bb5);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.context dd {
  margin: 0;
  color: var(--text, #dfe7f5);
}

/* ------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--panel);
}
.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  flex: 1 1 320px;
}
.palette button {
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text, #dfe7f5);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.palette button[aria-pressed="true"] {
  border-color: var(--accent, #4ea1ff);
  background: color-mix(in srgb, var(--accent, #4ea1ff) 22%, transparent);
}
.tools {
  display: flex;
  gap: 6px;
}

/* ---------------------------------------------------------------- board */

.board {
  display: grid;
  gap: 12px;
}
.pane {
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 26, 49, 0.9), rgba(10, 18, 36, 0.9));
  overflow: hidden;
}
.pane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.pane-head h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted, #9aa7c0);
}
.pane-hint {
  font-size: 11px;
  color: var(--muted, #7f8ca6);
}
.canvas {
  width: 100%;
}
#topo {
  height: 232px;
}
#seq {
  height: 470px;
}
.canvas svg {
  display: block;
  width: 100%;
  touch-action: none;
}

/* SVG bits (created in exam.js) */
.node-box {
  fill: #0e1a31;
  stroke: rgba(110, 150, 220, 0.35);
}
.node-box.is-active {
  stroke: rgba(120, 200, 255, 0.8);
}
.node-label {
  fill: #e7edf9;
  font-size: 13px;
  font-weight: 600;
}
.node-detail {
  fill: #8d9bb5;
  font-size: 10.5px;
}
.node-hit {
  cursor: pointer;
}
.wire {
  stroke: rgba(120, 200, 255, 0.5);
  stroke-width: 2;
}
.wire-hit {
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
}
.lifeline {
  stroke: rgba(120, 160, 220, 0.22);
  stroke-dasharray: 3 5;
}
.lane-head {
  fill: #0a1426;
  stroke: rgba(110, 150, 220, 0.3);
}
.lane-title {
  fill: #cfe0fb;
  font-size: 12px;
  font-weight: 600;
}
.arrow-line {
  stroke: #6ec1ff;
  stroke-width: 2;
}
.arrow-head {
  fill: #6ec1ff;
}
.arrow-label {
  fill: #cfe0fb;
  font-size: 11.5px;
  font-weight: 600;
}
.arrow-hit {
  stroke: transparent;
  stroke-width: 18;
  cursor: grab;
}
.arrow-group.is-selected .arrow-line,
.arrow-group.is-selected .arrow-head {
  stroke: #ffd479;
  fill: #ffd479;
}
.arrow-group.is-reference .arrow-line,
.arrow-group.is-reference .arrow-head {
  stroke: rgba(140, 240, 180, 0.85);
  fill: rgba(140, 240, 180, 0.85);
}
.arrow-group.is-reference .arrow-label {
  fill: rgba(160, 245, 200, 0.95);
}

/* ------------------------------------------------------------- actions */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.status {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted, #8d9bb5);
  min-height: 18px;
}
.action-buttons {
  display: flex;
  gap: 8px;
}

.result {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.result-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
/* Verdict and the detail line share a row and only wrap when they must. */
.result-copy {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 10px;
  row-gap: 2px;
}
.score-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-variant-numeric: tabular-nums;
}
.score-ring strong {
  font-size: 18px;
  line-height: 1;
}
.score-ring small {
  font-size: 9.5px;
  color: var(--muted, #8d9bb5);
}
.verdict {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.result-detail {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted, #8d9bb5);
}
.result-head .btn {
  padding: 8px 12px;
  font-size: 12px;
}
.breakdown {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 4px 16px;
}
.breakdown li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}
.breakdown li > span:first-child {
  white-space: nowrap;
}
.breakdown .bar {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.breakdown .bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent, #4ea1ff);
}
.breakdown .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted, #9aa7c0);
}

/* --------------------------------------------------------------- tutor */

.tutor {
  border-left: 1px solid var(--line-soft);
  background: var(--panel);
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: calc(100vh - 64px);
  position: sticky;
  top: 0;
}
.tutor[hidden] {
  display: none;
}
.tutor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.tutor-head h2 {
  margin: 0;
  font-size: 15px;
}
.tutor-meta {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted, #8d9bb5);
}
.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted, #9aa7c0);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.icon-btn:hover {
  background: var(--panel-2);
  color: var(--text, #e7edf9);
}
.tutor-log {
  overflow-y: auto;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  align-content: start;
  font-size: 13px;
  line-height: 1.55;
}
.tutor-msg {
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.tutor-msg.is-user {
  background: color-mix(in srgb, var(--accent, #4ea1ff) 14%, var(--panel-2));
  border-color: color-mix(in srgb, var(--accent, #4ea1ff) 40%, transparent);
  justify-self: end;
  max-width: 90%;
}
.tutor-msg.is-error {
  border-color: rgba(255, 120, 120, 0.4);
  color: #ffb4b4;
}
.tutor-form {
  display: grid;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line-soft);
}
.tutor-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-soft);
  background: var(--panel-2);
  color: var(--text, #e7edf9);
  font: inherit;
  font-size: 13px;
}
.tutor-form textarea:focus-visible {
  outline: 2px solid var(--accent, #4ea1ff);
  outline-offset: 1px;
}
.tutor-form .btn {
  justify-self: end;
}

/* ------------------------------------------------------- wide screens (PC) */

/* Topology and sequence share one row so the score and breakdown stay in view
   without scrolling. Both diagrams letterbox inside their SVG, so splitting the
   width barely changes their scale. Only applied on wide desktop viewports. */
@media (min-width: 1600px) {
  .exam-main {
    padding-top: 14px;
  }
  .workspace {
    gap: 10px;
  }
  .board {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-auto-rows: 420px;
  }
  .board .pane {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .board .canvas {
    min-height: 0;
    height: 100%;
  }
  #topo,
  #seq {
    height: 100%;
  }
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1080px) {
  .exam-shell,
  .exam-shell.tutor-open {
    grid-template-columns: 200px minmax(0, 1fr) 0;
  }
  #seq {
    height: 420px;
  }
}

@media (max-width: 820px) {
  .exam-shell,
  .exam-shell.tutor-open {
    grid-template-columns: minmax(0, 1fr);
  }
  .exam-rail {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    padding-bottom: 12px;
  }
  /* Mobile: the horizontal protocol tabs are the picker; drop the search block. */
  .rail-head {
    display: none;
  }
  .proto-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }
  .proto-list button {
    white-space: nowrap;
  }
  .exam-main {
    padding: 16px 14px 40px;
  }
  .tutor {
    position: fixed;
    inset: 64px 0 0;
    z-index: 30;
    border-left: 0;
    max-height: none;
  }
  #topo {
    height: 200px;
  }
  #seq {
    height: 380px;
  }
  .result-head {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .result-head .btn {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
