/* exam9mm shared styles. Rules every screen follows:
   - logical properties only (RTL and LTR from one stylesheet)
   - touch targets >= 44px, visible focus, nothing hover-only
   - no inline styles anywhere (the CSP forbids them); state goes through classes and data attributes */

:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #16202a;
  --muted: #55616d;
  --line: #d3dae1;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e3edfb;
  --ok: #14693f;
  --ok-bg: #e3f3ea;
  --bad: #a8211a;
  --bad-bg: #fbe8e6;
  --warn: #7d5200;
  --warn-bg: #fff1cf;
  --focus: #b86e00;
  --radius: 12px;
  --tap: 44px;
  --shadow: 0 1px 2px rgb(0 0 0 / 8%), 0 4px 14px rgb(0 0 0 / 6%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Hebrew", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161b;
    --surface: #1a2128;
    --surface-2: #232c35;
    --text: #e8edf2;
    --muted: #a6b1bc;
    --line: #313c47;
    --accent: #7fb0ff;
    --accent-text: #0b1b33;
    --accent-soft: #1d2f4a;
    --ok: #6fdba5;
    --ok-bg: #123424;
    --bad: #ff9d94;
    --bad-bg: #3b1714;
    --warn: #f3c874;
    --warn-bg: #352809;
    --focus: #ffcc66;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

:root[data-theme="dark"] {
  --bg: #11161b;
  --surface: #1a2128;
  --surface-2: #232c35;
  --text: #e8edf2;
  --muted: #a6b1bc;
  --line: #313c47;
  --accent: #7fb0ff;
  --accent-text: #0b1b33;
  --accent-soft: #1d2f4a;
  --ok: #6fdba5;
  --ok-bg: #123424;
  --bad: #ff9d94;
  --bad-bg: #3b1714;
  --warn: #f3c874;
  --warn-bg: #352809;
  --focus: #ffcc66;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-block-size: 100vh;
}

h1, h2, h3 {
  line-height: 1.25;
  margin-block: 0 0.5em;
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin-block: 0 1em; }
a { color: var(--accent); }
img { max-inline-size: 100%; block-size: auto; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

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

.page {
  max-inline-size: 760px;
  margin-inline: auto;
  padding: 16px;
}
.page.wide { max-inline-size: 1180px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-block-end: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; margin-inline-end: auto; }

.stack > * + * { margin-block-start: 12px; }
.stack-lg > * + * { margin-block-start: 24px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card.flush { padding: 0; overflow: hidden; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-block-size: var(--tap);
  min-inline-size: var(--tap);
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.quiet:hover { background: var(--surface-2); }
.btn.small { min-block-size: var(--tap); padding: 6px 12px; font-size: 0.9rem; }
.btn.block { display: flex; inline-size: 100%; }

.field { display: block; }
.field > .label { display: block; font-weight: 600; margin-block-end: 4px; }
.field > .hint { display: block; color: var(--muted); font-size: 0.875rem; margin-block-start: 4px; }
.field > .error { display: block; color: var(--bad); font-size: 0.9rem; margin-block-start: 4px; }

input[type="text"], input[type="email"], input[type="number"], input[type="search"],
input[type="tel"], input[type="password"], select, textarea {
  display: block;
  inline-size: 100%;
  min-block-size: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-block-size: 96px; resize: vertical; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bad); }
input[type="checkbox"], input[type="radio"] { inline-size: 22px; block-size: 22px; accent-color: var(--accent); flex: none; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-block-size: var(--tap);
  cursor: pointer;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.seg > button {
  min-block-size: var(--tap);
  min-inline-size: var(--tap);
  padding: 6px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.seg > button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.seg > button + button { border-inline-start: 1px solid var(--line); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.notice { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.notice.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.notice.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

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

.table-wrap { overflow-x: auto; }
table.table { inline-size: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: start; border-block-end: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 0.85rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.actions { white-space: nowrap; }

/* ---- dialog and toast ---------------------------------------------- */

dialog.modal {
  inline-size: min(560px, calc(100vw - 24px));
  max-block-size: calc(100vh - 24px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgb(0 0 0 / 50%); }
dialog.modal .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-block-start: 16px; }

.toasts {
  position: fixed;
  inset-inline: 12px;
  inset-block-end: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 50;
}
.toast {
  pointer-events: auto;
  max-inline-size: 520px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.toast.bad { background: var(--bad); color: var(--bg); }

/* ---- student exam -------------------------------------------------- */

.exam-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; justify-content: space-between; }
.timer { font-size: 1.25rem; font-weight: 700; }
.timer[data-low="true"] { color: var(--bad); }
.progress { block-size: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; block-size: 100%; background: var(--accent); inline-size: calc(var(--p, 0) * 1%); }

.question-text { font-size: 1.15rem; font-weight: 600; white-space: pre-wrap; margin-block-end: 12px; }
.question-image { display: block; max-block-size: 320px; margin-block-end: 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

.options { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-block-size: 56px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  touch-action: manipulation;
}
.option:hover { border-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.option input { position: absolute; opacity: 0; inline-size: 1px; block-size: 1px; }
.option .letter {
  flex: none;
  display: grid;
  place-items: center;
  inline-size: 34px;
  block-size: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  font-weight: 700;
}
.option:has(input:checked) .letter { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.option .text { flex: 1 1 auto; overflow-wrap: anywhere; white-space: pre-wrap; }

.qnav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.qnav button {
  min-inline-size: var(--tap);
  min-block-size: var(--tap);
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.qnav button[data-answered="true"] { background: var(--accent-soft); border-color: var(--accent); }
.qnav button[aria-current="step"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.save-state { font-size: 0.875rem; color: var(--muted); }
.save-state[data-state="offline"] { color: var(--bad); font-weight: 700; }

.result { text-align: center; padding-block: 24px; }
.result .verdict { font-size: 2rem; font-weight: 800; margin-block-end: 8px; }
.result[data-passed="true"] .verdict { color: var(--ok); }
.result[data-passed="false"] .verdict { color: var(--bad); }
.result .score { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.spinner {
  display: inline-block;
  inline-size: 20px;
  block-size: 20px;
  border: 3px solid var(--line);
  border-block-start-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.qr { inline-size: 100%; block-size: auto; max-inline-size: 260px; }
.qr .qr-bg { fill: #fff; }
.qr .qr-dot { fill: #000; }

/* ---- print --------------------------------------------------------- */

.print-only { display: none; }
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .topbar, .toasts, dialog { display: none !important; }
  .print-only { display: block; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .page, .page.wide { max-inline-size: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  .table th, .table td { border: 1px solid #888; padding: 4px 8px; }
  .table tbody tr:hover { background: none; }
  tr, img { break-inside: avoid; }
  .badge { border: 1px solid #000; background: none; color: #000; }
}

@page { size: A4; margin: 14mm; }
