/* ============================================================
   جلسة — Games V2 Design System (Phase 1 foundations)
   Tokens are namespaced --jz- so they can coexist with the
   legacy :root tokens in styles.css while components migrate.
   ============================================================ */
:root {
  /* Neutral night foundation; game accents carry the color. */
  --jz-ink: #090b0e;
  --jz-surface-1: #14171b;
  --jz-surface-2: #1c2025;
  --jz-line: rgba(255, 255, 255, .1);
  --jz-line-strong: rgba(255, 255, 255, .24);
  --jz-text: #ffffff;
  --jz-text-2: #aaa4c8;
  --jz-text-3: #87809f;
  --jz-purple: #7c3aed;
  --jz-pink: #f0469a;
  --jz-teal: #16d6b8;
  --jz-gold: #fbb034;
  --jz-coral: #ff6b5f;
  --jz-sky: #53b4ff;
  --jz-danger: #ff5470;

  /* Typography — TV-first clamp scale, Arabic line-height */
  --jz-font-display: Tajawal, Cairo, sans-serif;
  --jz-font-body: Cairo, sans-serif;
  --jz-fs-hero: 64px;
  --jz-fs-title: 40px;
  --jz-fs-section: 24px;
  --jz-fs-body: 16px;
  --jz-fs-note: 13px;
  --jz-lh-arabic: 1.8;

  /* Spacing — 4px base */
  --jz-s-1: 4px;
  --jz-s-2: 8px;
  --jz-s-3: 12px;
  --jz-s-4: 16px;
  --jz-s-5: 20px;
  --jz-s-6: 24px;
  --jz-s-7: 32px;
  --jz-s-8: 40px;
  --jz-s-9: 56px;

  /* Radii */
  --jz-r-s: 6px;
  --jz-r-m: 8px;
  --jz-r-l: 8px;
  --jz-r-xl: 8px;

  /* Elevation */
  --jz-shadow-1: 0 10px 30px rgba(0, 0, 0, .25);
  --jz-shadow-2: 0 24px 70px rgba(0, 0, 0, .42);

  /* Motion */
  --jz-t-fast: 120ms;
  --jz-t-base: 220ms;
  --jz-t-slow: 340ms;
  --jz-ease: cubic-bezier(.2, .7, .3, 1);

  /* Focus + touch */
  --jz-focus-ring: 3px solid var(--jz-gold);
  --jz-focus-offset: 4px;
  --jz-touch-min: 48px;

  /* Layers */
  --jz-z-dock: 40;
  --jz-z-modal: 60;
}

body {
  background: var(--jz-ink);
}

body::before {
  background:
    linear-gradient(120deg, rgba(22, 214, 184, .055), transparent 34%),
    linear-gradient(300deg, rgba(251, 176, 52, .045), transparent 40%);
}

body::after {
  opacity: .12;
  background-image:
    linear-gradient(rgba(255, 255, 255, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .08) 1px, transparent 1px);
  background-size: 64px 64px;
}

/* Screen-reader-only utility (announcers, hidden labels) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Small labelled icon command (e.g. reset progress) */
.icon-command {
  display: inline-flex;
  align-items: center;
  gap: var(--jz-s-2);
  min-height: var(--jz-touch-min);
  padding: 0 var(--jz-s-4);
  border: 1px solid var(--jz-line);
  border-radius: var(--jz-r-s);
  background: rgba(255, 255, 255, .05);
  color: var(--jz-text-2);
  font-weight: 800;
  font-size: var(--jz-fs-note);
  cursor: pointer;
  transition: border-color var(--jz-t-fast) var(--jz-ease), color var(--jz-t-fast) var(--jz-ease);
}
.icon-command:hover,
.icon-command:focus-visible { border-color: var(--jz-line-strong); color: var(--jz-text); }
.icon-command:focus-visible { outline: var(--jz-focus-ring); outline-offset: var(--jz-focus-offset); }
.icon-command.is-armed { border-color: rgba(255, 84, 112, .5); color: #ff9aae; }

/* Wave 3: active Host/TV screens own one viewport and never rely on page scroll.
   Two-layer lock: `:has()` for modern engines + `html.jz-host-locked` fallback
   toggled by settings-selection.js observer for older TV browsers. */
html.jz-host-locked,
html.jz-host-locked body,
html.jz-host-locked #app,
body:has(.jz-host-active),
body:has(.jz-host-active) #app {
  overflow: hidden !important;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
}
html.jz-host-locked #app,
body:has(.jz-host-active) #app {
  visibility: hidden;
}
.jz-host-active {
  overflow: hidden !important;
  overscroll-behavior: none;
}
.jz-host-active .live-shell,
.jz-host-active .barra-shell,
.jz-host-active .wassif-shell,
.jz-host-active .ng-shell {
  height: 100dvh;
  min-height: 0;
  padding-block: clamp(8px, 1.6vh, 18px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
.jz-host-active .live-top,
.jz-host-active .barra-top,
.jz-host-active .wassif-top,
.jz-host-active .ng-top {
  min-height: 56px;
  margin-bottom: clamp(6px, 1.2vh, 14px);
}
.jz-host-active [data-live-host],
.jz-host-active [data-barra-host],
.jz-host-active [data-wassif-host],
.jz-host-active [data-host] { min-height: 0; overflow: hidden; }
.jz-host-active .live-question,
.jz-host-active .barra-stage,
.jz-host-active .wassif-stage,
.jz-host-active .ng-stage {
  width: min(1180px, 100%);
  height: 100%;
  min-height: 0;
  margin: 0 auto;
}
.jz-host-active .live-question,
.jz-host-active .barra-stage > .barra-card,
.jz-host-active .wassif-stage > .wassif-card,
.jz-host-active .ng-stage > .ng-card {
  height: 100%;
  min-height: 0;
  padding: clamp(12px, 2vh, 22px);
  overflow: hidden;
}
.jz-host-active .live-timer,
.jz-host-active .barra-timer,
.jz-host-active .wassif-timer,
.jz-host-active .ng-timer {
  width: clamp(68px, 10vh, 88px);
  height: clamp(68px, 10vh, 88px);
  margin-bottom: clamp(6px, 1vh, 12px);
  font-size: clamp(26px, 4vh, 32px);
}
.jz-host-active .ng-icon,
.jz-host-active .barra-role-icon,
.jz-host-active .wassif-role-icon { font-size: clamp(32px, 6vh, 56px); }
.jz-host-active .ng-board,
.jz-host-active .ng-scores,
.jz-host-active .live-scoreboard,
.jz-host-active .barra-scoreboard,
.jz-host-active .wassif-scoreboard {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: clamp(5px, .8vh, 9px);
}
.jz-host-active .ng-player,
.jz-host-active .ng-score,
.jz-host-active .live-score,
.jz-host-active .barra-score,
.jz-host-active .wassif-score { padding-block: clamp(6px, 1vh, 11px); }

/* Canonical single-select option. The check marker keeps selection non-color-only. */
.jz-setting-options { display: flex; flex-wrap: wrap; gap: 8px; }
.jz-setting-option {
  position: relative;
  min-width: 52px;
  min-height: 48px;
  padding: 9px 38px 9px 14px;
  border: 1px solid var(--jz-line-strong);
  border-radius: var(--jz-r-m);
  background: var(--jz-surface-2);
  color: var(--jz-text);
  font-weight: 800;
  cursor: pointer;
}
.jz-setting-option::after {
  content: '✓';
  position: absolute;
  inset-inline-start: 12px;
  top: 50%;
  width: 20px;
  height: 20px;
  border: 1px solid var(--jz-line-strong);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: transparent;
  transform: translateY(-50%);
}
.jz-setting-option:hover { border-color: rgba(255,255,255,.45); background: rgba(255,255,255,.1); }
.jz-setting-option:focus-visible { outline: var(--jz-focus-ring); outline-offset: 3px; }
.jz-setting-option.is-selected,
.jz-setting-option[aria-pressed="true"] {
  border-width: 2px;
  border-color: var(--jz-teal);
  background: rgba(22,214,184,.14);
  box-shadow: var(--jz-shadow-1);
}
.jz-setting-option.is-selected::after,
.jz-setting-option[aria-pressed="true"]::after {
  border-color: var(--jz-teal);
  background: var(--jz-teal);
  color: #06110f;
}
.jz-setting-option:disabled,
.jz-setting-option[aria-disabled="true"] { opacity: .45; cursor: not-allowed; box-shadow: none; }

@media (max-height: 800px) {
  .jz-host-active .live-title,
  .jz-host-active .barra-title,
  .jz-host-active .wassif-title,
  .jz-host-active .ng-title { font-size: clamp(26px, 4vh, 34px); }
  .jz-host-active h2 { margin-block: 6px; }
  .jz-host-active .ng-muted { line-height: 1.45; }
  .jz-host-active .ng-actions,
  .jz-host-active .live-actions,
  .jz-host-active .barra-actions,
  .jz-host-active .wassif-actions { margin-top: 8px; }
  .jz-host-active .ng-card[data-action-panel] { margin-top: 8px !important; padding: 10px; }
}

/* Per-stage composition built from the shared viewport contract. */
.jz-host-active [data-live-game] { height: 100%; min-height: 0; }
.jz-host-active .live-question {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 18px;
}
.jz-host-active .live-question .live-timer { grid-column: 2; grid-row: 1 / span 3; }
.jz-host-active .live-question [data-live-question-team],
.jz-host-active .live-question [data-live-qcount],
.jz-host-active .live-question h1 { grid-column: 1; }
.jz-host-active .live-question h1 { margin: 4px 0 8px; font-size: clamp(28px, 4.5vh, 48px); }
.jz-host-active .live-options { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; align-self: stretch; }
.jz-host-active .live-option { min-height: 0; padding: clamp(8px,1.4vh,14px); }
.jz-host-active .live-host-controls,
.jz-host-active .live-scoreboard { grid-column: 1 / -1; }

.jz-host-active [data-draw-stage] > .ng-card,
.jz-host-active [data-vote-stage] > .ng-card {
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto;
  gap: 8px;
}
.jz-host-active [data-draw-stage] .ng-canvas-wrap,
.jz-host-active [data-vote-stage] .ng-canvas-wrap { min-height: 0; height: 100%; }
.jz-host-active [data-draw-stage] .ng-canvas,
.jz-host-active [data-vote-stage] .ng-canvas { height: 100%; aspect-ratio: auto; object-fit: contain; }
.jz-host-active [data-draw-stage] [data-live-scores] { grid-template-columns: repeat(4,minmax(0,1fr)); }

.jz-host-active [data-game] > .ng-card {
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto auto;
  gap: 8px;
}
.jz-host-active [data-game] > .ng-card > .ng-grid { min-height: 0; margin-top: 0 !important; }
.jz-host-active [data-game] > .ng-card > .ng-grid > .ng-card { min-height: 0; padding: 12px; overflow: hidden; }
.jz-host-active [data-game] .ng-list { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; }
.jz-host-active [data-game] .ng-row,
.jz-host-active [data-game] .ng-answer { padding: 6px 9px; }
.jz-host-active [data-game] [data-scores] { grid-template-columns: repeat(4,minmax(0,1fr)); margin-top: 0 !important; }

.jz-host-active [data-stage] > .ng-card {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  grid-template-rows: auto auto auto minmax(0,1fr) auto;
  align-items: center;
  column-gap: 20px;
}
.jz-host-active [data-stage] [data-round],
.jz-host-active [data-stage] [data-phase-title],
.jz-host-active [data-stage] [data-phase-text] { grid-column: 1; }
.jz-host-active [data-stage] [data-phase-icon],
.jz-host-active [data-stage] [data-timer] { grid-column: 2; }
.jz-host-active [data-stage] [data-phase-icon] { grid-row: 1 / span 2; }
.jz-host-active [data-stage] [data-timer] { grid-row: 3 / span 2; }
.jz-host-active [data-stage] [data-board],
.jz-host-active [data-stage] [data-action-panel],
.jz-host-active [data-stage] .ng-actions { grid-column: 1 / -1; }
.ng-phase-change > .ng-card { animation: jz-phase-in 260ms var(--jz-ease); }
@keyframes jz-phase-in { from { opacity:.35; transform:translateY(8px); } to { opacity:1; transform:none; } }

@media (max-width: 1100px), (max-height: 740px) {
  .jz-host-active [data-game] .ng-list { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .jz-host-active [data-draw-stage] [data-live-scores] { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .jz-host-active .live-scoreboard { grid-template-columns: repeat(4,minmax(0,1fr)); }
}

/* Motion is an enhancement, never a requirement */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 620px) {
  :root {
    --jz-fs-hero: 48px;
    --jz-fs-title: 32px;
    --jz-fs-section: 21px;
    --jz-fs-body: 15px;
  }
}

@media (min-width: 1500px) {
  :root {
    --jz-fs-hero: 72px;
    --jz-fs-title: 44px;
    --jz-fs-section: 27px;
    --jz-fs-body: 18px;
    --jz-fs-note: 14px;
  }
}
