@font-face { font-family: Cairo; font-weight: 400; font-display: swap; src: url(/fonts/cairo-arabic-400-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(/fonts/cairo-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 800; font-display: swap; src: url(/fonts/cairo-arabic-800-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Cairo; font-weight: 400; font-display: swap; src: url(/fonts/cairo-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF; }
@font-face { font-family: Cairo; font-weight: 700; font-display: swap; src: url(/fonts/cairo-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF; }
@font-face { font-family: Cairo; font-weight: 800; font-display: swap; src: url(/fonts/cairo-latin-800-normal.woff2) format('woff2'); unicode-range: U+0000-00FF; }

:root {
  --bg: #101827;
  --bg2: #182338;
  --panel: #1f2c45;
  --line: #2e3d5c;
  --text: #f1f4fa;
  --muted: #9aa8c4;
  --gold: #f5b83d;
  --red: #d9443b;
  --red-dark: #9e2a24;
  --red-soft: #f6d3cf;
  --blue: #2f7fd1;
  --blue-dark: #1e5592;
  --blue-soft: #cfe2f6;
  --neutral: #d9c9a3;
  --neutral-dark: #a8966c;
  --assassin: #15151b;
  --card: #f7f1e3;
  --card-text: #23201a;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { overflow-x: hidden; }
body {
  font-family: Cairo, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 50% -200px, #22325a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
a { color: var(--gold); }

/* ===== أزرار ===== */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700;
  background: var(--gold); color: #1b1404; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, filter .15s; min-height: 42px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .9rem; }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.wa { background: #25d366; color: #06301a; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; width: 38px; height: 38px; display: inline-grid; place-items: center; font-size: 1.05rem; }

/* ===== الهيدر ===== */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  position: sticky; top: 0; z-index: 5; background: rgba(16,24,39,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--text); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--red) 0 50%, var(--blue) 50% 100%); display: grid; place-items: center; font-size: .9rem; color: #fff; }
.topbar .spacer { flex: 1; }
.code-chip { background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; padding: 4px 10px; font-weight: 700; letter-spacing: 2px; direction: ltr; font-size: .9rem; }
.count-chip { color: var(--muted); font-size: .85rem; }

main { max-width: 1100px; margin: 0 auto; padding: 12px; }

/* ===== شريط الحالة ===== */
.status {
  text-align: center; font-weight: 700; padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); margin-bottom: 10px; line-height: 1.5;
}
.status.red { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.status.blue { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.status .clue-word { display: inline-block; background: var(--card); color: var(--card-text); padding: 0 12px; border-radius: 8px; margin: 0 4px; font-size: 1.15rem; }
.status .clue-num { display: inline-block; background: var(--gold); color: #1b1404; min-width: 30px; border-radius: 8px; padding: 0 6px; }
.timer { font-variant-numeric: tabular-nums; color: var(--gold); margin-inline-start: 8px; }

/* ===== اللوحة ===== */
.board {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(4px, 1.2vw, 10px);
  max-width: 860px; margin: 0 auto;
}
.card {
  position: relative; aspect-ratio: 1.45; border-radius: 10px; border: 0; padding: 4px;
  background: var(--card); color: var(--card-text);
  box-shadow: 0 3px 0 #c9bd9f, 0 6px 14px rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-weight: 800; font-size: clamp(.7rem, 3.3vw, 1.25rem); line-height: 1.15; overflow: hidden;
  transition: transform .12s, box-shadow .15s, background .25s;
  word-break: break-word;
}
.card .word { position: relative; z-index: 1; }
.card::before { /* شريط علوي رفيع بلون المفتاح لرئيس الجواسيس */
  content: ''; position: absolute; inset: 0 0 auto 0; height: 0; transition: height .2s;
}
.card.clickable:hover { transform: translateY(-2px); }
.card.clickable { cursor: pointer; }
.card:not(.clickable) { cursor: default; }

/* مفتاح رئيس الجواسيس (غير مكشوف) */
.card.key-red { background: var(--red-soft); box-shadow: 0 3px 0 #e2a7a1, 0 6px 14px rgba(0,0,0,.25); }
.card.key-blue { background: var(--blue-soft); box-shadow: 0 3px 0 #9fc1e6, 0 6px 14px rgba(0,0,0,.25); }
.card.key-neutral { background: var(--card); }
.card.key-assassin { background: #3a3a44; color: #fff; box-shadow: 0 3px 0 #111, 0 6px 14px rgba(0,0,0,.3); }
.card.key-red::before { height: 6px; background: var(--red); }
.card.key-blue::before { height: 6px; background: var(--blue); }
.card.key-assassin::before { height: 6px; background: #000; }

/* مكشوفة */
.card.revealed { color: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,.15); }
.card.revealed.c-red { background: repeating-linear-gradient(135deg, var(--red) 0 12px, #cf3d34 12px 24px); }
.card.revealed.c-blue { background: repeating-linear-gradient(135deg, var(--blue) 0 12px, #2a74c0 12px 24px); }
.card.revealed.c-neutral { background: repeating-linear-gradient(135deg, var(--neutral) 0 12px, #d1c096 12px 24px); color: #3b3322; }
.card.revealed.c-assassin { background: var(--assassin); }
.card.revealed .emblem { position: absolute; inset: auto auto 4px 6px; font-size: clamp(.7rem, 2.4vw, 1rem); opacity: .85; }
.card.revealed .word { opacity: .9; font-size: .85em; }
.board.spy .card.revealed { opacity: .55; }
.board.over .card:not(.revealed) { opacity: .9; }
.card.flip { animation: flip .45s ease; }
@keyframes flip { 0% { transform: rotateY(90deg); } 100% { transform: rotateY(0); } }

.card .sugg {
  position: absolute; inset: 3px 3px auto auto; z-index: 2; display: flex; flex-wrap: wrap; gap: 2px; justify-content: flex-end; max-width: 95%;
}
.card .sugg span { background: var(--gold); color: #1b1404; font-size: clamp(.5rem, 1.8vw, .7rem); border-radius: 6px; padding: 0 4px; font-weight: 700; }
.card .confirm {
  position: absolute; inset: auto 3px 3px auto; z-index: 3; border: 0; border-radius: 6px; background: #1b1404; color: var(--gold);
  font-size: clamp(.55rem, 2vw, .8rem); padding: 1px 6px; font-weight: 800;
}

/* ===== منطقة الإجراء ===== */
.actionbar { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 12px auto; max-width: 860px; }
.clue-form { display: flex; gap: 6px; width: 100%; max-width: 520px; }
.clue-form input { flex: 1; min-width: 0; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--card-text); padding: 8px 16px; font-weight: 700; }
.clue-form select { border-radius: 999px; border: 1.5px solid var(--line); background: var(--panel); color: var(--text); padding: 6px 10px; font-weight: 700; }

/* ===== الفرق والسجل ===== */
.teams { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr); gap: 8px; max-width: 860px; margin: 12px auto 0; align-items: stretch; }
.team { border-radius: var(--radius); padding: 10px; min-height: 150px; min-width: 0; }
.team.red { background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%); }
.team.blue { background: linear-gradient(180deg, var(--blue) 0%, var(--blue-dark) 100%); }
.team .score { font-size: 2rem; font-weight: 800; text-align: center; line-height: 1; }
.team .tname { text-align: center; font-weight: 700; opacity: .9; margin-bottom: 6px; }
.team h4 { margin: 8px 0 4px; font-size: .78rem; opacity: .8; font-weight: 700; }
.team .members { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { background: rgba(255,255,255,.18); border-radius: 999px; padding: 1px 9px; font-size: .82rem; display: inline-flex; gap: 4px; align-items: center; }
.pill.me { background: #fff; color: #111; }
.pill.off { opacity: .5; }
.pill .x { border: 0; background: none; color: inherit; padding: 0; font-size: .8rem; opacity: .7; }
.team .join { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.team .join .btn { background: rgba(255,255,255,.92); color: #111; min-height: 32px; padding: 4px 8px; font-size: .78rem; line-height: 1.3; white-space: normal; width: 100%; }
.team.active { outline: 3px solid var(--gold); outline-offset: 2px; }

.log { min-width: 0; overflow-wrap: anywhere; background: var(--card); color: var(--card-text); border-radius: var(--radius); padding: 8px; font-size: .8rem; max-height: 260px; overflow: auto; }
.log h3 { margin: 0 0 6px; font-size: .85rem; text-align: center; color: #6b604a; }
.log ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.log li { border-radius: 6px; padding: 2px 6px; }
.log li.red { background: var(--red-soft); }
.log li.blue { background: var(--blue-soft); }
.log li b { font-weight: 800; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
.dot.red { background: var(--red); } .dot.blue { background: var(--blue); } .dot.neutral { background: var(--neutral-dark); } .dot.assassin { background: #000; }

/* ===== اللوبي ===== */
.lobby { display: grid; gap: 12px; max-width: 860px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel h2 { margin: 0 0 10px; font-size: 1.1rem; }
.share { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.share .qr { width: 150px; height: 150px; background: #fff; border-radius: 10px; padding: 6px; }
.share .qr img { width: 100%; height: 100%; display: block; }
.linkbox { display: flex; gap: 6px; align-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 10px; }
.linkbox code { flex: 1; min-width: 0; direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; color: var(--muted); }
.share .btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.settings label { display: block; margin: 8px 0 4px; font-weight: 700; font-size: .9rem; }
.settings select, .settings textarea { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); padding: 8px; }
.settings textarea { min-height: 90px; resize: vertical; }
.muted { color: var(--muted); font-size: .85rem; }
.center { text-align: center; }
.start-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ===== نوافذ ===== */
.modal { position: fixed; inset: 0; background: rgba(5,10,20,.7); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: 100%; max-width: 420px; max-height: 90dvh; overflow: auto; }
.modal h2 { margin-top: 0; }
.modal input[type=text] { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); padding: 10px 12px; font-size: 1.05rem; margin: 8px 0 12px; }
.rules li { margin-bottom: 6px; line-height: 1.6; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #000d; color: #fff; padding: 8px 16px; border-radius: 999px; z-index: 30; font-weight: 700; max-width: 92vw; text-align: center; }

.winner-banner { text-align: center; padding: 14px; border-radius: var(--radius); font-size: 1.3rem; font-weight: 800; margin-bottom: 10px; }
.winner-banner.red { background: var(--red); } .winner-banner.blue { background: var(--blue); }

/* ===== الصفحة الرئيسية ===== */
.hero { text-align: center; padding: 40px 16px 20px; }
.hero h1 { font-size: clamp(2.2rem, 9vw, 3.6rem); margin: 0; line-height: 1.1; }
.hero h1 .r { color: var(--red); } .hero h1 .b { color: var(--blue); }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 520px; margin: 10px auto 22px; }
.hero .btn { font-size: 1.15rem; padding: 14px 34px; }
.demo-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 360px; margin: 26px auto; transform: rotate(-3deg); }
.demo-grid div { aspect-ratio: 1.45; border-radius: 6px; background: var(--card); }
.demo-grid .r { background: var(--red); } .demo-grid .b { background: var(--blue); } .demo-grid .k { background: var(--assassin); } .demo-grid .n { background: var(--neutral); }
.howto { max-width: 680px; margin: 0 auto 40px; padding: 0 16px; }
.howto ol { line-height: 1.9; padding-inline-start: 20px; }
.join-code { display: flex; gap: 6px; max-width: 320px; margin: 14px auto 0; }
.join-code input { flex: 1; min-width: 0; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; text-transform: uppercase; letter-spacing: 2px; direction: ltr; text-align: center; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

@media (max-width: 560px) {
  main { padding: 8px; }
  .teams { gap: 5px; }
  .team { padding: 7px 5px; }
  .team .score { font-size: 1.6rem; }
  .pill { font-size: .72rem; padding: 0 6px; }
  .log { font-size: .7rem; padding: 5px; }
  .share { grid-template-columns: minmax(0, 1fr); }
  .share .qr { margin: 0 auto; width: 170px; height: 170px; }
  .card { border-radius: 7px; padding: 2px; }
  .topbar .brand span.txt { display: none; }
}
