/* Pulses Datasets. Tokens from the Pulses design system (colors_and_type.css). */
@font-face {
  font-family: "Exo 2";
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/Exo2-VariableFont_wght.ttf") format("truetype");
}
@font-face {
  font-family: "Noto Kufi Arabic";
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/noto-kufi-arabic-arabic-wght-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E;
}

:root {
  --blue: #2863DA;
  --blue-dark: #1f55c2;
  --navy: #00204C;
  --sky: #82BBFF;
  --silver: #F1F5F8;
  --ice: #EBEFFA;
  --ink: #030303;
  --muted: #6D6D6D;
  --border: #EAEAEA;
  --danger: #C62828;
  --ok: #1B7F4A;
  --rec: #E5383B;
  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(0, 32, 76, 0.10);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --sans: "Exo 2", "Noto Kufi Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  --arabic: "Noto Kufi Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --mono: Menlo, "SF Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--silver);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }
code { font-family: var(--mono); font-size: 0.9em; }
h1, h2 { line-height: 1.15; margin: 0 0 12px; color: var(--navy); }
h1 { font-size: 30px; font-weight: 600; }
h2 { font-size: 20px; font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
[dir="rtl"], .ar, .ar-cell { font-family: var(--arabic); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 12px; color: var(--blue); font-weight: 600; margin: 0 0 6px; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: #fff; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); font-weight: 600; font-size: 18px; }
.brand span { border-left: 1px solid var(--border); padding-left: 10px; }
.topnav { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topnav form { margin: 0; }
.who { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flash { background: var(--navy); color: #fff; padding: 10px 24px; font-size: 14px; }

.container { max-width: 1180px; margin: 0 auto; padding: 28px 16px 64px; }
.page-title { margin: 8px 0 20px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

/* Cards */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card.narrow { max-width: 480px; margin: 40px auto; }
.card.wide-ish { max-width: 720px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-bottom: 20px; }
.grid .card { margin: 0; }
.ds-card { display: flex; flex-direction: column; }
.ds-card .actions { margin-top: auto; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--navy); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
input, textarea, select {
  font: inherit; font-weight: 400; color: var(--ink);
  border: 1px solid #C1D8E6; border-radius: var(--radius-sm); padding: 10px 12px; background: #fff;
}
input:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(40, 99, 218, 0.35); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--blue); }
.code-input { font-family: var(--mono); font-size: 28px; letter-spacing: 0.4em; text-align: center; }
.copy-field { width: 100%; font-family: var(--mono); font-size: 13px; margin: 12px 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  border: 1px solid var(--blue); background: var(--blue); color: #fff;
  border-radius: 999px; padding: 10px 20px; transition: background 120ms var(--ease), transform 120ms var(--ease);
}
.btn:hover { background: var(--blue-dark); }
.btn:active { transform: scale(0.98); }
.btn.ghost { background: #fff; color: var(--blue); }
.btn.ghost:hover { background: var(--ice); }
.btn.big { font-size: 18px; padding: 14px 28px; min-height: 56px; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; }
.linkish.danger { color: var(--danger); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.inactive td { opacity: 0.45; }
.ar-cell { font-size: 17px; text-align: right; }
.chip { display: inline-flex; gap: 4px; align-items: center; background: var(--ice); border-radius: 999px; padding: 2px 10px; margin: 2px; font-size: 13px; }
.danger-zone summary { cursor: pointer; color: var(--danger); margin-top: 6px; }
.danger-zone .stack { margin-top: 8px; gap: 8px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid #C1D8E6; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--navy); border-bottom-color: var(--blue); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: var(--radius-sm); padding: 16px; box-shadow: 0 1px 2px rgba(0, 32, 76, 0.06); }
.stat .v { display: block; font-size: 30px; font-weight: 300; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }

/* Video grid */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.video-card { margin: 0; background: #fff; border-radius: var(--radius-sm); overflow: hidden; box-shadow: 0 1px 2px rgba(0, 32, 76, 0.06); border: 1px solid var(--border); }
.video-card video { width: 100%; aspect-ratio: 16 / 9; background: var(--navy); display: block; object-fit: contain; }
.video-card figcaption { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.video-card.rejected { opacity: 0.5; border-color: var(--danger); }
.gloss-ar { font-size: 48px; }
.consent-text { white-space: pre-wrap; background: var(--silver); border-radius: var(--radius-sm); padding: 16px; margin: 16px 0; font-size: 15px; line-height: 1.8; max-height: 50vh; overflow: auto; }

/* ---------------- Recorder ---------------- */
.rec-body { background: var(--navy); }
.rec-body .topbar { background: var(--navy); border-color: rgba(255, 255, 255, 0.1); }
.rec-body .brand, .rec-body .who { color: #fff; }
.rec-body .brand img { filter: brightness(0) invert(1); }
.rec-body .topnav .linkish, .rec-body .topnav a { color: var(--sky); }
.rec-main { max-width: 920px; margin: 0 auto; padding: 16px 16px 40px; color: #fff; }

.rec-progress { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--sky); margin-bottom: 14px; }
.bar { flex: 1; height: 6px; background: rgba(255, 255, 255, 0.12); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--sky); transition: width 240ms var(--ease); }

.prompt-card { background: #fff; color: var(--navy); border-radius: var(--radius); text-align: center; padding: 14px 16px 18px; margin-bottom: 14px; }
.prompt-card .eyebrow { margin-bottom: 0; }
.prompt-word { font-family: var(--arabic); font-weight: 700; font-size: clamp(44px, 9vw, 104px); line-height: 1.35; min-height: 1.35em; word-break: break-word; }
.recorder[data-state="loading"] .prompt-word { opacity: 0.25; }
.prompt-signs { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.prompt-signs span { font-family: var(--arabic); font-size: 15px; color: var(--navy); background: var(--ice); border-radius: 999px; padding: 3px 12px; }
.prompt-signs span + span::before { content: none; }
.sentence-label, .recorder.is-sentence .word-label { display: none; }
.recorder.is-sentence .sentence-label { display: block; }
.recorder.is-sentence .prompt-word { font-size: clamp(28px, 5vw, 56px); line-height: 1.6; padding: 8px 0; }

.stage { position: relative; aspect-ratio: 16 / 9; width: min(100%, calc(52vh * 16 / 9)); margin: 0 auto; background: #000; border-radius: var(--radius); overflow: hidden; border: 4px solid transparent; transition: border-color 160ms var(--ease); }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mirror { transform: scaleX(-1); }
#review { display: none; object-fit: contain; background: #000; }
.recorder[data-state="review"] #review, .recorder[data-state="uploading"] #review { display: block; }
.recorder[data-state="recording"] .stage { border-color: var(--rec); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: rgba(229, 56, 59, 0.45); } }

.rec-dot { position: absolute; top: 14px; left: 14px; display: none; align-items: center; gap: 6px; background: var(--rec); color: #fff; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; letter-spacing: 0.1em; }
.recorder[data-state="recording"] .rec-dot { display: inline-flex; }
.rec-timer { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; background: rgba(0, 0, 0, 0.35); display: none; }
.rec-timer span { display: block; height: 100%; width: 0; background: var(--rec); }
.recorder[data-state="recording"] .rec-timer { display: block; }

.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 160px; font-weight: 700; color: #fff; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5); pointer-events: none; }
.countdown.tick { animation: tick 700ms var(--ease); }
@keyframes tick { from { transform: scale(1.4); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); opacity: 0.9; } }

.overlay { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; background: var(--navy); }
.overlay h2 { color: #fff; font-size: 32px; }
.overlay p { max-width: 520px; margin: 0; color: #DFE7F5; }
.overlay .error { color: #FFB4B4; }

.controls { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 16px; min-height: 96px; }
.controls .btn { min-width: 240px; }
.btn.rec { background: #fff; color: var(--rec); border-color: #fff; }
.btn.rec:hover { background: #FFECEC; }
.btn.rec .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--rec); }
.btn.stop { background: var(--rec); border-color: var(--rec); }
.btn.stop .square { width: 16px; height: 16px; border-radius: 3px; background: #fff; }
.review-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.review-actions .btn { min-width: 180px; }
.uploading { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 8px; align-items: center; color: var(--sky); }
.uploading .bar { width: 100%; flex: none; }
.controls .linkish { color: var(--sky); }
.controls .error { color: #FFB4B4; text-align: center; max-width: 620px; }
.hint { text-align: center; color: #9FB3D1; }
kbd { font-family: var(--mono); background: rgba(255, 255, 255, 0.12); border-radius: 4px; padding: 1px 6px; }

.black-warning { position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%); background: rgba(0, 32, 76, 0.92); color: #fff; border: 2px solid #FFB4B4; border-radius: var(--radius-sm); padding: 16px; display: flex; flex-direction: column; gap: 6px; text-align: center; font-size: 15px; }
.black-warning[hidden] { display: none; }
.black-warning b { font-family: var(--arabic); font-size: 18px; }
.camera-pick { display: none; flex-direction: row; align-items: center; gap: 8px; color: var(--sky); font-weight: 400; font-size: 13px; }
.camera-pick select { background: var(--navy); color: #fff; border-color: rgba(130, 187, 255, 0.4); padding: 6px 10px; max-width: 280px; font-size: 13px; }
.recorder.multi-camera[data-state="ready"] .camera-pick,
.recorder.multi-camera[data-state="review"] .camera-pick,
.recorder.camera-black[data-state="ready"] .camera-pick { display: inline-flex; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* state visibility */
.ready-only, .recording-only, .review-only, .uploading-only { display: none !important; }
.recorder[data-state="ready"] .ready-only { display: inline-flex !important; }
.recorder[data-state="recording"] .recording-only { display: inline-flex !important; }
.recorder[data-state="review"] .review-only { display: flex !important; }
.recorder[data-state="uploading"] .uploading-only { display: flex !important; }
.recorder[data-state="intro"] .intro-only,
.recorder[data-state="done"] .done-only,
.recorder[data-state="closed"] .closed-only { display: flex; }
.recorder[data-state="countdown"] .controls { visibility: hidden; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .who { display: none; }
  .brand span { display: none; }
  .card { padding: 18px; }
  .stage { aspect-ratio: 3 / 4; width: min(100%, calc(50vh * 3 / 4)); }
  .controls .btn { min-width: 0; width: 100%; }
  .review-actions { width: 100%; }
  .review-actions .btn { flex: 1; min-width: 0; }
  .hint { display: none; }
  .table { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
