:root {
  --bg: #0E0817;
  --bg-2: #160B26;
  --bg-3: #1E1033;
  --bg-4: #2A1748;
  --accent: #9B5CF6;
  --accent-2: #C4A0FF;
  --accent-dim: rgba(155, 92, 246, 0.18);
  --line: rgba(155, 92, 246, 0.32);
  --text: #F4EFFC;
  --text-dim: #B9A8D4;
  --text-mute: #8B7AA6;
  --danger: #E23D4A;
  --danger-dim: rgba(226, 61, 74, 0.18);
  --gold: #E7C57A;
  --ok: #6FCB9A;
  --font: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --radius: 6px;
  --host-h: 72px;
}

@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Medium.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("../fonts/IBMPlexSansArabic-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.45;
  overflow-x: clip;
  min-height: 100%;
}
html[lang="ar"] { direction: rtl; }
html[lang="en"] { direction: ltr; }
body { min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 560px at 80% -10%, rgba(155, 92, 246, 0.14), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
body.is-live .hostbar { display: none; }
.screen.is-on { display: flex; }

/* ===== Host bar ===== */
.hostbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--host-h);
  padding: 10px 22px;
  background: rgba(14, 8, 23, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(160%);
  flex-wrap: wrap;
}
.hostbar .brand {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-inline-end: auto;
}
.hostbar .brand strong {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.hostbar .brand span {
  color: var(--text-mute);
  font-size: 0.75rem;
  font-weight: 500;
}
.ai-chip, .lang-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: var(--accent-dim);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius);
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-chip[data-path="ollama"] { border-color: rgba(111, 203, 154, 0.5); color: var(--ok); }
.ai-chip[data-path="bank"] { color: var(--text-dim); }
.ai-chip[data-path="webllm"] { color: var(--gold); }
.ai-chip[data-path="busy"] { color: var(--gold); }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  line-height: 1.3;
  transition: background 0.28s var(--ease), border-color 0.28s var(--ease), transform 0.2s var(--ease), opacity 0.28s var(--ease);
}
.btn:hover { background: var(--bg-4); border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #16061f;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(226, 61, 74, 0.5); color: #ffd5d8; }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; }

/* ===== Setup ===== */
.setup {
  padding: 28px 40px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.hero-copy h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4.4vw, 3.4rem);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: -0.03em;
}
.hero-copy p.lead {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  max-width: 46rem;
  line-height: 1.5;
}
.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 28px;
  align-items: start;
}
.panel {
  background: rgba(22, 11, 38, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-2);
}
.teams { display: flex; flex-direction: column; gap: 14px; }
.team-card {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px;
}
.team-head {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.team-head input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-weight: 600;
}
.members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.members input {
  width: 160px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { color: var(--text-dim); font-size: 0.85rem; font-weight: 500; }
.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  width: 100%;
}
.checks { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 16px; }
.checks label { display: flex; gap: 8px; align-items: flex-start; color: var(--text-dim); font-size: 0.92rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hint { color: var(--text-mute); font-size: 0.82rem; margin-top: 12px; line-height: 1.45; }
.preview-card {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--bg);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius);
}
.preview-card .k { color: var(--text-mute); font-size: 0.75rem; font-weight: 600; }
.preview-card .v { font-weight: 600; font-size: 1.1rem; line-height: 1.4; margin-top: 4px; }

/* ===== Countdown / On air ===== */
.studio { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.breaking-bar {
  display: flex;
  align-items: stretch;
  min-height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.breaking-tag {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 0 22px;
  background: var(--accent);
  color: #16061f;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.15rem;
}
.ticker-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  background: var(--bg-2);
  min-width: 0;
}
.ticker {
  display: inline-flex;
  gap: 48px;
  white-space: nowrap;
  will-change: transform;
  animation: ticker 36s linear infinite;
  padding-inline: 24px;
  font-weight: 500;
  color: var(--text);
}
html[lang="ar"] .ticker { animation-name: ticker-rtl; }
@keyframes ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@keyframes ticker-rtl {
  from { transform: translateX(0); }
  to { transform: translateX(50%); }
}
.onair-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--bg);
  border-inline-start: 1px solid var(--line);
}
.onair-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  border-radius: 2px;
}
.onair-badge .dot {
  width: 8px;
  height: 8px;
  background: #fff;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.2rem;
  min-width: 4.5ch;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(24px, 5vh, 64px) clamp(24px, 6vw, 96px) 24px;
  min-height: 0;
  position: relative;
}
.headline-kicker {
  color: var(--accent-2);
  font-weight: 600;
  font-size: clamp(0.85rem, 1.3vw, 1.05rem);
  margin: 0 0 10px;
  letter-spacing: 0.02em;
}
.headline {
  margin: 0;
  font-size: clamp(1.8rem, 3.6vw, 3.35rem);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: -0.03em;
  max-width: 22ch;
}
.twist-slam {
  margin-top: clamp(20px, 4vh, 40px);
  padding: 18px 22px;
  background: var(--bg-3);
  border: 1px solid var(--accent);
  border-inline-start-width: 6px;
  border-radius: var(--radius);
  max-width: min(42rem, 100%);
  transform-origin: right center;
}
html[lang="en"] .twist-slam { transform-origin: left center; }
.twist-slam .k {
  color: var(--danger);
  font-weight: 700;
  font-size: 0.9rem;
  margin: 0 0 6px;
  letter-spacing: 0.04em;
}
.twist-slam .v {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.02em;
}
.twist-slam.is-in {
  animation: slam 0.55s var(--ease);
}
@keyframes slam {
  0% { opacity: 0; transform: translateY(14px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.flash {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: rgba(155, 92, 246, 0.18);
  opacity: 0;
}
.flash.is-on { animation: flash 0.45s var(--ease); }
@keyframes flash {
  0% { opacity: 0.7; }
  100% { opacity: 0; }
}

.count-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
}
.count-num {
  font-size: clamp(6rem, 18vw, 12rem);
  font-weight: 700;
  line-height: 1;
  color: var(--accent-2);
  letter-spacing: -0.05em;
}
.count-wrap h2 { margin: 8px 0 20px; font-size: clamp(1.4rem, 3vw, 2rem); }
.count-wrap .pre-headline {
  max-width: 20ch;
  font-size: clamp(1.3rem, 2.4vw, 1.8rem);
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-dim);
}

.lower-third {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  padding: 0 clamp(24px, 6vw, 96px) 18px;
}
.nameplate {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-inline-start: 6px solid var(--accent);
  padding: 10px 18px 12px;
  min-width: min(520px, 100%);
  max-width: 100%;
}
.nameplate .now {
  font-size: 0.8rem;
  color: var(--accent-2);
  font-weight: 600;
}
.nameplate .who {
  font-size: clamp(1.3rem, 2.4vw, 1.9rem);
  font-weight: 700;
  line-height: 1.3;
}
.nameplate .next {
  color: var(--text-mute);
  font-size: 0.92rem;
  margin-top: 2px;
}
.round-meta {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.95rem;
  text-align: end;
}
.timer-track {
  height: 8px;
  background: var(--bg-3);
  width: 100%;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: right center;
  transform: scaleX(1);
}
html[lang="en"] .timer-fill { transform-origin: left center; }
.timer-fill.is-run { transition: transform 0.2s linear; }

.host-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 22px 16px;
  border-top: 1px solid var(--line);
  background: rgba(14, 8, 23, 0.9);
}
.kbd {
  display: inline-block;
  border: 1px solid var(--line);
  padding: 0 6px;
  border-radius: 3px;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
}
.help { color: var(--text-mute); font-size: 0.8rem; margin-inline-start: auto; }

/* ===== Vote / board ===== */
.vote, .board {
  padding: 32px 40px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.vote h1, .board h1 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 3.4vw, 2.8rem);
  letter-spacing: -0.03em;
  line-height: 1.28;
}
.sub { color: var(--text-dim); margin: 0 0 28px; }
.vote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
  max-width: 920px;
}
.vote-card {
  text-align: start;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.28s var(--ease), background 0.28s var(--ease), transform 0.2s var(--ease);
}
.vote-card:hover, .vote-card.is-pick {
  border-color: var(--accent);
  background: var(--bg-3);
}
.vote-card.is-pick { box-shadow: inset 0 0 0 1px var(--accent); }
.vote-card .team { color: var(--accent-2); font-size: 0.85rem; font-weight: 600; }
.vote-card .nm { font-size: 1.45rem; font-weight: 700; line-height: 1.3; }
.vote-card .twist { color: var(--text-dim); font-size: 0.92rem; }

.rows { display: flex; flex-direction: column; gap: 12px; }
.row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 14px 18px;
  border-radius: var(--radius);
}
.row .rank { font-weight: 700; font-size: 1.3rem; color: var(--accent-2); }
.row .pts { font-weight: 700; font-size: 1.4rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; background: var(--bg-4); margin-top: 8px; }
.bar-fill { height: 100%; background: var(--accent); transform-origin: right center; }
html[lang="en"] .bar-fill { transform-origin: left center; }

.overlay-help {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 14, 0.78);
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.overlay-help.is-on { display: flex; }
.overlay-help .box {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 520px;
  width: 100%;
}
.overlay-help h2 { margin: 0 0 12px; }
.overlay-help dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; }
.overlay-help dt { color: var(--accent-2); font-weight: 600; }
.overlay-help dd { margin: 0; color: var(--text-dim); }

@media (max-width: 800px) {
  .setup, .vote, .board { padding: 20px 16px 32px; }
  .setup-grid, .lower-third { grid-template-columns: 1fr; }
  .hostbar { padding: 10px 14px; }
  .headline { max-width: none; }
  .twist-slam { max-width: none; }
  .stage { padding: 20px 16px 16px; }
  .lower-third { padding: 0 16px 12px; }
  .members input { width: 100%; }
  .help { display: none; }
  .ai-chip { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .ticker, .onair-badge .dot, .twist-slam.is-in, .flash.is-on { animation: none !important; }
  .timer-fill, .btn, .vote-card, .bar-fill { transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .hostbar, .panel { background: var(--bg-2); backdrop-filter: none; }
}
