/* DigitalClass — design tokens, layout and components. Logical properties
   throughout so the whole UI mirrors correctly when dir="rtl" (Arabic). */

/* "Nocturne" — flat dark theme: surfaces sit at the same level as the page,
   cards are the only thing that steps up a shade, hairlines are the text
   colour at low alpha rather than a separate border hue, and the accent is a
   soft periwinkle used both filled (chips) and as an outline (buttons). */
:root {
  --bg: #161826;
  --surface: #161826;
  --surface-2: #1e2030;
  --surface-3: #232532;
  --border: rgba(233, 233, 237, .14);
  --text: #e9e9ed;
  --muted: rgba(233, 233, 237, .58);
  --primary: #9184d9;
  --primary-soft: rgba(145, 132, 217, .16);
  --primary-strong: #423a6a;
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 10px 28px rgba(0, 0, 0, .3);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #f4f6fb;
  --surface-2: #eceef7;
  --surface-3: #ffffff;
  --border: rgba(22, 24, 46, .12);
  --text: #17182b;
  --muted: rgba(23, 24, 43, .58);
  --primary: #6a5acd;
  --primary-soft: rgba(106, 90, 205, .12);
  --primary-strong: #ded8f7;
  --shadow: 0 8px 24px rgba(20, 20, 40, .08);
}

html[lang="ar"] { --font: "Cairo", "Segoe UI", "Tahoma", system-ui, sans-serif; }

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.28rem; } h3 { font-size: 1.06rem; }
p { margin: 0 0 .8rem; }
code, pre, .mono { font-family: var(--mono); }

/* ------------------------------------------------------------- app shell */

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.2rem; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-block-end: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 750; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  inline-size: 30px; block-size: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; font-weight: 800; font-size: .95rem;
}
.topbar-spacer { flex: 1; }

.layout { flex: 1; display: grid; grid-template-columns: 232px 1fr; align-items: start; }
.sidebar {
  position: sticky; top: 47px; block-size: calc(100vh - 47px); overflow-y: auto;
  padding: 1rem .7rem; border-inline-end: 1px solid var(--border); background: var(--surface);
}
.side-link {
  display: flex; align-items: center; gap: .65rem; padding: .55rem .7rem; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 550; font-size: .93rem; margin-block-end: 2px;
}
.side-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.side-link.active { background: var(--primary-soft); color: var(--primary); }
.ic {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  inline-size: 18px; block-size: 18px; vertical-align: -4px; color: var(--primary);
}
.ic svg { inline-size: 100%; block-size: 100%; }
.side-link .ic {
  font-size: 1.05rem; inline-size: 20px; block-size: 20px; text-align: center;
  color: var(--primary); display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.side-link .ic svg { inline-size: 18px; block-size: 18px; }
.ic-inline {
  inline-size: 15px; block-size: 15px; vertical-align: -3px; color: var(--primary); flex: none;
}
/* min-inline-size:0 stops this grid item from being sized by its widest
   child (grid items default to min-width:auto, which forces page scroll). */
main { padding: 1.5rem 1.7rem 4rem; max-inline-size: 1180px; min-inline-size: 0; }

/* Bottom tab bar: phones only. */
.tabbar { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  /* Off-canvas drawer. Hiding is done with `display`, never with a transition
     or transform, so the panel is reliably out of the way even where those are
     disabled (reduced-motion settings, embedded webviews, screenshot tools). */
  .sidebar {
    display: none;
    position: fixed; inset-block: 47px 0; inset-inline-start: 0;
    inline-size: 250px; z-index: 45; box-shadow: var(--shadow);
    padding-block-end: calc(64px + env(safe-area-inset-bottom));
  }
  .sidebar.open { display: block; animation: drawer-in .2s ease; }
  @keyframes drawer-in { from { opacity: 0; translate: -12px 0; } }
  html[dir="rtl"] .sidebar.open { animation-name: drawer-in-rtl; }
  @keyframes drawer-in-rtl { from { opacity: 0; translate: 12px 0; } }
  main { padding: .9rem .8rem calc(78px + env(safe-area-inset-bottom)); }

  .tabbar {
    position: fixed; inset-block-end: 0; inset-inline: 0; z-index: 46;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(12px); border-block-start: 1px solid var(--border);
    padding-block-end: env(safe-area-inset-bottom);
  }
  .tabbar-link {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: .45rem .2rem .35rem; color: var(--muted); font-size: .64rem; font-weight: 600;
    text-decoration: none; min-block-size: 52px; justify-content: center;
  }
  .tabbar-link:hover { text-decoration: none; }
  .tabbar-link .ic { font-size: 1.25rem; line-height: 1; }
  .tabbar-link .lbl { max-inline-size: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar-link.active { color: var(--primary); }
}

/* --------------------------------------------------------------- widgets */

.card {
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
}
.card + .card { margin-block-start: 1rem; }
.card-hover { transition: transform .15s ease, border-color .15s ease; }
.card-hover:hover { transform: translateY(-2px); border-color: var(--primary); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.center { text-align: center; }
.mt { margin-block-start: 1rem; } .mb { margin-block-end: 1rem; }
.hidden { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; transition: background .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
/* The accent is an outline, not a fill — this theme keeps every surface flat
   and lets the periwinkle border/text carry the emphasis instead. */
.btn-primary { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-soft); }
.btn-success { background: var(--success); border-color: var(--success); color: #05261a; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); background: var(--success); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, .12); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .32rem .62rem; font-size: .8rem; }
.btn-lg { padding: .8rem 1.5rem; font-size: 1rem; }
.btn-block { inline-size: 100%; }

input, select, textarea {
  inline-size: 100%; padding: .55rem .7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .92rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { min-block-size: 90px; resize: vertical; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-block-end: .3rem; }
.field { margin-block-end: .85rem; }

.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem;
  border-radius: 999px; font-size: .75rem; font-weight: 650;
  background: var(--surface-3); color: var(--muted);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: rgba(52, 211, 153, .16); color: var(--success); }
.badge-warning { background: rgba(251, 191, 36, .16); color: var(--warning); }
.badge-danger  { background: rgba(248, 113, 113, .16); color: var(--danger); }

/* Minimal taxonomy label — no fill, small tracked caps, used on course/class
   cards where a solid pill would compete with the stat badges next to it. */
.tag-label {
  font-size: .68rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--primary);
}

.progress { block-size: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; block-size: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; transition: inline-size .4s ease; }

.stat { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .v { font-size: 1.55rem; font-weight: 750; line-height: 1.15; }
.stat .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.avatar {
  inline-size: 34px; block-size: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-3); font-weight: 700; font-size: .82rem; flex: none; color: var(--text);
}
.avatar-lg { inline-size: 62px; block-size: 62px; font-size: 1.4rem; }

table { inline-size: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .6rem; text-align: start; border-block-end: 1px solid var(--border); }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

pre {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .8rem .9rem; overflow-x: auto; font-size: .85rem; line-height: 1.6; direction: ltr; text-align: start;
}
:not(pre) > code { background: var(--surface-3); padding: .1rem .35rem; border-radius: 5px; font-size: .88em; direction: ltr; display: inline-block; }
.code-editor {
  font-family: var(--mono); font-size: .88rem; line-height: 1.6; min-block-size: 190px;
  direction: ltr; text-align: start; tab-size: 2; white-space: pre; overflow-wrap: normal; overflow-x: auto;
}

/* CodeMirror replaces a .code-editor textarea in place — same footprint,
   real syntax highlighting. Falls back to the plain textarea above if the
   CDN script never loads, so nothing here is load-bearing. */
.CodeMirror {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: .88rem; line-height: 1.6;
  height: auto; min-block-size: 90px; direction: ltr; text-align: start;
}
.CodeMirror-scroll { min-height: 90px; }
.CodeMirror.cm-readonly { opacity: .92; }
.CodeMirror.cm-readonly .CodeMirror-cursor { display: none; }

/* --------------------------------------------------------------- quizzes */

.q-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-3); padding: 1.2rem; }
.q-prompt { font-size: 1.08rem; font-weight: 620; margin-block-end: .9rem; }
.opt {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .85rem; margin-block-end: .5rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  cursor: pointer; transition: border-color .12s ease, background .12s ease;
}
.opt:hover { border-color: var(--primary); }
.opt.selected { border-color: var(--primary); background: var(--primary-soft); }
.opt.correct { border-color: var(--success); background: rgba(52, 211, 153, .12); }
.opt.wrong { border-color: var(--danger); background: rgba(248, 113, 113, .1); }
.opt .key {
  inline-size: 25px; block-size: 25px; border-radius: 7px; display: grid; place-items: center; flex: none;
  background: var(--surface-3); font-weight: 700; font-size: .8rem;
}
.opt.selected .key { background: var(--primary); color: #fff; }

.chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .75rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: .87rem; font-weight: 550;
}
.chip.selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip[draggable="true"] { cursor: grab; }

.bucket {
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm); padding: .7rem;
  min-block-size: 82px; background: var(--surface-2);
}
.bucket.over { border-color: var(--primary); background: var(--primary-soft); transition: border-color .12s ease, background .12s ease; }
.bucket h4 { font-size: .85rem; margin-block-end: .5rem; color: var(--muted); }

.order-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; margin-block-end: .4rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: grab; transition: border-color .12s ease, background .12s ease, opacity .12s ease;
}
.order-item .idx { inline-size: 22px; color: var(--muted); font-weight: 700; font-size: .85rem; }
.order-item .drag-handle { color: var(--muted); cursor: grab; }
.order-item.dragging { opacity: .45; }
.order-item.drag-over { border-color: var(--primary); background: var(--primary-soft); }

.blank-input { inline-size: 130px; display: inline-block; padding: .2rem .45rem; margin: 0 .2rem; }
.cloze { font-family: var(--mono); font-size: .9rem; line-height: 2.4; white-space: pre-wrap; direction: ltr; text-align: start; }

.code-lines { counter-reset: ln; }
.code-line {
  display: flex; gap: .8rem; padding: .12rem .5rem; border-radius: 5px; cursor: pointer;
  font-family: var(--mono); font-size: .85rem; direction: ltr;
}
.code-line:hover { background: var(--surface-3); }
.code-line.selected { background: var(--danger); color: #fff; }
.code-line .n { color: var(--muted); inline-size: 22px; text-align: end; flex: none; }

.timer {
  font-variant-numeric: tabular-nums; font-weight: 750; font-size: 1.05rem;
  padding: .25rem .7rem; border-radius: 999px; background: var(--surface-3);
}
.timer.warn { background: rgba(251, 191, 36, .18); color: var(--warning); }
.timer.danger { background: rgba(248, 113, 113, .18); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.q-nav { display: flex; flex-wrap: wrap; gap: .3rem; }
.q-dot {
  inline-size: 30px; block-size: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-size: .8rem; font-weight: 650;
}
.q-dot.answered { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.q-dot.current { outline: 2px solid var(--accent); }

/* --------------------------------------------------------------- parties */

.party-hero {
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; color: var(--text); text-align: center;
}
.pin-display {
  font-family: var(--mono); font-size: 2.6rem; font-weight: 800; letter-spacing: .35em;
  padding: .6rem 1rem; background: var(--surface-2); color: var(--primary); border-radius: var(--radius);
  display: inline-block; direction: ltr;
}
.pin-input { font-family: var(--mono); font-size: 1.7rem; text-align: center; letter-spacing: .3em; text-transform: uppercase; direction: ltr; }
.player-tag {
  display: inline-flex; align-items: center; gap: .45rem; padding: .35rem .75rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: .87rem; font-weight: 600;
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.party-opt {
  padding: 1.4rem; border-radius: var(--radius); font-size: 1.05rem; font-weight: 650;
  color: #fff; cursor: pointer; border: none; text-align: start; transition: transform .12s ease;
}
.party-opt:hover { transform: scale(1.02); }
.party-opt:disabled { opacity: .45; cursor: not-allowed; }
.po-0 { background: #ef4444; } .po-1 { background: #3b82f6; }
.po-2 { background: #f59e0b; } .po-3 { background: #10b981; }
.po-4 { background: #8b5cf6; } .po-5 { background: #ec4899; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: .8rem; }
.podium-step { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; padding: .8rem; text-align: center; inline-size: 130px; }
.podium-1 { block-size: 150px; border-color: var(--warning); }
.podium-2 { block-size: 118px; }
.podium-3 { block-size: 95px; }

/* ------------------------------------------------------- misc components */

.toast-host { position: fixed; inset-block-end: 1.2rem; inset-inline-end: 1.2rem; z-index: 90; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-inline-start: 3px solid var(--primary);
  border-radius: var(--radius-sm); padding: .7rem 1rem; box-shadow: var(--shadow); max-inline-size: 330px;
  animation: slide .25s ease; font-size: .9rem;
}
.toast.success { border-inline-start-color: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
@keyframes slide { from { transform: translateY(12px); opacity: 0; } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 16, .68); z-index: 80;
  display: grid; place-items: center; padding: 1rem; backdrop-filter: blur(3px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  inline-size: min(660px, 100%); max-block-size: 88vh; overflow-y: auto; box-shadow: var(--shadow); padding: 1.3rem;
}

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; inset-block-start: calc(100% + 6px); inset-inline-end: 0; min-inline-size: 250px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .4rem; z-index: 50; max-block-size: 420px; overflow-y: auto;
}
.dropdown-item { display: block; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--text); font-size: .88rem; cursor: pointer; }
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-item.unread { background: var(--primary-soft); }

.dot-badge {
  position: absolute; inset-block-start: -3px; inset-inline-end: -3px; min-inline-size: 17px; block-size: 17px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700;
  display: grid; place-items: center; padding: 0 4px;
}

.spark { display: flex; align-items: flex-end; gap: 3px; block-size: 54px; }
.spark > i { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-block-size: 2px; opacity: .85; }
.spark > i:hover { background: var(--accent); }

.bar-row { display: grid; grid-template-columns: 120px 1fr 46px; gap: .6rem; align-items: center; margin-block-end: .45rem; font-size: .84rem; }
.bar { block-size: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; block-size: 100%; background: var(--primary); border-radius: 999px; }

.markdown h1, .markdown h2, .markdown h3 { margin-block: 1.3rem .6rem; }
.markdown ul, .markdown ol { padding-inline-start: 1.4rem; }
.markdown table { margin-block: 1rem; }
.markdown blockquote { border-inline-start: 3px solid var(--primary); margin: 0; padding-inline-start: 1rem; color: var(--muted); }

.tabs { display: flex; gap: .3rem; border-block-end: 1px solid var(--border); margin-block-end: 1.1rem; overflow-x: auto; }
.tab { padding: .55rem .9rem; border: none; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; border-block-end: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-block-end-color: var(--primary); }

.cert {
  border: 3px double var(--primary); border-radius: var(--radius); padding: 2.2rem; text-align: center;
  background: linear-gradient(160deg, var(--surface), var(--surface-3));
}

.empty-state { text-align: center; padding: 2.6rem 1rem; color: var(--muted); }
.empty-state .ic { font-size: 2.6rem; display: block; margin-block-end: .5rem; opacity: .55; }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius-sm); block-size: 70px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ------------------------------------------------ question media & images */

.q-media { margin: 0 0 1rem; }
.q-media img, .q-media video {
  inline-size: 100%; max-block-size: 340px; object-fit: contain;
  border-radius: var(--radius); background: var(--surface-3); display: block;
}
.q-media audio { inline-size: 100%; }
.q-media figcaption { font-size: .78rem; color: var(--muted); margin-block-start: .35rem; text-align: center; }

/* Image choice grid */
.img-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.img-tile {
  position: relative; padding: 0; border: 2px solid var(--border); background: var(--surface-2);
  border-radius: var(--radius); overflow: hidden; cursor: pointer; display: block;
  transition: border-color .15s ease, transform .1s ease;
}
.img-tile:hover { border-color: var(--primary); }
.img-tile.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.img-tile img { inline-size: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.img-tile-tick {
  position: absolute; inset-block-start: .4rem; inset-inline-start: .4rem;
  inline-size: 26px; block-size: 26px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0, 0, 0, .6); color: #fff; font-weight: 700; font-size: .8rem;
}
.img-tile.selected .img-tile-tick { background: var(--primary); }
.img-tile-label {
  display: block; padding: .4rem .5rem; font-size: .82rem; font-weight: 600;
  color: var(--text); text-align: start;
}

/* Clickable image canvas (hotspot / labelling) */
/* The click box must be exactly the image box: zone and pin coordinates are
   percentages of it. So the image fills the canvas width and sets its own
   height — capping the height instead would letterbox and shift the maths.
   An explicit width is also what gives a viewBox-only SVG a size at all. */
.img-canvas {
  position: relative; display: block; inline-size: 100%; max-inline-size: 560px;
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
  cursor: crosshair; touch-action: manipulation; line-height: 0;
}
.img-canvas img { inline-size: 100%; block-size: auto; display: block; }
.img-canvas.review { cursor: default; }
.img-pin {
  position: absolute; inline-size: 22px; block-size: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: var(--primary); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5); pointer-events: none;
}
.img-pin.ok { background: var(--success); }
.img-pin.bad { background: var(--danger); }
.img-zone {
  position: absolute; border: 2px dashed var(--success);
  background: rgba(52, 211, 153, .18); border-radius: 6px; pointer-events: none;
}
.img-marker {
  position: absolute; margin: -14px 0 0 -14px;
  inline-size: 28px; block-size: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); color: var(--text); border: 2px solid var(--primary);
  font-weight: 700; font-size: .8rem; cursor: pointer; line-height: 1;
}
.img-marker.done { background: var(--primary); color: #fff; }
.marker-row { gap: .5rem; margin: 0; }
.marker-num {
  inline-size: 26px; block-size: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--surface-3);
  font-weight: 700; font-size: .78rem;
}

/* Ordering images */
.img-order { display: grid; gap: .5rem; }
.img-order-item {
  display: flex; align-items: center; gap: .7rem; padding: .5rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.img-order-item img { inline-size: 84px; block-size: 60px; object-fit: cover; border-radius: 6px; flex: none; }
.img-order-rank {
  inline-size: 26px; block-size: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .78rem;
}
.img-order-caption { flex: 1; font-size: .88rem; }
.img-order-moves { display: flex; gap: .3rem; margin-inline-start: auto; }

/* Review: the picture the student picked, next to the expected one */
.review-thumbs { display: flex; gap: .6rem; flex-wrap: wrap; margin-block: .6rem; }
.review-thumb { margin: 0; inline-size: 128px; }
.review-thumb img {
  inline-size: 100%; aspect-ratio: 4 / 3; object-fit: cover;
  border-radius: var(--radius-sm); border: 2px solid var(--border); display: block;
}
.review-thumb.ok img { border-color: var(--success); }
.review-thumb.bad img { border-color: var(--danger); }
.review-thumb.want img { border-color: var(--success); border-style: dashed; }
.review-thumb figcaption { font-size: .74rem; color: var(--muted); text-align: center; margin-block-start: .25rem; }
.review-thumb.want figcaption::before { content: '✓ '; color: var(--success); }
.review-thumb.bad figcaption::before { content: '✕ '; color: var(--danger); }

.tt-cell { min-inline-size: 46px; font-family: var(--mono); font-weight: 700; }
.tt-cell.answered { border-color: var(--primary); color: var(--primary); }

/* A real two-sided card instead of a plain show/hide toggle. */
.flip-card { perspective: 1200px; cursor: pointer; margin-block-end: .5rem; }
.flip-card:focus-visible .flip-inner { outline: 2px solid var(--primary); outline-offset: 2px; }
.flip-inner {
  position: relative; min-block-size: 140px; transition: transform .5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-card-lg .flip-inner { min-block-size: 230px; }
.flip-front, .flip-back {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; background: var(--surface-2);
}
.flip-front .flip-icon { font-size: 2rem; margin-block-end: .4rem; }
.flip-back { transform: rotateY(180deg); background: var(--primary-soft); font-weight: 620; font-size: 1.1rem; }

/* --------------------------------------------------- question authoring */

.build-media summary { cursor: pointer; font-weight: 600; font-size: .88rem; padding: .3rem 0; }
.build-thumb {
  max-inline-size: 100%; max-block-size: 170px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); display: block;
}
.build-empty {
  padding: 1rem; text-align: center; color: var(--muted); font-size: .84rem;
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
}
.build-img-list { display: grid; gap: .45rem; }
.build-img-row {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .45rem; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.build-img-row.is-answer { border-color: var(--success); }
.build-img-row img { inline-size: 68px; block-size: 50px; object-fit: cover; border-radius: 5px; flex: none; }
.build-img-row input { flex: 1; min-inline-size: 120px; }
.build-canvas {
  position: relative; display: block; inline-size: 100%; max-inline-size: 460px; line-height: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; cursor: crosshair;
}
.build-canvas img { inline-size: 100%; block-size: auto; display: block; }
.build-zone {
  position: absolute; border: 2px solid var(--warning); background: rgba(251, 191, 36, .2);
  border-radius: 5px; color: var(--text); font-size: .7rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}
.build-zone.is-answer { border-color: var(--success); background: rgba(52, 211, 153, .25); }
.build-marker {
  position: absolute; margin: -13px 0 0 -13px; inline-size: 26px; block-size: 26px;
  border-radius: 50%; display: grid; place-items: center; background: var(--primary);
  color: #fff; font-weight: 700; font-size: .75rem; line-height: 1;
}

/* ----------------------------------------------------- join codes & rows */

.join-card { display: grid; gap: .8rem; border-color: var(--primary); }
.join-lead strong { font-size: 1rem; }
.join-controls { display: flex; gap: .5rem; }
.code-input {
  font-family: var(--mono); font-size: 1.25rem; letter-spacing: .28em; text-transform: uppercase;
  text-align: center; direction: ltr; flex: 1; min-inline-size: 0;
}
.code-card { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.code-value {
  font-family: var(--mono); font-size: 1.85rem; font-weight: 800; letter-spacing: .22em;
  color: var(--primary); direction: ltr; user-select: all; line-height: 1.2;
}
.search-input { inline-size: 100%; max-inline-size: 320px; }
.filters { align-items: stretch; }
.chips-scroll { display: flex; gap: .4rem; overflow-x: auto; padding-block-end: 2px; scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll .chip { white-space: nowrap; }

.user-row {
  display: flex; align-items: center; gap: .6rem; padding: .5rem 0;
  border-block-end: 1px solid var(--border); flex-wrap: wrap;
}
.role-select { inline-size: auto; min-inline-size: 118px; }
.course-row { padding: .55rem 0; border-block-end: 1px solid var(--border); color: inherit; }
.course-row:hover { text-decoration: none; background: var(--surface-2); }
.dot-color { inline-size: 9px; block-size: 30px; border-radius: 5px; flex: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-actions { min-inline-size: 190px; }
.chat-log { max-block-size: 340px; overflow-y: auto; }

/* --------------------------------------------------------- live classroom */

.live-invite { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.live { display: grid; gap: .6rem; }
.live-stage {
  display: grid; grid-template-columns: 1fr; gap: .5rem;
  background: #000; border-radius: var(--radius); overflow: hidden;
  min-block-size: 200px; max-block-size: min(52vh, 440px);
}
.live-stage .live-tile.big { block-size: 100%; aspect-ratio: auto; }
.live-stage .live-avatar { inline-size: 84px; block-size: 84px; font-size: 1.7rem; }
.live-stage.multi { grid-template-columns: repeat(2, 1fr); }
.live-placeholder { display: grid; place-items: center; color: var(--muted); padding: 2.4rem 1rem; font-size: .9rem; }

.live-strip {
  display: flex; gap: .45rem; overflow-x: auto; padding-block-end: 3px; scrollbar-width: thin;
}
.live-strip .live-tile { flex: 0 0 132px; }

.live-tile {
  position: relative; background: var(--surface-3); border-radius: var(--radius-sm);
  overflow: hidden; aspect-ratio: 16 / 10; display: grid; place-items: center;
}
.live-tile.big { aspect-ratio: 16 / 9; border-radius: 0; background: #000; }
.live-tile.hand { outline: 2px solid var(--warning); outline-offset: -2px; }
.live-tile video { inline-size: 100%; block-size: 100%; object-fit: cover; display: block; background: #000; }
.live-avatar {
  inline-size: 54px; block-size: 54px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 1.15rem;
}
.live-name {
  position: absolute; inset-block-end: 0; inset-inline: 0; padding: .25rem .5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78)); color: #fff;
  font-size: .72rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.live-bar {
  display: flex; align-items: center; gap: .45rem; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .4rem .6rem;
}
.live-btn {
  inline-size: 42px; block-size: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer;
  display: grid; place-items: center; transition: background .15s ease, transform .1s ease;
}
.live-btn:hover { transform: scale(1.06); }
.live-btn.on { background: var(--primary); border-color: var(--primary); }
.live-btn.off { background: var(--surface-3); opacity: .75; }
.live-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; margin-inline-start: auto; }
.live-count { font-size: .82rem; color: var(--muted); padding-inline: .4rem; }

.live-host summary { cursor: pointer; font-weight: 600; font-size: .9rem; padding: .5rem 0; }
.live-host-list { display: grid; gap: .3rem; }
.live-host-row {
  display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem;
  background: var(--surface-2); border-radius: var(--radius-sm); margin: 0; font-weight: 500;
}
.live-host-row input[type="checkbox"] { inline-size: auto; margin: 0; }
.live-host-row > span:first-of-type { flex: 1; }

/* ----------------------------------------------------------- phone tuning */

@media (max-width: 700px) {
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.12rem; }
  body { font-size: 14.5px; }

  /* Keep the top bar to one row: icons only, no wordy labels. */
  .topbar { padding: .5rem .6rem; gap: .3rem; }
  .topbar .brand { font-size: .95rem; }
  .lang-label, .user-name { display: none; }
  .topbar .btn-sm { padding: .35rem .5rem; min-block-size: 36px; }

  .card { padding: .85rem; border-radius: 12px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: .55rem; }
  .stat { padding: .7rem .75rem; }
  .stat .v { font-size: 1.25rem; }
  .stat .k { font-size: .68rem; }

  .between { gap: .6rem; }
  .course-actions { min-inline-size: 100%; }
  .search-input { max-inline-size: 100%; }

  /* Comfortable thumb targets everywhere. */
  .btn { padding: .6rem 1rem; min-block-size: 42px; }
  .btn-sm { padding: .4rem .7rem; min-block-size: 34px; }
  input, select, textarea { font-size: 16px; }   /* stops iOS zoom-on-focus */

  .tabs { gap: 0; }
  .tab { padding: .6rem .7rem; font-size: .85rem; }

  .q-card { padding: .9rem; }
  .q-prompt { font-size: 1rem; }
  .opt { padding: .75rem; }
  .q-dot { inline-size: 34px; block-size: 34px; }
  .party-opt { padding: 1rem; font-size: .95rem; }
  .pin-display { font-size: 1.8rem; letter-spacing: .22em; }
  .code-value { font-size: 1.5rem; }

  .live-stage.multi { grid-template-columns: 1fr; }
  .live-strip .live-tile { flex-basis: 108px; }
  .live-bar { justify-content: center; border-radius: var(--radius); }
  .live-btn { inline-size: 46px; block-size: 46px; }
  .live-btn.danger { margin-inline-start: 0; }

  .img-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .5rem; }
  .img-order-item img { inline-size: 64px; block-size: 48px; }
  .build-img-row img { inline-size: 54px; block-size: 40px; }
  .q-media img, .q-media video { max-block-size: 240px; }

  .modal { padding: 1rem; max-block-size: 92vh; }
  .toast-host { inset-inline: .6rem; inset-block-end: calc(72px + env(safe-area-inset-bottom)); }
  .toast { max-inline-size: 100%; }
  .dropdown-menu { position: fixed; inset-inline: .6rem; inset-block-start: 54px; min-inline-size: 0; }
  .podium-step { inline-size: 96px; }
  table { font-size: .82rem; }
  th, td { padding: .45rem .4rem; }
}

@media (max-width: 380px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .tabbar-link .lbl { font-size: .58rem; }
}

/* Arabic reads right-to-left, but code and PINs must stay left-to-right. */
html[dir="rtl"] pre, html[dir="rtl"] .code-editor, html[dir="rtl"] .cloze,
html[dir="rtl"] .pin-display, html[dir="rtl"] .pin-input, html[dir="rtl"] .code-line,
html[dir="rtl"] .code-input, html[dir="rtl"] .code-value, html[dir="rtl"] .CodeMirror { direction: ltr; text-align: center; }
html[dir="rtl"] pre, html[dir="rtl"] .code-editor, html[dir="rtl"] .code-line, html[dir="rtl"] .CodeMirror { text-align: start; }
html[dir="rtl"] .spark { flex-direction: row-reverse; }
