:root {
  --bg: #f3f4f5;
  --surface: #ffffff;
  --surface-2: #f7f8f8;
  --text: #1f2326;
  --muted: #646b70;
  --border: #d9dcdf;
  --primary: #173f35;
  --primary-dark: #0f2c24;
  --primary-tint: #eef3f1;
  --correct: #12784f;
  --correct-tint: #ebf6f0;
  --wrong: #b3261e;
  --wrong-tint: #fcefee;
  --radius: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Almarai", "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.85;
  overflow-x: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[data-focus]:focus { outline: none; }

.wrap { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 28px; padding-bottom: 56px; outline: none; }

h1, h2, h3 { margin: 0; line-height: 1.5; font-weight: 700; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
p { margin: 0; }
.muted { color: var(--muted); }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 3px solid var(--primary);
}
.header-inner { display: flex; align-items: center; min-height: 76px; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 16px; color: inherit; text-decoration: none; min-width: 0; }
.logo { display: block; height: 52px; width: auto; flex: none; }
.logo + .brand-title { border-inline-start: 1px solid var(--border); padding-inline-start: 16px; }
.brand-title { font-weight: 700; font-size: 1rem; line-height: 1.5; }

/* Panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
}
.card + .card, .card + .section { margin-top: 16px; }
.section { margin-top: 32px; }
.section > h2 { margin-bottom: 10px; }

.intro h1 { margin-bottom: 8px; }
.intro p { color: var(--muted); }
.intro .meta { margin-top: 12px; color: var(--text); font-weight: 700; }

.notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: var(--primary-tint); border-color: #cddbd6; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; min-width: 120px; padding: 8px 24px;
  border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 700; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: #c3c7cb; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

/* Form */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 12px; font-weight: 700; font-size: 1.1rem; }

.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 600px) { .choice-grid { grid-template-columns: 1fr; } }

.choice {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.choice:hover { border-color: #b9bec2; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .label { flex: 1; min-width: 0; line-height: 1.6; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-tint); }
.choice input:focus-visible ~ .dot { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Radio indicator, shared by department choices and answer options */
.dot {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #9aa1a6; background: #fff;
}
.choice input:checked ~ .dot,
.option[aria-checked="true"] .dot { border-color: var(--primary); box-shadow: inset 0 0 0 4px #fff; background: var(--primary); }

.field { margin-top: 20px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.field input:focus { border-color: var(--primary); outline: none; }

.error { color: var(--wrong); margin-top: 10px; font-weight: 700; }
.note { margin-top: 12px; color: var(--muted); font-size: .88rem; }

/* Question */
.q-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; font-size: .92rem; font-weight: 700; margin-bottom: 10px; }
.progress { height: 4px; background: #e6e8ea; margin-bottom: 24px; }
.progress > span { display: block; height: 100%; background: var(--primary); }

.q-text { font-size: 1.2rem; line-height: 1.9; }
.q-hint { margin-top: 6px; color: var(--muted); font-size: .92rem; }

.options { display: grid; gap: 8px; margin-top: 20px; }
.options.tf { grid-template-columns: 1fr 1fr; }
.option {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: start;
  padding: 12px 16px; min-height: 52px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  line-height: 1.7;
}
.option:hover { border-color: #b9bec2; }
.option[aria-checked="true"] { border-color: var(--primary); background: var(--primary-tint); }

.q-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }

/* Results */
.score { font-size: 1.15rem; margin-top: 6px; }
.score b { font-size: 2rem; color: var(--primary); }

.details { margin: 16px 0 0; display: grid; gap: 4px; }
.details div { display: flex; gap: 8px; }
.details dt { color: var(--muted); min-width: 110px; }
.details dd { margin: 0; font-weight: 700; }

.table { width: 100%; border-collapse: collapse; margin-top: 20px; font-size: .95rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: start; }
.table th { background: var(--surface-2); font-weight: 700; color: var(--muted); }
.table .num { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }

.filters { display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 14px; }
.filter {
  padding: 6px 16px; min-height: 38px;
  border: 1px solid var(--border); background: var(--surface); font-size: .92rem;
  margin-inline-start: -1px;
}
.filter:first-child { border-start-start-radius: var(--radius); border-end-start-radius: var(--radius); margin-inline-start: 0; }
.filter:last-child { border-start-end-radius: var(--radius); border-end-end-radius: var(--radius); }
.filter[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; position: relative; }

.review { display: grid; gap: 12px; }
.review-item { border-inline-start: 4px solid var(--border); }
.review-item.is-correct { border-inline-start-color: var(--correct); }
.review-item.is-wrong { border-inline-start-color: var(--wrong); }
.ri-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: .92rem; font-weight: 700; margin-bottom: 8px; }
.is-correct .status { color: var(--correct); }
.is-wrong .status { color: var(--wrong); }
.ri-q { font-weight: 700; margin-bottom: 12px; }
.ri-options { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.ri-options li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); line-height: 1.7;
}
.ri-options .txt { flex: 1; min-width: 0; }
.ri-options .mark { flex: none; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.ri-options li.correct { background: var(--correct-tint); border-color: var(--correct); }
.ri-options li.correct .mark { color: var(--correct); }
.ri-options li.chosen-wrong { background: var(--wrong-tint); border-color: var(--wrong); }
.ri-options li.chosen-wrong .mark { color: var(--wrong); }
.ri-box { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.ri-box h3 { font-size: .88rem; color: var(--muted); }
.q-text, .ri-q, .ri-box p { white-space: pre-line; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

@media (max-width: 600px) {
  .card { padding: 18px 16px; }
  h1 { font-size: 1.25rem; }
  .q-text { font-size: 1.08rem; }
  .logo { height: 40px; }
  .brand { gap: 12px; }
  .logo + .brand-title { padding-inline-start: 12px; font-size: .9rem; }
  .q-nav .btn { flex: 1; min-width: 0; }
  .ri-options li { flex-wrap: wrap; row-gap: 0; }
  .ri-options .mark { order: -1; flex-basis: 100%; }
}

@media print {
  .no-print, .filters { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .site-header { border-bottom-width: 2px; }
  .card { break-inside: avoid; }
  main.wrap { padding: 12px 0 0; max-width: none; }
}
