/* =========================================================
   حَبْكَة | الهوية الخاصة فوق هوية أثَر
   المكان: مشغل حياكة ليلي. الإجابات خيوط، والحقيقة الخيط الذهبي.
   ألوان الحالات: ذهبي = الحقيقة والكسب، قرمزي = التمويه والانخداع، فيروزي = تم وأُرسل
   ========================================================= */

/* ---------- ثيم اللعبة الخاص: قماش الليل (الافتراضي) ---------- */
[data-theme="habka"]{
  --bg:#1B1030;
  --bg-paint:
    radial-gradient(900px 480px at 50% -12%, rgba(245,184,61,.17), transparent 62%),
    radial-gradient(700px 520px at 105% 105%, rgba(229,72,77,.15), transparent 60%),
    radial-gradient(600px 420px at -5% 70%, rgba(130,87,229,.16), transparent 60%),
    #1B1030;
  --text:#FBF3E4; --text-2:#D9C8E8;
  --accent:#F5B83D; --accent-hover:#FFD27A; --on-accent:#2A1503;
  --hl:#F5B83D; --hl-2:#FFD27A;
  --surface:rgba(255,255,255,.06); --surface-2:rgba(255,255,255,.12);
  --solid:#2A1946; --line:rgba(251,243,228,.17);
  --cell:rgba(255,255,255,.09); --cell-label:rgba(251,243,228,.45);
  --shadow:0 10px 30px rgba(0,0,0,.38); --scrim:rgba(10,4,22,.78);
}
[data-theme="habka"] .logo-main{display:none;}
[data-theme="habka"] .logo-rev{display:block;}
.theme-dot[data-set-theme="habka"]{background:linear-gradient(135deg,#1B1030 50%,#F5B83D 50%);}

/* ألوان الحالات لكل ثيم */
:root{--gold:#F5B83D; --gold-d:#A8700A; --on-gold:#2A1503; --lie:#E5484D; --lie-d:#9C2327; --ok:#2FBF9B; --deep:rgba(0,0,0,.32);}
[data-theme="light"]{--gold:#E9A51B; --gold-d:#A8700A; --lie:#D93A40; --ok:#149A79; --deep:rgba(10,36,99,.20);}
[data-theme="blue"]{--gold:#FFD166; --lie:#FF6B6F; --ok:#7CF2D2; --deep:rgba(8,40,110,.45);}

/* ---------- الأساس ---------- */
*{box-sizing:border-box; margin:0;}
html,body{overflow-x:clip;}
html{-webkit-text-size-adjust:100%;}
body{min-height:100dvh; font-family:"Thmanyah Sans","IBM Plex Sans Arabic",system-ui,sans-serif; font-weight:500;
  color:var(--text); background:var(--bg-paint); background-attachment:fixed; line-height:1.7; -webkit-tap-highlight-color:transparent;}
button,input{font:inherit; color:inherit;}
button{cursor:pointer; border:0; background:none;}
[hidden]{display:none !important;}
/* نسيج القماش + نقش أدوات الحياكة */
body::before{content:""; position:fixed; inset:0; z-index:-1; pointer-events:none; opacity:.05; background:var(--text);
  -webkit-mask:url(img/pattern.svg) 0 0/220px; mask:url(img/pattern.svg) 0 0/220px;}
body::after{content:""; position:fixed; inset:0; z-index:-1; pointer-events:none; opacity:.035;
  background:repeating-linear-gradient(0deg,var(--text) 0 1px,transparent 1px 4px),repeating-linear-gradient(90deg,var(--text) 0 1px,transparent 1px 4px);}

/* ---------- الشريط العلوي ---------- */
.topbar{display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px clamp(12px,3vw,28px);}
.brand{display:flex; align-items:center; gap:10px; min-width:0; text-decoration:none; color:inherit;}
.brand .logo{height:46px; width:auto; flex:none;}
.brand-text{display:flex; flex-direction:column; min-width:0; line-height:1.35;}
.brand-text strong{font-size:1.15rem;}
.brand-text small{color:var(--text-2); font-size:.8rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:42vw;}
.top-tools{display:flex; align-items:center; gap:8px; flex:none;}
.icon-btn{width:40px; height:40px; border-radius:50%; display:grid; place-items:center; background:var(--surface); border:1px solid var(--line);}
.snd .bars{display:flex; align-items:center; gap:3px; height:18px;}
.snd .bars i{width:3.5px; height:100%; border-radius:3px; background:var(--text); transform-origin:50% 100%; transform:scaleY(.35);}
.snd[aria-pressed="true"] .bars i{animation:eq 1s ease-in-out infinite;}
.snd[aria-pressed="true"] .bars i:nth-child(2){animation-delay:-.35s; animation-duration:.8s;}
.snd[aria-pressed="true"] .bars i:nth-child(3){animation-delay:-.6s; animation-duration:1.15s;}
.snd[aria-pressed="true"] .bars i:nth-child(4){animation-delay:-.2s; animation-duration:.9s;}
@keyframes eq{0%,100%{transform:scaleY(.3);}50%{transform:scaleY(1);}}
.snd[aria-pressed="false"] .bars{opacity:.45;}
.net{display:flex; align-items:center; gap:6px; font-size:.75rem; padding:4px 10px; border-radius:999px; background:var(--surface); border:1px solid var(--line);}
.net i{width:8px; height:8px; border-radius:50%; background:var(--lie);}
.net[data-on="true"] i{background:var(--ok); box-shadow:0 0 0 0 var(--ok); animation:live 1.8s ease-out infinite;}
@keyframes live{to{box-shadow:0 0 0 8px transparent;}}
.theme-dot{width:26px; height:26px;}
@media (max-width:520px){ .net b{display:none;} .theme-switch{gap:4px; padding:4px;} .theme-dot{width:22px; height:22px;} }

/* ---------- المسرح ---------- */
#stage{width:min(100%,720px); margin:0 auto; padding:6px clamp(14px,4vw,24px) 40px;}
.scene{display:grid; gap:16px;}
h1,h2,h3{line-height:1.4;}
.kicker{display:inline-flex; align-items:center; gap:8px; font-size:.85rem; font-weight:700; color:var(--gold); letter-spacing:0;}
.kicker::before{content:""; width:22px; border-top:2.5px dashed var(--gold);}
.muted{color:var(--text-2); font-size:.92rem;}
.center{text-align:center; justify-items:center;}

/* أزرار مجسّمة تنزل عند الضغط */
.btn{display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:52px; padding:10px 22px; border-radius:16px; font-weight:700; font-size:1.05rem;
  background:var(--gold); color:var(--on-gold); box-shadow:0 5px 0 var(--gold-d); transition:transform .08s ease-out, box-shadow .08s ease-out, filter .15s; touch-action:manipulation; user-select:none;}
.btn.is-down{transform:translateY(4px); box-shadow:0 1px 0 var(--gold-d);}
.btn.ghost{background:var(--surface-2); color:var(--text); box-shadow:0 5px 0 var(--deep); border:1px solid var(--line);}
.btn.ghost.is-down{box-shadow:0 1px 0 var(--deep);}
.btn.lie{background:var(--lie); color:#fff; box-shadow:0 5px 0 var(--lie-d);}
.btn.lie.is-down{box-shadow:0 1px 0 var(--lie-d);}
.btn:disabled{filter:grayscale(.7) opacity(.55); cursor:not-allowed;}
.btn.wide{width:100%;}
.btn.small{min-height:40px; padding:6px 14px; font-size:.9rem; border-radius:12px; box-shadow:0 3px 0 var(--deep);}
.row{display:flex; gap:10px; flex-wrap:wrap;}
.row > *{flex:1 1 150px;}

.card{background:var(--solid); border:1px solid var(--line); border-radius:22px; padding:18px; box-shadow:var(--shadow);}
/* حافة مخيّطة */
.stitched{position:relative;}
.stitched::after{content:""; position:absolute; inset:7px; border:2px dashed color-mix(in srgb,var(--gold) 55%,transparent); border-radius:16px; pointer-events:none;}

.field{width:100%; min-height:56px; padding:10px 16px; border-radius:16px; background:var(--surface); border:2px solid var(--line); font-size:1.1rem; font-weight:700; outline:none; transition:border-color .15s, box-shadow .15s;}
.field:focus{border-color:var(--gold); box-shadow:0 0 0 4px color-mix(in srgb,var(--gold) 25%,transparent);}
.field::placeholder{color:var(--cell-label); font-weight:500;}

/* ---------- صورة البطل: إبرة تحبك عقدة ---------- */
.hero{display:grid; justify-items:center; gap:2px; padding-top:6px;}
.hero svg{width:min(260px,62vw); height:auto; overflow:visible;}
.hero .thread{fill:none; stroke:var(--gold); stroke-width:5; stroke-linecap:round; stroke-dasharray:640; stroke-dashoffset:640; animation:sew 1.5s cubic-bezier(.16,1,.3,1) .15s forwards;}
.hero .thread.b{stroke:var(--lie); stroke-width:4; animation-delay:.45s;}
.hero .needle{transform-origin:206px 40px; animation:needle 3.2s ease-in-out infinite;}
.hero .needle path{fill:var(--text);} .hero .needle ellipse{fill:var(--bg);}
.hero .knot{fill:var(--gold); transform-origin:130px 78px; transform:scale(0); animation:knot .5s var(--spring,cubic-bezier(.34,1.5,.64,1)) 1.2s forwards;}
@keyframes sew{to{stroke-dashoffset:0;}}
@keyframes needle{0%,100%{transform:rotate(0);}50%{transform:rotate(-7deg) translateY(-3px);}}
@keyframes knot{to{transform:scale(1);}}
.title{font-size:clamp(2.6rem,11vw,4rem); font-weight:700; line-height:1.5;}
.title b{color:var(--gold);}
.tag{font-size:1.05rem; color:var(--text-2); text-align:center; max-width:30ch;}

.steps{display:grid; grid-template-columns:repeat(3,1fr); gap:10px;}
.step{background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:12px 10px; text-align:center; font-size:.85rem; line-height:1.55;}
.step b{display:grid; place-items:center; width:30px; height:30px; margin:0 auto 6px; border-radius:50%; background:var(--gold); color:var(--on-gold);}
.step em{font-style:normal; color:var(--gold); font-weight:700;}
.note{font-size:.82rem; color:var(--text-2); background:var(--surface); border:1px dashed var(--line); border-radius:12px; padding:8px 12px; text-align:center;}

/* ---------- أزرار الخياطة (اللاعبون) ---------- */
.pl{--c:#8257E5; display:grid; justify-items:center; gap:3px; width:64px; text-align:center; position:relative;}
.pl .bt{position:relative; width:46px; height:46px; border-radius:50%; background:var(--c); box-shadow:inset 0 -4px 0 rgba(0,0,0,.25), inset 0 0 0 4px rgba(255,255,255,.22), 0 3px 0 rgba(0,0,0,.25);
  display:grid; place-items:center; color:#fff; font-weight:700; font-size:1.15rem; transition:filter .25s, transform .25s;}
.pl .bt::before{content:""; position:absolute; inset:5px; border-radius:50%; border:2px dashed rgba(255,255,255,.55);}
.pl .bt span{position:relative; text-shadow:0 1px 2px rgba(0,0,0,.5);}
.pl .nm{font-size:.72rem; font-weight:700; max-width:64px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.pl .sc{font-size:.7rem; color:var(--text-2);}
.pl.me .nm{color:var(--gold);}
.pl .tick{position:absolute; top:-4px; inset-inline-start:4px; width:20px; height:20px; border-radius:50%; background:var(--ok); color:#06261d; font-size:.75rem; display:grid; place-items:center; font-weight:700; transform:scale(0); transition:transform .3s var(--spring,ease);}
.pl.done .tick{transform:scale(1);}
.pl .crown{position:absolute; top:-12px; inset-inline-end:6px; font-size:.7rem; background:var(--gold); color:var(--on-gold); border-radius:6px; padding:0 5px; line-height:1.5;}
/* خرج من اللعبة: الزر ينطفئ ويتشقق وعليه عين مشطوبة */
.pl.away .bt{filter:grayscale(1) brightness(.75); animation:wob 1.1s ease-in-out infinite; outline:2.5px dashed var(--lie); outline-offset:3px;}
.pl.away .bt span{visibility:hidden;}
.pl.away .bt::after{content:""; position:absolute; inset:9px; background:#fff;
  -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M4 3l16 18'/%3E%3C/svg%3E") center/contain no-repeat;
  mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M4 3l16 18'/%3E%3C/svg%3E") center/contain no-repeat;}
.pl.away .nm{color:var(--lie);}
.pl .outs{position:absolute; top:-8px; inset-inline-end:0; white-space:nowrap; font-size:.62rem; background:var(--lie); color:#fff; border-radius:8px; padding:0 5px; line-height:1.6; font-weight:700;}
.pl.off .bt{filter:grayscale(1) opacity(.45);}
@keyframes wob{0%,100%{transform:rotate(-7deg);}50%{transform:rotate(7deg);}}

.strip{display:flex; gap:4px; padding:8px clamp(12px,4vw,24px) 4px; overflow-x:auto; scrollbar-width:none; width:min(100%,720px); margin:0 auto;}
.strip::-webkit-scrollbar{display:none;}
.strip .pl{flex:none; width:56px;}
.strip .pl .bt{width:38px; height:38px; font-size:1rem;}
.players{display:flex; flex-wrap:wrap; gap:12px 8px; justify-content:center; min-height:76px;}

/* ---------- الغرفة ---------- */
.code{display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;}
.code b{font-size:clamp(2rem,9vw,2.8rem); letter-spacing:.12em; color:var(--gold); direction:ltr; line-height:1.2;}
.set{display:grid; gap:8px;}
.set > span{font-size:.85rem; font-weight:700; color:var(--text-2);}
.chips{display:flex; flex-wrap:wrap; gap:8px;}
.chip{min-height:42px; padding:6px 14px; border-radius:12px; background:var(--surface); border:1.5px solid var(--line); font-weight:700; font-size:.92rem; box-shadow:0 3px 0 var(--deep); transition:transform .08s, box-shadow .08s, background .15s; touch-action:manipulation;}
.chip.is-down{transform:translateY(3px); box-shadow:0 0 0 var(--deep);}
.chip[aria-pressed="true"]{background:var(--gold); color:var(--on-gold); border-color:transparent; box-shadow:0 3px 0 var(--gold-d);}
.chip:disabled{opacity:.75; cursor:default;}

/* ---------- المؤقت: خيط ينسلّ من البكرة ---------- */
.timer{--p:1; display:flex; align-items:center; gap:10px;}
.timer .track{flex:1; height:10px; border-radius:99px; background:var(--cell); overflow:hidden;}
.timer .fill{height:100%; width:100%; border-radius:99px; transform-origin:100% 50%; transform:scaleX(var(--p));
  background:repeating-linear-gradient(-45deg,var(--gold) 0 8px,color-mix(in srgb,var(--gold) 70%,#000) 8px 12px);}
.timer .sec{min-width:2.4ch; text-align:center; font-weight:700; font-size:1.15rem; font-variant-numeric:tabular-nums;}
.timer.hot .fill{background:repeating-linear-gradient(-45deg,var(--lie) 0 8px,var(--lie-d) 8px 12px);}
.timer.hot .sec{color:var(--lie); animation:beat .5s ease-in-out infinite;}
@keyframes beat{50%{transform:scale(1.22);}}

/* ---------- السؤال ---------- */
.q{text-align:center; padding:22px 18px;}
.q .cat{display:inline-block; font-size:.78rem; font-weight:700; padding:2px 12px; border-radius:99px; background:var(--surface-2); color:var(--text-2); margin-bottom:8px;}
.q p{font-size:clamp(1.2rem,5vw,1.6rem); font-weight:700; line-height:1.7;}
.q.mini{padding:12px 14px;} .q.mini p{font-size:clamp(1rem,4vw,1.2rem);}
.mo-w{display:inline-block; will-change:transform;}

.wait{display:grid; justify-items:center; gap:8px; text-align:center; padding:18px;}
.wait .spool{width:58px; height:58px; border-radius:50%; border:6px dashed var(--gold); animation:spin 4s linear infinite;}
.wait.ok .spool{border-color:var(--ok);}
@keyframes spin{to{transform:rotate(-360deg);}}
.err{color:var(--lie); font-weight:700; font-size:.92rem; min-height:1.6em; text-align:center;}

/* ---------- اختيار الفئة ---------- */
.cats{display:grid; gap:12px;}
.cat-card{display:flex; align-items:center; gap:12px; text-align:start; padding:16px 18px; border-radius:18px; background:var(--solid); border:2px solid var(--line); font-weight:700; font-size:1.15rem; box-shadow:0 5px 0 var(--deep); transition:transform .08s, box-shadow .08s; touch-action:manipulation;}
.cat-card i{flex:none; width:38px; height:38px; border-radius:50%; background:var(--gold); color:var(--on-gold); display:grid; place-items:center; font-style:normal;}
.cat-card.is-down{transform:translateY(4px); box-shadow:0 1px 0 var(--deep);}
.cat-card:disabled{cursor:default;}
.cat-card.picked{border-color:var(--gold); background:color-mix(in srgb,var(--gold) 16%,var(--solid));}

/* ---------- خيارات التصويت ---------- */
.opts{display:grid; gap:12px; grid-template-columns:1fr;}
@media (min-width:600px){ .opts{grid-template-columns:1fr 1fr;} }
.opt{position:relative; display:grid; gap:6px; align-content:center; min-height:68px; padding:12px 16px; text-align:start; border-radius:18px; background:var(--solid); border:2px solid var(--line);
  font-weight:700; font-size:1.1rem; line-height:1.6; box-shadow:0 5px 0 var(--deep); transition:transform .08s ease-out, box-shadow .08s ease-out, border-color .2s, background .25s, opacity .25s; touch-action:manipulation; overflow:hidden;}
.opt.is-down{transform:translateY(4px); box-shadow:0 1px 0 var(--deep);}
.opt .tx{position:relative; z-index:1; overflow-wrap:anywhere;}
.opt[aria-disabled="true"]{cursor:default;}
.opt.mine{opacity:.55; border-style:dashed;}
.opt.mine::after{content:"تمويهك"; position:absolute; top:6px; inset-inline-end:10px; font-size:.68rem; color:var(--text-2);}
.opt.chosen{border-color:var(--gold); background:color-mix(in srgb,var(--gold) 18%,var(--solid)); box-shadow:0 5px 0 var(--gold-d);}
.opts.locked .opt:not(.chosen):not(.mine){opacity:.6;}
/* الكشف */
.opt .meta{display:flex; flex-wrap:wrap; align-items:center; gap:6px; font-size:.8rem; font-weight:700; color:var(--text-2);}
.opt .who{display:inline-flex; align-items:center; gap:4px; padding:1px 8px 1px 4px; border-radius:99px; background:var(--surface-2); color:var(--text);}
.opt .who i{width:14px; height:14px; border-radius:50%; background:var(--c);}
.opt .stamp{position:absolute; top:8px; inset-inline-end:10px; z-index:2; padding:0 10px; border:2.5px solid currentColor; border-radius:8px; font-size:.82rem; transform:rotate(-8deg); letter-spacing:0; background:color-mix(in srgb,var(--solid) 80%,transparent);}
.opt.is-fake{border-color:var(--lie); background:color-mix(in srgb,var(--lie) 13%,var(--solid)); box-shadow:0 5px 0 var(--lie-d);}
.opt.is-fake .stamp{color:var(--lie);}
.opt.is-true{border-color:var(--gold); background:color-mix(in srgb,var(--gold) 22%,var(--solid)); box-shadow:0 5px 0 var(--gold-d), 0 0 0 4px color-mix(in srgb,var(--gold) 30%,transparent);}
.opt.is-true .stamp{color:var(--gold);}
.opt.is-dim{opacity:.5;}
.verdict{text-align:center; font-size:1.2rem; font-weight:700; padding:12px; border-radius:16px; background:var(--surface);}
.verdict.good{color:var(--gold);} .verdict.bad{color:var(--lie);}

/* ---------- النتائج ---------- */
.board{display:grid; gap:8px;}
.brow{--c:#8257E5; display:flex; align-items:center; gap:10px; padding:8px 14px; border-radius:14px; background:var(--solid); border:1px solid var(--line);}
.brow .rk{width:1.6em; text-align:center; font-weight:700; color:var(--text-2);}
.brow i{flex:none; width:26px; height:26px; border-radius:50%; background:var(--c); box-shadow:inset 0 0 0 3px rgba(255,255,255,.22);}
.brow .nm{flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:700;}
.brow .dl{font-size:.8rem; font-weight:700; color:var(--on-gold); background:var(--gold); border-radius:8px; padding:0 8px; direction:ltr;}
.brow .pt{min-width:2.5ch; text-align:center; font-weight:700; font-size:1.2rem; font-variant-numeric:tabular-nums;}
.brow.me{border-color:var(--gold);}
.brow.first .rk{color:var(--gold);}

/* ---------- المنصة ---------- */
.podium{display:flex; align-items:flex-end; justify-content:center; gap:10px; height:250px; padding-top:10px;}
.pod{--c:#8257E5; --h:120px; flex:1; max-width:130px; display:grid; justify-items:center; gap:4px;}
.pod .pl{width:auto;}
.pod .bar{width:100%; height:var(--h); border-radius:14px 14px 4px 4px; background:linear-gradient(var(--c),color-mix(in srgb,var(--c) 60%,#000)); display:grid; place-items:start center; padding-top:8px; font-weight:700; font-size:1.5rem; color:#fff; transform-origin:50% 100%; box-shadow:inset 0 0 0 3px rgba(255,255,255,.15);}
.pod.p1{--h:150px;} .pod.p2{--h:110px;} .pod.p3{--h:80px;}
.pod.p1 .bt{box-shadow:inset 0 -4px 0 rgba(0,0,0,.25), inset 0 0 0 4px rgba(255,255,255,.22), 0 0 0 4px var(--gold), 0 0 26px var(--gold);}
.win-name{font-size:clamp(1.6rem,7vw,2.4rem); font-weight:700; color:var(--gold); text-align:center;}

/* ---------- نافذة وتنبيه وقصاصات ---------- */
.modal{position:fixed; inset:0; z-index:70; display:grid; place-items:center; padding:20px; background:var(--scrim);}
.modal-card{width:min(100%,380px); background:var(--solid); border:1px solid var(--line); border-radius:22px; padding:22px; display:grid; gap:16px; text-align:center; font-weight:700;}
.modal-row{display:flex; gap:10px;} .modal-row .btn{flex:1;}
.toast{position:fixed; bottom:22px; left:50%; transform:translateX(-50%); z-index:80; background:var(--text); color:var(--bg); padding:8px 18px; border-radius:99px; font-weight:700; font-size:.92rem; max-width:90vw; text-align:center;}
#confetti{position:fixed; inset:0; width:100%; height:100%; z-index:60; pointer-events:none;}

@media (max-width:420px){ .steps{grid-template-columns:1fr;} .step{display:flex; align-items:center; gap:10px; text-align:start;} .step b{margin:0; flex:none;} }
@media (prefers-reduced-motion: reduce){
  .hero .thread{animation:none; stroke-dashoffset:0;} .hero .knot{animation:none; transform:none;}
  .hero .needle,.pl.away .bt,.wait .spool,.timer.hot .sec,.snd .bars i,.net i{animation:none !important;}
}
