  :root {
    --ink: #eee;
    --muted: #9a9a9a;
    --hud: #b8b8b8;
    --panel: rgba(18, 18, 18, 0.94);
    --panel-line: #333;
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body {
    margin: 0; width: 100%; height: 100%; height: 100dvh; overflow: hidden; background: #000;
    font-family: Ubuntu, system-ui, -apple-system, sans-serif; color: var(--ink);
    touch-action: none; -webkit-user-select: none; user-select: none;
  }
  canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: #000; }

  body.in-menu .hud-game { display: none !important; }

  /* --- Main Menu (opaque, mobile-first) --- */
  #mainMenu {
    position: fixed; inset: 0; display: none; place-items: center;
    background: #0d0f12;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    overflow-y: auto;
    z-index: 30; touch-action: manipulation;
  }
  body.in-menu #mainMenu { display: grid; }
  #menuCard {
    width: min(340px, 100%); padding: 24px 20px;
    border-radius: 16px; background: #16191f;
    border: 1px solid #262b34;
    display: flex; flex-direction: column; gap: 14px; text-align: center;
  }
  #menuTitle {
    margin: 0 0 4px; font-size: clamp(26px, 7vw, 32px); font-weight: 700;
    letter-spacing: -0.02em; color: #fff;
  }
  #nickInput {
    width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
    font: 500 16px/1.2 inherit;
    background: #0d0f12; border: 1px solid #2d333e;
    color: #fff; outline: none; -webkit-user-select: text; user-select: text;
    transition: border-color 120ms;
  }
  #nickInput::placeholder { color: #7c8492; }
  #nickInput:focus { border-color: #7ee84b; }
  #playBtn {
    width: 100%; min-height: 48px; padding: 12px 16px; border-radius: 12px; border: 0;
    font: 700 17px/1.2 inherit; color: #0b1406; background: #7ee84b;
    cursor: pointer; transition: filter 120ms, transform 80ms;
  }
  #playBtn:active { transform: scale(0.98); filter: brightness(0.95); }
  @media (max-height: 440px) {
    #menuCard { padding: 16px 18px; gap: 10px; }
    #menuTitle { font-size: 24px; margin-bottom: 0; }
    #nickInput, #playBtn { min-height: 44px; padding: 10px 14px; }
  }

  /* --- HUD --- */
  .score {
    position: fixed; left: max(16px, env(safe-area-inset-left)); top: 58px;
    font-weight: 700; font-size: clamp(14px, 4.4vh, 24px); color: var(--hud);
    text-shadow: 0 0 2px #000, 0 0 2px #000; pointer-events: none;
  }
  #pauseBtn {
    position: fixed; left: max(14px, env(safe-area-inset-left)); top: 10px;
    width: 40px; height: 40px; border-radius: 10px; border: 2px solid rgba(160,160,160,0.5);
    background: rgba(20,20,20,0.55); padding: 0; cursor: pointer; display: grid; place-items: center;
    z-index: 6;
  }
  #pauseBtn svg { width: 18px; height: 18px; fill: var(--hud); }
  #pauseModal {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
    display: none; place-items: center; z-index: 20;
  }
  #pauseModal.open { display: grid; }
  #pauseCard {
    background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px;
    padding: 20px 24px; min-width: min(280px, calc(100vw - 40px)); text-align: center;
    color: var(--ink); font-size: 15px; box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  }
  #pauseCard .btns { display: flex; justify-content: center; gap: 12px; margin-top: 16px; }
  #pauseCard button {
    font: inherit; padding: 8px 20px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--panel-line); background: #222; color: var(--ink);
  }
  #pauseCard button#pauseYes { background: #b33838; border-color: #d24b4b; }

  /* Left side: the joystick appears wherever you touch, while you touch. */
  #joyZone { position: fixed; left: 0; top: 0; bottom: 0; width: 62%; touch-action: none; }
  .joystick-base {
    position: fixed; width: 23vh; height: 23vh; min-width: 96px; min-height: 96px;
    left: 12%; top: 62%; transform: translate(-50%, -50%);
    border-radius: 50%; background: rgba(255, 255, 255, 0.11);
    opacity: 0; transition: opacity 80ms; pointer-events: none;
  }
  .joystick-base.shown { opacity: 1; }
  .joystick-stick {
    position: absolute; left: 50%; top: 50%; width: 50%; height: 50%;
    transform: translate(-50%, -50%); border-radius: 50%;
    background: rgba(0, 0, 0, 0.7); box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
    pointer-events: auto;
  }

  /* Right side: two round action buttons, where the game has them. */
  .action {
    position: fixed; width: 19vh; height: 19vh; min-width: 64px; min-height: 64px;
    transform: translate(-50%, -50%); border-radius: 50%;
    background: rgba(0, 0, 0, 0.2); border: 3px solid #454545;
    display: grid; place-items: center; padding: 0; cursor: pointer; touch-action: none;
  }
  .action:active { background: rgba(80, 80, 80, 0.35); }
  .action svg { stroke: #d1d1d1; width: 52%; height: 52%; }
  .action.unavailable { border-color: #2a2a2a; }
  .action.unavailable svg { stroke: #7a7b7d; }
  #splitBtn { left: 90%; top: 67%; }
  #feedBtn  { left: 84.6%; top: 87.5%; }

  #fsBtn {
    position: fixed; right: max(14px, env(safe-area-inset-right)); top: 10px;
    width: 40px; height: 40px; border-radius: 10px; border: 2px solid rgba(160,160,160,0.5);
    background: rgba(20,20,20,0.55); padding: 0; cursor: pointer; display: grid; place-items: center;
  }
  #fsBtn svg { width: 20px; height: 20px; stroke: var(--hud); }
  #fsToast {
    position: fixed; right: max(14px, env(safe-area-inset-right)); top: 58px; max-width: min(300px, calc(100vw - 28px));
    padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-line);
    color: var(--ink); font: 13px/1.4 system-ui, sans-serif; display: none; z-index: 5;
  }
  #fsToast.show { display: block; }

  /* --- Leaderboard (square icon button, collapsed by default) --- */
  #leaderboard {
    position: fixed; right: max(14px, env(safe-area-inset-right)); top: 58px;
    display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
    z-index: 6;
  }
  #lbToggle {
    width: 40px; height: 40px; border-radius: 10px;
    border: 2px solid rgba(160, 160, 160, 0.5);
    background: rgba(20, 20, 20, 0.55);
    padding: 0; cursor: pointer; display: grid; place-items: center;
  }
  #lbToggle svg { width: 20px; height: 20px; stroke: var(--hud); }
  #leaderboard.expanded #lbToggle {
    border-color: rgba(220, 220, 220, 0.8);
    background: rgba(35, 35, 35, 0.8);
  }
  #lbList {
    display: none; width: min(190px, 46vw); padding: 8px 10px;
    border-radius: 10px; background: rgba(20, 20, 20, 0.78);
    border: 1px solid rgba(160, 160, 160, 0.35);
    color: var(--ink);
  }
  #leaderboard.expanded #lbList { display: block; }
  .lb-row {
    display: flex; gap: 6px; padding: 2px 0;
    font-size: 12px; line-height: 1.35; color: #ddd;
    font-variant-numeric: tabular-nums;
  }
  .lb-row.me { color: #7ee84b; font-weight: 700; }
  .lb-rank { flex: 0 0 auto; color: #8c8c8c; min-width: 18px; }
  .lb-row.me .lb-rank { color: #7ee84b; }
  .lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lb-sep { height: 1px; margin: 4px 0; background: rgba(255, 255, 255, 0.14); }
