:root{
    --teal:#4DA6A6;
    --sage:#7DBD9C;
    --cream:#F2E9DB;
    --amber:#F5C16C;
    --slate:#6D7A85;
    --night:#141E30;
    --night2:#1F2E4A;
    --ink:#2B2620;
    --card:#FFFFFF;
    --danger:#C1594F;
    --radius:22px;
  }
  *{box-sizing:border-box; margin:0; padding:0;}
  html,body{height:100%;}
  body{
    font-family:'Cairo', sans-serif;
    background: radial-gradient(1200px 800px at 50% -10%, #EDE3D0 0%, #DDD0B6 55%, #C9BB9C 100%);
    color:var(--ink);
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:20px;
  }
  .phone{
    width:100%;
    max-width:430px;
    height:min(92vh, 900px);
    background:var(--cream);
    border-radius:38px;
    box-shadow:0 30px 60px -20px rgba(20,15,5,.45), 0 0 0 10px #fff, 0 0 0 12px #cbbfa2;
    overflow:hidden;
    position:relative;
    display:flex;
    flex-direction:column;
  }
  .screen{
    position:absolute;
    inset:0;
    display:flex;
    flex-direction:column;
    padding:26px 22px 22px;
    opacity:0;
    pointer-events:none;
    transform: translateY(14px);
    transition: opacity .35s ease, transform .35s ease;
    overflow-y:auto;
  }
  .screen.active{
    opacity:1;
    pointer-events:auto;
    transform: translateY(0);
  }
  .screen.night{
    background: linear-gradient(180deg, var(--night) 0%, var(--night2) 100%);
    color:#EDE9DD;
  }
  .screen.dark-card{ color:#EDE9DD; }

  h1,h2,h3{ font-family:'Tajawal', sans-serif; }

  .eyebrow{
    font-size:13px;
    color:var(--slate);
    letter-spacing:.5px;
    margin-bottom:6px;
    font-weight:600;
  }
  .night .eyebrow{ color:#9FB2C9; }

  /* HOME */
  .home-hero{
    flex:1;
    display:flex;
    flex-direction:column;
    justify-content:flex-end;
    background:
      radial-gradient(120px 120px at 78% 18%, rgba(245,193,108,.5), transparent 70%),
      linear-gradient(180deg, #2C3E56 0%, #45607E 55%, #6D7A85 100%);
    border-radius:26px;
    padding:26px 20px;
    position:relative;
    overflow:hidden;
    margin-bottom:18px;
    min-height:340px;
  }
  .skyline{
    position:absolute; bottom:0; left:0; right:0; height:120px;
    background: linear-gradient(180deg, transparent, rgba(20,25,35,.55));
  }
  .moon{
    position:absolute; top:26px; left:26px; width:46px; height:46px; border-radius:50%;
    background:var(--amber); box-shadow:0 0 40px 10px rgba(245,193,108,.45);
  }
  .home-title{
    color:#fff; font-size:34px; font-weight:900; line-height:1.15; position:relative; z-index:2;
  }
  .home-sub{
    color:#D9E2EA; font-size:13px; margin-top:8px; position:relative; z-index:2;
  }
  .menu{ display:flex; flex-direction:column; gap:10px; }
  .btn{
    display:flex; align-items:center; justify-content:center; gap:8px;
    border:none; cursor:pointer;
    font-family:'Cairo',sans-serif; font-weight:700; font-size:15px;
    padding:16px 18px; border-radius:16px;
    transition: transform .15s ease, filter .15s ease;
  }
  .btn:active{ transform: scale(.97); }
  .btn-primary{ background:linear-gradient(135deg, var(--teal), #3E8F8F); color:#fff; box-shadow:0 10px 20px -8px rgba(77,166,166,.6);}
  .btn-secondary{ background:#fff; color:var(--ink); border:1.5px solid #E4D9C3; }
  .btn-ghost{ background:transparent; color:var(--slate); font-weight:600; }
  .btn-danger{ background:linear-gradient(135deg,#C1594F,#9C3D34); color:#fff; }
  .btn-amber{ background:linear-gradient(135deg,var(--amber),#E0A24A); color:#3A2A0E; }
  .btn:disabled{ opacity:.4; cursor:not-allowed; }

  /* SETUP */
  .field{ margin-bottom:18px; }
  .field label{ display:block; font-weight:700; font-size:14px; margin-bottom:8px; }
  .stepper{ display:flex; align-items:center; justify-content:space-between; background:#fff; border-radius:14px; padding:10px 14px; border:1.5px solid #E4D9C3; }
  .stepper button{ width:38px; height:38px; border-radius:10px; border:none; background:var(--cream); font-size:20px; font-weight:700; color:var(--teal); cursor:pointer; }
  .stepper .val{ font-size:20px; font-weight:800; }
  .chips{ display:flex; gap:8px; flex-wrap:wrap; }
  .chip{ padding:10px 14px; border-radius:12px; background:#fff; border:1.5px solid #E4D9C3; font-size:13px; font-weight:600; cursor:pointer; color:var(--ink); }
  .chip.active{ background:var(--teal); color:#fff; border-color:var(--teal); }
  .toggle-row{ display:flex; align-items:center; justify-content:space-between; background:#fff; border:1.5px solid #E4D9C3; border-radius:14px; padding:14px 16px; }
  .switch{ width:46px; height:26px; border-radius:20px; background:#DCD2BB; position:relative; cursor:pointer; flex-shrink:0; }
  .switch.on{ background:var(--sage); }
  .switch .dot{ position:absolute; top:3px; right:3px; width:20px; height:20px; border-radius:50%; background:#fff; transition:.2s; }
  .switch.on .dot{ transform:translateX(-20px); }

  /* HEADER */
  .topbar{ display:flex; align-items:center; gap:12px; margin-bottom:18px; }
  .back{ width:36px; height:36px; border-radius:10px; background:#fff; border:1.5px solid #E4D9C3; display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:16px; }
  .night .back{ background:rgba(255,255,255,.08); border-color:rgba(255,255,255,.15); color:#fff; }
  .title{ font-size:17px; font-weight:800; }

  .grow{ flex:1; }
  .foot{ margin-top:auto; padding-top:16px; display:flex; flex-direction:column; gap:10px; }

  /* auth forms */
  .form-field{ margin-bottom:14px; }
  .form-field label{ display:block; font-size:13px; font-weight:700; margin-bottom:6px; color:var(--ink); }
  .form-field input{
    width:100%; padding:14px 16px; border-radius:14px; border:1.5px solid #E4D9C3;
    background:#fff; font-family:'Cairo'; font-size:14px; outline:none; color:var(--ink);
  }
  .form-field input:focus{ border-color:var(--teal); }
  .form-field .hint{ font-size:11px; color:var(--slate); margin-top:5px; }
  .form-error{
    background:#F6DEDB; color:var(--danger); border:1.5px solid #E9BEB8; border-radius:12px;
    padding:10px 14px; font-size:12.5px; font-weight:600; margin-bottom:14px; display:none;
  }
  .form-error.show{ display:block; }
  .auth-tabs{ display:flex; gap:8px; margin-bottom:20px; background:#EADFC6; padding:5px; border-radius:14px; }
  .auth-tab{ flex:1; text-align:center; padding:10px; border-radius:10px; font-weight:700; font-size:13px; cursor:pointer; color:var(--slate); }
  .auth-tab.active{ background:#fff; color:var(--ink); box-shadow:0 4px 10px -4px rgba(0,0,0,.2); }
  .spinner{ width:18px; height:18px; border-radius:50%; border:2.5px solid rgba(255,255,255,.4); border-top-color:#fff; animation:spin .7s linear infinite; display:inline-block; vertical-align:middle; }
  @keyframes spin{ to{ transform:rotate(360deg); } }

  /* names list */
  .name-row{ display:flex; align-items:center; gap:10px; background:#fff; border:1.5px solid #E4D9C3; border-radius:14px; padding:8px 10px; margin-bottom:10px; }
  .avatar{ width:34px; height:34px; border-radius:50%; background:var(--sage); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:800; font-size:14px; flex-shrink:0; }
  .name-row input{ flex:1; border:none; background:transparent; font-family:'Cairo'; font-size:14px; font-weight:600; outline:none; }

  /* pass device */
  .center-stage{ flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:22px; }
  .pass-name{ font-size:26px; font-weight:900; color:var(--amber); }
  .role-card{
    width:100%; max-width:280px; background:linear-gradient(160deg,#1D2B44,#101826);
    border:1.5px solid rgba(245,193,108,.4); border-radius:20px; padding:26px 20px; text-align:center;
    box-shadow:0 20px 40px -15px rgba(0,0,0,.5);
  }
  .role-icon{ font-size:44px; margin-bottom:10px; }
  .role-name{ font-size:22px; font-weight:900; color:var(--amber); margin-bottom:10px; }
  .role-desc{ font-size:13px; color:#C9D2DE; line-height:1.7; }

  .timer-ring{ width:150px; height:150px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:36px; font-weight:900; background: conic-gradient(var(--teal) var(--pct,0%), rgba(255,255,255,.12) 0); position:relative; }
  .timer-ring::before{ content:''; position:absolute; inset:10px; border-radius:50%; background:var(--night2); }
  .timer-ring span{ position:relative; z-index:2; color:#fff; }
  .timer-ring-light::before{ background:#fff; box-shadow:inset 0 0 0 1.5px #E4D9C3; }
  .timer-ring-light span{ color:var(--ink); }

  .player-pick{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
  .pick-card{ background:rgba(255,255,255,.06); border:1.5px solid rgba(255,255,255,.12); border-radius:14px; padding:12px; text-align:center; cursor:pointer; font-weight:700; font-size:13px; }
  .pick-card.selected{ background:var(--amber); color:#3A2A0E; border-color:var(--amber); }
  .pick-card.dead{ opacity:.3; pointer-events:none; text-decoration:line-through; }
  .screen:not(.night) .pick-card{ background:#fff; border-color:#E4D9C3; color:var(--ink); }

  .vote-row{ display:flex; align-items:center; justify-content:space-between; background:#fff; border:1.5px solid #E4D9C3; border-radius:14px; padding:12px 14px; margin-bottom:8px; cursor:pointer; }
  .vote-row.selected{ border-color:var(--teal); background:#EAF5F3; }
  .radio{ width:20px; height:20px; border-radius:50%; border:2px solid #C9BC9F; }
  .vote-row.selected .radio{ border-color:var(--teal); background:var(--teal); }

  .narrator-box{
    background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.12); border-radius:16px;
    padding:16px; font-size:14px; line-height:1.8; color:#DCE4EC; margin-bottom:18px;
  }
  .screen:not(.night) .narrator-box{ background:#fff; border-color:#E4D9C3; color:var(--ink); }

  .badge{ display:inline-block; padding:5px 12px; border-radius:20px; font-size:12px; font-weight:700; }
  .badge-dead{ background:#F6DEDB; color:var(--danger); }
  .badge-saved{ background:#E1F0DF; color:#3C7A4C; }

  .result-crest{ width:100px; height:100px; margin:0 auto 16px; border-radius:50%; background:linear-gradient(135deg,var(--amber),#E0A24A); display:flex; align-items:center; justify-content:center; font-size:44px; }
  .stat-grid{ display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:18px 0; }
  .stat-box{ background:#fff; border:1.5px solid #E4D9C3; border-radius:14px; padding:14px; text-align:center; }
  .stat-box .n{ font-size:22px; font-weight:900; color:var(--teal); }
  .stat-box .l{ font-size:11px; color:var(--slate); margin-top:2px; }

  ::-webkit-scrollbar{ width:0; }

  /* Toast (بديل عن alert) */
  .toast{
    position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
    background:#233650; color:#fff; padding:12px 20px; border-radius:12px; font-size:13px;
    box-shadow:0 10px 30px -10px rgba(0,0,0,.5); opacity:0; pointer-events:none;
    transition:opacity .25s ease, bottom .25s ease; z-index:200; font-weight:600; max-width:90vw; text-align:center;
  }
  .toast.show{ opacity:1; bottom:34px; }

  /* عدّاد تلقائي بمرحلة الليل */
  .countdown-num{
    font-family:'Tajawal', sans-serif; font-size:56px; font-weight:900; color:var(--amber);
    width:100px; height:100px; border-radius:50%; display:flex; align-items:center; justify-content:center;
    background:rgba(245,193,108,.08); border:2px solid rgba(245,193,108,.35);
  }

  /* ترتيب الجلسة الدائري */
  .seating-circle-wrap{
    display:flex; align-items:center; justify-content:center; position:relative;
  }
  .seating-circle{
    position:relative; width:320px; height:320px; margin:10px auto; max-width:90vw;
  }
  .seat-node{
    position:absolute; width:64px; height:64px; margin-left:-32px; margin-top:-32px;
    display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  }
  .seat-badge{
    width:40px; height:40px; border-radius:50%; background:linear-gradient(135deg,var(--teal),#3E8F8F);
    color:#fff; display:flex; align-items:center; justify-content:center; font-weight:900; font-size:15px;
    box-shadow:0 6px 14px -6px rgba(0,0,0,.4);
  }
  .seat-label{
    font-size:11px; font-weight:700; color:var(--ink); text-align:center; max-width:78px;
    overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  }

  /* وضع الجلسة الأونلاين */
  .mp-player-list{ width:100%; max-width:320px; display:flex; flex-direction:column; gap:8px; max-height:220px; overflow-y:auto; }
  .mp-player-row{
    background:#fff; border:1.5px solid #E4D9C3; border-radius:12px; padding:10px 14px; font-size:14px; font-weight:600;
  }
  .night .mp-player-row{ background:rgba(255,255,255,.06); border-color:rgba(255,255,255,.12); color:#EDE9DD; }
  .mp-qr-box{
    background:#fff; padding:14px; border-radius:16px; display:flex; align-items:center; justify-content:center;
    width:228px; height:228px; margin:6px auto;
  }

  /* زر واتساب العائم */
  .wa-float{
    position:absolute; bottom:22px; left:22px; width:52px; height:52px; border-radius:50%;
    background:#25D366; color:#fff; display:flex; align-items:center; justify-content:center;
    font-size:24px; box-shadow:0 10px 20px -6px rgba(37,211,102,.6); cursor:pointer; z-index:20;
  }

  /* ستيبرات عدد الأدوار */
  .role-count-row{
    display:flex; align-items:center; justify-content:space-between; background:#fff;
    border:1.5px solid #E4D9C3; border-radius:12px; padding:10px 14px; margin-bottom:8px; font-size:14px; font-weight:600;
  }
  .mini-stepper{ display:flex; align-items:center; gap:10px; }
  .mini-stepper button{
    width:28px; height:28px; border-radius:8px; border:none; background:var(--cream); color:var(--teal);
    font-size:16px; font-weight:800; cursor:pointer;
  }
  .mini-val{ min-width:18px; text-align:center; font-weight:800; }

  /* زر الخروج من اللعبة */
  .exit-game-btn{
    position:absolute; top:16px; left:16px; width:34px; height:34px; border-radius:50%;
    background:rgba(0,0,0,.35); color:#fff; border:1.5px solid rgba(255,255,255,.3);
    font-size:15px; align-items:center; justify-content:center; cursor:pointer; z-index:50;
  }
