/* ==========================================================================
   Takamul MCQ Exam — main.css
   Premium, minimal UI in white / black / space gray
   Stack: pure HTML + CSS + JavaScript (no frameworks)
   ========================================================================== */

/* ---------- CSS Variables: Space-Gray Palette ---------- */
:root {
  /* Canvas & Surfaces */
  --bg: #f5f6f7;          /* clean light gray canvas */
  --surface: #ffffff;     /* cards / surfaces */
  --elevated: #fcfcfd;    /* subtle contrast surface */

  /* Text & Lines */
  --ink: #0f1115;         /* near-black */
  --muted: #6b7280;       /* gray-500 */
  --line: #e5e7eb;        /* subtle divider */

  /* Brand / Accent (deep space gray) */
  --brand: #111827;

  /* States */
  --ok: #0ea5e9;          /* cyan-ish for neutral success */
  --warn: #b00020;        /* premium red for alert/urgency */

  /* Effects */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(15,17,21,0.08);
  --shadow-sm: 0 2px 10px rgba(15,17,21,0.06);

  /* Typography */
  --fs-hero: clamp(28px, 4vw, 36px);
  --fs-h1: clamp(22px, 3vw, 28px);
  --fs-h2: clamp(18px, 2.4vw, 22px);
  --fs-body: 16px;
  --fs-small: 14px;
  --lh-tight: 1.2;
  --lh-normal: 1.6;

  /* Spacing */
  --gutter: clamp(16px, 3vw, 24px);
  --gap: 16px;
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

html {
  color-scheme: light;
  hanging-punctuation: first last;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-size: var(--fs-body);
  line-height: var(--lh-normal);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Layout Shell (optional helpers if needed by ui.js) ---------- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* Top header for the exam screen */
.header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.header__title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.header__title-text {
  font-size: var(--fs-h2);
  font-weight: 700;
  letter-spacing: .2px;
}
.header__subtitle {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--muted);
}
.header__meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3vw, 28px);
  margin: 30px 0px;
}

/* Elevated subtle wrapper for start/result screens */
.panel {
  background: var(--elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(16px, 3vw, 22px);
}

/* ---------- Typography ---------- */
h1, h2, h3 {
  margin: 0 0 8px 0;
  line-height: var(--lh-tight);
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); color: var(--brand); }
p { margin: 0 0 10px 0; color: var(--muted); }

.lead {
  font-size: 17px;
  color: var(--ink);
}

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--brand);
  --btn-fg: #fff;
  --btn-bd: transparent;

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  letter-spacing: .2px;
  cursor: pointer;
  user-select: none;
  transition: transform .06s ease, box-shadow .2s ease, opacity .2s ease;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(17,24,39,.12);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn[disabled],
.btn:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Variants */
.btn--ghost {
  --btn-bg: #fff;
  --btn-fg: var(--ink);
  --btn-bd: var(--line);
  box-shadow: none;
}
.btn--muted {
  --btn-bg: #fafafa;
  --btn-fg: var(--muted);
  --btn-bd: var(--line);
  box-shadow: none;
}

/* Inline (text) button */
.btn-inline {
  background: transparent;
  border: 0;
  color: var(--brand);
  padding: 0;
  height: auto;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Timer & Progress ---------- */
.timer {
  font-weight: 800;
  letter-spacing: .3px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  min-width: 84px;
  text-align: center;
}
.timer__value {
  font: inherit;
}
.timer.warning { color: var(--warn); border-color: #f2c6cb; background: #fff7f8; }

.progress {
  block-size: 10px;
  inline-size: 100%;
  background: #eef1f4;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress__bar {
  block-size: 100%;
  inline-size: 0%;
  background: linear-gradient(90deg, #1f2937 0%, #111827 100%);
  transition: inline-size .3s ease;
}

/* ---------- Question Block ---------- */
.question {
  display: grid;
  gap: 14px;
}
.question__counter {
  font-size: var(--fs-small);
  color: var(--muted);
}
.question__text {
  font-size: clamp(18px, 2.4vw, 20px);
  font-weight: 700;
  letter-spacing: .2px;
  color: var(--ink);
}

/* ---------- Options (custom radios) ---------- */
.options {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}
.option {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
  box-shadow: var(--shadow-sm);
}
.option:hover {
  border-color: #d7dbe2;
  background: #fcfcfd;
}
.option:focus-within {
  outline: 3px solid color-mix(in srgb, var(--brand) 12%, transparent);
  outline-offset: 2px;
}

.option__radio {
  position: relative;
  inline-size: 20px;
  block-size: 20px;
}
.option__radio input {
  position: absolute;
  inline-size: 20px;
  block-size: 20px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.option__bullet {
  inline-size: 20px;
  block-size: 20px;
  border-radius: 999px;
  border: 2px solid #c9ced6;
  display: grid;
  place-items: center;
  transition: border-color .2s ease, background .2s ease;
}
.option__bullet::after {
  content: "";
  inline-size: 10px;
  block-size: 10px;
  border-radius: 999px;
  background: transparent;
  transition: background .2s ease, transform .2s ease;
  transform: scale(.6);
}
/* Custom radio checked state */
.option__radio input:checked + .option__bullet {
  border-color: var(--brand);
  background: #0f11150a;
}
.option__radio input:checked + .option__bullet::after {
  background: var(--brand);
  transform: scale(1);
}

.option__text {
  color: var(--ink);
  font-size: 15px;
  line-height: var(--lh-normal);
}

/* Selected state via :has(), with a safe fallback for browsers without :has() */
.option:has(input:checked) {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 6px 22px rgba(17, 24, 39, .10);
}

/* ---------- Actions Row ---------- */
.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ---------- Result Summary ---------- */
.result {
  display: grid;
  gap: 16px;
}
.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.summary__tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.summary__k {
  display: block;
  font-size: 13px;
  color: var(--muted);
}
.summary__v {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .3px;
}

/* Wrong answers review list */
.review {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}
.review__item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 14px;
}
.review__q {
  font-weight: 700;
  margin-bottom: 8px;
}
.badge {
  display: inline-block;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--muted);
}
.badge--wrong {
  border-color: #f2c6cb;
  background: #fff7f8;
  color: var(--warn);
}
.badge--right {
  border-color: #caeaf6;
  background: #f0fbff;
  color: #0369a1;
}

/* ---------- Set selection ---------- */
.set-grid {
  display: grid;
  gap: 16px;
  margin-top: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.set-card {
  display: grid;
  gap: 12px;
}
.set-card__eyebrow {
  display: flex;
  justify-content: flex-start;
}
.set-card__meta .badge {
  width: max-content;
}
.set-card__actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 6px;
}

/* ---------- Utility ---------- */
.stack { display: grid; gap: var(--gap); }
.center {
  display: grid;
  place-items: center;
  text-align: center;
}
.muted { color: var(--muted); }
.divider {
  height: 1px;
  background: var(--line);
  margin: 10px 0;
  border: 0;
}
.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: #fff;
  border-radius: 6px;
  padding: 3px 6px;
}

/* Screen wrappers (start/exam/result) for ui.js to swap */
.screen { display: grid; gap: 18px; }
.screen--start .lead { font-size: 18px; }

/* ---------- Focus & A11y ---------- */
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 15%, transparent);
  outline-offset: 2px;
}
.sr-only {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px,1px,1px,1px);
  white-space: nowrap;
}

/* ---------- Animations ---------- */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fade-in-up .24s ease both; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .header {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .header__meta {
    justify-content: space-between;
  }
  .summary {
    grid-template-columns: 1fr;
  }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1 1 auto; }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Print (result page only is meaningful) ---------- */
@media print {
  body { background: #fff; }
  .card, .panel {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  .btn, .actions, .progress { display: none !important; }
}

/* ==========================================================================
   End of main.css
   ========================================================================== */
