/* The student exam screen: green rail, white cards, an LCD clock. Square-cornered like the rest of the app.

   The page sets <body class="exam-mode"> (hiding the site header) and fills the window: a rail of
   question numbers, a stage with the passage and the options, and a bar of buttons at the bottom.
   Saved preferences pick the rail side (dock-*), whether passage and options sit side by side
   (swap), and where the clock goes (clock-*). */

@font-face {
  font-family: "DSEG7";
  src: url("../vendor/fonts/DSEG7Classic-Bold.woff2") format("woff2");
  font-display: swap;
}

body.exam-mode .site-header { display: none; }
body.exam-mode main { max-width: none; padding: 0; }

.exam-shell, .qview {
  --ex-accent: var(--brand);
  --ex-accent-deep: var(--brand-deep);
  --ex-accent-soft: var(--brand-soft);
  --ex-bg: #e2e2e2;
  --ex-card: #ffffff;
  --ex-text: #1b1b1b;
  --ex-muted: #8a8a8a;
}
.exam-shell {
  display: grid;
  grid-template-columns: 5rem 1fr;
  height: 100vh;
  background: var(--ex-bg);
  color: var(--ex-text);
}
/* Dark: the same dark as the rest of the site (page, cards and text come from its tokens), with the deep
   brand shades for the question list, and the bright one for the title. */
[data-theme="dark"] .exam-shell, [data-theme="dark"] .qview {
  --ex-bg: var(--bg); --ex-card: color-mix(in srgb, var(--brand-bright) 11%, var(--bg)); --ex-text: var(--text); --ex-muted: var(--text-muted);
  --ex-accent-deep: var(--brand-night2);
}
[data-theme="dark"] .exam-rail, [data-theme="dark"] .rail-exit { background: var(--brand-night); }
[data-theme="dark"] .rail-exit:hover { background: var(--brand-night2); }
/* Buttons and the selected answer use the same bright brand colour (with dark ink) as the dashboard's buttons. */
[data-theme="dark"] .exam-shell, [data-theme="dark"] .qview { --ex-accent: var(--brand-bright); }
[data-theme="dark"] .exam-shell .bar-btn, [data-theme="dark"] .exam-shell .round,
[data-theme="dark"] .exam-shell .choice.selected .choice-btn { background: var(--brand-bright); color: var(--brand-ink); }
[data-theme="dark"] .exam-shell .bar-btn.on { background: var(--ex-card); color: var(--brand-bright); }
[data-theme="dark"] .arrange-bar { background: var(--brand-night); }
[data-theme="dark"] .arrange-done { color: var(--brand-night); }
[data-theme="dark"] .exam-title h1 { color: var(--brand-bright); }
/* Colour-blind friendly: blue instead of green for anything that signals "selected" or "done". */
[data-cb="protanopia"] .exam-shell, [data-cb="deuteranopia"] .exam-shell, [data-cb="protanopia"] .qview, [data-cb="deuteranopia"] .qview { --ex-accent: #0b5cad; --ex-accent-deep: #083f78; --ex-accent-soft: #2a7fd0; }

.exam-shell { --sq: 3.4rem; --rail: calc(var(--sq) + 1.4rem); }
.exam-shell { grid-template-columns: var(--rail) 1fr; }
.exam-shell.dock-right { grid-template-columns: 1fr var(--rail); }
.exam-shell.dock-right .exam-rail { order: 2; }
.exam-shell.dock-top, .exam-shell.dock-bottom { grid-template-columns: 1fr; grid-template-rows: var(--rail) 1fr; }
.exam-shell.dock-bottom { grid-template-rows: 1fr var(--rail); }
.exam-shell.dock-bottom .exam-rail { order: 2; }
.exam-shell.dock-top .exam-rail, .exam-shell.dock-bottom .exam-rail { flex-direction: row; align-items: center; padding: 0 0.7rem; overflow-x: auto; overflow-y: hidden; }
.exam-shell.dock-top .rail-list, .exam-shell.dock-bottom .rail-list { display: flex; }

/* ---- the rail ---- */
.exam-rail { cursor: grab; touch-action: pan-y; background: var(--ex-accent); padding: 0.75rem 0.6rem; overflow: auto; display: flex; flex-direction: column; gap: 0.6rem; }
.rail-exit { display: grid; place-items: center; flex: none; height: 2.2rem; color: #fff; position: sticky; top: 0; left: 0; z-index: 2; background: var(--ex-accent); border-radius: var(--radius-lg); }
.rail-exit:hover { background: rgb(255 255 255 / 15%); }
.rail-exit svg { width: 1.4rem; height: 1.4rem; }
.rail-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: var(--sq); gap: 0.6rem; }
.rail-q { position: relative; width: var(--sq); height: var(--sq); aspect-ratio: 1; flex: none; padding: 0; border: 0; background: var(--ex-accent-deep); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.rail-q:hover { filter: brightness(1.15); }
.rail-q.answered { background: var(--ex-accent-soft); }
.rail-q.seen::after { content: ""; position: absolute; right: 0.5rem; bottom: 0.5rem; width: 0.45rem; height: 0.45rem; background: #fff; border-radius: var(--radius-round); } /* seen, not answered: a little circle */
.rail-q.current { outline: 3px solid #fff; outline-offset: -3px; }
.rail-q.flagged { box-shadow: inset 0 0 0 2px #ffd54a; } /* marked "to review" */
.rail-q.locked { opacity: 0.6; }
.rail-flag { position: absolute; right: 0.3rem; top: 0.25rem; width: 1rem; height: 1rem; display: grid; }
.rail-flag svg { width: 100%; height: 100%; }

/* ---- the stage ---- */
.exam-stage { display: grid; grid-template-rows: 1fr auto; gap: 0.9rem; padding: 1rem 1.2rem; min-height: 0; position: relative; }
.exam-panels { --pw: 1fr; --aw: 1fr; display: grid; grid-template-columns: minmax(0, var(--pw, 1fr)) 0.9rem minmax(0, var(--aw, 1fr)); min-height: 0; }
.exam-panels.no-passage { grid-template-columns: 1fr; gap: 1.1rem; }
.exam-panels.swap { grid-template-columns: minmax(0, var(--aw, 1fr)) 0.9rem minmax(0, var(--pw, 1fr)); }
.exam-panels.swap .exam-passage { order: 3; }
.exam-panels.swap .exam-split { order: 2; }

/* The divider: drag it to choose how wide the passage is compared with the options. */
.exam-split { cursor: col-resize; touch-action: none; position: relative; }
.exam-split::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: transparent; }
.exam-split:hover::after, .exam-split:focus-visible::after { background: var(--ex-accent); }

/* Dragging the question list: the edge it will dock to lights up. */
.exam-shell.dragging { cursor: grabbing; user-select: none; }
.dock-hint { position: fixed; z-index: 30; background: color-mix(in srgb, var(--ex-accent) 35%, transparent); border: 3px solid var(--ex-accent); pointer-events: none; }
.dock-hint.edge-left { left: 0; top: 0; bottom: 0; width: 6rem; }
.dock-hint.edge-right { right: 0; top: 0; bottom: 0; width: 6rem; }
.dock-hint.edge-top { left: 0; right: 0; top: 0; height: 6rem; }
.dock-hint.edge-bottom { left: 0; right: 0; bottom: 0; height: 6rem; }

.exam-passage { background: var(--ex-card); padding: 1.4rem 1.7rem; overflow-y: auto; min-height: 0; }
.exam-title { margin-bottom: 1rem; }
.exam-title h1 { margin: 0 0 0.35rem; font-size: 1.75rem; color: var(--ex-accent); letter-spacing: -0.01em; }
.exam-code { margin: 0; color: var(--ex-muted); font-size: 0.8rem; }
.exam-passage .md { text-align: left; hyphens: auto; line-height: 1.65; }
.exam-passage .md :is(h1,h2,h3,h4,h5,h6, table, pre) { text-align: left; }
.exam-passage .md > p { margin-bottom: 1em; }

.exam-answer { display: flex; flex-direction: column; gap: 0.8rem; overflow-y: auto; min-height: 0; padding: 0.1rem; }
.exam-stem { padding: 0.2rem 0.2rem 0.3rem; font-weight: 600; font-size: 1.05rem; line-height: 1.5; }
.exam-stem .md > :first-child { margin-top: 0; }
.exam-locked { margin: 0; padding: 0.55rem 0.9rem; background: rgb(0 0 0 / 7%); color: var(--ex-muted); }

.choices { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.choice { position: relative; }
.choice-btn {
  display: flex; align-items: flex-start; gap: 0.9rem; width: 100%; padding: 0.95rem 3rem 0.95rem 1.15rem;
  border: 0; background: var(--ex-card); color: var(--ex-text);
  font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.choice-letter { min-width: 1.2rem; font-weight: 800; }
.choice-text { flex: 1; min-width: 0; }
.choice:hover .choice-btn { box-shadow: inset 0 0 0 2px var(--ex-accent-soft); }
.choice.selected .choice-btn { background: var(--ex-accent); color: #fff; box-shadow: none; }
.choice.eliminated .choice-btn { background: rgb(0 0 0 / 5%); color: var(--ex-muted); text-decoration: line-through; box-shadow: none; }
.choice-btn:disabled { cursor: not-allowed; opacity: 0.6; }

/* The small mouse icon says "right-click to cross out"; the same button works by tap or keyboard. */
.choice-x { position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%); display: grid; place-items: center; padding: 0.3rem; border: 0; background: none; color: var(--ex-muted); cursor: pointer; opacity: 0; }
.choice-x svg { width: 1.35rem; height: 1.35rem; }
.choice:hover .choice-x, .choice-x:focus-visible, .choice.eliminated .choice-x { opacity: 1; }
.choice.selected .choice-x { color: #fff; }
@media (hover: none) { .choice-x { opacity: 1; } }

/* ---- the bottom bar ---- */
.exam-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.bar-group { display: flex; align-items: center; gap: 0.6rem; }
.exam-bar.clock-bottom-right .bar-group:first-child { order: 2; }

.lcd {
  font-family: "DSEG7", ui-monospace, monospace; font-size: 1.6rem; letter-spacing: 0.06em; line-height: 1;
  height: 3rem; box-sizing: border-box; display: inline-flex; align-items: center; padding: 0 0.9rem; border: 3px solid var(--ex-accent); background: #000; color: #fff;
  font-variant-numeric: tabular-nums;
}
.lcd.low { color: #ff6a5c; border-color: #b3261e; }

.round, .bar-btn { border: 0; background: var(--ex-accent); color: #fff; font: inherit; cursor: pointer; }
.round { width: 3rem; height: 3rem; display: grid; place-items: center; } /* the accessibility button */
.bar-btn { display: inline-flex; align-items: center; gap: 0.5rem; height: 3rem; padding: 0 1.2rem; font-weight: 600; }
.bar-btn svg { width: 1.3rem; height: 1.3rem; }
.bar-btn.icon-only { padding: 0 1rem; }
.bar-btn.strong { padding: 0 1.5rem; }
.bar-btn.on { background: var(--ex-card); color: var(--ex-accent); box-shadow: inset 0 0 0 2px var(--ex-accent); }
.bar-btn:hover:not(:disabled), .round:hover { filter: brightness(1.12); }
.bar-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.save-status { color: var(--ex-muted); font-size: 0.8rem; }
.save-status.error { color: #b3261e; }

/* Clocks that the student asked to have in a top corner float over the page. */
.float-clock { position: fixed; z-index: 30; }
.float-clock.clock-top-left { top: 0.8rem; left: 6rem; }
.float-clock.clock-top-right { top: 0.8rem; right: 1.2rem; }

@media (max-width: 52rem) {
  .exam-shell, .exam-shell.dock-right { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .exam-shell.dock-right .exam-rail { order: 0; }
  .exam-rail { flex-direction: row; padding: 0.5rem; }
  .rail-list { display: flex; }
  .rail-q { width: 3rem; flex: none; }
  .exam-panels { grid-template-columns: 1fr; }
  .exam-bar { gap: 0.6rem; }
}

/* The accessibility popup sits right above its button. */
.pop-host { position: relative; display: inline-flex; }
.a11y-pop { position: absolute; left: 0; bottom: calc(100% + 0.5rem); z-index: 40; width: 17rem; padding: 0.8rem; display: grid; gap: 0.6rem;
  background: var(--bg); color: var(--text); border: 2px solid var(--ex-accent); animation: pop 0.15s ease-out; transform-origin: bottom left; }
.a11y-pop .row { gap: 0.5rem; }
.a11y-pop label { font-size: 0.85rem; }
.a11y-pop select { width: 100%; }

/* ---- the answer sheet popup, shown before handing in ---- */
.sheet-pop { --ex-accent: var(--brand); --ex-accent-deep: var(--brand-deep); --ex-accent-soft: var(--brand-soft); --ex-card: var(--bg); --ex-text: var(--text); --ex-muted: var(--text-muted); }
.sheet-body { display: grid; grid-template-columns: minmax(15rem, 20rem) minmax(0, 1fr); gap: 1.1rem; height: 62vh; }
.sheet, .sheet-question { overflow-y: auto; min-height: 0; padding-right: 0.4rem; }
.sheet-rows { list-style: none; margin: 0.4rem 0 0; padding: 0; display: grid; gap: 0.25rem; }
.sheet-row { position: relative; width: 100%; display: flex; align-items: center; gap: 0.45rem; padding: 0.3rem 0.5rem; border: 1px solid var(--border); background: transparent; color: inherit; font: inherit; cursor: pointer; }
.sheet-row:hover { background: color-mix(in srgb, var(--ex-accent) 8%, transparent); }
.sheet-row.current { border-color: var(--ex-accent); box-shadow: inset 0 0 0 2px var(--ex-accent); }
.sheet-row.flagged { background: rgb(255 213 74 / 18%); }
.sheet-row.blank .sheet-n { color: var(--bad); }
.sheet-n { min-width: 1.8rem; font-weight: 800; text-align: right; }
.bubble { width: 1.7rem; height: 1.7rem; display: grid; place-items: center; border: 2px solid var(--ex-muted); font-size: 0.8rem; font-weight: 700; color: var(--ex-muted); transition: background-color 0.15s, color 0.15s; }
.bubble.filled { background: var(--ex-text); border-color: var(--ex-text); color: var(--ex-card); }
.bubble.struck { text-decoration: line-through; opacity: 0.5; }
.sheet-row .rail-flag { position: static; margin-left: auto; width: 1rem; height: 1rem; color: #b8860b; }
.sheet-question .exam-title h1 { font-size: 1.3rem; }
@media (max-width: 52rem) { .sheet-body { grid-template-columns: 1fr; height: auto; max-height: 62vh; overflow-y: auto; } }

.slot { display: contents; } /* wraps the clock and save status, which live across redraws */

/* ---- arranging: the button bar can sit on top, and every piece can be dragged ---- */
.exam-stage.bar-top { grid-template-rows: auto 1fr; }
.exam-stage.bar-top .exam-bar { order: -1; }
.exam-bar { cursor: grab; }
.exam-bar button, .exam-bar a { cursor: pointer; }
.exam-answer, .exam-passage { cursor: grab; }
.exam-answer > *, .exam-passage > * { cursor: auto; }
.exam-answer button, .exam-passage a { cursor: pointer; }
.clock-spot { display: inline-flex; }
.exam-shell.dragging, .exam-shell.dragging * { cursor: grabbing !important; }
.drop-hint {
  position: fixed; z-index: 30; pointer-events: none; box-sizing: border-box;
  background: color-mix(in srgb, var(--ex-accent) 28%, transparent); border: 3px solid var(--ex-accent);
  transition: left 0.2s var(--ease-out), top 0.2s var(--ease-out), width 0.2s var(--ease-out), height 0.2s var(--ease-out);
  animation: fade 0.15s var(--ease-out);
}

/* A piece being dragged lifts off the page: it follows the pointer, above everything, and glides home on drop. */
.lifted { background: var(--ex-bg); border-radius: var(--radius-lg); position: relative; z-index: 60; opacity: 0.96; outline: 3px solid var(--ex-accent); outline-offset: -3px; transition: none !important; will-change: transform; }
.exam-shell.dragging .lifted, .exam-shell.dragging .lifted * { cursor: grabbing !important; }

/* ---- the practice view (Preferences → arrange the exam screen) ---- */
.arrange-bar {
  position: fixed; z-index: 70; left: 0; right: 0; top: 0; height: 3.2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 1rem;
  background: var(--ex-accent-deep); color: #fff; font-size: 0.9rem;
}
.arrange-actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }
.arrange-chip, .arrange-done { font: inherit; font-size: 0.85rem; color: #fff; background: transparent; border: 1px solid rgb(255 255 255 / 55%); padding: 0.35rem 0.8rem; cursor: pointer; border-radius: var(--radius); display: inline-flex; align-items: center; gap: 0.4rem; }
.arrange-chip[aria-pressed="true"] { background: rgb(255 255 255 / 22%); }
.arrange-chip:hover, .arrange-done:hover { background: rgb(255 255 255 / 30%); }
.arrange-done { background: #fff; color: var(--ex-accent-deep); border-color: #fff; font-weight: 600; }
.arrange-done .icon { width: 1.1em; height: 1.1em; margin: 0; }
.exam-shell.sample { margin-top: 3.2rem; height: calc(100vh - 3.2rem); }
.arrange-text { flex: 1; min-width: 0; }
.exam-shell.sample .float-clock.clock-top-left, .exam-shell.sample .float-clock.clock-top-right { top: 4rem; }
@media (max-width: 52rem) { .arrange-bar { height: auto; padding: 0.5rem 1rem; flex-wrap: wrap; } .exam-shell.sample { margin-top: 5.5rem; height: auto; } }

/* A rail along the top or bottom scrolls sideways; a finger can scroll it, and dragging across it still moves it. */
.exam-shell.dock-top .exam-rail, .exam-shell.dock-bottom .exam-rail { touch-action: pan-x; }

/* The accessibility popup normally opens above its button; it opens below when the bar is at the top. */
.a11y-pop.below { bottom: auto; top: calc(100% + 0.5rem); transform-origin: top left; }
.a11y-pop.from-right { left: auto; right: 0; }

/* phones: the list on top stays put, the text and answers flow, the buttons stay under your thumb */
@media (max-width: 52rem) {
  .exam-rail { position: sticky; top: 0; z-index: 20; }
  .exam-stage { grid-template-rows: auto auto; align-content: start; padding: 0.8rem 0.8rem 0; }
  .exam-panels { align-content: start; gap: 1rem; }
  .exam-split { display: none; }
  .exam-bar { position: sticky; bottom: 0; z-index: 20; margin: 0 -0.8rem; padding: 0.5rem 0.8rem; background: var(--ex-bg); flex-wrap: nowrap; }
  .exam-bar .bar-group { gap: 0.4rem; }
  .exam-bar .bar-label { display: none; }
  .bar-btn { padding: 0 0.9rem; }
  .bar-btn.strong { padding: 0 1.1rem; }
  .exam-bar .save-status { display: none; }
}
.bar-label { white-space: nowrap; }

/* A question preview (css/question-view: lib/question-view.js): the exam screen's own panels, title, text, enunciado and choices,
   on the same grey, but not full-window and not interactive. It has one column or two by the room it has, as the exam screen
   does on a phone. The correct option is marked, for the teacher. */
.qview { container-type: inline-size; background: var(--ex-bg); color: var(--ex-text); padding: 0.8rem; text-transform: none; }
.qview .exam-panels { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.8rem; }
.qview .exam-panels.no-passage { grid-template-columns: 1fr; }
.qview .exam-passage, .qview .exam-answer { overflow: visible; }
.choice-static { cursor: default; } /* a choice in a preview: looks like the exam screen's, does nothing */
.qview .choice:hover .choice-btn { box-shadow: none; }
.qview .choice.correct .choice-btn { box-shadow: inset 0 0 0 2px var(--good); }
.qview .choice-tag { flex: none; font-size: 0.8em; font-weight: 700; color: var(--good); }
@container (max-width: 46rem) { .qview .exam-panels { grid-template-columns: 1fr; } }
