/* EduArabia brand system — tokens from dev/Edu/Brand/design.md
   Flat by default: no shadows; hierarchy via color blocks + Mist bands.
   RTL-first: logical properties only (inline-start/end), never left/right. */

:root {
  /* colors */
  --primary: #1a6ef5;
  --secondary: #ffbe0a;
  --ink: #0f172a;
  --surface: #ffffff;
  --mist: #f1f5f9;
  --sky: #93c5fd;
  --cream: #fef3c7;
  --coral: #ff5c5c;          /* error (closest brand hue, per design.md) */

  /* radii — soft modular blocks, never 0px */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;

  /* spacing — 8px grid */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 48px;

  --w-narrow: 680px;
  --w-default: 1120px;

  --font-latin: "Poppins", "Segoe UI", system-ui, sans-serif;
  /* Graphik Arabic is licensed — IBM Plex Sans Arabic is the flagged
     fallback (design.md). Drop GraphikArabic woff2 in static/fonts/ +
     an @font-face here and it takes over automatically. */
  --font-arabic: "Graphik Arabic", "IBM Plex Sans Arabic", "Tajawal", sans-serif;
}

* { box-sizing: border-box; }

/* the hidden attribute must always win, even against display rules on classes */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-arabic);
  font-size: 16px;
  line-height: 1.8;               /* Arabic needs the room (design.md) */
  -webkit-font-smoothing: antialiased;
}

[dir="ltr"] body,
body[dir="ltr"] {
  font-family: var(--font-latin);
  line-height: 1.6;
}

h1, h2, h3 { line-height: 1.3; margin: 0 0 var(--sp-md); font-weight: 800; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
a { color: var(--primary); text-decoration: none; transition: opacity 150ms ease; }
a:hover { opacity: .85; }

/* ---------- layout ---------- */

.container {
  max-width: var(--w-default);
  margin-inline: auto;
  padding-inline: var(--sp-md);
}
.container--narrow { max-width: var(--w-narrow); }

.band {
  background: var(--mist);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  height: 48px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--primary);
  color: #fff;                     /* white on brand blue: 4.57:1, keep it */
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 150ms ease, opacity 150ms ease;
}
.btn:hover { filter: brightness(.92); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn--secondary { background: var(--secondary); color: var(--ink); } /* yellow never carries white */
.btn--ghost { background: transparent; color: var(--ink); }
.btn--danger { background: var(--coral); color: #fff; }
.btn--sm { height: 36px; padding: 0 16px; font-size: 13px; }

/* uppercase labels are a Latin-only affordance — Arabic has no case */
[dir="ltr"] .btn { text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }

/* ---------- cards, chips, callouts ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sky);
  color: var(--ink);
  border-radius: 9999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
}
.chip--cream { background: var(--cream); }

.callout {
  background: var(--cream);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: var(--sp-md);
}
.callout--error { background: var(--coral); color: #fff; }

/* ---------- forms ---------- */

.input {
  width: 100%;
  height: 48px;
  padding: 0 var(--sp-md);
  border: 2px solid var(--mist);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 150ms ease;
}
.input:focus { outline: none; border-color: var(--primary); }

.label {
  display: block;
  margin-block-end: var(--sp-sm);
  font-size: 13px;
  font-weight: 600;
}
[dir="ltr"] .label { text-transform: uppercase; letter-spacing: .06em; }

/* ---------- scattered-squares pattern (signature motif) ----------
   Rules from design.md: ≥2 colors, mandatory gaps, never one solid block. */

.sq-cluster {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  gap: 6px;                        /* the mandatory gaps */
  width: max-content;
}
.sq {
  width: 14px;
  height: 14px;
  border-radius: var(--r-sm);
}
.sq--blue   { background: var(--primary); }
.sq--yellow { background: var(--secondary); }
.sq--sky    { background: var(--sky); }
.sq--navy   { background: var(--ink); }
.sq--gap    { background: transparent; }

/* logo mark: 2×2 mini cluster used in headers/player bar */
.logo-mark {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  gap: 4px;
  flex-shrink: 0;
}
.logo-mark .sq { width: 12px; height: 12px; border-radius: 4px; }

.brand-lockup {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-weight: 800;
  color: var(--ink);
  font-size: 17px;
}

/* ---------- topbar (admin) ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
  padding: var(--sp-md);
  max-width: var(--w-default);
  margin-inline: auto;
}
.topbar__actions { display: flex; align-items: center; gap: var(--sp-sm); }

/* ---------- lists ---------- */

.stack { display: flex; flex-direction: column; gap: var(--sp-md); }
.row { display: flex; align-items: center; gap: var(--sp-md); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.muted { opacity: .6; font-size: 14px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  text-align: start;
  padding: var(--sp-sm) var(--sp-md);
  border-block-end: 1px solid var(--mist);
}
.table th { font-size: 12px; font-weight: 600; opacity: .6; }

/* ---------- card overflow menu ---------- */

.card-menu { position: relative; }
.card-menu summary { list-style: none; cursor: pointer; }
.card-menu summary::-webkit-details-marker { display: none; }
/* real 40px+ tap target on phones — a bare "⋯" is too easy to miss */
.card-menu summary.btn--ghost,
details > summary.btn--ghost { background: var(--mist); min-width: 40px; }
.card-menu__panel {
  position: absolute;
  inset-inline-end: 0;
  z-index: 10;
  min-width: 240px;
  margin-block-start: 8px;
}

/* ---------- upload zone ---------- */

.upload-zone {
  border: 2px dashed var(--sky);
  border-radius: var(--r-lg);
  padding: var(--sp-xl) var(--sp-lg);
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
  background: var(--surface);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--mist);
}
.upload-zone input[type=file] { display: none; }

.progress {
  height: 8px;
  background: var(--mist);
  border-radius: 9999px;
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 9999px;
  transition: width 150ms ease;
}

/* ---------- player (public course view) ---------- */

body.player {
  display: flex;
  flex-direction: column;
  height: 100dvh;              /* dvh dodges the iOS URL-bar viewport bug */
  overflow: hidden;
}
@supports not (height: 100dvh) {
  body.player { height: 100vh; }
}

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
  height: 48px;
  padding-inline: var(--sp-md);
  background: var(--surface);
  border-block-end: 1px solid var(--mist);
  flex-shrink: 0;
}
.player-bar__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-shrink: 0;
}
.player-bar__badge {
  font-size: 12px;
  padding: 2px 10px;
  display: inline-block;             /* inline-flex clips without an ellipsis */
  max-width: 32vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.player-bar__select {
  height: 32px;
  border: 2px solid var(--mist);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  max-width: 40vw;
}
.player-bar__btn {
  height: 32px;
  width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--mist);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
  transition: background 150ms ease;
}
.player-bar__btn:hover { background: var(--sky); }

.player-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  .card { padding: var(--sp-md); }
  .band { padding: var(--sp-md); }
}

/* ---------- session gate — join / resume / locked / closed overlay ---------- */
/* Covers the (not-yet-loaded) course area below the brand bar. The SCORM
   APIs live in the page regardless — only the iframe waits (gotcha #1). */

.gate {
  position: fixed;
  inset: 48px 0 0 0;                 /* below the player bar */
  z-index: 40;
  background: var(--mist);
  display: flex;
  align-items: flex-start;           /* flex-start + auto margins so a tall */
  justify-content: center;           /* card stays fully scrollable, never   */
  padding: var(--sp-md);             /* clipped above the viewport on a phone */
  overflow-y: auto;
}

.gate__card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: var(--sp-xl) var(--sp-lg);
  margin-block: auto;                /* centers when it fits, 0 when it spills */
  position: relative;                /* anchor for the language toggle */
}

.gate__lang { position: absolute; top: 12px; inset-inline-end: 12px; }

.gate__card .logo-mark--lg .sq { width: 18px; height: 18px; border-radius: 5px; }
.gate__card .logo-mark { margin-bottom: var(--sp-md); }

.gate__form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  text-align: start;
  margin-top: var(--sp-lg);
}

.gate__form .label { display: flex; flex-direction: column; gap: var(--sp-xs); }
.gate__form .input { width: 100%; }

.gate__err {
  color: var(--coral);
  font-weight: 700;
  margin: var(--sp-sm) 0 0;
}

.gate__leave { margin-top: var(--sp-md); }

/* ---------- live board ---------- */

.bar {
  height: 10px;
  background: var(--mist);
  border-radius: 999px;
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 600ms ease;   /* rows morph every 3s — glide, don't jump */
}

.chip--sky  { background: var(--sky); }
.chip--mist { background: var(--mist); }

/* ---------- projector view (the ROOM sees this) ---------- */

.projector__stage {
  padding: var(--sp-xl) var(--sp-lg);
  max-width: 1100px;
  margin-inline: auto;
}

.projector__join { text-align: center; }

.projector__qr svg {
  width: min(48vh, 420px);
  height: min(48vh, 420px);
  background: #fff;
  border-radius: var(--r-lg);
  padding: 12px;
  border: 1px solid var(--mist);
}

.projector__url { font-size: 20px; font-weight: 600; word-break: break-all; }

.projector__names {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  justify-content: center;
  margin-top: var(--sp-lg);
}

.projector__prow {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  margin-bottom: var(--sp-md);
  font-size: 20px;
}

.projector__pname { min-width: 220px; font-weight: 600; }

.bar__fill--done { background: var(--secondary); }

.projector__lrow {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  font-size: 24px;
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-xs);
}

.projector__lrow--first {
  background: var(--cream);
  font-size: 30px;
  font-weight: 800;
}

.projector__rank {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
  border-radius: 50%;
  font-family: var(--font-latin); font-weight: 800;
}

.projector__lrow--first .projector__rank { background: var(--secondary); color: var(--ink); }

.projector__score { font-family: var(--font-latin); font-weight: 800; }

/* ---------- question matrix (the analytics payoff) ---------- */

.matrix { border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { border: 1px solid var(--mist); text-align: center; }

.matrix__namehead, .matrix__name {
  text-align: start;
  padding: 6px 12px;
  position: sticky;
  inset-inline-start: 0;
  background: var(--surface);
  white-space: nowrap;
  font-weight: 600;
}
.matrix__qhead { padding: 6px; min-width: 30px; }
.matrix__qhead span { font-family: var(--font-latin); font-size: 11px; color: var(--ink); }

.mcell {
  width: 28px; height: 28px;
  display: inline-block;         /* legend swatches flow inline in a <p> */
  vertical-align: middle;
  border-radius: 4px;
  background: var(--mist);       /* not answered */
}
/* inside the grid the same class is a real table cell — inline-block would
   pull it out of table layout and the columns would collapse together */
td.mcell {
  display: table-cell;
  border-radius: 0;
  width: 30px;
  color: #fff;
  font-size: 12px;
}
.mcell--correct   { background: #16a34a; color: #fff; }
.mcell--incorrect { background: var(--coral); color: #fff; }
.mcell--other     { background: var(--cream); }

.hardq {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--mist);
}
.hardq:last-child { border-bottom: 0; }
.hardq__pct {
  font-family: var(--font-latin);
  font-weight: 800;
  min-width: 56px;
  text-align: center;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
.hardq__pct--bad { background: var(--coral); color: #fff; }
.hardq__pct--mid { background: var(--cream); color: var(--ink); }
.hardq__pct--ok  { background: #dcfce7; color: #14532d; }
.hardq__label { flex: 1; }

.matrix__key { margin: var(--sp-sm) 0 0; padding-inline-start: 24px; }
.matrix__key li { padding: 2px 0; }
