/* Exam platform — one stylesheet for the whole site.
 *
 * Light theme only, on purpose. An exam page is read under stress, often on a
 * school machine with a cheap panel; one predictable high-contrast surface is
 * worth more than a preference toggle. Everything else follows from that:
 * generous type, quiet colour, and no motion that could distract.
 *
 * Direction: the interface is laid out left-to-right, but every piece of
 * content a person wrote — a question, an answer, a name — carries dir="auto"
 * so Persian text reads right-to-left inside its own box.
 */

:root {
  --ink-900: #11161d;
  --ink-700: #2c3542;
  --ink-500: #5b6676;
  --ink-300: #98a2b0;
  --paper:   #ffffff;
  --paper-2: #f5f7fa;
  --paper-3: #eceff4;
  --line:    #dde3ea;
  --line-strong: #c3ccd8;

  --accent:      #1f4e9c;
  --accent-ink:  #16386f;
  --accent-weak: #e9f0fb;

  --ok:     #12683d;
  --ok-weak:#e6f4ec;
  --warn:   #8a5d00;
  --warn-weak:#fdf3e0;
  --danger: #a4231c;
  --danger-weak:#fbeceb;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(17, 22, 29, .06), 0 2px 8px rgba(17, 22, 29, .06);
  --shadow-lg: 0 8px 32px rgba(17, 22, 29, .16);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Vazirmatn",
          Tahoma, "Iranian Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper-2);
  color: var(--ink-900);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }

/* A visible focus ring everywhere. Keyboard use is not an edge case, and in
 * the exam room it may be the only way a student navigates. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- layout ---------- */

.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page--narrow { max-width: 620px; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row--end { justify-content: flex-end; }
.row--between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-500); }
.small { font-size: .875rem; }
.tabular { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: .6rem 1rem;
}
.topbar__inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.topbar__title { font-weight: 650; }
.topbar__who { color: var(--ink-500); font-size: .875rem; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }

/* ---------- controls ---------- */

button, .button {
  font: inherit;
  font-weight: 550;
  padding: .55rem 1rem;
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink-900);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
button:hover:not(:disabled) { background: var(--paper-3); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-ink); }
button.danger { background: var(--paper); border-color: var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-weak); }
button.quiet { border-color: transparent; background: transparent; color: var(--accent); min-height: 36px; padding: .3rem .5rem; }
button.quiet:hover:not(:disabled) { background: var(--accent-weak); }
button.small { min-height: 34px; padding: .25rem .6rem; font-size: .875rem; }

label { display: block; font-weight: 550; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: .55rem .7rem;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-900);
}
textarea { min-height: 8rem; resize: vertical; line-height: 1.6; }
input:disabled, textarea:disabled, select:disabled { background: var(--paper-3); color: var(--ink-500); }
.field { margin-bottom: .9rem; }
.field__hint { font-size: .825rem; color: var(--ink-500); margin-top: .25rem; }
.field--inline { display: flex; align-items: center; gap: .5rem; }
.field--inline label { margin: 0; }
.field--inline input[type="checkbox"] { width: auto; min-height: 0; }

/* ---------- feedback ---------- */

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--ink-300);
  background: var(--paper);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.notice--info   { border-left-color: var(--accent); background: var(--accent-weak); }
.notice--ok     { border-left-color: var(--ok);     background: var(--ok-weak); }
.notice--warn   { border-left-color: var(--warn);   background: var(--warn-weak); }
.notice--danger { border-left-color: var(--danger); background: var(--danger-weak); }

.badge {
  display: inline-block;
  font-size: .78rem; font-weight: 600;
  padding: .1rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--paper-2);
  color: var(--ink-700);
  white-space: nowrap;
}
.badge--ok     { background: var(--ok-weak);     border-color: var(--ok);     color: var(--ok); }
.badge--warn   { background: var(--warn-weak);   border-color: var(--warn);   color: var(--warn); }
.badge--danger { background: var(--danger-weak); border-color: var(--danger); color: var(--danger); }
.badge--accent { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-ink); }

#toasts {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; z-index: 60; width: min(560px, calc(100vw - 2rem));
}
.toast {
  background: var(--ink-900); color: #fff;
  padding: .7rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.toast--error { background: var(--danger); }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .925rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-500); font-weight: 600; }
tbody tr:hover { background: var(--paper-2); }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-500); padding: 1.5rem; text-align: center; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab {
  border: none; background: none; min-height: 40px;
  padding: .5rem .85rem; border-bottom: 3px solid transparent;
  color: var(--ink-500); font-weight: 550; border-radius: 0;
}
.tab:hover { background: var(--paper-3); }
.tab[aria-current="page"] { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17, 22, 29, .45);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 70;
}
.modal {
  background: var(--paper); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: 85vh; overflow: auto; padding: 1.25rem;
}

/* ---------- sign-in ---------- */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.signin .card { width: min(420px, 100%); }
.signin__mark { font-weight: 700; letter-spacing: -.01em; font-size: 1.35rem; margin-bottom: .25rem; }

/* =====================================================================
 * The exam room
 * ===================================================================== */

/* Selection is off across the interface; the answer box turns it back on,
 * because editing your own sentence needs it. Copy, cut and paste are blocked
 * by script in every case, including inside the box. */
body.exam {
  user-select: none;
  -webkit-user-select: none;
  background: var(--paper-2);
  font-size: 17px;
}
body.exam textarea {
  user-select: text;
  -webkit-user-select: text;
}

.exam-bar {
  position: sticky; top: 0; z-index: 20;
  background: var(--paper); border-bottom: 1px solid var(--line);
  padding: .5rem 1rem;
}
.exam-bar__inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
}
.exam-bar__title { font-weight: 650; }

.clock {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 650;
  padding: .1rem .6rem;
  border-radius: var(--radius);
  background: var(--paper-3);
  color: var(--ink-900);
  letter-spacing: .02em;
}
.clock--warn   { background: var(--warn-weak);   color: var(--warn); }
.clock--danger { background: var(--danger-weak); color: var(--danger); }
.clock__label { display: block; font-family: var(--sans); font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-500); }

.exam-layout {
  max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 6rem;
  display: grid; grid-template-columns: 200px 1fr; gap: 1.5rem; align-items: start;
}
@media (max-width: 820px) {
  .exam-layout { grid-template-columns: 1fr; }
  .navigator { position: static; }
}

.navigator { position: sticky; top: 4.5rem; }
.navigator__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: .4rem; }
.navigator__item {
  min-height: 44px; padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--paper); font-variant-numeric: tabular-nums; font-weight: 600;
}
.navigator__item--answered { background: var(--accent-weak); border-color: var(--accent); color: var(--accent-ink); }
.navigator__item[aria-current="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.navigator__key { font-size: .8rem; color: var(--ink-500); margin-top: .75rem; }

.question { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow); }
.question__meta { display: flex; justify-content: space-between; gap: 1rem; color: var(--ink-500); font-size: .875rem; margin-bottom: .75rem; }
.question__stem { font-size: 1.15rem; line-height: 1.6; margin-bottom: 1.25rem; white-space: pre-wrap; }

.options { display: grid; gap: .6rem; }
.option {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .85rem 1rem; min-height: 56px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--paper); cursor: pointer; text-align: left; width: 100%;
  line-height: 1.5;
}
.option:hover { background: var(--paper-2); }
.option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-weak); box-shadow: inset 0 0 0 1px var(--accent); }
.option__mark {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line-strong); display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; color: var(--ink-500);
}
.option[aria-pressed="true"] .option__mark { border-color: var(--accent); background: var(--accent); color: #fff; }
.option__body { flex: 1 1 auto; }

.answer-state { font-size: .85rem; color: var(--ink-500); min-height: 1.4rem; }
.answer-state--saved { color: var(--ok); }
.answer-state--pending { color: var(--warn); }
.answer-state--failed { color: var(--danger); font-weight: 600; }

.exam-nav { display: flex; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; }

/* The lock screen. Neutral by design: it says the exam is still running and
 * how to get back, and nothing about why it appeared. */
.lock {
  position: fixed; inset: 0; z-index: 90;
  background: var(--paper);
  display: grid; place-items: center; padding: 2rem; text-align: center;
}
.lock__inner { max-width: 420px; }
.lock__clock { font-family: var(--mono); font-size: 2.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Printing the exam is blocked; this is the belt to the script's braces. */
@media print {
  body.exam > * { display: none !important; }
  body.exam::after {
    content: "This exam cannot be printed.";
    display: block; padding: 4rem; font-family: sans-serif; font-size: 18pt;
  }
}

/* ---------- results ---------- */

.score { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-question { border-top: 1px solid var(--line); padding: 1rem 0; }
.result-question:first-of-type { border-top: none; }
.answer-echo {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem; white-space: pre-wrap; margin: .5rem 0;
}
.feedback { border-left: 3px solid var(--accent); background: var(--accent-weak); padding: .6rem .8rem; border-radius: 0 var(--radius) var(--radius) 0; }
