/* ============================================================
   🎁 قرعة الهدايا التفاعلية — TikTok Live
   صندوق أوراق مغلقة بالنيون — Mobile first (بدون سكرول)
============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: #fff;
  font-family: 'Cairo', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(180, 92, 255, .17), transparent 62%),
    radial-gradient(820px 520px at 8% 108%, rgba(255, 46, 136, .15), transparent 62%),
    linear-gradient(180deg, #0c0718 0%, #060310 100%);
  background-attachment: fixed;
  overflow-y: auto;
}

#app {
  --glow: #ff2e88;
  --glow-soft: rgba(255, 46, 136, .45);
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  user-select: none;
}

/* ---------- الهيدر ---------- */
.topbar { display: flex; align-items: center; gap: 8px; }
.title-box { flex: 1; text-align: center; min-width: 0; }
.topbar-spacer { width: 34px; flex: none; }
/* أيقونة الضبط: شفافة 50% وأصغر */
#settingsBtn { width: 34px; height: 34px; font-size: 1rem; opacity: .5; }
#settingsBtn:active { opacity: 1; }
.neon-title {
  margin: 0;
  font-size: clamp(.95rem, 4.2vw, 1.18rem);
  font-weight: 900;
  letter-spacing: .3px;
  color: #fff;
  text-shadow: 0 0 6px rgba(255,255,255,.35), 0 0 14px var(--glow), 0 0 34px var(--glow-soft);
  animation: neonFlicker 6s linear infinite;
}
@keyframes neonFlicker {
  0%, 89%, 94%, 100% { opacity: 1; }
  90% { opacity: .8; }
  92% { opacity: .95; }
  96% { opacity: .85; }
}

.icon-btn {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.07);
  color: #fff; font-size: 1.1rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, opacity .2s;
}
.icon-btn:active { transform: scale(.88); }

/* ---------- أيقونات الهدايا (صور تيك توك) ---------- */
.gift-icon { object-fit: cover; display: block; background: #12101c; }
.rule-ico { flex: none; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; }
.rule-ico .gift-icon {
  width: 26px; height: 26px; border-radius: 7px;
  box-shadow: 0 0 10px rgba(255,255,255,.12);
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 45%, transparent);
}
.gb-ico { display: flex; align-items: center; justify-content: center; font-size: 2rem; filter: drop-shadow(0 0 10px var(--c)); }
.gb-ico .gift-icon {
  width: 44px; height: 44px; border-radius: 11px;
  border: 2px solid var(--c);
  box-shadow: 0 0 14px var(--c);
}
.result-gift .gift-icon {
  width: 84px; height: 84px; border-radius: 18px;
  border: 2px solid var(--glow);
  box-shadow: 0 0 24px var(--glow-soft);
  margin: 0 auto;
}

/* ---------- شروط اللعبة ---------- */
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; }
.rule-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 9px;
  border-radius: 13px;
  font-size: clamp(.66rem, 2.6vw, .76rem);
  font-weight: 400;
  line-height: 1.3;
  background: rgba(255,255,255,.05);
  border: 1.5px solid rgba(255,255,255,.22);
  border-color: color-mix(in srgb, var(--c) 55%, transparent);
  box-shadow: 0 0 10px rgba(255,255,255,.06), inset 0 0 14px rgba(0,0,0,.35);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 22%, transparent), inset 0 0 14px rgba(0,0,0,.35);
}

/* ---------- صندوق القرعة الزجاجي ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}
.draw-box-wrap { position: relative; width: min(84vw, 42dvh, 430px); }
.draw-box {
  position: relative;
  aspect-ratio: 1 / 0.82;
  border-radius: 26px;
  background:
    linear-gradient(160deg, rgba(255,255,255,.09), rgba(255,255,255,.02) 40%),
    rgba(16, 10, 30, .55);
  border: 2px solid var(--glow);
  box-shadow:
    0 0 34px var(--glow-soft),
    inset 0 0 40px rgba(0,0,0,.55),
    inset 0 0 8px var(--glow-soft);
  overflow: hidden;
  transition: box-shadow .5s ease, border-color .5s ease;
}
.draw-box.stirring { animation: boxShake .38s ease-in-out infinite; }
.draw-box.landed { box-shadow: 0 0 60px var(--glow), inset 0 0 40px rgba(0,0,0,.5), inset 0 0 8px var(--glow-soft); }
@keyframes boxShake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-5px, 3px) rotate(-1.1deg); }
  40% { transform: translate(5px, -3px) rotate(1deg); }
  60% { transform: translate(-4px, -2px) rotate(-0.8deg); }
  80% { transform: translate(4px, 2px) rotate(0.9deg); }
}
.papers { position: absolute; inset: 0; }
.glass {
  position: absolute; inset: 0; pointer-events: none;
  z-index: 45;
  border-radius: inherit;
  background:
    linear-gradient(115deg, rgba(255,255,255,.16) 0%, rgba(255,255,255,.05) 18%, transparent 34%),
    linear-gradient(295deg, rgba(255,255,255,.09) 0%, transparent 26%),
    radial-gradient(120% 90% at 50% 120%, rgba(0,0,0,.35), transparent 55%);
  transition: opacity .6s ease;
}
.draw-box.landed .glass { opacity: .35; }
.box-emblem {
  position: absolute; top: 9px; left: 50%; transform: translateX(-50%);
  z-index: 46;
  width: 44px; height: 44px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2a1a4d, #0d0718 75%);
  border: 2px solid var(--glow);
  box-shadow: 0 0 14px var(--glow-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  transition: border-color .5s ease;
}
.box-emblem img { width: 72%; height: 72%; border-radius: 50%; object-fit: cover; }

/* ---------- الأوراق المغلقة ---------- */
.paper {
  position: absolute;
  left: 50%; top: 50%;
  width: 21%;
  aspect-ratio: 0.72;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.45);
  perspective: 300px;
}
.paper-inner {
  position: absolute; inset: 0;
  border-radius: 5px;
  background: radial-gradient(circle at 50% 45%, #ffffff 0%, #f6ecd8 70%, #efe0c4 100%);
  border: 1px solid rgba(120, 90, 40, .35);
}
.paper-front {
  position: absolute; inset: 0;
  border-radius: 5px;
  background: linear-gradient(160deg, #fffdf5 0%, #f3e9d3 100%);
  border: 1px solid rgba(120, 90, 40, .35);
  display: flex; align-items: center; justify-content: center;
  transform-origin: top center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform .55s cubic-bezier(.5, 0, .3, 1);
}
.seal {
  width: 44%; aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gc, #ff2e88);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--gc, #ff2e88) 70%, #fff), var(--gc, #ff2e88));
  box-shadow: 0 1px 3px rgba(0,0,0,.4), inset 0 -2px 4px rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.92);
  font-weight: 900;
  font-size: clamp(.6rem, 2.2vw, .95rem);
}
.paper.open .paper-front { transform: rotateX(-178deg); }
.paper.winner { z-index: 44 !important; }
.paper.winner.open { filter: drop-shadow(0 0 14px var(--glow-soft)); }
.paper.winner.open .paper-inner { box-shadow: 0 0 20px var(--glow-soft), inset 0 0 16px var(--glow-soft); }

/* حركة التحريك اليدوي: كل ورقة تتأرجح بين موضعين فريدين */
.draw-box.stirring .paper {
  animation: paperStir var(--dur, .6s) ease-in-out var(--del, 0s) infinite;
}
@keyframes paperStir {
  0%   { transform: translate(-50%, -50%) rotate(var(--ba, 0deg)); }
  25%  { transform: translate(calc(-50% + var(--dx1, 0%)), calc(-50% + var(--dy1, 0%))) rotate(calc(var(--ba, 0deg) + var(--da1, 0deg))); }
  50%  { transform: translate(-50%, -50%) rotate(var(--ba, 0deg)); }
  75%  { transform: translate(calc(-50% + var(--dx2, 0%)), calc(-50% + var(--dy2, 0%))) rotate(calc(var(--ba, 0deg) + var(--da2, 0deg))); }
  100% { transform: translate(-50%, -50%) rotate(var(--ba, 0deg)); }
}

/* ---------- أزرار الهدايا ---------- */
.controls { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.gift-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gift-btn {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 88px;
  padding: 10px 8px 9px;
  border-radius: 18px;
  border: 2px solid var(--c);
  background: linear-gradient(160deg, rgba(255,255,255,.1), rgba(255,255,255,.02) 60%), rgba(10,6,20,.6);
  box-shadow: 0 0 14px rgba(255,255,255,.05), inset 0 0 20px rgba(0,0,0,.4);
  box-shadow: 0 0 16px color-mix(in srgb, var(--c) 30%, transparent), inset 0 0 20px rgba(0,0,0,.4);
  color: #fff; font-family: inherit;
  cursor: pointer;
  transition: transform .12s ease, opacity .25s ease;
  touch-action: manipulation;
}
.gift-btn:active { transform: scale(.94); }
.gift-btn.disabled { opacity: .35; pointer-events: none; }
.gb-label { font-size: .95rem; font-weight: 900; line-height: 1.2; text-align: center; text-shadow: 0 0 10px var(--c); }
.gift-btn::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 32%, rgba(255,255,255,.16) 50%, transparent 68%);
  transform: translateX(-130%);
  animation: sheen 3.4s ease-in-out infinite;
  pointer-events: none;
}
.gift-btn:nth-child(2)::after { animation-delay: .5s; }
.gift-btn:nth-child(3)::after { animation-delay: 1s; }
.gift-btn:nth-child(4)::after { animation-delay: 1.5s; }
@keyframes sheen { 55%, 100% { transform: translateX(130%); } }

/* ---------- شاشة النتيجة ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 22px 16px;
  background: rgba(6, 3, 12, .82);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}
.overlay.hidden { display: none; }
#confetti { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.result-card {
  position: relative; z-index: 2;
  width: min(92vw, 400px);
  text-align: center;
  padding: 24px 20px 22px;
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(44,24,78,.97), rgba(13,7,24,.99));
  border: 2.5px solid var(--glow);
  box-shadow: 0 0 46px var(--glow-soft), 0 26px 70px rgba(0,0,0,.65), inset 0 0 44px rgba(0,0,0,.5);
  animation: cardIn .55s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes cardIn { from { transform: scale(.55) translateY(34px); opacity: 0; } }
.result-gift {
  font-size: 3.6rem; line-height: 1;
  filter: drop-shadow(0 0 16px var(--glow-soft));
  animation: giftBounce 1.3s ease-in-out infinite;
}
@keyframes giftBounce { 50% { transform: translateY(-9px) scale(1.07); } }
.result-title { margin-top: 6px; font-size: 1.25rem; font-weight: 900; color: var(--glow); text-shadow: 0 0 14px var(--glow-soft); }
.result-value {
  margin: 12px 0 4px;
  font-size: clamp(2.2rem, 10.5vw, 3.3rem);
  font-weight: 900; line-height: 1.2;
  text-shadow: 0 0 20px var(--glow-soft);
  word-break: break-word;
}
.result-value.amount { color: #ffd23f; text-shadow: 0 0 20px rgba(255, 210, 63, .55); }
.result-value.debt { color: #ff6b6b; text-shadow: 0 0 20px rgba(255, 107, 107, .55); }
.res-main { display: block; }
.res-full { display: block; font-size: 1rem; font-weight: 800; opacity: .8; margin-top: 5px; text-shadow: none; letter-spacing: .5px; }
.result-value img {
  width: min(270px, 74vw);
  border-radius: 22px;
  border: 3px solid var(--glow);
  box-shadow: 0 0 26px var(--glow-soft);
  display: block; margin: 0 auto;
}
.photo-caption { display: block; margin-top: 9px; font-size: .98rem; font-weight: 800; opacity: .95; text-shadow: none; }
.result-value.pop { animation: valuePop .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes valuePop { from { transform: scale(.35); opacity: 0; } }
.result-actions { margin-top: 18px; display: flex; justify-content: center; }
.btn-primary {
  font-family: inherit; font-size: 1.05rem; font-weight: 900;
  padding: 12px 36px; border-radius: 999px; border: none; cursor: pointer;
  color: #241500;
  background: linear-gradient(135deg, #ffd23f, #ff9d2e);
  box-shadow: 0 0 24px var(--glow-soft), 0 8px 24px rgba(0,0,0,.45);
  transition: transform .12s ease;
  touch-action: manipulation;
}
.btn-primary:active { transform: scale(.93); }

/* ---------- لوحة الإعدادات ---------- */
.settings-card {
  position: relative; z-index: 2;
  width: min(94vw, 520px);
  max-height: 86dvh;
  overflow-y: auto;
  text-align: right;
  padding: 20px 18px;
  border-radius: 24px;
  background: linear-gradient(165deg, rgba(44,24,78,.97), rgba(13,7,24,.99));
  border: 2px solid #22e0ff;
  box-shadow: 0 0 40px rgba(34,224,255,.25), 0 26px 70px rgba(0,0,0,.65);
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.settings-head h2 { margin: 0; font-size: 1.2rem; font-weight: 900; color: #22e0ff; text-shadow: 0 0 12px rgba(34,224,255,.5); }
.settings-title { font-size: 1rem; font-weight: 900; margin-top: 6px; }
.settings-hint { margin: 4px 0 10px; font-size: .8rem; opacity: .75; line-height: 1.6; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.btn-ghost {
  font-family: inherit; font-weight: 800; font-size: .9rem;
  color: #fff;
  background: rgba(255,255,255,.07);
  border: 1.5px solid rgba(255,255,255,.2);
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform .12s ease;
}
.btn-ghost:active { transform: scale(.95); }
.btn-primary[for] { display: inline-flex; align-items: center; padding: 10px 20px; font-size: .95rem; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.photo-cell {
  position: relative; border-radius: 12px; overflow: hidden;
  border: 1.5px solid rgba(255,255,255,.15);
  background: #12101c;
  aspect-ratio: 1 / 1;
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-rm {
  position: absolute; top: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(255, 60, 60, .92);
  color: #fff; font-size: .75rem; line-height: 1;
  cursor: pointer;
}
.photo-tag {
  position: absolute; bottom: 0; inset-inline: 0;
  background: rgba(0,0,0,.65);
  color: #ffd23f;
  font-size: .6rem; font-weight: 800;
  text-align: center; padding: 2px 0;
}

/* تبويب الذكور/الإناث في الإعدادات */
.photo-tabs { display: flex; gap: 8px; margin: 4px 0 12px; }
.ptab {
  flex: 1;
  font-family: inherit; font-size: .95rem; font-weight: 900;
  padding: 10px 8px; border-radius: 999px; cursor: pointer;
  color: #fff;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.2);
  transition: transform .12s ease, box-shadow .2s ease, border-color .2s ease;
}
.ptab:active { transform: scale(.96); }
.ptab.active[data-g="male"] { border-color: #3d8bfd; background: rgba(61,139,253,.16); box-shadow: 0 0 14px rgba(61,139,253,.45); }
.ptab.active[data-g="female"] { border-color: #ff2e88; background: rgba(255,46,136,.16); box-shadow: 0 0 14px rgba(255,46,136,.45); }
.photo-panel {
  border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 12px;
  background: rgba(0,0,0,.18);
}
.photo-panel.hidden { display: none; }
.count-line { margin-top: 10px; text-align: center; font-size: .75rem; font-weight: 700; opacity: .8; }
#settingsDoneBtn { margin-top: 16px; width: 100%; }

/* زر الصوت داخل الإعدادات */
.mute-toggle { width: 100%; margin: 0 0 12px; font-size: .92rem; }
.mute-toggle.muted { border-color: rgba(255, 107, 107, .75); color: #ffb3b3; box-shadow: 0 0 12px rgba(255, 107, 107, .25); }

/* صندوق الكود الاحتياطي */
.backup-code {
  width: 100%; min-height: 62px; resize: vertical;
  font-family: 'Cairo', monospace; font-size: .72rem; line-height: 1.6;
  color: #cfe9ff;
  background: rgba(0,0,0,.35);
  border: 1.5px solid rgba(34,224,255,.35);
  border-radius: 12px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.backup-code:focus { outline: none; border-color: rgba(34,224,255,.8); }

/* ---------- اختيار الجنس (قبل قرعة صورة الشريك) ---------- */
#genderOverlay { z-index: 60; }
.gender-card {
  position: relative; z-index: 2;
  width: min(90vw, 370px);
  text-align: center;
  padding: 26px 20px 18px;
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(44,24,78,.97), rgba(13,7,24,.99));
  border: 2.5px solid #ff9d2e;
  box-shadow: 0 0 46px rgba(255,157,46,.4), 0 26px 70px rgba(0,0,0,.65), inset 0 0 40px rgba(0,0,0,.5);
  animation: cardIn .45s cubic-bezier(.34, 1.56, .64, 1);
}
.gender-ico { font-size: 2.7rem; line-height: 1; filter: drop-shadow(0 0 14px rgba(255,157,46,.6)); animation: giftBounce 1.3s ease-in-out infinite; }
.gender-q { margin: 10px 0 16px; font-size: 1.12rem; font-weight: 900; }
.gender-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gender-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: inherit; font-size: 1.15rem; font-weight: 900; color: #fff;
  padding: 18px 10px 14px; border-radius: 18px; cursor: pointer;
  background: rgba(255,255,255,.05);
  border: 2px solid rgba(255,255,255,.25);
  touch-action: manipulation;
  transition: transform .12s ease, box-shadow .2s ease;
}
.gender-btn .g-emoji { font-size: 2.5rem; line-height: 1.1; }
.gender-btn.male { border-color: #3d8bfd; box-shadow: 0 0 16px rgba(61,139,253,.45); }
.gender-btn.male .g-emoji { filter: drop-shadow(0 0 10px rgba(61,139,253,.8)); }
.gender-btn.female { border-color: #ff2e88; box-shadow: 0 0 16px rgba(255,46,136,.45); }
.gender-btn.female .g-emoji { filter: drop-shadow(0 0 10px rgba(255,46,136,.8)); }
.gender-btn:active { transform: scale(.93); }
.gender-cancel {
  margin-top: 16px;
  font-family: inherit; font-size: .9rem; font-weight: 800;
  color: #fff; background: none; border: none; opacity: .6; cursor: pointer;
}
.gender-cancel:active { opacity: 1; }

/* شارة الجنس على بطاقة النتيجة */
.photo-badge {
  display: inline-block;
  margin: 0 auto 10px;
  padding: 3px 16px;
  border-radius: 999px;
  font-size: .82rem; font-weight: 800;
  background: rgba(255,255,255,.08);
  border: 1.5px solid var(--glow);
  box-shadow: 0 0 12px var(--glow-soft);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(16px);
  max-width: 90vw; text-align: center;
  padding: 9px 18px; border-radius: 999px;
  background: rgba(22, 12, 40, .96);
  border: 1.5px solid rgba(34, 224, 255, .6);
  color: #fff; font-size: .85rem; font-weight: 800;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 99;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- شاشات كبيرة (تابلت) ---------- */
@media (min-width: 720px) {
  #app { max-width: 640px; }
  .rules { grid-template-columns: repeat(4, 1fr); }
  .draw-box-wrap { width: min(40vh, 440px); }
  .gb-label { font-size: 1.1rem; }
}

/* ---------- الهاتف أفقي (ارتفاع قصير) ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #app { gap: 6px; }
  .rules { grid-template-columns: repeat(4, 1fr); }
  .draw-box-wrap { width: min(62dvh, 340px); }
  .gift-btn { min-height: 76px; }
  .gb-ico .gift-icon { width: 40px; height: 40px; }
}

/* ---------- حساسية الحركة ---------- */
@media (prefers-reduced-motion: reduce) {
  .neon-title, .draw-box.stirring, .gift-btn::after, .result-gift, .gender-ico { animation: none !important; }
}
