/* =============================================================
   Reveal Quest — نظام التصميم
   ============================================================= */

:root {
  --pink: #ec4899;
  --pink-soft: #fbcfe8;
  --blue: #3b82f6;
  --blue-soft: #bfdbfe;

  --bg: #fff7fb;
  --bg2: #eef2ff;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;

  --primary: #7c3aed;
  --primary-600: #6d28d9;
  --primary-soft: #ede9fe;
  --accent: #f59e0b;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px -20px rgba(31, 41, 55, 0.35);
  --shadow-sm: 0 8px 24px -12px rgba(31, 41, 55, 0.3);

  --tile-a: #ef4444;
  --tile-b: #3b82f6;
  --tile-c: #f59e0b;
  --tile-d: #10b981;

  --font: "Tajawal", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="pastel"] {
  --bg: #fef6fb; --bg2: #f0f7ff;
  --primary: #f472b6; --primary-600: #ec4899; --primary-soft: #fce7f3;
  --accent: #38bdf8; --text: #334155;
}
[data-theme="neon"] {
  --bg: #0b1020; --bg2: #131a33; --card: rgba(23, 31, 58, 0.85); --card-solid: #171f3a;
  --text: #e5e7eb; --muted: #94a3b8; --line: #2a3358;
  --primary: #22d3ee; --primary-600: #06b6d4; --primary-soft: #0e7490; --accent: #f472b6;
  --shadow: 0 20px 60px -20px rgba(34, 211, 238, 0.35);
}
[data-theme="gold"] {
  --bg: #fffdf5; --bg2: #fbf3df; --card: rgba(255, 255, 255, 0.95);
  --primary: #c79a3b; --primary-600: #a9802b; --primary-soft: #f7edcf; --accent: #1f2937;
  --text: #3f3b2f; --muted: #8a8268; --line: #ece3c8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--bg2), transparent 60%),
    radial-gradient(1000px 500px at -10% 110%, var(--primary-soft), transparent 55%),
    linear-gradient(135deg, var(--bg), var(--bg2));
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ---------- تخطيط ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(14px, 3vw, 32px);
}
.wrap { width: 100%; max-width: 920px; margin: auto; }
.wrap-narrow { width: 100%; max-width: 520px; margin: auto; }

.card {
  background: var(--card);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 40px);
}
[data-theme="neon"] .card { border-color: var(--line); }

.screen { animation: fadeUp 0.5s ease both; }

/* ---------- علوي ---------- */
.topbar {
  width: 100%; max-width: 920px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--primary-600); }
.brand-mini .dot { width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--blue)); box-shadow: 0 0 0 4px var(--primary-soft); }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- نصوص ---------- */
h1.title { font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 800; line-height: 1.15; }
.subtitle { color: var(--muted); font-size: clamp(1rem, 2.2vw, 1.2rem); margin-top: 10px; }
.gradient-text {
  background: linear-gradient(120deg, var(--pink), var(--primary), var(--blue));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.85rem; line-height: 1.6; }
.center { text-align: center; }
.muted { color: var(--muted); }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-weight: 800; font-size: 1rem;
  padding: 14px 22px; border-radius: var(--radius-sm); border: none; cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.2s; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-600)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { box-shadow: 0 14px 30px -10px var(--primary); }
.btn-ghost { background: transparent; color: var(--text); border: 1.5px solid var(--line); }
.btn-soft { background: var(--primary-soft); color: var(--primary-600); }
.btn-block { width: 100%; }
.btn-lg { padding: 18px 28px; font-size: 1.15rem; border-radius: 16px; }
.btn-xl { padding: 22px 30px; font-size: clamp(1.1rem, 3vw, 1.5rem); border-radius: 18px; width: 100%; }
.btn-pink { background: linear-gradient(135deg, #f472b6, var(--pink)); color: #fff; }
.btn-blue { background: linear-gradient(135deg, #60a5fa, var(--blue)); color: #fff; }
.btn-icon { padding: 10px 12px; border-radius: 10px; background: var(--primary-soft); color: var(--primary-600); border: none; cursor: pointer; font-weight: 700; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row.cols-2 > * { flex: 1 1 0; min-width: 140px; }
.stack { display: grid; gap: 14px; }
.mt { margin-top: 18px; } .mt-lg { margin-top: 28px; } .mb { margin-bottom: 16px; }

/* ---------- مدخلات ---------- */
.input, .select, textarea.input {
  width: 100%; font-family: inherit; font-size: 1.05rem; color: var(--text);
  padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--card-solid); transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft);
}
.input.big { text-align: center; font-size: 1.4rem; font-weight: 700; letter-spacing: 2px; }

/* خيارات شريحة (segmented) */
.seg { display: flex; gap: 8px; }
.seg .chip {
  flex: 1; text-align: center; padding: 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card-solid); cursor: pointer; font-weight: 700; transition: all 0.15s; user-select: none;
}
.seg .chip[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-600); transform: translateY(-1px); }
.chip.boy[aria-pressed="true"] { border-color: var(--blue); background: var(--blue-soft); color: var(--blue); }
.chip.girl[aria-pressed="true"] { border-color: var(--pink); background: var(--pink-soft); color: var(--pink); }

/* ---------- الصفحة الرئيسية ---------- */
.hero { text-align: center; }
.hero .badge {
  display: inline-block; padding: 6px 14px; border-radius: 999px; background: var(--primary-soft);
  color: var(--primary-600); font-weight: 700; font-size: 0.85rem; margin-bottom: 16px;
}
.choice-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 26px; }
.choice-cards .pick {
  border-radius: var(--radius); padding: 26px 20px; text-align: center; cursor: pointer;
  border: 2px solid transparent; transition: transform 0.15s, box-shadow 0.2s;
}
.pick.host { background: linear-gradient(135deg, var(--primary-soft), #fff); }
.pick.player { background: linear-gradient(135deg, var(--pink-soft), var(--blue-soft)); }
.pick:hover { transform: translateY(-3px); box-shadow: var(--shadow-sm); }
.pick .emoji { font-size: 2.6rem; }
.pick h3 { margin-top: 8px; font-size: 1.2rem; }
.how { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 26px; }
.how .step { display: flex; gap: 12px; align-items: flex-start; }
.how .num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary); color: #fff; font-weight: 800;
}

/* ---------- لوبي المضيف ---------- */
.lobby-grid { display: grid; grid-template-columns: 1fr 1.1fr; gap: 22px; align-items: start; }
.qr-box { background: #fff; padding: 16px; border-radius: var(--radius); display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.qr-box img, .qr-box canvas { border-radius: 8px; }
.code-pill {
  font-size: clamp(2rem, 8vw, 3.4rem); font-weight: 800; letter-spacing: 8px;
  background: var(--primary-soft); color: var(--primary-600); padding: 10px 18px; border-radius: 16px;
  display: inline-block; margin-top: 8px;
}
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.player-chip {
  background: var(--card-solid); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px;
  text-align: center; font-weight: 700; animation: pop 0.35s ease both; position: relative; overflow: hidden;
}
.player-chip .av { font-size: 1.4rem; }
.player-chip .sc { color: var(--muted); font-weight: 600; font-size: 0.85rem; }

/* ---------- شاشة السؤال ---------- */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.q-counter { font-weight: 800; color: var(--primary-600); }
.q-text { font-size: clamp(1.4rem, 4vw, 2.4rem); font-weight: 800; text-align: center; line-height: 1.3; margin: 10px 0 22px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  display: flex; align-items: center; gap: 12px; padding: clamp(16px, 3vw, 26px);
  border-radius: 16px; color: #fff; font-weight: 800; font-size: clamp(1.05rem, 2.6vw, 1.5rem);
  cursor: pointer; border: none; text-align: start; transition: transform 0.1s, filter 0.15s; min-height: 72px;
}
.tile:active { transform: scale(0.98); }
.tile .ico { font-size: 1.3em; flex: none; }
.tile.a { background: linear-gradient(135deg, #f87171, var(--tile-a)); }
.tile.b { background: linear-gradient(135deg, #60a5fa, var(--tile-b)); }
.tile.c { background: linear-gradient(135deg, #fbbf24, var(--tile-c)); }
.tile.d { background: linear-gradient(135deg, #34d399, var(--tile-d)); }
.tile.dim { filter: grayscale(0.6) brightness(0.8); opacity: 0.6; }
.tile.right { outline: 5px solid #16a34a; outline-offset: 2px; }
.tile.wrongpick { outline: 5px solid #dc2626; outline-offset: 2px; }

/* مؤقّت دائري */
.timer-ring { --p: 100; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 800;
  background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--line) 0); position: relative; flex: none; }
.timer-ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--card-solid); }
.timer-ring span { position: relative; z-index: 1; }
.timer-ring.warn { background: conic-gradient(#ef4444 calc(var(--p) * 1%), var(--line) 0); color: #ef4444; }

.answer-count { font-weight: 800; }
.answer-bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 10px; }
.answer-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 0; transition: width 0.3s; }

/* ---------- لوحة الصدارة ---------- */
.lb { display: grid; gap: 10px; }
.lb-row {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 14px;
  background: var(--card-solid); border: 1.5px solid var(--line); animation: slideIn 0.4s ease both;
}
.lb-row .rank { font-weight: 800; width: 36px; text-align: center; font-size: 1.2rem; }
.lb-row .nm { flex: 1; font-weight: 700; }
.lb-row .pts { font-weight: 800; color: var(--primary-600); }
.lb-row.top1 { background: linear-gradient(135deg, #fff7e0, #fff); border-color: var(--accent); }
.lb-row.top2 { background: linear-gradient(135deg, #f1f5f9, #fff); }
.lb-row.top3 { background: linear-gradient(135deg, #fde9d7, #fff); }

/* ---------- شاشة الفائز / التشويق ---------- */
.spotlight { text-align: center; }
.spotlight .crown { font-size: clamp(3rem, 12vw, 6rem); animation: float 2.4s ease-in-out infinite; }
.winner-name { font-size: clamp(1.6rem, 6vw, 3rem); font-weight: 800; margin: 6px 0; }
.suspense { color: var(--muted); font-size: 1.1rem; margin-top: 10px; animation: blink 1.6s infinite; }

.scratch {
  width: min(280px, 80vw); height: 180px; border-radius: 20px; margin: 18px auto;
  display: grid; place-items: center; cursor: pointer; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #cbd5e1, #94a3b8); color: #fff; font-weight: 800; font-size: 1.2rem;
  box-shadow: var(--shadow-sm); user-select: none;
}
.scratch .secret-face { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; transition: opacity 0.5s; }
.scratch.revealed .cover { opacity: 0; }
.scratch.revealed .secret-face { opacity: 1; }
.scratch .cover { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity 0.5s; background: linear-gradient(135deg, #94a3b8, #64748b); }

/* ---------- الكشف النهائي ---------- */
.reveal-full {
  position: fixed; inset: 0; z-index: 9000; display: grid; place-items: center; text-align: center;
  padding: 24px; animation: fadeIn 0.6s ease both;
}
.reveal-full.boy { background: radial-gradient(circle at 50% 30%, #dbeafe, #60a5fa 70%, #2563eb); }
.reveal-full.girl { background: radial-gradient(circle at 50% 30%, #fce7f3, #f472b6 70%, #db2777); }
.reveal-full .big { font-size: clamp(2.4rem, 10vw, 6rem); font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,0.25); animation: pop 0.7s ease both; }
.reveal-full .sub { color: #fff; font-size: clamp(1.1rem, 3vw, 1.6rem); margin-top: 12px; font-weight: 700; }
.reveal-full .stats { margin-top: 22px; display: inline-flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.reveal-full .stat { background: rgba(255,255,255,0.85); border-radius: 14px; padding: 12px 18px; font-weight: 800; color: var(--text); }

/* ---------- توست ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all 0.3s; z-index: 10000; max-width: 90vw; text-align: center;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

/* ---------- متفرقات ---------- */
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 0.9s linear infinite; margin: 18px auto; }
.divider { height: 1px; background: var(--line); margin: 20px 0; }
.kbd { font-family: monospace; background: var(--primary-soft); padding: 2px 8px; border-radius: 6px; font-weight: 700; }
.qlist-item { border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; background: var(--card-solid); }
.tag { display:inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--primary-soft); color: var(--primary-600); }

/* ---------- حركات ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(var(--rtl, -14px)); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake 0.3s; }
.pulse { animation: pulseGlow 1.8s infinite; }
@keyframes pulseGlow { 0% { box-shadow: 0 0 0 0 rgba(124,58,237,0.45); } 70% { box-shadow: 0 0 0 18px rgba(124,58,237,0); } 100% { box-shadow: 0 0 0 0 rgba(124,58,237,0); } }

/* ---------- متجاوب ---------- */
@media (max-width: 720px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .how { grid-template-columns: 1fr; }
  .choice-cards { grid-template-columns: 1fr; }
  .tiles { gap: 10px; }
}
@media (max-width: 380px) {
  .tiles { grid-template-columns: 1fr; }
}
