/* ─── Reset & Base ─── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --p1: #5A00D6;
      --p2: #7B2BFF;
      --p3: #C77DFF;
      --bg1: #1A0826;
      --bg2: #2A0D3A;
      --bg3: #3A1550;
      --acc: #FF9F1C;
      --acc2: #FFB84D;
      --success: #00FF9D;
      --danger: #FF3B3B;
      --card-bg: rgba(58, 21, 80, 0.6);
      --card-border: rgba(199, 125, 255, 0.3);
      --glow-purple: rgba(123, 43, 255, 0.5);
      --glow-green: rgba(0, 255, 157, 0.4);
      --glow-gold: rgba(255, 159, 28, 0.5);
    }

    html { font-size: 16px; }

    body {
      font-family: 'Tajawal', sans-serif;
      background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 55%, #200830 100%);
      min-height: 100vh;
      color: #fff;
      overflow-x: hidden;
      position: relative;
    }

    #stars-canvas {
      position: fixed;
      inset: 0;
      pointer-events: none;
      z-index: 0;
    }

    .page {
      position: relative;
      z-index: 1;
      max-width: 960px;
      margin: 0 auto;
      padding: 88px 20px 60px;
    }

    /* نفس زر العودة في login.html — ثابت أعلى اليمين (RTL) */
    .home-btn {
      position: fixed;
      top: 18px;
      right: 18px;
      background: linear-gradient(135deg, #7c3aed 0%, #a855f7 55%, #f59e0b 130%);
      color: white;
      border: 1px solid rgba(255, 255, 255, 0.3);
      padding: 12px 20px;
      border-radius: 999px;
      font-size: 1rem;
      font-weight: 800;
      letter-spacing: 0.2px;
      font-family: 'Tajawal', sans-serif;
      cursor: pointer;
      transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
      box-shadow: 0 14px 34px rgba(0,0,0,0.35), 0 0 34px rgba(124, 58, 237, 0.45);
      z-index: 1000;
      display: flex;
      align-items: center;
      gap: 10px;
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      overflow: hidden;
    }

    .home-btn::before {
      content: "";
      position: absolute;
      top: -30%;
      right: -120%;
      width: 60%;
      height: 170%;
      background: linear-gradient(120deg, transparent 0%, rgba(255,255,255,0.35) 50%, transparent 100%);
      transform: rotate(18deg);
      transition: right 0.5s ease;
      pointer-events: none;
    }

    .home-btn:hover {
      transform: translateY(-3px) scale(1.03);
      filter: saturate(1.1);
      box-shadow: 0 18px 38px rgba(0,0,0,0.38), 0 0 42px rgba(124, 58, 237, 0.55);
    }

    .home-btn:hover::before {
      right: 130%;
    }

    .home-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 31px;
      height: 31px;
      border-radius: 50%;
      background: rgba(255,255,255,0.24);
      border: 1px solid rgba(255,255,255,0.35);
      font-size: 0.95em;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.28);
      flex-shrink: 0;
    }

    .home-icon i {
      color: #ffffff;
      font-size: 0.95rem;
      text-shadow: 0 1px 6px rgba(0,0,0,0.35);
    }

    .home-btn-label {
      position: relative;
      top: 1px;
    }

    /* أعلى اليسار — إنشاء لعبة جديدة */
    .new-game-btn {
      position: fixed;
      top: 18px;
      left: 18px;
      background: linear-gradient(135deg, #059669 0%, #10b981 50%, #34d399 100%);
      color: white;
      border: 1px solid rgba(255, 255, 255, 0.3);
      padding: 12px 20px;
      border-radius: 999px;
      font-size: 1rem;
      font-weight: 800;
      letter-spacing: 0.2px;
      font-family: 'Tajawal', sans-serif;
      cursor: pointer;
      transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
      box-shadow: 0 14px 34px rgba(0,0,0,0.35), 0 0 34px rgba(16, 185, 129, 0.4);
      z-index: 1000;
      display: flex;
      align-items: center;
      gap: 10px;
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      overflow: hidden;
    }

    .new-game-btn::before {
      content: "";
      position: absolute;
      top: -30%;
      left: -120%;
      width: 60%;
      height: 170%;
      background: linear-gradient(120deg, transparent 0%, rgba(255,255,255,0.35) 50%, transparent 100%);
      transform: rotate(-18deg);
      transition: left 0.5s ease;
      pointer-events: none;
    }

    .new-game-btn:hover {
      transform: translateY(-3px) scale(1.03);
      filter: saturate(1.1);
      box-shadow: 0 18px 38px rgba(0,0,0,0.38), 0 0 42px rgba(16, 185, 129, 0.55);
    }

    .new-game-btn:hover::before {
      left: 130%;
    }

    @media (max-width: 768px) {
      .home-btn {
        position: absolute !important;
        top: 10px;
        right: 10px;
        padding: 9px;
        font-size: 0.9em;
        width: 46px;
        height: 46px;
        justify-content: center;
        gap: 0;
        z-index: 1000;
      }
      .new-game-btn {
        position: absolute !important;
        top: 10px;
        left: 10px;
        padding: 9px;
        font-size: 0.9em;
        width: 46px;
        height: 46px;
        justify-content: center;
        gap: 0;
        z-index: 1000;
      }
      .home-btn-label {
        display: none;
      }
    }

    @media (max-width: 480px) {
      .home-btn {
        padding: 8px;
        font-size: 0.82em;
        width: 42px;
        height: 42px;
      }
      .new-game-btn {
        padding: 8px;
        font-size: 0.82em;
        width: 42px;
        height: 42px;
      }
      .home-icon {
        width: 26px;
        height: 26px;
      }
    }

    .page-header {
      text-align: center;
      margin-bottom: 36px;
      animation: fadeSlideDown 0.6s ease both;
    }
    .page-header .eyebrow {
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 4px;
      color: var(--p3);
      text-transform: uppercase;
      opacity: 0.75;
      margin-bottom: 6px;
    }
    .page-header h1 {
      font-size: 28px;
      font-weight: 900;
      background: linear-gradient(135deg, #fff 30%, var(--p3));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    .empty-state {
      text-align: center;
      padding: 48px 24px;
      background: linear-gradient(145deg, rgba(58,21,80,0.7), rgba(42,13,58,0.85));
      border: 1px solid var(--card-border);
      border-radius: 18px;
      margin-bottom: 32px;
      animation: fadeSlideDown 0.6s ease both;
    }
    .empty-state p {
      font-size: 1.25rem;
      color: rgba(255,255,255,0.85);
      margin-bottom: 0;
    }

    .winner-section {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-bottom: 44px;
      animation: fadeSlideDown 0.7s 0.1s ease both;
    }

    .crown-icon {
      font-size: 48px;
      margin-bottom: -18px;
      position: relative;
      z-index: 2;
      filter: drop-shadow(0 0 18px #FFD700);
      animation: crownFloat 2.8s ease-in-out infinite;
    }
    @keyframes crownFloat {
      0%, 100% { transform: translateY(0) rotate(-5deg); }
      50%       { transform: translateY(-12px) rotate(5deg); }
    }

    .winner-card {
      position: relative;
      background: linear-gradient(145deg, rgba(123,43,255,0.35) 0%, rgba(90,0,214,0.55) 100%);
      border: 1.5px solid rgba(199,125,255,0.55);
      border-radius: 28px;
      padding: 36px 52px 32px;
      text-align: center;
      min-width: 280px;
      overflow: hidden;
      box-shadow:
        0 0 0 1px rgba(255,255,255,0.04) inset,
        0 0 60px var(--glow-purple),
        0 0 120px rgba(90,0,214,0.25);
      animation: winnerPulse 3s ease-in-out infinite;
    }
    @keyframes winnerPulse {
      0%, 100% { box-shadow: 0 0 0 1px rgba(255,255,255,0.04) inset, 0 0 60px var(--glow-purple), 0 0 120px rgba(90,0,214,0.25); }
      50%       { box-shadow: 0 0 0 1px rgba(255,255,255,0.06) inset, 0 0 90px rgba(123,43,255,0.75), 0 0 160px rgba(90,0,214,0.4); }
    }

    .winner-card::before {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(135deg, rgba(255,255,255,0.06) 0%, transparent 55%);
      border-radius: 28px;
      pointer-events: none;
    }

    .winner-floating-particles {
      position: absolute;
      inset: 0;
      pointer-events: none;
      overflow: hidden;
      border-radius: 28px;
    }

    .winner-badge {
      position: absolute;
      top: -1px; right: 20px;
      background: linear-gradient(135deg, #FFD700, #FF9F1C);
      color: var(--bg1);
      font-size: 11px;
      font-weight: 900;
      padding: 5px 16px;
      border-radius: 0 0 14px 14px;
      letter-spacing: 1.5px;
      box-shadow: 0 4px 16px var(--glow-gold);
    }

    .winner-avatar {
      width: 88px;
      height: 88px;
      border-radius: 50%;
      background: linear-gradient(135deg, var(--bg3), var(--p1));
      border: 3px solid var(--success);
      box-shadow: 0 0 24px var(--glow-green), 0 0 8px rgba(0,255,157,0.2) inset;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 42px;
      margin: 0 auto 14px;
      overflow: hidden;
    }
    .winner-avatar img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .winner-name {
      font-size: 24px;
      font-weight: 900;
      color: #fff;
      margin-bottom: 4px;
    }

    .winner-subtitle {
      font-size: 12px;
      color: var(--p3);
      opacity: 0.85;
      margin-bottom: 16px;
      letter-spacing: 1px;
    }

    .winner-score {
      font-size: 64px;
      font-weight: 900;
      line-height: 1;
      background: linear-gradient(135deg, var(--success), #80FFCB 60%, #fff);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      filter: drop-shadow(0 0 12px rgba(0,255,157,0.5));
      margin-bottom: 4px;
    }

    .winner-score-label {
      font-size: 12px;
      color: var(--p3);
      opacity: 0.7;
    }

    .section-title {
      text-align: center;
      font-size: 13px;
      font-weight: 700;
      color: var(--p3);
      letter-spacing: 3px;
      text-transform: uppercase;
      opacity: 0.75;
      margin-bottom: 18px;
    }

    .teams-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 14px;
      margin-bottom: 32px;
      animation: fadeSlideUp 0.7s 0.25s ease both;
    }
    @media (max-width: 620px) {
      .teams-grid { grid-template-columns: repeat(2, 1fr); }
    }

    .team-card {
      position: relative;
      background: linear-gradient(145deg, rgba(58,21,80,0.85), rgba(42,13,58,0.9));
      border: 1px solid var(--card-border);
      border-radius: 18px;
      padding: 18px 14px 16px;
      text-align: center;
      overflow: hidden;
      transition: transform 0.2s ease, box-shadow 0.2s ease;
      cursor: default;
    }
    .team-card::before {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(135deg, rgba(255,255,255,0.04) 0%, transparent 60%);
      border-radius: 18px;
      pointer-events: none;
    }
    .team-card:hover {
      transform: translateY(-4px);
      box-shadow: 0 10px 30px rgba(123,43,255,0.35);
    }
    .team-card.winner {
      border-color: rgba(0,255,157,0.5);
      box-shadow: 0 0 30px rgba(0,255,157,0.15), 0 0 60px rgba(0,255,157,0.08);
      transform: scale(1.04);
    }
    .team-card.winner:hover {
      transform: scale(1.07) translateY(-4px);
    }

    /* متصدرون متعادلون — ليس فوزاً فردياً */
    .team-card.tied-top {
      border-color: rgba(255, 159, 28, 0.55);
      box-shadow: 0 0 30px rgba(255, 159, 28, 0.2), 0 0 60px rgba(255, 159, 28, 0.1);
      transform: scale(1.04);
    }
    .team-card.tied-top:hover {
      transform: scale(1.07) translateY(-4px);
    }
    .team-card.tied-top .team-avatar-sm {
      border-color: rgba(255, 159, 28, 0.6);
      box-shadow: 0 0 14px rgba(255, 159, 28, 0.35);
    }
    .team-card.tied-top .team-score {
      color: var(--acc2);
    }
    .team-card.tied-top .progress-fill {
      background: linear-gradient(90deg, #D97706, var(--acc));
    }

    .winner-card.tie-state {
      border-color: rgba(255, 159, 28, 0.55);
      animation: tiePulse 3s ease-in-out infinite;
    }
    @keyframes tiePulse {
      0%, 100% { box-shadow: 0 0 0 1px rgba(255,255,255,0.04) inset, 0 0 50px rgba(255, 159, 28, 0.35), 0 0 100px rgba(255, 159, 28, 0.15); }
      50%       { box-shadow: 0 0 0 1px rgba(255,255,255,0.06) inset, 0 0 75px rgba(255, 159, 28, 0.5), 0 0 140px rgba(255, 159, 28, 0.22); }
    }
    .winner-card.tie-state .winner-score {
      background: linear-gradient(135deg, var(--acc), #FFD699 60%, #fff);
      -webkit-background-clip: text;
      background-clip: text;
      filter: drop-shadow(0 0 12px rgba(255, 159, 28, 0.45));
    }
    .winner-badge.tie-badge {
      background: linear-gradient(135deg, #F59E0B, #EA580C);
      color: #fff;
      box-shadow: 0 4px 16px rgba(245, 158, 11, 0.45);
    }

    .rank-badge {
      position: absolute;
      top: 10px;
      left: 10px;
      width: 24px;
      height: 24px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 11px;
      font-weight: 900;
    }
    .rank-1 {
      background: linear-gradient(135deg, #FFD700, #FF9F1C);
      color: var(--bg1);
      box-shadow: 0 0 10px rgba(255,215,0,0.6);
    }
    .rank-2 {
      background: linear-gradient(135deg, #D0D0D0, #A8A8A8);
      color: var(--bg1);
    }
    .rank-3 {
      background: linear-gradient(135deg, #CD7F32, #A0522D);
      color: #fff;
    }
    .rank-other {
      background: rgba(90,0,214,0.6);
      color: var(--p3);
      border: 1px solid var(--card-border);
    }

    .team-avatar-sm {
      width: 54px;
      height: 54px;
      border-radius: 50%;
      background: linear-gradient(135deg, var(--bg3), var(--p1));
      border: 2px solid var(--card-border);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 26px;
      margin: 0 auto 10px;
      transition: border-color 0.2s, box-shadow 0.2s;
      overflow: hidden;
    }
    .team-avatar-sm img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }
    .team-card.winner .team-avatar-sm {
      border-color: rgba(0,255,157,0.55);
      box-shadow: 0 0 14px var(--glow-green);
    }

    .team-name {
      font-size: 14px;
      font-weight: 700;
      color: #fff;
      margin-bottom: 6px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .team-score {
      font-size: 22px;
      font-weight: 900;
      color: var(--p3);
      margin-bottom: 10px;
    }
    .team-card.winner .team-score {
      color: var(--success);
    }

    .progress-track {
      height: 5px;
      background: rgba(255,255,255,0.07);
      border-radius: 99px;
      overflow: hidden;
    }
    .progress-fill {
      height: 100%;
      border-radius: 99px;
      background: linear-gradient(90deg, var(--p1), var(--p2));
      width: 0%;
      transition: width 1.6s cubic-bezier(0.22, 1, 0.36, 1);
    }
    .team-card.winner .progress-fill {
      background: linear-gradient(90deg, #00BF72, var(--success));
    }

    .chart-section {
      background: linear-gradient(145deg, rgba(58,21,80,0.7), rgba(42,13,58,0.85));
      border: 1px solid var(--card-border);
      border-radius: 18px;
      padding: 24px 22px;
      margin-bottom: 32px;
      animation: fadeSlideUp 0.7s 0.35s ease both;
    }

    .chart-label {
      font-size: 12px;
      font-weight: 700;
      color: var(--p3);
      letter-spacing: 2px;
      opacity: 0.7;
      margin-bottom: 20px;
    }

    .bar-row {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 12px;
    }
    .bar-row:last-child { margin-bottom: 0; }

    .bar-team-name {
      font-size: 13px;
      font-weight: 700;
      color: rgba(255,255,255,0.75);
      min-width: 68px;
      text-align: right;
    }

    .bar-track {
      flex: 1;
      height: 26px;
      background: rgba(255,255,255,0.05);
      border-radius: 8px;
      overflow: hidden;
      position: relative;
    }

    .bar-fill {
      height: 100%;
      border-radius: 8px;
      width: 0%;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      padding-right: 10px;
      transition: width 1.9s cubic-bezier(0.22, 1, 0.36, 1);
      position: relative;
      min-width: 0;
    }

    .bar-score {
      font-size: 11px;
      font-weight: 700;
      color: rgba(255,255,255,0.9);
      white-space: nowrap;
      position: absolute;
      right: 10px;
    }

    @keyframes fadeSlideDown {
      from { opacity: 0; transform: translateY(-24px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes fadeSlideUp {
      from { opacity: 0; transform: translateY(24px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    @keyframes confetti-rise {
      0%   { transform: translateY(0) scale(1) rotate(0deg);   opacity: 0.9; }
      100% { transform: translateY(-130px) scale(0.2) rotate(180deg); opacity: 0; }
    }
