/* Persian glyphs come from the bundled Vazirmatn subset; the unicode range keeps
   it from loading at all on an English page. */
@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #e4e4df;
  --accent: #2557d6;
  --accent-soft: #e8eefc;
  --on-accent: #ffffff;
  --ok: #1f8a4c;
  --ok-soft: #e3f3e9;
  --disabled: #c4c4be;
  --video-bg: #111111;
  --radius: 14px;
  --radius-sm: 10px;
  --gutter: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1d1d1c;
    --text: #ececea;
    --muted: #9d9d97;
    --line: #2e2e2c;
    --accent: #7ea2ff;
    --accent-soft: #1f2a44;
    --on-accent: #0b1430;
    --ok: #5cc98a;
    --ok-soft: #173023;
    --disabled: #4a4a47;
    --video-bg: #000000;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Vazirmatn", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html[lang="fa"] body {
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  line-height: 1.85;
}

[hidden] { display: none !important; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* ---- top bar ---------------------------------------------------------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(1320px + 2 * var(--gutter));
  margin: 0 auto;
  padding: 10px var(--gutter);
  padding-top: max(10px, env(safe-area-inset-top));
}
.title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.count {
  margin-inline-start: auto;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.languages { display: flex; gap: 4px; flex: none; }
.count[hidden] + .languages { margin-inline-start: auto; }
.languages button {
  min-height: 34px;
  padding: 4px 12px;
  font-size: 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.languages button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

.meter { height: 3px; background: var(--line); }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s ease; }

/* ---- shared ----------------------------------------------------------------- */

main { padding: 20px var(--gutter) calc(40px + env(safe-area-inset-bottom)); }

.page {
  max-width: 640px;
  margin: 8px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.page h1 { font-size: 24px; line-height: 1.3; margin: 0 0 12px; font-weight: 700; }
.page h2 { font-size: 16px; margin: 28px 0 10px; }
.page.center { text-align: center; }
.lead { margin: 0 0 8px; }
.muted, .note { color: var(--muted); }
.note { font-size: 14px; }

#loading { border: 0; background: none; box-shadow: none; display: grid; place-items: center; min-height: 40vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 28px; }
.page.center .actions { justify-content: center; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.primary, .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 24px;
  border-radius: 999px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.primary { background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); min-width: 160px; }
.primary:active:not(:disabled) { transform: scale(0.98); }
.primary:disabled { background: var(--line); border-color: var(--line); color: var(--disabled); cursor: not-allowed; }
.ghost { background: var(--surface); border: 1px solid var(--line); color: var(--text); min-height: 40px; padding: 8px 16px; }
.ghost svg { font-size: 14px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); font-size: 14px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* consent */
.agree {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.agree:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.agree input { width: 20px; height: 20px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }

/* instructions */
.how { list-style: none; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.how li {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 14px 8px; border-radius: var(--radius-sm); background: var(--bg); font-size: 14px; line-height: 1.4;
}
.how-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 20px; }
.criteria { margin: 0; padding: 0; list-style: none; counter-reset: q; }
.criteria li { counter-increment: q; display: grid; grid-template-columns: 28px 1fr; gap: 0 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.criteria li::before {
  content: counter(q); grid-row: span 2; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--muted); margin-top: 2px;
}
html[lang="fa"] .criteria li::before { content: counter(q, persian); }
.criteria b { font-weight: 600; }
.criteria span { color: var(--muted); font-size: 15px; }

/* background */
.background fieldset { border: 0; margin: 0; padding: 18px 0 0; min-width: 0; }
.background legend { font-weight: 600; padding: 0; margin-bottom: 10px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: inline-flex; align-items: center; min-height: 42px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 15px; background: var(--surface);
}
.pill input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* break / done */
.badge-icon {
  width: 56px; height: 56px; margin: 4px auto 16px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; background: var(--accent-soft); color: var(--accent);
}
.badge-icon.ok { background: var(--ok-soft); color: var(--ok); }
.code-box {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 12px;
  margin-top: 20px; padding: 18px; border: 1px dashed var(--line); border-radius: var(--radius-sm);
}
.code { font-size: 28px; font-weight: 700; letter-spacing: 0.14em; font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---- video screen ----------------------------------------------------------- */

.screen { max-width: 1320px; margin: 0 auto; display: grid; gap: 16px; }

.instruction {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}
.eyebrow { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
html[lang="fa"] .eyebrow { text-transform: none; letter-spacing: 0; font-size: 13px; }
.instruction-text { margin: 4px 0 0; font-size: 18px; line-height: 1.5; font-weight: 500; }
html[lang="fa"] .instruction-text { line-height: 1.9; }
.instruction-text.clamped { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.instruction .note { margin: 6px 0 0; font-size: 13px; }

.viewer { display: grid; gap: 10px; }

/* Wide screens: the three videos side by side, tabs unused. */
.tabs { display: none; }
.videos { display: grid; grid-template-columns: repeat(var(--count, 3), minmax(0, 1fr)); gap: 14px; }
.video { margin: 0; min-width: 0; }
.video-frame { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--video-bg); }
.video video { display: block; width: 100%; aspect-ratio: 16 / 9; background: var(--video-bg); }
.video figcaption { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.letter {
  flex: none; display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: 999px; font-weight: 700; font-size: 15px; background: var(--surface); border: 1px solid var(--line);
}
.watch { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.track { flex: 1; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear; }
.watch-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.video.ended .track i { background: var(--ok); width: 100% !important; }
.video.ended .watch-label { color: var(--ok); font-weight: 600; }
.video.ended .letter { border-color: var(--ok); color: var(--ok); }

.viewer-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }

/* the question panel */
.ask {
  scroll-margin: 72px 0 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.locked { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.locked .badge-icon { margin: 0; width: 44px; height: 44px; font-size: 20px; flex: none; background: var(--bg); color: var(--muted); }
.locked p { margin: 0; }

.ask-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step {
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: grid; place-items: center;
}
.step.answered { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.step.current { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.step-count { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.question-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-top: 6px; }
html[lang="fa"] .question-label { text-transform: none; letter-spacing: 0; font-size: 13px; }
.question-text { margin: 4px 0 16px; font-size: 19px; line-height: 1.45; font-weight: 600; }
html[lang="fa"] .question-text { line-height: 1.8; }
.definition { margin: -8px 0 16px; font-size: 14px; color: var(--muted); }

.choices { display: grid; grid-template-columns: repeat(var(--count, 3), minmax(0, 1fr)); gap: 14px; }
.choice {
  min-height: 56px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 18px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}
.choice small { font-size: 14px; font-weight: 500; color: var(--muted); }
.choice:hover { border-color: var(--accent); }
.choice:active { transform: scale(0.98); }
.choice[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.choice[aria-checked="true"] small { color: inherit; opacity: 0.85; }

.ask-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.ask-nav .forward { margin-inline-start: auto; }

.review { list-style: none; margin: 0 0 4px; padding: 0; }
.review li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.review li:first-child { border-top: 0; }
.review .label { flex: 1; min-width: 0; }
.review button {
  min-width: 44px; height: 36px; padding: 0 10px; border-radius: 999px; font-weight: 700;
  border: 0; background: var(--accent-soft); color: var(--accent);
}
.review-title { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 0 0 8px; }
.review-title .badge-icon { margin: 0; width: 28px; height: 28px; font-size: 15px; }
.submit-row { display: flex; justify-content: flex-end; margin-top: 16px; }

.fade-in { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- phones and narrow windows ---------------------------------------------- */
/* One video at a time behind letter tabs: three stacked players push the
   questions off the screen. */
@media (max-width: 899px) {
  main { padding-top: 12px; }
  .page { padding: 22px 18px; border-radius: 12px; }
  .page h1 { font-size: 21px; }
  .actions .primary { flex: 1; }
  .how li { padding: 12px 4px; font-size: 13px; }

  .screen { gap: 12px; }
  .instruction { padding: 12px 14px; }
  .instruction-text { font-size: 16px; }

  .tabs { display: grid; grid-template-columns: repeat(var(--count, 3), minmax(0, 1fr)); gap: 6px; padding: 4px; background: var(--line); border-radius: 12px; }
  .tab {
    min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted);
    display: flex; align-items: center; justify-content: center; gap: 6px;
  }
  .tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
  .tab .tick { color: var(--ok); font-size: 15px; }
  .videos { display: block; }
  .video:not(.active) { display: none; }
  .video figcaption .letter { display: none; }

  .viewer-bar .ghost { flex: none; }
  .ask { padding: 16px 14px; }
  .steps { gap: 4px; flex-wrap: nowrap; }
  .step { min-width: 28px; height: 28px; padding: 0 4px; }
  .step-count { display: none; }
  .question-text { font-size: 17px; }
  .choices { gap: 8px; }
  .choice { min-height: 56px; }
  .submit-row .primary { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- admin ------------------------------------------------------------------ */

.admin .bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line);
}
.admin .bar h1 { margin: 0; font-size: 17px; }
.admin .progress { color: var(--muted); font-size: 14px; }
.admin main { max-width: 1320px; margin: 0 auto; }
.admin .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.admin .panel h2 { margin-top: 0; font-size: 17px; }
.admin .narrow { max-width: 640px; margin: 24px auto; }
.admin table { border-collapse: collapse; width: 100%; font-size: 14px; }
.admin th, .admin td { text-align: start; padding: 5px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.admin .grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.admin .stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.admin .stat b { display: block; font-size: 28px; }
.admin .scroll { overflow-x: auto; }
@media (max-width: 900px) { .admin .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
