:root {
  --bg: #08070a;
  --panel: #131118;
  --panel-2: #1c1923;
  --line: #2a2631;
  --text: #f4f1f6;
  --muted: #9a93a3;
  --red: #ff2e4d;
  --red-dim: #5c1220;
  --green: #2ee59d;
  --gold: #ffc93c;
  --display: 'Lalezar', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --body: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --r: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
.bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 50% at 50% 110%, rgba(255, 46, 77, .18), transparent 70%),
    radial-gradient(40% 30% at 85% -5%, rgba(255, 46, 77, .08), transparent 70%);
}
body.alarm .bg { animation: alarm 1s ease-in-out infinite; }
@keyframes alarm { 50% { background-color: rgba(255, 46, 77, .12); } }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
input { font: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.15; }

#app { min-height: 100dvh; }

/* ───────── أزرار ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 54px; padding: 0 1.4em; border-radius: 999px;
  background: var(--red); color: #fff; font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 0 0 0 rgba(255, 46, 77, .5), 0 10px 30px -10px rgba(255, 46, 77, .6);
  transition: transform .15s ease, filter .15s ease;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.green { background: var(--green); color: #052; box-shadow: 0 10px 30px -12px rgba(46, 229, 157, .6); }
.btn.wide { width: 100%; }
.btn.small { min-height: 40px; font-size: .9rem; padding: 0 1em; }

/* ───────── الرئيسية ───────── */
.home {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 32px 16px; text-align: center;
}
.logo { font-family: var(--display); font-size: clamp(72px, 22vw, 150px); line-height: .9; color: var(--text); position: relative; }
.logo::after {
  content: ''; position: absolute; left: 50%; bottom: -14px; width: 60%; height: 14px; transform: translateX(-50%);
  border-radius: 50%; background: radial-gradient(closest-side, #000 60%, transparent), var(--red-dim);
  box-shadow: 0 0 30px rgba(255, 46, 77, .5);
}
.tagline { color: var(--muted); font-size: 1.05rem; max-width: 22em; }
.home-actions { display: grid; gap: 14px; width: min(360px, 100%); }
.join-row { display: flex; gap: 10px; }
.join-row .btn { flex: none; padding: 0 1.1em; }
.join-row input, .name-input {
  flex: 1; width: 100%; min-width: 0; min-height: 54px; padding: 0 18px; border-radius: 999px;
  background: var(--panel); color: var(--text); border: 1.5px solid var(--line); font-size: 1.15rem; text-align: center;
}
.join-row input:focus, .name-input:focus { outline: none; border-color: var(--red); }
.hint { color: var(--muted); font-size: .85rem; }
.brandline { color: var(--muted); font-size: .8rem; opacity: .7; }

/* ───────── التلفزيون ───────── */
.tv { min-height: 100dvh; display: flex; flex-direction: column; padding: clamp(16px, 3vw, 40px); gap: clamp(12px, 2vw, 28px); }
.tv-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); }
.tv-top .mini-logo { font-family: var(--display); font-size: clamp(26px, 3vw, 40px); color: var(--text); }
.tv-top .meta { display: flex; gap: 14px; align-items: center; font-size: clamp(14px, 1.3vw, 18px); }
.tv-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: clamp(14px, 2.2vw, 30px); }
.tv-foot { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.big { font-size: clamp(40px, 7vw, 110px); }
.huge { font-size: clamp(56px, 11vw, 170px); }
.sub { color: var(--muted); font-size: clamp(16px, 2vw, 30px); max-width: 28em; }
.kicker { color: var(--red); font-family: var(--display); font-size: clamp(18px, 2.2vw, 32px); letter-spacing: .02em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 0 0 1.5px var(--line); }

.lobby { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: clamp(16px, 3vw, 48px); align-items: center; width: 100%; max-width: 1300px; }
.qr-card { background: var(--panel); border-radius: 28px; padding: clamp(18px, 2.4vw, 32px); display: grid; gap: 14px; justify-items: center; border: 1px solid var(--line); }
.qr-card .qr { background: #fff; padding: 14px; border-radius: 18px; width: min(100%, 340px); aspect-ratio: 1; }
.qr-card .qr svg { width: 100%; height: 100%; display: block; }
.code { font-family: var(--display); font-size: clamp(48px, 6vw, 88px); letter-spacing: .12em; color: var(--gold); direction: ltr; line-height: 1; }
.url { direction: ltr; color: var(--muted); font-size: clamp(13px, 1.2vw, 17px); }
.lobby-side { display: grid; gap: 22px; text-align: start; }
.count-line { font-family: var(--display); font-size: clamp(26px, 3vw, 44px); }
.count-line small { font-family: var(--body); font-size: .45em; color: var(--muted); margin-inline-start: 10px; }
.settings { display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.seg { display: flex; gap: 6px; background: var(--bg); border-radius: 999px; padding: 4px; width: max-content; max-width: 100%; }
.seg button { padding: 8px 18px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--red); }
.set-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.set-row .label { min-width: 6em; font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px;
  background: var(--panel-2); font-weight: 600; font-size: clamp(15px, 1.4vw, 20px); border: 1.5px solid transparent;
}
.chip.ok { border-color: var(--green); }
.chip.off { opacity: .45; }
.chip.dead { opacity: .35; text-decoration: line-through; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.chip.offline .dot { background: var(--muted); }
.enter .chip { animation: pop .35s cubic-bezier(.2, .9, .3, 1.3) both; }

/* المؤقت */
.timer { --p: 1; width: clamp(90px, 11vw, 150px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; position: relative; }
.timer::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--red) calc(var(--p) * 360deg), var(--line) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
}
.timer span { font-family: var(--display); font-size: clamp(30px, 4vw, 56px); }
.timer.low span { color: var(--red); animation: beat .5s ease-in-out infinite; }
.timer.sm { width: 64px; }
.timer.sm span { font-size: 24px; }
.timer.sm::before { -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px)); mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px)); }
@keyframes beat { 50% { transform: scale(1.12); } }

.progress { color: var(--muted); font-size: clamp(16px, 1.8vw, 26px); }
.progress b { color: var(--text); }

/* خريطة الشك */
.ring { position: relative; height: min(60vh, 58vw); aspect-ratio: 1.7; max-width: 94vw; }
.ring-center { position: absolute; inset: 22% 25%; display: grid; place-items: center; align-content: center; gap: 10px; text-align: center; }
.seat {
  position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 6px;
  width: clamp(80px, 10vw, 140px);
}
.seat .face {
  width: clamp(52px, 6vw, 84px); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); font-family: var(--display); font-size: clamp(22px, 2.6vw, 36px); border: 2px solid var(--line); position: relative;
  transition: border-color .3s, box-shadow .3s;
}
.seat.done .face { border-color: var(--green); }
.seat .nm { font-weight: 700; font-size: clamp(13px, 1.3vw, 19px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.seat .tally { display: flex; gap: 8px; font-weight: 700; font-size: clamp(14px, 1.4vw, 20px); }
.seat .tally .s { color: var(--red); }
.seat .tally .t { color: var(--green); }
.seat .delta { font-size: .75em; color: var(--muted); }
.seat.focus .face { border-color: var(--red); box-shadow: 0 0 0 6px rgba(255, 46, 77, .18), 0 0 40px rgba(255, 46, 77, .7); }
.seat.silenced .face::after { content: '🤐'; position: absolute; font-size: 22px; transform: translate(70%, -70%); }
.enter .seat .tally { animation: drop .5s cubic-bezier(.2, .9, .3, 1.3) both; animation-delay: calc(var(--i) * 140ms + 400ms); }
.enter .seat.focus .face { animation: glow 1s ease-out both; animation-delay: calc(var(--n) * 140ms + 700ms); }
.map-focus { font-family: var(--display); font-size: clamp(22px, 3vw, 44px); color: var(--red); }
.enter .map-focus { animation: rise .6s ease-out both; animation-delay: calc(var(--n) * 140ms + 900ms); }
@keyframes drop { from { opacity: 0; transform: translateY(-14px) scale(.6); } }
@keyframes glow { from { box-shadow: none; border-color: var(--line); } }

/* المتكلم */
.speaker-name { font-family: var(--display); font-size: clamp(56px, 10vw, 160px); line-height: 1; }
.queue { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; color: var(--muted); }
.queue .chip.now { border-color: var(--red); color: var(--text); }

/* الإعلانات */
.reveal-name { font-family: var(--display); font-size: clamp(54px, 9vw, 150px); line-height: 1; }
.reveal-role { display: inline-flex; align-items: center; gap: .3em; font-family: var(--display); font-size: clamp(30px, 4.5vw, 70px); color: var(--gold); }
.reveal-role.mafia { color: var(--red); }
.enter .reveal-name { animation: slam .6s cubic-bezier(.2, .9, .3, 1.2) both; animation-delay: .5s; }
.enter .reveal-role { animation: rise .7s ease-out both; animation-delay: 2.2s; }
.enter .late { animation: rise .6s ease-out both; animation-delay: 3s; }
.out-list { display: flex; gap: clamp(20px, 4vw, 60px); flex-wrap: wrap; justify-content: center; }
.out-item { display: grid; gap: 8px; justify-items: center; }
@keyframes slam { from { opacity: 0; transform: scale(2.2); filter: blur(10px); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }

.roulette { font-family: var(--display); font-size: clamp(54px, 9vw, 150px); min-height: 1.1em; }

.winner { font-family: var(--display); font-size: clamp(50px, 9vw, 140px); line-height: 1; }
.winner.mafia { color: var(--red); text-shadow: 0 0 40px rgba(255, 46, 77, .6); }
.winner.town { color: var(--green); text-shadow: 0 0 40px rgba(46, 229, 157, .5); }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); gap: 10px; width: min(1100px, 100%); }
.roster .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.roster .row.mafia { border-color: var(--red-dim); background: linear-gradient(90deg, var(--panel), rgba(255, 46, 77, .08)); }
.roster .row .r { color: var(--muted); font-size: .9em; white-space: nowrap; }
.roster .row.dead .n { opacity: .5; }

/* ───────── التليفون ───────── */
.phone { min-height: 100dvh; display: flex; flex-direction: column; padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); gap: 16px; max-width: 520px; margin: 0 auto; }
.ph-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ph-top .who { font-weight: 700; display: flex; gap: 8px; align-items: center; min-width: 0; }
.ph-top .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-pill { padding: 8px 14px; border-radius: 999px; background: var(--panel-2); font-weight: 600; font-size: .9rem; white-space: nowrap; }
.ph-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 18px; text-align: center; }
.ph-body > .timer { margin-inline: auto; }
.ph-title { font-family: var(--display); font-size: clamp(30px, 9vw, 44px); line-height: 1.15; }
.ph-sub { color: var(--muted); }
.ph-foot { display: grid; gap: 10px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 22px 18px; display: grid; gap: 12px;
}
.role-card { text-align: center; justify-items: center; }
.role-card .ic { font-size: 64px; line-height: 1; }
.role-card h2 { font-size: 44px; }
.role-card.mafia { border-color: var(--red); box-shadow: 0 0 40px -10px rgba(255, 46, 77, .6); }
.role-card.mafia h2 { color: var(--red); }
.role-card p { color: #d6d0dc; margin: 0; line-height: 1.7; }
.mates { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.enter .role-card { animation: flip .6s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes flip { from { opacity: 0; transform: perspective(600px) rotateY(80deg); } }

.cover {
  min-height: 300px; border-radius: 24px; display: grid; place-items: center; gap: 10px; align-content: center;
  background: repeating-linear-gradient(135deg, var(--panel), var(--panel) 14px, var(--panel-2) 14px, var(--panel-2) 28px);
  border: 1.5px dashed var(--line); width: 100%;
}
.cover .ph-title { font-size: 32px; }

.picks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: center; }
.pick {
  min-height: 58px; padding: 10px; border-radius: 16px; background: var(--panel); border: 1.5px solid var(--line);
  font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: border-color .15s, background .15s, transform .1s;
}
.pick:active { transform: scale(.97); }
.pick.on { border-color: var(--red); background: rgba(255, 46, 77, .12); }
.pick.on.green { border-color: var(--green); background: rgba(46, 229, 157, .1); }
.pick.taken { opacity: .3; }
.task-card .ph-title { font-size: 28px; }

.result { font-family: var(--display); font-size: 34px; }
.result.hit { color: var(--red); }
.log { display: grid; gap: 6px; color: var(--muted); font-size: .9rem; }

.dead-badge { font-size: 76px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel-2); border: 1px solid var(--line); padding: 12px 20px; border-radius: 999px; transition: .25s;
  max-width: calc(100% - 32px); text-align: center; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.conn { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: .85rem; z-index: 9; }

@media (max-width: 820px) {
  .lobby { grid-template-columns: 1fr; }
  .ring { aspect-ratio: 1.2; height: auto; width: 94vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
