/* غدّار — night town. One deliberate dark look, red for danger and death. */
:root {
  --bg: #0B0D11;
  --bg-2: #12151C;
  --card: #181C25;
  --line: #262B36;
  --fg: #EEEEF0;
  --muted: #8E92A0;
  --red: #E0353C;
  --red-deep: #9E1A20;
  --gold: #E8B65A;
  --green: #4CC38A;
  --font: 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 17px; line-height: 1.6;
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(224, 53, 60, .14), transparent 70%);
  background-attachment: fixed; overscroll-behavior: none;
}
#app { max-width: 720px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); min-height: 100%; display: flex; flex-direction: column; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }
input {
  font: inherit; color: var(--fg); background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 14px 20px; width: 100%; font-size: 18px;
}
input::placeholder { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 26px;
  border-radius: 999px; font-weight: 800; font-size: 18px; background: var(--red); color: #fff;
  transition: transform .12s ease, background .2s ease, opacity .2s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: var(--card); border: 1px solid var(--line); color: var(--fg); }
.btn.ok { background: var(--green); color: #07130D; }
.btn.small { min-height: 40px; padding: 0 16px; font-size: 15px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.grow { flex: 1; }

/* ---------- home ---------- */
.home { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 36px; padding-block: 24px; }
.brand { text-align: center; }
.brand .logo { font-size: clamp(84px, 26vw, 140px); font-weight: 900; line-height: 1; letter-spacing: -.02em; }
.brand .logo span { color: var(--red); }
.brand .logo-img { width: min(300px, 72vw); height: auto; display: block; margin: 0 auto; }
.brand .tag { color: var(--muted); font-size: 20px; margin-top: 10px; }
.join-code { display: flex; gap: 10px; }
.join-code input { text-align: center; letter-spacing: .3em; text-transform: uppercase; font-weight: 800; }
.footer { text-align: center; color: var(--muted); font-size: 13px; margin-top: auto; padding-top: 24px; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.top .title { flex: 1; min-width: 0; }
.top h2 { font-size: 24px; font-weight: 900; }
.top .hint { color: var(--muted); font-size: 15px; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 20px; flex: none; }
.timer { position: relative; width: 64px; height: 64px; flex: none; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer .track { fill: none; stroke: var(--line); stroke-width: 6; }
.timer .bar { fill: none; stroke: var(--fg); stroke-width: 6; stroke-linecap: round; transition: stroke .3s; }
.timer.low .bar { stroke: var(--red); }
.timer b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.timer.low b { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- players grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; }
.pc {
  position: relative; background: var(--card); border: 2px solid transparent; border-radius: var(--r); padding: 10px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; overflow: hidden;
  transition: border-color .2s, transform .15s, opacity .3s;
}
.pc img { width: 100%; max-width: 92px; aspect-ratio: 1; border-radius: 50%; object-fit: cover; background: var(--bg-2); }
.pc .nm { font-weight: 800; font-size: 15px; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc .sub { font-size: 12px; color: var(--muted); min-height: 18px; }
.pc.can { cursor: pointer; }
.pc.can:active { transform: scale(.96); }
.pc.can:hover { border-color: var(--line); }
.pc.sel { border-color: var(--red); box-shadow: 0 0 0 4px rgba(224, 53, 60, .18); }
.pc.speak { border-color: var(--gold); box-shadow: 0 0 24px rgba(232, 182, 90, .35); }
.pc.speak img { animation: talk 1.4s ease-in-out infinite; }
@keyframes talk { 50% { box-shadow: 0 0 0 6px rgba(232, 182, 90, .3); } }
.pc.dead { opacity: .45; }
.pc.dead img { filter: grayscale(1); }
.pc .ribbon { z-index: 2; position: absolute; top: 14px; left: -30px; width: 110px; height: 18px; background: #000; transform: rotate(-45deg); box-shadow: 0 0 0 1px rgba(255,255,255,.3), 0 2px 6px rgba(0,0,0,.6); }
.pc .badge { z-index: 3; position: absolute; top: 6px; right: 6px; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px; background: var(--red); color: #fff; font-weight: 900; font-size: 14px; display: grid; place-items: center; }
.pc .badge.ok { background: var(--green); color: #07130D; }
.pc.off { opacity: .35; }
.pc .me { position: absolute; top: 6px; left: 6px; font-size: 11px; background: var(--fg); color: var(--bg); border-radius: 999px; padding: 0 8px; font-weight: 800; }
.mate { color: var(--red); font-weight: 800; }

/* ---------- panels ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.dock { position: sticky; bottom: 0; padding-top: 14px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); margin-top: auto; }
.code-box { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.code-box b { font-size: 30px; letter-spacing: .25em; font-weight: 900; }
.avatars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.avatars button { border-radius: 50%; overflow: hidden; aspect-ratio: 1; border: 3px solid transparent; padding: 0; position: relative; }
.avatars img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatars button.on { border-color: var(--red); transform: scale(1.06); }
.avatars button:disabled { opacity: .2; cursor: not-allowed; }
.section-title { font-size: 15px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }

/* ---------- role card ---------- */
.role-card { border-radius: 24px; padding: 28px 20px; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; border: 1px solid var(--line); background: var(--card); }
.role-card .ico { font-size: 72px; line-height: 1; }
.role-card h2 { font-size: 34px; font-weight: 900; }
.role-card p { color: #D4D6DD; font-size: 18px; line-height: 1.8; max-width: 36ch; }
.role-card.mafia { background: linear-gradient(170deg, #3A0E11, var(--card) 70%); border-color: var(--red-deep); }
.role-card.mafia h2 { color: var(--red); }
.team { font-size: 14px; padding: 4px 14px; border-radius: 999px; background: var(--bg-2); color: var(--muted); }

/* ---------- night ---------- */
body.night { background-image: radial-gradient(ellipse 70% 40% at 50% -5%, rgba(80, 100, 180, .16), transparent 70%); }
.moon { font-size: 64px; text-align: center; margin: 12px 0; }

/* ---------- overlay / death card ---------- */
#overlay { position: fixed; inset: 0; background: rgba(5, 6, 9, .88); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 24px; }
.reveal { display: flex; flex-direction: column; align-items: center; gap: 20px; text-align: center; }
.reveal h2 { font-size: 30px; font-weight: 900; }
.flip { width: 220px; height: 300px; perspective: 1000px; }
.flip .inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.2, .8, .2, 1); }
.flip.turn .inner { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; border-radius: 20px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.flip .front { background: linear-gradient(160deg, var(--red), #5E0E12); box-shadow: 0 24px 60px rgba(224, 53, 60, .4); }
.flip .front img { width: 120px; height: 120px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .9); object-fit: cover; filter: grayscale(.6); }
.flip .front b { font-size: 26px; font-weight: 900; }
.flip .ribbon { position: absolute; top: 22px; left: -40px; width: 160px; height: 26px; background: #000; transform: rotate(-45deg); }
.flip .back { background: var(--card); border: 1px solid var(--line); transform: rotateY(180deg); padding: 16px; }
.flip .back .ico { font-size: 64px; }
.flip .back b { font-size: 30px; font-weight: 900; }
.flip .back.mafia b { color: var(--red); }
.drop { animation: drop .6s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes drop { from { transform: translateY(-40px) scale(.9); opacity: 0; } }

/* ---------- end ---------- */
.win { text-align: center; padding: 20px 0; }
.win .big { font-size: 64px; }
.win h2 { font-size: 34px; font-weight: 900; margin-top: 8px; }
.win.mafia h2 { color: var(--red); }

/* ---------- help ---------- */
.help-role { display: flex; gap: 14px; align-items: flex-start; }
.help-role .ico { font-size: 40px; line-height: 1; }
.help-role h3 { font-size: 20px; font-weight: 800; }
.help-role p { color: #C9CBD3; }
.steps { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; color: #C9CBD3; }

#toast { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 20px; border-radius: 999px; font-weight: 700; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.mic { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--bg-2); color: var(--muted); white-space: nowrap; }
.mic.on { background: rgba(76, 195, 138, .15); color: var(--green); }

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

[hidden] { display: none !important; }
