/* Shared base for every page. Values come from /brand/tokens/tokens.css.
   Layout uses logical properties only (inline-start/end, block-start/end), so
   <html dir="rtl"> mirrors everything; never use left/right here. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-block: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: var(--weight-body) var(--step-1)/var(--leading-body) var(--font-body);
  -webkit-font-smoothing: antialiased;
}
img, svg, video { display: block; max-width: 100%; }
[hidden] { display: none !important; }
picture { display: contents; }
a { color: inherit; text-underline-offset: .2em; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: var(--weight-display); line-height: var(--leading-tight); margin: 0; text-wrap: balance; }
p { margin: 0; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
/* Headings get focus on navigation only so screen readers announce them. */
[tabindex="-1"]:focus { box-shadow: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.wrap { max-width: 1120px; margin-inline: auto; padding-inline: var(--gutter); }
.muted { color: var(--text-muted); }
.ico { width: 20px; height: 20px; flex: none; }
[dir="rtl"] .ico.dir { transform: scaleX(-1); }
bdi[dir="ltr"] { unicode-bidi: isolate; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap); padding-inline: var(--space-5); border-radius: var(--radius-md); border: 0;
  font-weight: var(--weight-strong); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, box-shadow .15s;
}
.btn.primary { background: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, var(--text)); }
.btn.secondary { background: transparent; color: var(--text); box-shadow: inset 0 0 0 2px var(--field-border); }
.btn.secondary:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.btn.gold { background: var(--ilm-emas-light); color: var(--ilm-green-900); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 2px currentColor; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding-inline: var(--space-4); font-size: var(--step-0); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { border-radius: var(--radius-md); }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: var(--radius-md);
  border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }

/* ── Forms ── */
.field { display: grid; gap: var(--space-1); }
.field > span:first-child { font-weight: var(--weight-strong); font-size: var(--step-0); }
.field .hint { font-size: var(--step-0); color: var(--text-muted); }
.field .err { font-size: var(--step-0); color: var(--danger); font-weight: var(--weight-strong); }
.input {
  min-height: var(--tap); width: 100%; padding-inline: var(--space-3); border-radius: var(--radius-md);
  border: 1.5px solid var(--field-border); background: var(--surface-raised); color: var(--text);
}
textarea.input { padding-block: var(--space-2); resize: vertical; }
.input:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-md); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input.ltr { direction: ltr; text-align: start; }
[dir="rtl"] .input.ltr { text-align: end; }
.phone-row { display: flex; gap: var(--space-2); direction: ltr; }
.phone-row .cc { flex: none; display: grid; place-items: center; padding-inline: var(--space-3); border-radius: var(--radius-md); background: var(--surface); font-weight: var(--weight-strong); }
.check { display: flex; gap: var(--space-3); align-items: start; font-size: var(--step-0); }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
.form { display: grid; gap: var(--space-4); }
.form-error { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: color-mix(in srgb, var(--danger) 12%, var(--bg)); color: var(--danger); font-weight: var(--weight-strong); }

/* ── Surfaces ── */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: var(--space-4); }
.card.raised { background: var(--surface-raised); box-shadow: 0 1px 0 var(--line); }
.stack { display: grid; gap: var(--space-3); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.kicker { font-size: var(--step-0); color: var(--text-muted); font-weight: var(--weight-strong); }

/* Status: always colour + icon + word. */
.pill {
  display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-3); border-radius: var(--radius-pill);
  font-size: var(--step-0); font-weight: var(--weight-strong); background: var(--bg); color: var(--text); white-space: nowrap;
}
.pill .ico { width: 14px; height: 14px; }
.pill.ok { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--bg)); }
.pill.bad { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--bg)); }
.pill.wait { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, var(--bg)); }
.pill.info { color: var(--text); background: var(--surface); }

.banner { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--banner-bg); color: var(--banner-text); font-weight: var(--weight-strong); text-decoration: none; }
.banner .ico { margin-inline-start: auto; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--live); flex: none; }
@media (prefers-reduced-motion: no-preference) {
  .live-dot { animation: live 1.6s ease-in-out infinite; }
  @keyframes live { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); } 50% { box-shadow: 0 0 0 6px transparent; } }
}

/* ── Language switch ── */
[data-lang-switch] { display: inline-flex; background: var(--surface); border-radius: var(--radius-pill); padding: 3px; }
[data-lang-switch] button {
  min-height: 36px; min-width: 44px; padding-inline: var(--space-3); border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-muted); font-weight: var(--weight-strong); font-size: var(--step-0); cursor: pointer;
}
[data-lang-switch] button[lang="ar"] { font-family: var(--font-arabic); font-size: var(--step-1); line-height: 1; }
[data-lang-switch] button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); }

/* ── Demo-mode notice ── */
.demo-note { background: var(--ilm-emas-light); color: var(--ilm-green-900); font-size: var(--step-0); font-weight: var(--weight-strong); text-align: center; padding: var(--space-2) var(--gutter); }

/* ── Toast ── */
.toast {
  position: fixed; inset-inline: var(--gutter); inset-block-end: calc(88px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 480px; margin-inline: auto; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--ilm-ink); color: var(--ilm-paper); font-weight: var(--weight-strong); text-align: center;
  opacity: 0; translate: 0 8px; pointer-events: none; transition: opacity .2s, translate .2s;
}
.toast.show { opacity: 1; translate: 0 0; }
.toast.bad { background: var(--danger); color: #fff; }

/* ── Empty states ── */
.empty { display: grid; justify-items: center; text-align: center; gap: var(--space-3); padding: var(--space-7) var(--space-4); color: var(--text-muted); }
.empty img { width: 40px; height: 40px; opacity: .8; }
.empty p { max-width: 36ch; }

/* ── Arabic: bigger, looser, never letter-spaced (tokens.css sets the scale). ── */
:lang(ar) body, body:lang(ar) { font-family: var(--font-arabic); }
:lang(ar) h1, :lang(ar) h2, :lang(ar) h3, :lang(ar) h4 { font-family: var(--font-display); line-height: 1.35; }

/* An on-screen key the student should look for (Share, ⋮). */
.key { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-sm); background: var(--surface); vertical-align: middle; }
.key .ico { width: 17px; height: 17px; }
