/* Game Zone styles — the <style> block of game.php, loaded only on /game. */
  :root {
    --bg:     #f1f2f4;
    --bg-2:   #e8e9ec;
    --card:   #ffffff;
    --text:   #15171c;
    --sub:    #6b7280;
    --border: rgba(0,0,0,.09);
    --accent: rgba(250, 108, 0, 1);
    --accent-hover: #d35400;
    --accent-soft: rgba(250,108,0,.12);
    --shadow: 0 6px 24px rgba(0,0,0,.07);
    --board:  #c98a52;
    --board-2:#b9783f;
    --hole:   #5a3a22;
    --hole-2: #3f2716;
    --shaft:  #b9bcc4;
    --shaft-2:#8a8e98;
    --head:   #d7dae0;
    --sky:    #eaf1f6;
    --sky-2:  #dbe7ef;
  }
  [data-theme="dark"] {
    --bg:     #0f0f10;
    --bg-2:   #161617;
    --card:   #212126;
    --text:   #f0f0f2;
    --sub:    #a6acb4;
    --border: rgba(255,255,255,.14);
    --accent-hover: #f39c12;
    --shadow: 0 6px 24px rgba(0,0,0,.4);
    --board:  #7a5333;
    --board-2:#634126;
    --hole:   #20140c;
    --hole-2: #120a05;
    --sky:    #14171c;
    --sky-2:  #0d0f12;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  [dir="rtl"] { font-family: 'Tajawal', 'Plus Jakarta Sans', system-ui, sans-serif; }

  body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background:
      radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%),
      linear-gradient(180deg, var(--bg), var(--bg-2));
    color: var(--text);
    /* Non-scrolling full screen, offset for the fixed site header (64px desktop) */
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: calc(64px + 10px) 0 12px;
  }
  @media (max-width: 768px) {
    /* Mobile: clear the 56px header and the fixed bottom nav (60px + safe area) */
    body { padding: calc(56px + 8px) 0 calc(60px + 8px + env(safe-area-inset-bottom)); }
  }
  /* Horizontal insets live on the wrapper (border-box) so the right gutter
     can never be eaten by flex centering — keeps content fully on-screen. */
  .shell {
    width: 100%; max-width: 668px;
    padding-left:  max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    flex: 1; min-height: 0; display: flex; flex-direction: column;
  }

  /* ── Menu ────────────────────────────────────────────── */
  .menu { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
  .menu-head { text-align: center; margin-bottom: 20px; }
  .chip {
    display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .6px;
    text-transform: uppercase; color: var(--accent); background: var(--accent-soft);
    padding: 5px 13px; border-radius: 20px; margin-bottom: 12px;
  }
  .menu-head h1 { font-size: clamp(26px, 7vw, 34px); font-weight: 800; letter-spacing: -.6px; }
  .menu-head p { font-size: 14px; color: var(--sub); margin-top: 6px; }

  .game-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
  @media (min-width: 540px) { .game-grid { grid-template-columns: repeat(3, 1fr); } }

  .game-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 18px; padding: 20px; cursor: pointer;
    box-shadow: var(--shadow); text-align: left;
    color: var(--text);                 /* buttons don't inherit text colour — set it so titles aren't black-on-black in dark mode */
    display: flex; flex-direction: column; gap: 10px;
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s;
    position: relative; overflow: hidden;
  }
  .gc-name { color: var(--text); }
  .game-card:hover { transform: translateY(-3px); border-color: var(--accent); }
  .game-card:active { transform: translateY(0) scale(.99); }
  .gc-icon {
    width: 54px; height: 54px; border-radius: 15px;
    background: linear-gradient(140deg, var(--accent-soft), transparent);
    box-shadow: inset 0 0 0 1px var(--border);
    color: var(--accent); display: grid; place-items: center; flex-shrink: 0;
  }
  .gc-icon svg { width: 28px; height: 28px; }
  .gc-name { font-size: 18px; font-weight: 800; letter-spacing: -.2px; }
  .gc-desc { font-size: 13.5px; color: var(--sub); line-height: 1.5; flex: 1; }
  .gc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; }
  .gc-best { font-size: 12px; font-weight: 700; color: var(--sub); }
  .gc-best b { color: var(--accent); }
  .gc-play {
    font-size: 13px; font-weight: 800; color: var(--accent);
    display: inline-flex; align-items: center; gap: 5px;
    transition: gap .15s ease;
  }
  .game-card:hover .gc-play { gap: 10px; }
  .gc-tag {
    display: inline-block; vertical-align: middle; margin-left: 6px;
    font-size: 9.5px; font-weight: 800; letter-spacing: .5px; color: #fff;
    background: var(--accent); padding: 2px 7px; border-radius: 20px;
  }
  .gc-feature { border-color: var(--accent); }
  .gc-feature::after {
    content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
    background: radial-gradient(120px 90px at 100% 0%, var(--accent-soft), transparent 70%);
  }

  /* Mobile: fill the screen between the header and the bottom nav without ever
     overflowing under either. The two cards split the available height equally
     (minmax(0,1fr) lets them shrink below their content), and the description
     clamps so a card can never push past its share. */
  @media (max-width: 768px) {
    .menu { justify-content: flex-start; gap: 12px; }
    .menu-head { margin-bottom: 2px; }
    .game-grid {
      flex: 1; min-height: 0; gap: 10px;
      grid-template-columns: 1fr;
      grid-template-rows: repeat(3, minmax(0, 1fr));
    }
    .game-card { min-height: 0; overflow: hidden; justify-content: center; padding: 14px 16px; gap: 6px; }
    .gc-icon { width: 42px; height: 42px; border-radius: 12px; }
    .gc-icon svg { width: 22px; height: 22px; }
    .gc-desc {
      display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
      overflow: hidden; flex: 0 1 auto;
    }
  }

  /* ── Play view ───────────────────────────────────────── */
  .play { display: none; }
  .play.active { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .menu.gz-hidden { display: none; }

  .play-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-shrink: 0; }
  /* Match the site's button language: 8px radius, 1.5px outline, weight 600 */
  .back-btn, .sound-btn {
    background: transparent; border: 1.5px solid var(--border); border-radius: 8px;
    height: 40px; color: var(--text); cursor: pointer; font-family: inherit; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s, color .15s, transform .12s;
  }
  .back-btn:hover, .sound-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
  .back-btn:active, .sound-btn:active { transform: scale(.96); }
  .back-btn { padding: 0 18px; gap: 6px; font-size: 14px; font-weight: 600; }
  .back-btn svg { width: 16px; height: 16px; }
  [dir="rtl"] .back-btn svg { transform: scaleX(-1); }
  .play-title { font-size: 18px; font-weight: 800; letter-spacing: -.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .play-head .spacer { flex: 1; }
  .sound-btn { width: 40px; flex-shrink: 0; }
  .sound-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
  .sound-btn svg { width: 19px; height: 19px; }

  .game-card-wrap {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 18px; padding: 14px; box-shadow: var(--shadow);
    flex: 1; min-height: 0; display: flex; flex-direction: column;
  }

  /* Shared HUD */
  .gz-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 6px; }
  .stat { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 9px 6px; text-align: center; }
  .gz-stat-label { font-size: 10.5px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: .4px; }
  .stat-value { font-size: 23px; font-weight: 800; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
  .stat-value.warn { color: var(--accent); }
  .stat-value.lives { color: #ff6b6b; letter-spacing: 3px; }
  .stat-value.lives.low { animation: lifepulse .5s; }
  @keyframes lifepulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.25); } }
  .ticker { text-align: center; color: var(--accent); font-size: 13px; font-weight: 700; min-height: 18px; margin: 6px 0 10px; flex-shrink: 0; }

  /* ── In-game HUD (overlaid inside the stage, themed per game) ───────── */
  .ig-hud {
    position: absolute; top: 8px; left: 8px; right: 8px; z-index: 6;
    display: flex; justify-content: space-between; gap: 7px; pointer-events: none;
  }
  .ig-stat {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 5px 6px 6px; border-radius: 11px; border: 1px solid rgba(255,255,255,.16);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
  }
  .ig-label { font-size: 9px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; opacity: .82; line-height: 1; }
  .ig-val { font-size: clamp(15px, 5cqmin, 21px); font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .ig-val.lives { color: #ff6b6b; letter-spacing: 2px; }
  .ig-val.lives.low { animation: lifepulse .5s; }
  .ig-ticker {
    position: absolute; left: 8px; right: 8px; top: 56px; z-index: 3; text-align: center;
    pointer-events: none; font-size: 14px; font-weight: 800; letter-spacing: .3px;
    min-height: 18px; text-shadow: 0 2px 6px rgba(0,0,0,.55);
  }
  /* Whack — warm timber */
  .ig-hud--whack .ig-stat { background: rgba(58,33,15,.52); color: #f4e6d4; }
  .ig-hud--whack .ig-val  { color: #fff; }
  .ig-hud--whack .ig-val.lives { color: #ff6b6b; }
  .ig-hud--whack ~ .ig-ticker, .ig-ticker.t-whack { color: #ffd9a8; }
  /* Tower — sky glass + gold */
  .ig-hud--tower .ig-stat { background: rgba(16,26,42,.42); color: #d9e6f3; }
  .ig-hud--tower .ig-val  { color: #fff; }
  .ig-hud--tower .ig-stat:nth-child(2) .ig-val { color: #ffd75e; }
  .ig-ticker.t-tower { color: #ffe08a; }
  /* Site Run — dark/orange */
  .ig-hud--run .ig-stat { background: rgba(0,0,0,.36); color: #e7eef5; }
  .ig-hud--run .ig-val  { color: #fff; }
  .ig-hud--run .ig-stat:nth-child(2) .ig-val { color: #f5b41a; }
  .ig-ticker.t-run { color: #ffd75e; }

  /* Stage fills the remaining height and acts as a size container so the
     board can be the largest square that fits (100cqmin) with no scrolling. */
  .stage { position: relative; flex: 1; min-height: 0; border-radius: 14px; overflow: hidden;
    container-type: size; display: flex; align-items: center; justify-content: center; }

  /* ── Whack board ─────────────────────────────────────── */
  .board {
    position: relative; border-radius: 14px;
    width: min(100%, 82vmin); height: min(100%, 82vmin);   /* fallback */
    width: 100cqmin; height: 100cqmin;                      /* largest square in the stage */
    padding: clamp(8px, 3.2cqmin, 16px);
    background:
      repeating-linear-gradient(180deg, rgba(0,0,0,.05) 0 2px, transparent 2px 26px),
      linear-gradient(160deg, var(--board), var(--board-2));
    box-shadow: inset 0 2px 8px rgba(0,0,0,.22);
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    gap: clamp(6px, 2.6cqmin, 12px);
    touch-action: manipulation; user-select: none; -webkit-user-select: none;
  }
  .board.playing { cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36"><g transform="rotate(-38 18 18)"><rect x="16" y="13" width="4" height="20" rx="2" fill="%238a5a2b"/><rect x="8" y="5" width="20" height="9" rx="3" fill="%23737884"/><rect x="8" y="5" width="20" height="3.5" rx="1.75" fill="%23a7adb8"/></g></svg>') 9 7, pointer; }
  .board.shake { animation: shake .3s; }
  @keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }

  /* Full-size tiles — always present; only the face changes (flip in place) */
  .tile {
    position: relative; aspect-ratio: 1/1; border-radius: 12px;
    background: linear-gradient(160deg, #caa173, #ab7945);
    box-shadow: inset 0 2px 3px rgba(255,255,255,.22), inset 0 -4px 7px rgba(0,0,0,.32), 0 2px 4px rgba(0,0,0,.2);
    border: 1px solid rgba(0,0,0,.16);
    display: grid; place-items: center; overflow: hidden; cursor: inherit;
  }
  [data-theme="dark"] .tile { background: linear-gradient(160deg, #7c5a38, #5a3f26); }
  .tile.flip { animation: tileflip .18s ease; }
  @keyframes tileflip { 0% { transform: rotateX(78deg); } 100% { transform: rotateX(0); } }
  .tile.hit { animation: tilehit .13s ease; }
  @keyframes tilehit { 50% { transform: scale(.9); } }

  .tile .dent { width: 26%; height: 26%; border-radius: 50%;
    background: radial-gradient(circle at 50% 38%, rgba(0,0,0,.4), rgba(0,0,0,.1)); transition: opacity .15s; }
  .tile .face { position: absolute; width: 60%; height: 60%; display: grid; place-items: center;
    opacity: 0; transform: scale(.4); pointer-events: none;
    transition: opacity .12s ease, transform .14s cubic-bezier(.34,1.56,.64,1); }
  .tile .face .ic { width: 100%; height: 100%; display: block; }
  .tile.nail .f-nail, .tile.gold .f-nail { opacity: 1; transform: none; }
  .tile.bomb .f-bomb { opacity: 1; transform: none; }
  .tile.nail .dent, .tile.gold .dent, .tile.bomb .dent { opacity: 0; }
  .f-nail { color: #c8cdd6; }
  .tile.gold .f-nail { color: #ffd75e; }

  .hammer-fx { position: absolute; left: 6%; top: -10%; width: 50%; z-index: 4; pointer-events: none;
    transform-origin: 70% 85%; animation: hammerswing .28s ease-out forwards; }
  .hammer-fx svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
  @keyframes hammerswing { 0% { transform: rotate(-62deg); } 55% { transform: rotate(10deg); } 100% { transform: rotate(2deg); opacity: 0; } }

  .spark { position: absolute; left: 50%; top: 40%; pointer-events: none; transform: translate(-50%,-50%); }
  .spark span { position: absolute; width: 4px; height: 4px; background: #fff3d6; border-radius: 50%; animation: spark .35s ease-out forwards; }
  @keyframes spark { to { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.4); } }
  .float-pts { position: absolute; left: 50%; top: 16%; transform: translateX(-50%);
    font-weight: 800; font-size: 18px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.5);
    pointer-events: none; animation: floatUp .65s ease-out forwards; }
  .float-pts.neg { color: #ff6b6b; }
  @keyframes floatUp { to { opacity: 0; transform: translate(-50%,-26px); } }

  /* ── Tower canvas ────────────────────────────────────── */
  .tower-stage { width: 100%; height: 100%; display: block;
    border-radius: 14px; background: linear-gradient(180deg, var(--sky), var(--sky-2)); touch-action: manipulation; }

  /* ── Site Run canvas ─────────────────────────────────── */
  .run-stage { width: 100%; height: 100%; display: block; border-radius: 14px;
    background: #0d0f12; touch-action: none; -webkit-user-select: none; user-select: none; }
  .run-hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
    font-size: 12px; font-weight: 600; color: rgba(255,255,255,.85); background: rgba(0,0,0,.32);
    padding: 5px 12px; border-radius: 20px; pointer-events: none; z-index: 4; white-space: nowrap; }
  .run-hint.gz-hidden { display: none; }

  /* ── Overlay ─────────────────────────────────────────── */
  .overlay {
    position: absolute; inset: 0; border-radius: 14px;
    background: rgba(0,0,0,.66); backdrop-filter: blur(3px);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 22px; color: #fff; gap: 6px; z-index: 5;
  }
  .overlay.gz-hidden { display: none; }
  .overlay h2 { font-size: 23px; font-weight: 800; }
  .overlay p { font-size: 14px; opacity: .92; max-width: 320px; line-height: 1.5; }
  .overlay .final { font-size: 46px; font-weight: 800; color: var(--accent); line-height: 1.05; margin: 2px 0; }
  .overlay .best-line { font-size: 13px; opacity: .9; }
  .overlay .newbest { color: #ffe08a; font-weight: 700; }
  .gz-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--accent); color: #fff; border: none; border-radius: 12px;
    padding: 14px 34px; font-size: 15px; font-weight: 700; cursor: pointer;
    font-family: inherit; text-decoration: none; transition: background .15s, transform .1s; margin-top: 10px;
  }
  .gz-btn:hover { background: var(--accent-hover); }
  .gz-btn:active { transform: scale(.97); }

  /* ── Leaderboard entry (on the menu) ─────────────────── */
  .lb-open {
    margin-top: 14px; display: inline-flex; align-items: center; gap: 7px;
    background: transparent; border: 1.5px solid var(--border); color: var(--text);
    border-radius: 22px; padding: 9px 20px; font-family: inherit; font-weight: 700;
    font-size: 13.5px; cursor: pointer; transition: background .15s, border-color .15s, color .15s, transform .12s;
  }
  .lb-open:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
  .lb-open:active { transform: scale(.97); }
  .lb-open svg { width: 16px; height: 16px; }

  /* ── Leaderboard view (full hub panel, toggled like .play) ─ */
  .board-view { display: none; }
  .board-view.active { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .lb-wrap { gap: 12px; }
  .lb-tabs { display: flex; gap: 6px; flex-shrink: 0; }
  .lb-tab {
    flex: 1; min-width: 0; background: var(--bg); border: 1.5px solid var(--border); color: var(--text);
    border-radius: 10px; padding: 9px 5px; font-family: inherit; font-weight: 700; font-size: 12.5px;
    line-height: 1.2; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  }
  .lb-tab:hover { border-color: var(--accent); }
  .lb-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .lb-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .lb-you {
    position: sticky; top: 0; z-index: 1; background: var(--accent-soft); color: var(--text);
    border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 700; margin-bottom: 8px;
  }
  .lb-you b { color: var(--accent); }
  .lb-empty { text-align: center; color: var(--sub); padding: 34px 12px; font-size: 14px; }

  .lb-list { list-style: none; margin: 0; padding: 0; }
  .lb-list li { display: flex; align-items: center; gap: 10px; padding: 11px 8px; border-bottom: 1px solid var(--border); }
  .lb-list li:last-child { border-bottom: none; }
  .lb-list li.me { background: var(--accent-soft); border-radius: 10px; border-bottom-color: transparent; }
  .lb-rk { width: 34px; flex-shrink: 0; text-align: center; font-weight: 800; font-size: 15px; color: var(--sub); }
  .lb-nm { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lb-sc { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; flex-shrink: 0; }

  /* ── Mini leaderboard inside the game-over overlay ────── */
  .lb-mini { width: 100%; max-width: 320px; margin-top: 4px; }
  .lb-status { font-size: 13px; opacity: .9; min-height: 16px; }
  .lb-login { width: 100%; max-width: 320px; text-align: center; }
  .lb-login-text { font-size: 13.5px; line-height: 1.5; opacity: .95; margin-bottom: 10px; }
  .lb-login .lb-more { display: block; margin: 8px auto 0; }
  .lb-rank { font-size: 13.5px; opacity: .95; margin-bottom: 7px; }
  .lb-rank b { color: #ffd75e; }
  .lb-mini .lb-list li { padding: 5px 8px; border-bottom: 1px solid rgba(255,255,255,.14); }
  .lb-mini .lb-rk { color: rgba(255,255,255,.85); width: 26px; font-size: 14px; }
  .lb-mini .lb-nm { color: #fff; }
  .lb-mini .lb-sc { color: #ffd75e; }
  .lb-form { display: flex; gap: 8px; width: 100%; max-width: 320px; }
  .lb-name {
    flex: 1; min-width: 0; padding: 11px 13px; border-radius: 10px;
    border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.12); color: #fff;
    font-family: inherit; font-size: 14px;
  }
  .lb-name::placeholder { color: rgba(255,255,255,.6); }
  .lb-name:focus { outline: none; border-color: var(--accent); }
  .lb-save {
    background: var(--accent); color: #fff; border: none; border-radius: 10px; padding: 0 18px;
    font-weight: 700; font-family: inherit; font-size: 14px; cursor: pointer; flex-shrink: 0;
  }
  .lb-save:disabled { opacity: .6; cursor: default; }
  .lb-more {
    margin-top: 9px; background: transparent; border: none; color: #fff; opacity: .85;
    font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer; text-decoration: underline;
  }
  .lb-more:hover { opacity: 1; }

  @media (prefers-reduced-motion: reduce) {
    .pop, .hole.hit .pop { transition: transform .05s linear; }
    .spark span, .float-pts { animation-duration: .01s; }
    .game-card:hover { transform: none; }
  }
