/* ==========================================================================
   Russian Hand - Main menu overlay (src/ui/MainMenu.js)

   Dark green felt, gold accents. Colours come from the CSS variables of style.css (with the same values as
   fallbacks), every class is prefixed menu-, and everything is written with logical properties so the
   layout mirrors itself under dir="rtl". Loaded after style.css (MainMenu links it itself if the page does
   not).

   Layout model
   - Base rules: one column (phones, portrait).
   - Wide or short-landscape block: profile card and game modes side by side.
   - Hover feedback only exists for real pointers; touch gets :active feedback instead.
   z-index 150 sits above the game header (120) and below the game dialogs (200: rules, lobby, confirm),
   so those open on top of the menu.
   ========================================================================== */

body.menu-open {
  overflow: hidden;
}

.menu-overlay {
  --menu-gold: var(--gold-accent, #f59e0b);
  --menu-gold-soft: #fbbf24;
  --menu-gold-pale: #fde68a;
  --menu-gold-deep: #d97706;
  --menu-ink: #1f1300;
  --menu-text: var(--text-main, #f8fafc);
  --menu-muted: var(--text-muted, #94a3b8);
  --menu-line: var(--panel-border, rgba(245, 158, 11, 0.25));
  --menu-ok: #34d399;
  --menu-warn: #fbbf24;
  --menu-danger: #f87171;
  --menu-gap: 14px;
  --menu-radius: 18px;

  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 150;
  display: flex;
  isolation: isolate;
  overflow: hidden;
  color: var(--menu-text);
  font-family: inherit;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background:
    radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 20px 20px,
    radial-gradient(ellipse at 50% 0%, rgba(245, 158, 11, 0.12), transparent 55%),
    radial-gradient(circle at 50% 45%, #1d5236 0%, #0d2c1c 62%, #05140c 100%);
  animation: menuFade 0.25s ease-out;
}

.menu-overlay[hidden],
.menu-overlay [hidden] {
  display: none !important;
}

.menu-overlay,
.menu-overlay *,
.menu-overlay *::before,
.menu-overlay *::after {
  box-sizing: border-box;
}

.menu-overlay h1,
.menu-overlay h2,
.menu-overlay p {
  margin: 0;
}

/* Big faint card suits in two corners: felt-table decoration, never part of the content. */
.menu-overlay::before,
.menu-overlay::after {
  position: absolute;
  z-index: -1;
  pointer-events: none;
  font-size: clamp(9rem, 38vmin, 22rem);
  line-height: 1;
  color: var(--menu-gold);
  opacity: 0.05;
}

.menu-overlay::before {
  content: '♠';
  inset-block-start: -2rem;
  inset-inline-start: -1.5rem;
  transform: rotate(-12deg);
}

.menu-overlay::after {
  content: '♦';
  inset-block-end: -3rem;
  inset-inline-end: -1.5rem;
  transform: rotate(14deg);
}

.menu-overlay button {
  margin: 0;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.menu-overlay :focus-visible {
  outline: 3px solid #fef3c7;
  outline-offset: 3px;
}

.menu-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Scroll area and shell ---- */
.menu-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}

/* margin-block: auto centres the menu when it is shorter than the screen and lets it scroll from the top when not. */
.menu-shell {
  width: 100%;
  max-width: 560px;
  margin-block: auto;
  display: flex;
  flex-direction: column;
  gap: var(--menu-gap);
  animation: menuRise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* ---- Cards ---- */
.menu-card {
  position: relative;
  padding: 16px;
  border-radius: var(--menu-radius);
  border: 1px solid var(--menu-line);
  background: linear-gradient(180deg, rgba(14, 36, 25, 0.94), rgba(6, 18, 12, 0.94));
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.menu-card::before {
  content: '';
  position: absolute;
  inset-block-start: 0;
  inset-inline: 22px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--menu-gold), transparent);
  opacity: 0.7;
}

.menu-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-block-end: 14px;
}

.menu-brand {
  min-width: 0;
}

.menu-title {
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  font-weight: 800;
  line-height: 1.2;
  color: var(--menu-gold-soft);
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .menu-title {
    background: linear-gradient(180deg, #fff1b8 0%, #f59e0b 55%, #b45309 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
  }
}

.menu-subtitle {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--menu-muted);
}

html[lang="en"] .menu-title,
html[lang="en"] .menu-subtitle {
  letter-spacing: 0.04em;
}

/* ---- Connection dot ---- */
.menu-conn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 50%;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--menu-line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--menu-muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.menu-conn-dot,
.menu-auth-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.menu-conn-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-conn[data-state="online"] { color: var(--menu-ok); }
.menu-conn[data-state="connecting"] { color: var(--menu-warn); }
.menu-conn[data-state="offline"] { color: var(--menu-danger); }

.menu-conn[data-state="connecting"] .menu-conn-dot,
.menu-auth[data-tone="busy"] .menu-auth-dot {
  animation: menuPulse 1.2s ease-in-out infinite;
}

/* ---- Profile ---- */
.menu-identity {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.menu-avatar {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--menu-gold);
  font-size: 2rem;
  line-height: 1;
  overflow: hidden;
  background: radial-gradient(circle at 30% 25%, #2a6b46, #0d2c1c);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18), 0 6px 14px rgba(0, 0, 0, 0.5);
}

/* The player's Google photo fills the round avatar. */
.menu-avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.menu-identity-info {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-name-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
}

.menu-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.25rem;
  font-weight: 800;
}

.menu-level-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-level-badge {
  flex: none;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  color: var(--menu-ink);
  background: linear-gradient(135deg, #fde68a, #f59e0b);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}

.menu-xp {
  flex: 1;
  min-width: 40px;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.menu-xp-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--menu-gold-deep), var(--menu-gold-soft));
  transition: width 0.6s ease;
}

.menu-xp-text {
  min-height: 1.2em;
  font-size: 0.75rem;
  color: var(--menu-muted);
}

.menu-profile-card[data-state="empty"] .menu-level-badge,
.menu-profile-card[data-state="empty"] .menu-chips {
  opacity: 0.55;
}

/* ---- Nickname editor ---- */
.menu-name-form {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-name-form .menu-input {
  flex: 1 1 auto;
}

.menu-msg {
  min-height: 1.35em;
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--menu-muted);
}

.menu-msg[data-tone="error"],
.menu-name-msg {
  color: var(--menu-danger);
}

.menu-name-msg {
  flex: 1 1 100%;
  min-height: 0;
}

.menu-name-msg:empty {
  display: none;
}

/* ---- Chips and record ---- */
.menu-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-block-start: 14px;
}

.menu-chips {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(245, 158, 11, 0.5);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.24), rgba(245, 158, 11, 0.08));
}

/* The shine is a gradient band sliding across the pill (transform only, so it never repaints). It plays a few times
   and stops: a looping animation would keep the compositor busy for as long as the menu is open. */
.menu-chips::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 40%, rgba(255, 255, 255, 0.32) 50%, transparent 60%);
  transform: translateX(-100%);
  animation: menuShine 5.5s ease-in-out 3;
}

.menu-coin {
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f59e0b 55%, #b45309);
  box-shadow: inset 0 0 0 3px rgba(120, 53, 15, 0.35), 0 1px 3px rgba(0, 0, 0, 0.5);
}

.menu-coin::after {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.5px dashed rgba(120, 53, 15, 0.55);
}

.menu-chips-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--menu-gold-pale);
  font-variant-numeric: tabular-nums;
}

.menu-chips-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--menu-muted);
}

.menu-record {
  font-size: 0.8rem;
  color: var(--menu-muted);
}

/* ---- Sign-in line ---- */
.menu-auth {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-block-start: 12px;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--menu-muted);
}

.menu-auth[data-tone="ok"] { color: var(--menu-ok); }
.menu-auth[data-tone="warn"] { color: var(--menu-warn); }

/* ---- Account: Google sign-in (guest/anonymous player) and sign-out (Google player) ---- */
.menu-account {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-block-start: 12px;
}

.menu-google {
  flex: 1 1 220px;
  color: #1f2937;
  border: 1px solid #dadce0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.menu-google-logo {
  flex: none;
  width: 20px;
  height: 20px;
}

.menu-signout {
  flex: 1 1 auto;
}

.menu-google:active,
.menu-signout:active {
  transform: scale(0.98);
}

.menu-google:disabled,
.menu-signout:disabled {
  opacity: 0.55;
  cursor: default;
}

@media (hover: hover) and (pointer: fine) {
  .menu-google:hover {
    background: #f1f5f9;
  }
}

/* ---- Buttons ---- */
.menu-icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--menu-gold-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.menu-btn {
  min-height: 48px;
  padding: 10px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 14px;
  border: 1px solid var(--menu-line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--menu-text);
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.menu-btn--primary {
  border: none;
  color: var(--menu-ink);
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 55%, #d97706 100%);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.35);
}

.menu-btn--compact {
  flex: none;
  min-height: 44px;
  padding: 8px 14px;
}

.menu-btn--wide {
  width: 100%;
}

.menu-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--menu-line);
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font: inherit;
  /* 16px or more: iOS Safari zooms the page on focus into anything smaller, and the zoom sticks. */
  font-size: 16px;
}

.menu-input:focus {
  border-color: var(--menu-gold);
}

.menu-input[aria-invalid="true"] {
  border-color: var(--menu-danger);
}

.menu-btn:disabled,
.menu-mode:disabled,
.menu-resume:disabled,
.menu-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Game modes ---- */
.menu-modes {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-mode {
  width: 100%;
  min-height: 72px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: var(--menu-radius);
  border: 1px solid var(--menu-line);
  background: linear-gradient(180deg, rgba(20, 48, 34, 0.94), rgba(8, 22, 15, 0.94));
  color: var(--menu-text);
  text-align: start;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, filter 0.2s ease;
}

.menu-mode--primary {
  border-color: #fcd34d;
  color: var(--menu-ink);
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 55%, #d97706 100%);
  box-shadow: 0 10px 26px rgba(245, 158, 11, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.menu-mode-icon {
  flex: none;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-size: 1.6rem;
  line-height: 1;
  background: rgba(0, 0, 0, 0.28);
}

.menu-mode--primary .menu-mode-icon {
  background: rgba(255, 255, 255, 0.38);
}

.menu-mode-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-mode-label {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
}

.menu-mode-desc {
  font-size: 0.8rem;
  line-height: 1.35;
  opacity: 0.8;
}

/* Border corner turned into a chevron; physical borders on purpose, mirrored for RTL below. */
.menu-mode-chevron {
  flex: none;
  width: 10px;
  height: 10px;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  transform: rotate(-45deg);
  opacity: 0.7;
}

[dir="rtl"] .menu-mode-chevron {
  transform: rotate(135deg);
}

.menu-resume {
  min-height: 52px;
  padding: 10px 16px;
  border-radius: var(--menu-radius);
  border: 1px dashed var(--menu-gold);
  background: rgba(245, 158, 11, 0.12);
  color: var(--menu-gold-pale);
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

/* ---- Quick match search ---- */
.menu-searching {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 16px;
  text-align: center;
}

.menu-spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(245, 158, 11, 0.2);
  border-top-color: var(--menu-gold);
  animation: menuSpin 1s linear infinite;
}

.menu-searching-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--menu-gold-pale);
}

.menu-pips {
  display: flex;
  gap: 8px;
}

.menu-pip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--menu-line);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.menu-pip.is-filled {
  border-color: var(--menu-gold-soft);
  background: var(--menu-gold);
  box-shadow: 0 0 8px var(--gold-glow, rgba(245, 158, 11, 0.65));
}

.menu-searching-meta {
  font-size: 0.9rem;
  color: var(--menu-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Footer ---- */
.menu-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.menu-chip-btn {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--menu-line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--menu-text);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

/* ---- Custom Rooms dialog ---- */
.menu-dialog-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.72);
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  animation: menuFade 0.2s ease-out;
}

.menu-dialog {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: menuRise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.menu-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.menu-dialog-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--menu-gold-soft);
}

.menu-dialog-note {
  margin-block-start: -6px;
  font-size: 0.85rem;
  color: var(--menu-muted);
  text-align: center;
}

.menu-dialog-subtitle {
  font-weight: 800;
  color: var(--menu-gold-pale);
}

.menu-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--menu-muted);
}

.menu-divider::before,
.menu-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--menu-line);
}

.menu-join-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-join-row {
  display: flex;
  gap: 8px;
}

.menu-code-input {
  flex: 1;
  text-align: center;
  text-indent: 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.menu-code-input::placeholder {
  font-weight: 400;
  opacity: 0.35;
}

/* ---- Fallback toast (used only when no UI toast is wired) ---- */
.menu-toast {
  position: absolute;
  z-index: 10;
  inset-inline: 0;
  inset-block-end: max(16px, env(safe-area-inset-bottom, 0px));
  width: fit-content;
  max-width: calc(100% - 32px);
  margin-inline: auto;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--menu-line);
  background: rgba(15, 23, 42, 0.96);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.menu-toast[data-type="error"] { background: rgba(127, 29, 29, 0.97); border-color: var(--menu-danger); }
.menu-toast[data-type="warning"] { border-color: var(--menu-warn); }
.menu-toast[data-type="success"] { border-color: var(--menu-ok); }

/* ---- Press feedback (touch and mouse) ---- */
.menu-mode:active:not(:disabled),
.menu-btn:active:not(:disabled),
.menu-resume:active:not(:disabled) {
  transform: scale(0.985);
}

.menu-chip-btn:active,
.menu-icon-btn:active {
  background: rgba(245, 158, 11, 0.22);
}

/* ---- Pointer-only hover feedback ---- */
@media (hover: hover) and (pointer: fine) {
  .menu-mode:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: var(--menu-gold);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  }

  .menu-mode--primary:hover:not(:disabled),
  .menu-btn--primary:hover:not(:disabled) {
    filter: brightness(1.08);
  }

  .menu-btn:not(.menu-btn--primary):hover:not(:disabled),
  .menu-chip-btn:hover,
  .menu-icon-btn:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: var(--menu-gold);
  }

  .menu-resume:hover:not(:disabled) {
    background: rgba(245, 158, 11, 0.22);
  }
}

/* ---- Narrow phones ---- */
@media (max-width: 359px) {
  .menu-scroll {
    padding:
      max(16px, env(safe-area-inset-top, 0px))
      max(10px, env(safe-area-inset-right, 0px))
      max(16px, env(safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left, 0px));
  }

  .menu-card {
    padding: 14px 12px;
  }

  .menu-avatar {
    width: 54px;
    height: 54px;
    font-size: 1.7rem;
  }

  .menu-mode {
    gap: 10px;
    padding: 10px 12px;
  }

  .menu-mode-icon {
    width: 42px;
    height: 42px;
  }

  .menu-footer {
    gap: 6px;
  }

  .menu-chip-btn {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
}

/* ---- Wide screens and landscape phones: profile and modes side by side ---- */
@media (min-width: 820px), (orientation: landscape) and (max-height: 520px) {
  .menu-shell {
    max-width: 960px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "profile main"
      "footer footer";
    align-items: start;
    gap: var(--menu-gap) 20px;
  }

  .menu-profile-card { grid-area: profile; }
  .menu-main { grid-area: main; }
  .menu-footer { grid-area: footer; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .menu-overlay {
    --menu-gap: 10px;
  }

  .menu-scroll {
    padding-block: max(10px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-bottom, 0px));
  }

  .menu-card {
    padding: 12px;
  }

  .menu-card-top {
    margin-block-end: 6px;
  }

  .menu-title {
    font-size: 1.5rem;
  }

  .menu-avatar {
    width: 52px;
    height: 52px;
    font-size: 1.6rem;
  }

  .menu-stats,
  .menu-auth {
    margin-block-start: 8px;
  }

  .menu-chips {
    padding: 6px 14px;
  }

  .menu-main,
  .menu-modes {
    gap: 8px;
  }

  .menu-mode {
    min-height: 60px;
    padding: 8px 12px;
  }

  .menu-mode-icon {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
  }

  .menu-searching {
    gap: 8px;
    padding: 12px;
  }

  .menu-spinner {
    width: 40px;
    height: 40px;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  .menu-mode-desc,
  .menu-subtitle {
    display: none;
  }
}

/* ---- Motion ---- */
@keyframes menuFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes menuRise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes menuSpin {
  to { transform: rotate(360deg); }
}

@keyframes menuPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes menuShine {
  0%, 45% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* No sliding, no spinning, no looping shine. The spinner stays visible as a static ring with a gold arc. */
@media (prefers-reduced-motion: reduce) {
  .menu-overlay,
  .menu-shell,
  .menu-dialog-layer,
  .menu-dialog,
  .menu-chips::after,
  .menu-spinner,
  .menu-conn-dot,
  .menu-auth-dot {
    animation: none;
  }

  .menu-xp-fill,
  .menu-mode,
  .menu-btn,
  .menu-chip-btn,
  .menu-pip {
    transition: none;
  }
}

/* ==========================================================================
   Player Profile modal (src/ui/ProfileModal.js) - opened from the menu header or the player's own badge.
   Lives on document.body so it also works during a match; it carries its own colour tokens. No blur, and it only
   animates opacity/transform. z-index 250 sits above the game dialogs (200) and the menu (150).
   ========================================================================== */
.pf-layer {
  --pf-gold: #f59e0b;
  --pf-gold-soft: #fbbf24;
  --pf-gold-pale: #fde68a;
  --pf-text: #f8fafc;
  --pf-muted: #94a3b8;
  --pf-line: rgba(245, 158, 11, 0.3);

  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.82);
  overscroll-behavior: contain;
  animation: pfFade 0.2s ease-out;
}

.pf-layer[hidden] {
  display: none !important;
}

.pf-layer,
.pf-layer *,
.pf-layer *::before,
.pf-layer *::after {
  box-sizing: border-box;
}

.pf-card {
  position: relative;
  width: min(100%, 420px);
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 20px 20px;
  border-radius: 20px;
  border: 1px solid var(--pf-line);
  background: linear-gradient(160deg, #123a27 0%, #0b2216 70%);
  color: var(--pf-text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  animation: pfRise 0.24s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.pf-close {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-end: 8px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--pf-gold-soft);
  font-size: 1.1rem;
  cursor: pointer;
}

.pf-close:focus-visible {
  outline: 2px solid var(--pf-gold);
  outline-offset: 2px;
}

.pf-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-inline-end: 40px;
}

.pf-avatar {
  flex: none;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  border: 2px solid var(--pf-gold);
  background: radial-gradient(circle at 30% 25%, #2a6b46, #0d2c1c);
  font-size: 2.2rem;
  line-height: 1;
}

.pf-avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.pf-identity {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.pf-name {
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.pf-level {
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fbbf24, #d97706);
  color: #1f1300;
  font-size: 0.8rem;
  font-weight: 800;
}

.pf-xp {
  height: 8px;
  margin-block-start: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.pf-xp-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
}

.pf-xp-text {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--pf-muted);
}

.pf-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 0;
}

.pf-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
}

/* Balance and best score are the headline numbers: they span the full row. */
.pf-stat--balance,
.pf-stat--bestScore {
  grid-column: 1 / -1;
}

.pf-stat--balance {
  border-color: var(--pf-line);
  background: rgba(245, 158, 11, 0.1);
}

.pf-stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--pf-muted);
}

.pf-stat-value {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--pf-gold-pale);
  font-variant-numeric: tabular-nums;
}

/* Matches, wins and win rate share one row of three smaller tiles. */
.pf-stat--matches .pf-stat-value,
.pf-stat--wins .pf-stat-value,
.pf-stat--winRate .pf-stat-value {
  font-size: 1.2rem;
}

.pf-stat-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--pf-muted);
}

.pf-note {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--pf-gold-soft);
}

@keyframes pfFade {
  from { opacity: 0; }
}

@keyframes pfRise {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
}

@media (prefers-reduced-motion: reduce) {
  .pf-layer,
  .pf-card {
    animation: none;
  }
}

/* The avatar and name of the menu header open the profile: buttons that look like the text/avatar they replace. */
.menu-open-profile {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button.menu-name.menu-open-profile {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: start;
}

button.menu-avatar.menu-open-profile {
  padding: 0;
}

.menu-open-profile:active {
  transform: scale(0.97);
}

.menu-open-profile:focus-visible {
  outline: 2px solid var(--menu-gold);
  outline-offset: 3px;
}

/* ---- Create Private Room: table settings (timer, stake, rules) ---- */
.menu-create-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-block-end: 14px;
}

.menu-choice-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-choice-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--menu-gold-soft);
}

.menu-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.menu-choice {
  flex: 1 1 auto;
  min-width: 52px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid var(--menu-line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--menu-text);
  font: inherit;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.menu-choice.is-selected {
  border-color: transparent;
  color: var(--menu-ink);
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 60%, #d97706 100%);
}

.menu-choice:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.menu-choice:active:not(:disabled) {
  transform: scale(0.96);
}

.menu-choice:focus-visible {
  outline: 2px solid var(--menu-gold);
  outline-offset: 2px;
}

.menu-choice-note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--menu-muted);
}

@media (hover: hover) and (pointer: fine) {
  .menu-choice:hover:not(:disabled):not(.is-selected) {
    background: rgba(255, 255, 255, 0.12);
  }
}