html, body {
    margin: 0; padding: 0; overflow: hidden;
    width: 100%; height: 100%;
    background: #0d1912;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
  }
  #app { position: fixed; inset: 0; }
  canvas { display: block; touch-action: none; }

  #hud {
    position: fixed; top: 0; left: 0; right: 0;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 14px 16px;
    pointer-events: none;
    z-index: 5;
  }
  #scoreBox {
    background: rgba(8, 16, 11, 0.88);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 16px;
    padding: 10px 22px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  }
  #scoreBox .team-p { color: #ffd447; }
  #scoreBox .team-a { color: #7fd4ff; }
  #scoreBox .num { font-size: 28px; min-width: 26px; text-align: center; }
  #scoreBox .sep { opacity: 0.5; font-weight: 400; }

  #timerBox {
    background: rgba(8, 16, 11, 0.88);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 16px;
    padding: 10px 22px;
    color: #fff;
    font-weight: 700;
    font-size: 26px;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  }
  #timerBox.warn { color: #ff6b6b; }

  #hint {
    position: fixed;
    bottom: 22px; left: 0; right: 0;
    text-align: center;
    color: rgba(255,255,255,0.75);
    font-size: 13px;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.4s ease;
  }

  #turnBadge {
    position: fixed;
    top: 68px; left: 0; right: 0;
    text-align: center;
    pointer-events: none;
    z-index: 5;
  }
  #turnBadge span {
    display: inline-block;
    background: rgba(10,20,14,0.72);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 12px;
    color: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    transition: background 0.2s ease, color 0.2s ease;
  }
  #turnBadge span.penalty {
    background: #ff6b6b;
    color: #2a0000;
    font-weight: 700;
  }
  #stallBar {
    position: fixed;
    top: 100px; left: 50%; transform: translateX(-50%);
    width: 120px; height: 5px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    overflow: hidden;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  #stallBar.show { opacity: 1; }
  #stallBar i {
    display: block; height: 100%; width: 0%;
    background: #ff6b6b;
    transition: width 0.08s linear;
  }

  #pauseBtn {
    position: fixed;
    top: 14px; left: 69%;
    transform: translateX(-50%);
    min-width: 70px;
    height: 52px;
    padding: 5px;
    border-radius: 14px;
    background: #ffd447;
    border: none;
    color: #1a1400;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.3px;
    display: flex; align-items: center; justify-content: center;
    gap: 6px;
    z-index: 6;
    box-shadow: 0 6px 18px rgba(255, 212, 71, 0.45);
  }
  #pauseBtn:active { transform: translateX(-50%) scale(0.95); }

  #pauseScreen {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.88);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px;
    z-index: 12;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  #pauseScreen.show { opacity: 1; pointer-events: all; }
  #pauseScreen h1 { color: #fff; font-size: 26px; margin: 0 0 8px 0; }

  /* ---- all pause-screen buttons: uniform yellow rounded style ---- */
  #pauseScreen button,
  #exitConfirm button,
  #settingsScreen button,
  #helpScreen button {
    background: #ffd447;
    color: #1a1400;
    border: none;
    padding: 14px 36px;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    min-width: 200px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    box-shadow: 0 4px 14px rgba(255,212,71,0.35);
  }
  #pauseScreen button:active,
  #exitConfirm button:active,
  #settingsScreen button:active,
  #helpScreen button:active { transform: scale(0.96); }

  #confettiLayer {
    position: fixed; inset: 0;
    z-index: 9;
    pointer-events: none;
    overflow: hidden;
  }
  .confetti-piece {
    position: absolute;
    top: -24px;
    width: 8px;
    height: 14px;
    opacity: 0.95;
    will-change: transform;
    animation-name: confettiFall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
  }
  @keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    85% { opacity: 1; }
    100% { transform: translateY(115vh) rotate(540deg); opacity: 0; }
  }

  #goalBanner {
    position: fixed;
    top: 13%; left: 0; right: 0;
    text-align: center;
    z-index: 8;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.25s ease, transform 0.25s ease;
  }
  #goalBanner.show {
    opacity: 1;
    transform: scale(1);
    animation: goalPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  #goalBanner .goalTitle {
    font-size: 56px;
    font-weight: 800;
    color: #ffd447;
    text-shadow: 0 4px 18px rgba(0,0,0,0.55);
    letter-spacing: 2px;
  }
  #goalBanner .goalScore {
    margin-top: 8px;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    background: rgba(8, 16, 11, 0.85);
    display: inline-block;
    padding: 7px 24px;
    border-radius: 999px;
  }
  #goalBanner .goalScorer {
    margin-top: 10px;
    font-size: 16px;
    font-weight: 700;
    color: #ffd447;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
  }
  @keyframes goalPop {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
  }

  #refereePopup {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.82);
    display: flex; align-items: center; justify-content: center;
    z-index: 13;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
  }
  #refereePopup.show { opacity: 1; }
  #refereePopup .card {
    background: rgba(10, 20, 14, 0.95);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 18px;
    padding: 24px 26px;
    display: flex; flex-direction: column; align-items: center;
    gap: 12px;
    max-width: 290px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  }
  #refereePopup img {
    width: 88px; height: 88px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #ff6b6b;
  }
  #refereePopup .refTitle {
    color: #ff6b6b;
    font-weight: 800;
    font-size: 18px;
  }
  #refereePopup .refText {
    color: rgba(255,255,255,0.85);
    font-size: 13.5px;
    line-height: 1.6;
    margin: 0;
  }

  /* ---- exit confirmation, settings, help screens ---- */
  #exitConfirm, #settingsScreen, #helpScreen {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.92);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; z-index: 14;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  #exitConfirm.show, #settingsScreen.show, #helpScreen.show {
    opacity: 1; pointer-events: all;
  }
  #exitConfirm p { color: #fff; font-size: 17px; }
  #settingsScreen h1, #helpScreen h1 { color: #fff; font-size: 22px; margin: 0; }

  /* help screen text in a styled box */
  #helpScreen .helpBox {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 16px;
    padding: 20px 24px;
    max-width: 320px;
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    line-height: 2.2;
    text-align: center;
  }

  /* settings rows */
  .settingRow {
    display: flex; align-items: center; justify-content: space-between;
    width: 260px; color: #fff; font-size: 15px;
  }
  .volSlider { width: 150px; accent-color: #ffd447; }

  .toggleSwitch { position: relative; display: inline-block; width: 50px; height: 26px; }
  .toggleSwitch input { opacity: 0; width: 0; height: 0; }
  .toggleTrack {
    position: absolute; cursor: pointer; inset: 0;
    background: rgba(255,255,255,0.25); border-radius: 26px;
    transition: 0.25s;
  }
  .toggleTrack::before {
    content: ''; position: absolute; left: 3px; top: 3px;
    width: 20px; height: 20px; background: #fff; border-radius: 50%;
    transition: 0.25s;
  }
  .toggleSwitch input:checked + .toggleTrack { background: #4aa11e; }
  .toggleSwitch input:checked + .toggleTrack::before { transform: translateX(24px); }

  #endScreen {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.88);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px;
    z-index: 10;
    opacity: 0; pointer-events: none;
    transition: opacity 0.4s ease;
  }
  #endScreen.show { opacity: 1; pointer-events: all; }
  #endScreen h1 {
    color: #fff; font-size: 30px; margin: 0;
    letter-spacing: 0.5px;
  }
  #endScreen .resultLine { color: rgba(255,255,255,0.65); font-size: 15px; margin: 0 0 8px 0; }
  #endScreen .finalScore {
    color: #fff; font-size: 46px; font-weight: 800;
    display: flex; align-items: center; gap: 16px;
  }
  #endScreen .finalScore .p { color: #ffd447; }
  #endScreen .finalScore .a { color: #7fd4ff; }
  #endScreen .finalScore .vs { font-size: 20px; color: rgba(255,255,255,0.4); font-weight: 400; }
  #restartBtn {
    background: #ffd447; color: #1a1400;
    border: none; padding: 14px 34px; border-radius: 999px;
    font-size: 16px; font-weight: 700;
    box-shadow: 0 6px 20px rgba(255, 212, 71, 0.35);
  }
  #mapReturnBtn {
    background: rgba(255,255,255,0.08); color: #fff;
    border: 1px solid rgba(255,255,255,0.2); padding: 12px 30px; border-radius: 999px;
    font-size: 14px; font-weight: 700;
  }


  /* --------------------------------------------------------------
     Scorers table (end screen): team names, divider line, then
     each team's scorers with goal minute, football-style layout.
  -------------------------------------------------------------- */
  .scorersTable {
    width: 100%;
    max-width: 360px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 18px;
    padding: 14px 16px 16px 16px;
    margin: 2px 0 4px 0;
  }
  .scorersTable.empty { display: none; }
  .scorersHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .scorersTeamName {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.5px;
  }
  .scorersTeamName.p { color: #ffd447; }
  .scorersTeamName.a { color: #7fd4ff; }
  .scorersDivider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
    margin: 10px 0 10px 0;
  }
  .scorersBody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .scorersRow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
  }
  .scorersCell {
    flex: 1;
    font-size: 12.5px;
    color: rgba(255,255,255,0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .scorersCell.p { text-align: left; }
  .scorersCell.a { text-align: right; }
  .scorersCell:empty::before { content: ''; }
  .scorersMinute {
    color: rgba(255,255,255,0.55);
    font-weight: 600;
    font-size: 11.5px;
    margin: 0 4px;
  }


  .rosterGlass {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 22px;
    padding: 18px 20px;
    margin-top: 14px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
    max-width: 420px;
    width: 100%;
    text-align: center;
  }
  .rosterHeading {
    color: #ffd447;
    font-size: 18px;
    margin: 0 0 14px 0;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.4);
  }
  .rosterTeams {
    display: flex;
    gap: 14px;
    justify-content: center;
  }
  .rosterTeam {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    padding: 12px 8px;
    max-height: 42vh;
    overflow-y: auto;
  }
  .rosterTeam h3 {
    margin: 0 0 10px 0;
    font-size: 13px;
    letter-spacing: 1px;
  }
  .rosterTeam-player h3 { color: #ffd447; }
  .rosterTeam-ai h3 { color: #7fd4ff; }
  .rosterTeam ul {
    list-style: none;
    margin: 0; padding: 0;
    display: flex; flex-direction: column;
    gap: 6px;
  }
  .rosterTeam li {
    color: #fff;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 999px;
    padding: 5px 8px;
  }
  .rosterTeam li .num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 11px;
    background: rgba(255,255,255,0.18);
  }

  #startScreen {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.92);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px;
    z-index: 11;
    text-align: center;
    padding: 0 30px;
  }
  #startScreen h1 { color: #fff; font-size: 24px; margin: 0 0 4px 0; }
  #startScreen p { color: rgba(255,255,255,0.6); font-size: 13.5px; line-height: 1.7; max-width: 330px; margin: 0; }
  #startBtn {
    margin-top: 20px;
    background: #ffd447;
    color: #1a1400;
    border: none;
    padding: 14px 40px;
    border-radius: 999px;
    font-size: 17px;
    font-weight: 700;
  }
  #startBtn:active { transform: scale(0.96); }
  .hidden { display: none !important; }

  #colorScreen, #levelScreen {
    position: fixed; inset: 0;
    background: rgba(4, 10, 6, 0.92);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px;
    z-index: 11;
    text-align: center;
    padding: 0 30px;
  }
  #colorScreen h1, #levelScreen h1 { color: #fff; font-size: 24px; margin: 0 0 4px 0; }
  #colorScreen p, #levelScreen p { color: rgba(255,255,255,0.6); font-size: 13.5px; line-height: 1.7; max-width: 330px; margin: 0; }

  .colorPickerBlock { margin-top: 8px; }
  .colorPickerTitle { font-size: 13px; letter-spacing: 1px; margin: 0 0 10px 0; }
  .colorPickerTitle.player { color: #ffd447; }
  .colorPickerTitle.ai { color: #7fd4ff; }

  #loadingScreen {
    position: fixed; inset: 0;
    background: #060b07 url('../img/load.webp') center center / cover no-repeat;
    display: flex; align-items: flex-end; justify-content: center;
    z-index: 20;
  }
  .loadingBottom {
    width: 100%;
    max-width: 420px;
    padding: 0 32px 60px 32px;
    box-sizing: border-box;
  }
  .loadingLabel {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
    margin-bottom: 10px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.7);
  }
  .loadingLabel #loadingPercent {
    color: #5ec8ff;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
  }
  .loadingBarTrack {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4), inset 0 1px 2px rgba(0,0,0,0.3);
  }
  .loadingBarFill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #1a6fd6, #4fa8ff, #7fd4ff);
    background-size: 200% 100%;
    box-shadow: 0 0 12px rgba(95, 180, 255, 0.75);
    transition: width 0.35s ease;
    animation: loadingBarShine 1.6s linear infinite;
  }
  @keyframes loadingBarShine {
    0% { background-position: 0% 0; }
    100% { background-position: -200% 0; }
  }

  .kitPreview {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 0 10px 0;
  }
  .kitPreviewCanvas {
    width: 110px; height: 150px;
    border-radius: 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.18);
  }

  .colorSwatches { display: flex; gap: 10px; justify-content: center; }
  .swatch {
    width: 42px; height: 42px;
    border-radius: 12px;
    border: 3px solid rgba(255,255,255,0.15);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
    box-shadow: 0 4px 10px rgba(0,0,0,0.35);
  }
  .swatch:active { transform: scale(0.92); }
  .swatch.selected {
    border-color: #fff;
    transform: scale(1.08);
    box-shadow: 0 0 0 3px rgba(255,255,255,0.25), 0 4px 14px rgba(0,0,0,0.5);
  }

  .levelDisplay {
    color: #ffd447;
    font-size: 40px;
    font-weight: 800;
  }
  .levelDisplay .levelMax { color: rgba(255,255,255,0.4); font-size: 18px; font-weight: 400; }
  #levelSlider {
    width: 260px;
    accent-color: #ffd447;
    margin: 6px 0 4px 0;
  }
  #colorNextBtn, #levelNextBtn {
    margin-top: 20px;
    background: #ffd447;
    color: #1a1400;
    border: none;
    padding: 14px 40px;
    border-radius: 999px;
    font-size: 17px;
    font-weight: 700;
  }
  #colorNextBtn:active, #levelNextBtn:active { transform: scale(0.96); }

  /* ردیف دکمه‌های ناوبری (قبلی + بعدی/شروع) در صفحات انتخاب رنگ و ترکیب تیم‌ها */
  .preMatchNav {
    margin-top: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .preMatchNav #colorNextBtn,
  .preMatchNav #startBtn {
    margin-top: 0;
  }
  .navBackBtn {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.22);
    padding: 14px 26px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
  }
  .navBackBtn:active { transform: scale(0.96); }

