:root {
  /* BANFES logo palette (sampled from brand mark) */
  --brand-navy: #173d54;
  --brand-navy-deep: #103848;
  --brand-gold: #e19335;
  --brand-gold-soft: #f8e9d4;
  --bg: #eef2f5;
  --bg-glow: #d5e0e8;
  --panel: #ffffff;
  --ink: #173d54;
  --muted: #5b6b78;
  --line: #d5dde4;
  --line-strong: #b8c4ce;
  --accent: #173d54;
  --accent-soft: #e7eef3;
  --ok: #0f6b3c;
  --ok-soft: #e7f6ee;
  --warn: #e19335;
  --warn-soft: #f8e9d4;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --shadow: 0 1px 2px rgba(23, 61, 84, 0.04), 0 8px 24px rgba(23, 61, 84, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI", "Tahoma", "Noto Sans Arabic", "Noto Naskh Arabic", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.55 var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 10% -10%, var(--bg-glow), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #e7eef8, transparent 50%),
    var(--bg);
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
}

header.topbar .brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  flex-shrink: 0;
}

header.topbar .brand:hover {
  color: var(--brand-navy-deep);
}

.brand-logo {
  height: 2.35rem;
  width: auto;
  display: block;
  border-radius: 8px;
  object-fit: contain;
}

.brand-text {
  line-height: 1;
}

header.topbar .who {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.65rem;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

header.topbar .who-name {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header.topbar .who button {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.lang-switch,
.logout-form {
  display: inline-flex;
  margin: 0;
}

.lang-btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  line-height: 1.2;
}

.lang-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--brand-navy);
}

/*
  RTL layout follows html[dir=rtl] automatically via flex/grid start/end.
  Do not use flex-direction: row-reverse here — that double-flips and undoes RTL.
*/
[dir="rtl"] .meta,
[dir="rtl"] .muted,
[dir="rtl"] td,
[dir="rtl"] th {
  unicode-bidi: plaintext;
}

main {
  max-width: 820px;
  margin: 1.75rem auto 2.5rem;
  padding: 0 1rem;
}

main.wide {
  max-width: 1120px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

h1 {
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
  line-height: 1.25;
}

h2 {
  font-size: 1.12rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
}

.muted {
  color: var(--muted);
}

.meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0 0 1rem;
  line-height: 1.45;
}

.meta a {
  color: var(--accent);
}

button,
.button {
  font: inherit;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    transform 0.12s ease;
}

button:hover,
.button:hover {
  border-color: var(--ink);
}

button:active,
.button:active {
  transform: translateY(1px);
}

button.primary,
.button.primary {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #fff;
}

button.primary:hover,
.button.primary:hover {
  background: var(--brand-navy-deep);
  border-color: var(--brand-navy-deep);
}

.button.gold,
button.gold {
  background: var(--brand-gold);
  border-color: var(--brand-gold);
  color: var(--brand-navy-deep);
  font-weight: 650;
}

.button.gold:hover,
button.gold:hover {
  background: #c97d28;
  border-color: #c97d28;
  color: #fff;
}

button.danger,
.button.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

button.danger:hover,
.button.danger:hover {
  background: #961f18;
  border-color: #961f18;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.actions {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.actions .spacer {
  flex: 1;
  min-width: 0.5rem;
}

label.option {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
  background: #fbfcfe;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

label.option:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

label.option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

label.option input {
  margin: 0.55rem 0 0;
  accent-color: var(--accent);
}

label.option .opt-letter {
  flex-shrink: 0;
  width: 1.7rem;
  height: 1.7rem;
  margin-top: 0.2rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--line);
}

label.option:has(input:checked) .opt-letter {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.field {
  margin-bottom: 1.05rem;
}

.field label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 61, 84, 0.15);
}

.field textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.field input[type="checkbox"] {
  width: auto;
  padding: 0;
  margin-inline-end: 0.4rem;
  accent-color: var(--accent);
}

.field label.check {
  display: flex;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 500;
}

.field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
  padding: 0.35rem;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius-sm) + 4px);
}

.subnav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 550;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.subnav a:hover {
  color: var(--ink);
  background: #fff;
}

.subnav a.active {
  color: #fff;
  background: var(--accent);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.row-actions form {
  display: inline;
  margin: 0;
}

.row-actions .button,
.row-actions button {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.panel h2 a,
.panel h1 a,
td a {
  color: inherit;
  text-decoration: none;
}

td a:hover,
.panel h2 a:hover,
.panel h1 a:hover {
  color: var(--accent);
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.messages li {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  border: 1px solid var(--line);
  background: var(--panel);
}

.messages li.error {
  border-color: #f0b4b0;
  background: var(--bad-soft);
  color: var(--bad);
}

.messages li.success {
  border-color: #b7e0c8;
  background: var(--ok-soft);
  color: var(--ok);
}

.errorlist {
  color: var(--bad);
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  font-size: 0.88rem;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  text-align: start;
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.93rem;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 650;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f7f9fc;
}

tbody tr:hover td {
  background: #fafbfe;
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #fff;
}

.pill.waiting {
  color: var(--warn);
  border-color: #efd29a;
  background: var(--warn-soft);
}

.pill.started,
.pill.in_progress {
  color: var(--accent);
  border-color: #b7c9f0;
  background: var(--accent-soft);
}

.pill.submitted,
.pill.completed {
  color: var(--ok);
  border-color: #b7e0c8;
  background: var(--ok-soft);
}

.pill.flagged,
.pill.failed {
  color: var(--bad);
  border-color: #f0b4b0;
  background: var(--bad-soft);
}

.progress {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 1.1rem;
}

.progress a,
.progress button {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--panel);
  padding: 0;
}

.progress a.done,
.progress button.done {
  border-color: #b7e0c8;
  color: var(--ok);
  background: var(--ok-soft);
}

.progress a.current,
.progress button.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.timer.low {
  color: var(--bad);
}

.banner {
  border: 1px solid #efd29a;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.95rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.alert-banner {
  border: 1px solid #f0b4b0;
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  font-weight: 650;
}

tr.row-flagged td {
  background: var(--bad-soft);
}

.banner .rec-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 12rem;
}

/* —— Recording gate —— */
.rec-gate {
  max-width: 920px;
  margin: 0 auto;
}

.rec-gate-panel {
  margin-bottom: 0;
  padding: 1.75rem;
}

.rec-gate-panel h1 {
  font-size: 1.6rem;
}

.rec-steps {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
}

.rec-steps li {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
  background: #f3f6fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
}

.rec-steps li strong {
  color: var(--accent);
  margin-inline-end: 0.25rem;
}

.rec-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.1rem 0 1.25rem;
}

.rec-preview-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f141d;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.rec-preview-card figcaption {
  padding: 0.5rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
}

.rec-preview-card video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #0f141d;
}

@media (max-width: 720px) {
  .rec-previews {
    grid-template-columns: 1fr;
  }
}

.rec-pip {
  position: fixed;
  inset-inline-end: 1rem;
  bottom: 1rem;
  z-index: 40;
  width: 168px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--accent);
  background: #111;
  box-shadow: 0 12px 32px rgba(21, 32, 51, 0.28);
  pointer-events: none;
}

.rec-pip video {
  display: block;
  width: 100%;
  height: 126px;
  object-fit: cover;
  background: #111;
}

.rec-pip-label {
  position: absolute;
  inset-inline-start: 0.45rem;
  bottom: 0.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: var(--bad);
  padding: 0.18rem 0.45rem;
  border-radius: 5px;
}

@media (max-width: 640px) {
  .rec-pip {
    width: 118px;
    inset-inline-end: 0.6rem;
    bottom: 0.6rem;
  }

  .rec-pip video {
    height: 88px;
  }
}

.checklist {
  display: grid;
  gap: 0.4rem;
  margin: 1rem 0 0;
  max-height: 22rem;
  overflow: auto;
  padding-inline-end: 0.25rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: #fbfcfe;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.check-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.check-row input {
  margin: 0;
  accent-color: var(--accent);
}

/* —— MathLive / question editor —— */
.question-math-form .math-editor,
math-field.math-editor {
  display: block;
  width: 100%;
  min-height: 3.5rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  font-size: 1.18rem;
  direction: rtl;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.question-math-form .math-editor:focus,
math-field.math-editor:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 61, 84, 0.15);
  background: #fff;
}

.math-question-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 0.85rem;
  margin-bottom: 1.1rem;
  background: linear-gradient(180deg, #f8faff 0%, #fff 48%);
}

.math-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 0.5rem;
}

.math-option-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  background: #fff;
}

.math-option-card .field {
  margin-bottom: 0;
}

.math-option-card label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.math-option-card .opt-badge {
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.math-meta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  .math-options-grid,
  .math-meta-row {
    grid-template-columns: 1fr;
  }
}

.math-block {
  margin: 0.5rem 0 1.1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: #f7f9fc;
  border: 1px solid var(--line);
}

.math-block math-field,
.math-inline math-field,
td math-field {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  font-size: 1.08rem;
  pointer-events: none;
}

.math-inline {
  display: block;
  flex: 1;
  min-width: 0;
}

/* —— Login —— */
.auth-wrap {
  max-width: 420px;
  margin: 2.5rem auto 0;
}

.auth-wrap .panel {
  padding: 1.75rem;
}

.auth-wrap h1 {
  font-size: 1.7rem;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.auth-logo {
  height: 2.6rem;
  width: auto;
  border-radius: 8px;
}

/* —— Face verification gate —— */
.face-verify-wrap {
  max-width: 520px;
}

.face-gate .face-preview {
  position: relative;
  margin: 0.85rem 0 1rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0f141d;
  aspect-ratio: 4 / 3;
}

.face-gate .face-preview video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #0f141d;
}

.face-gate .actions {
  margin-top: 0.85rem;
}

/* —— Question editor page —— */
.qpage {
  text-align: start;
}

.qpage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.qpage-kicker {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.qpage-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
  letter-spacing: -0.02em;
}

.qpage-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 36rem;
}

.qpage-sub code {
  font-size: 0.85em;
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.qpage-errors {
  grid-column: 1 / -1;
}

.qpage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 1.1rem;
  align-items: start;
}

@media (max-width: 960px) {
  .qpage-grid {
    grid-template-columns: 1fr;
  }
}

.qcard,
.qpreview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.qcard {
  padding: 1.25rem 1.35rem 1.4rem;
}

.qcard-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.qcard-top h2 {
  margin: 0;
  font-size: 1.05rem;
}

.qcard-top-spaced {
  margin-top: 1.35rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.qlabel {
  display: block;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

.qbtn-math {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 650;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid #9db7ef;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}

.qbtn-math:hover {
  background: #d9e5fb;
  border-color: var(--accent);
}

.qcard textarea,
.qcard input[type="text"],
.qcard input[type="number"],
.qcard select,
.qinput {
  font: inherit;
  width: 100%;
  display: block;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  margin: 0 0 0.85rem;
}

.qcard textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.55;
}

.qcard textarea:focus,
.qcard input:focus,
.qcard select:focus,
.qinput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 61, 84, 0.14);
  background: #fff;
}

.qchoices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

@media (max-width: 640px) {
  .qchoices {
    grid-template-columns: 1fr;
  }
}

.qchoice {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: #f8fafc;
}

.qchoice input {
  margin-bottom: 0;
  background: #fff;
}

.qchoice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.qbadge {
  display: inline-grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.qbadge.is-correct {
  background: var(--ok);
}

.qmeta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-top: 1.15rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.qmeta .field {
  margin: 0;
}

.qmeta .field label {
  margin-bottom: 0.35rem;
}

.qmeta select,
.qmeta input {
  margin-bottom: 0;
}

.qactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: flex-start;
  margin-top: 1.25rem;
}

.qpreview {
  padding: 1.15rem 1.2rem 1.3rem;
  background: linear-gradient(180deg, #f7f9fd 0%, #fff 40%);
}

.qpreview-sticky {
  position: sticky;
  top: 4.75rem;
}

.qpreview h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
}

.qpreview-label {
  margin: 0.85rem 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.qpreview-stem {
  min-height: 4rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--accent);
  background: #fff;
  font-size: 1.05rem;
  font-weight: 600;
}

.qpreview-opt {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}

.qpreview-opt .latex-content {
  flex: 1;
  min-width: 0;
}

.qpreview-opt.is-correct {
  border-color: #86d3a8;
  background: var(--ok-soft);
}

.qpreview-correct {
  margin: 1rem 0 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.qpreview-correct strong {
  color: var(--ok);
}

/* Math modal */
.qmath[hidden] {
  display: none !important;
}

.qmath {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.qmath-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 51, 0.45);
  backdrop-filter: blur(2px);
}

.qmath-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(21, 32, 51, 0.22);
  padding: 1.15rem 1.25rem 1.25rem;
}

.qmath-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.qmath-bar h3 {
  margin: 0;
  font-size: 1.1rem;
}

.qmath-hint {
  margin: 0 0 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.qmath-field-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  padding: 0.35rem 0.5rem;
  margin-bottom: 1rem;
}

.qmath-field-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 61, 84, 0.14);
  background: #fff;
}

math-field.qmath-field {
  width: 100%;
  min-height: 64px;
  font-size: 1.15rem;
  outline: none;
  direction: ltr !important;
  border: none;
  background: transparent;
}

.qmath-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

body.qmath-open {
  overflow: hidden;
}

.latex-content .katex,
.latex-content .katex-display,
math-field.qmath-field,
math-field.qmath-field * {
  direction: ltr !important;
  unicode-bidi: embed;
}

.text-danger {
  color: var(--bad);
}

math-virtual-keyboard,
.ML__keyboard {
  z-index: 1200000 !important;
}
