/* ════════════════════════════════════════════════════════════════════
   TypeArena — FINAL MOBILE UI v3
   Полная переделка интерфейса для мобильных
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  /* ─────── BODY & APP ─────── */
  body {
    --safe-top: max(env(safe-area-inset-top), 8px);
    --safe-bottom: max(env(safe-area-inset-bottom), 8px);
  }

  html, body {
    position: fixed;
    width: 100%;
    height: 100vh;
    overflow: hidden;
  }

  #app {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
  }

  /* ─────── HIDE OLD TOPBAR & PROFILE ─────── */
  .topbar,
  .profile-pill,
  .topbar-spacer {
    display: none !important;
  }

  /* ─────── MAIN CONTENT AREA ─────── */
  .main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-top: 0;
    padding-bottom: 0 !important;
    position: relative;
  }

  /* ─────── PAGES (Absolute Positioning) ─────── */
  .page {
    position: absolute !important;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    padding-bottom: 80px;
    display: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 260ms cubic-bezier(0.2, 0.7, 0.2, 1), 
                visibility 260ms cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  .page.visible {
    display: block;
    opacity: 1;
    visibility: visible;
  }

  .page::-webkit-scrollbar {
    width: 4px;
  }

  .page::-webkit-scrollbar-thumb {
    background: rgba(88, 166, 255, 0.3);
    border-radius: 2px;
  }

  /* ─────── BOTTOM NAVIGATION BAR ─────── */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    padding-bottom: var(--safe-bottom);
    background: linear-gradient(
      to top,
      rgba(13, 17, 23, 0.98),
      rgba(13, 17, 23, 0.92)
    );
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    z-index: 200;
    gap: 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
  }

  /* ─────── NAVIGATION BUTTONS ─────── */
  .bottom-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 60px;
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    font-size: 0;
    padding: 0;
    position: relative;
  }

  .bottom-nav-btn:active {
    background: rgba(88, 166, 255, 0.06);
  }

  /* Icon */
  .bottom-nav-btn .icon {
    font-size: 22px;
    line-height: 1;
    display: block;
  }

  /* Label */
  .bottom-nav-btn .label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  /* Active state */
  .bottom-nav-btn.active {
    color: var(--accent);
  }

  .bottom-nav-btn.active .icon {
    color: var(--accent);
  }

  .bottom-nav-btn.active .label {
    color: var(--accent);
  }

  .bottom-nav-btn.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
  }

  /* ─────── GAME PAGE FULLSCREEN ─────── */
  #page-game {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    z-index: 150;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* All game wrappers */
  .classic-wrapper,
  .falling-wrapper,
  .zombie-wrapper,
  .osu-wrapper,
  .sapper-wrapper,
  .detective-wrapper,
  .boss-wrapper,
  .royale-wrapper,
  .hacker-wrapper {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    z-index: 151;
  }

  /* ─────── HUD (SCORE, WPM, ETC) ─────── */
  .classic-hud,
  .falling-hud,
  .zombie-hud,
  .osu-hud,
  .sapper-hud,
  .detective-hud,
  .boss-hud,
  .royale-hud,
  .hacker-hud {
    order: 1;
    flex-shrink: 0;
    padding: 6px 8px !important;
    gap: 6px !important;
    font-size: 0.65rem !important;
    background: rgba(13, 17, 23, 0.85);
    border-bottom: 1px solid rgba(88, 166, 255, 0.1);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    min-height: auto;
    line-height: 1.2;
  }

  .hud-item {
    font-size: 0.65rem !important;
    padding: 2px 4px !important;
    white-space: nowrap;
    display: flex;
    gap: 2px;
    align-items: center;
  }

  .hud-item strong {
    font-weight: 700;
    color: var(--accent);
  }

  /* Hide some HUD items on very small screens */
  @media (max-width: 480px) {
    .hud-item:nth-child(n + 6) {
      display: none;
    }
  }

  /* ─────── GAME CONTENT (scrollable area) ─────── */
  .classic-text-area,
  .falling-field,
  .zombie-list,
  .zombie-text-area,
  .osu-arena,
  .sapper-board,
  .detective-board,
  .boss-arena,
  .boss-spell-area,
  .royale-leaderboard,
  .royale-text-area,
  .hacker-arena {
    order: 2;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
  }

  /* ─────── KEYBOARD SECTION (fixed at bottom) ─────── */
  #global-keyboard-section {
    position: fixed;
    bottom: 60px; /* Above bottom nav */
    left: 0;
    right: 0;
    width: 100%;
    z-index: 160;
    max-height: 280px;
    overflow: hidden;
    background: var(--bg);
    border-top: 1px solid var(--border);
  }

  .keyboard-section {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0 !important;
    max-height: 280px;
    width: 100%;
  }

  /* Virtual keyboard styling */
  #virtual-keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
    gap: 2px;
    padding: 4px;
    background: var(--bg2);
  }

  .key {
    padding: 8px 4px !important;
    font-size: 0.7rem !important;
    border-radius: 4px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.1s, box-shadow 0.1s;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text);
  }

  .key:active {
    background: var(--accent);
    color: white;
    box-shadow: none;
  }

  /* ─────── GAME-SPECIFIC LAYOUTS ─────── */

  /* Classic Mode */
  .classic-wrapper .classic-hud {
    order: 1;
  }

  .classic-wrapper .classic-text-area {
    order: 2;
    padding: 12px 10px !important;
    font-size: 1.2rem !important;
    line-height: 1.9 !important;
    text-align: center;
    word-break: break-word;
  }

  /* Falling Mode */
  .falling-wrapper .falling-field {
    order: 2;
    min-height: 220px;
  }

  /* Zombie Mode */
  .zombie-wrapper .zombie-list {
    order: 2;
    flex-shrink: 0;
    max-height: 60px;
    margin-bottom: 4px;
  }

  .zombie-wrapper .zombie-text-area {
    order: 3;
    padding: 10px 8px !important;
    font-size: 1.1rem !important;
  }

  /* OSU Mode */
  .osu-wrapper .osu-arena {
    order: 2;
    justify-content: center;
    align-items: center;
    padding: 12px 8px !important;
    gap: 16px;
  }

  .osu-circle {
    width: 54px !important;
    height: 54px !important;
    font-size: 1.6rem !important;
    flex-shrink: 0;
  }

  /* Sapper Mode */
  .sapper-wrapper .sapper-hud {
    order: 1;
  }

  .sapper-wrapper .sapper-board {
    order: 2;
    flex: 1;
  }

  .sapper-wrapper .sb-code-display {
    order: 3;
    flex-shrink: 0;
    padding: 8px !important;
    font-size: 0.95rem !important;
    border-top: 1px solid var(--border);
  }

  /* Detective Mode */
  .detective-wrapper .detective-board {
    order: 2;
    padding: 16px 10px !important;
    font-size: 1.1rem !important;
    text-align: center;
  }

  .det-sentence {
    line-height: 1.8 !important;
  }

  /* Boss Mode */
  .boss-wrapper .boss-hud {
    order: 1;
  }

  .boss-wrapper .boss-arena {
    order: 2;
    flex-shrink: 0;
    max-height: 100px;
    padding: 6px 8px !important;
    overflow: hidden;
  }

  .boss-wrapper .boss-spell-area {
    order: 3;
    flex: 1;
    padding: 8px 6px !important;
  }

  .bs-spell-text {
    font-size: 1rem !important;
  }

  /* Royale Mode */
  .royale-wrapper .royale-leaderboard {
    order: 2;
    flex-shrink: 0;
    max-height: 80px;
  }

  .royale-wrapper .royale-text-area {
    order: 3;
    flex: 1;
    padding: 8px !important;
  }

  /* Hacker Mode */
  .hacker-wrapper .hacker-arena {
    order: 2;
    flex-direction: column;
    padding: 12px 8px !important;
    gap: 12px;
  }

  .hacker-display {
    padding: 12px 16px !important;
  }

  .hk-word {
    font-size: 1.3rem !important;
  }

  /* ─────── HOME PAGE RESPONSIVE ─────── */
  #page-home {
    padding: 0 !important;
  }

  .home-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .home-hero {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
  }

  .home-hero-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .hero-title {
    font-size: 1.4rem !important;
    font-weight: 800;
    line-height: 1.2;
    margin: 0 !important;
  }

  .hero-subtitle {
    font-size: 0.85rem;
    color: var(--text2);
    margin: 0 !important;
    line-height: 1.5;
  }

  .quick-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 8px;
  }

  .qs-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px;
    background: var(--bg2);
    border-radius: 8px;
    text-align: center;
  }

  .qs-val {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent);
  }

  .qs-lbl {
    font-size: 0.65rem;
    color: var(--text2);
    font-weight: 600;
  }

  .home-hero-vip {
    display: none !important;
  }

  .home-ui-toggle {
    display: none !important;
  }

  .section-label {
    padding: 10px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text2);
    letter-spacing: 0.05em;
  }

  .mode-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 8px 12px;
  }

  .mode-card {
    padding: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 10px;
    align-items: start;
  }

  .mode-card:active {
    background: rgba(88, 166, 255, 0.15);
    border-color: var(--accent);
  }

  .mc-icon {
    font-size: 1.8rem;
    grid-column: 1 / 2;
    grid-row: 1 / 3;
  }

  .mc-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    grid-column: 2;
  }

  .mc-desc {
    font-size: 0.75rem;
    color: var(--text2);
    line-height: 1.4;
    grid-column: 2;
  }

  .mc-badge {
    display: none;
  }

  .mode-card.ui-advanced {
    display: none;
  }

  /* ─────── OTHER PAGES ─────── */
  .page {
    padding-bottom: 80px !important;
  }

  /* ─────── SCROLLBAR STYLING ─────── */
  .main-content::-webkit-scrollbar,
  .classic-text-area::-webkit-scrollbar,
  .falling-field::-webkit-scrollbar,
  .zombie-list::-webkit-scrollbar,
  .sapper-board::-webkit-scrollbar,
  .boss-spell-area::-webkit-scrollbar {
    width: 4px;
  }

  .main-content::-webkit-scrollbar-track,
  .classic-text-area::-webkit-scrollbar-track,
  .falling-field::-webkit-scrollbar-track,
  .zombie-list::-webkit-scrollbar-track,
  .sapper-board::-webkit-scrollbar-track,
  .boss-spell-area::-webkit-scrollbar-track {
    background: transparent;
  }

  .main-content::-webkit-scrollbar-thumb,
  .classic-text-area::-webkit-scrollbar-thumb,
  .falling-field::-webkit-scrollbar-thumb,
  .zombie-list::-webkit-scrollbar-thumb,
  .sapper-board::-webkit-scrollbar-thumb,
  .boss-spell-area::-webkit-scrollbar-thumb {
    background: rgba(88, 166, 255, 0.3);
    border-radius: 2px;
  }
}

/* ════════════════════════════════════════════════════════════════════
   GRAPHICS QUALITY SETTINGS — ULTRA AGGRESSIVE OPTIMIZATION
   ════════════════════════════════════════════════════════════════════ */

/* LOW GRAPHICS — MAXIMUM PERFORMANCE */
body[data-graphics="low"] {
  --transition: none;
  --animation: none;
}

body[data-graphics="low"] * {
  animation: none !important;
  transition: none !important;
  animation-duration: 0s !important;
  transition-duration: 0s !important;
}

/* Remove all blur effects */
body[data-graphics="low"] .topbar,
body[data-graphics="low"] .bottom-nav,
body[data-graphics="low"] .keyboard-section,
body[data-graphics="low"] #virtual-keyboard {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Remove shadows */
body[data-graphics="low"] * {
  box-shadow: none !important;
  text-shadow: none !important;
  filter: none !important;
}

/* Disable fancy effects */
body[data-graphics="low"] .key:active {
  background: var(--accent);
  color: white;
  box-shadow: none !important;
  filter: none !important;
}

body[data-graphics="low"] .mode-card:active {
  background: rgba(88, 166, 255, 0.1);
  box-shadow: none !important;
}

/* Remove gradient backgrounds */
body[data-graphics="low"] .bottom-nav {
  background: var(--bg) !important;
  border-top: 1px solid var(--border);
}

/* Disable hover effects */
body[data-graphics="low"] .bottom-nav-btn:hover,
body[data-graphics="low"] .key:hover,
body[data-graphics="low"] .mode-card:hover {
  opacity: 1;
  background: unchanged;
}

/* Remove transform animations */
body[data-graphics="low"] .confetti,
body[data-graphics="low"] .particle,
body[data-graphics="low"] [class*="animate"],
body[data-graphics="low"] [class*="bounce"],
body[data-graphics="low"] [class*="pulse"] {
  animation: none !important;
  transform: none !important;
}

/* Simplify game elements */
body[data-graphics="low"] .osu-circle {
  box-shadow: none !important;
  filter: none !important;
}

body[data-graphics="low"] .boss-avatar {
  filter: none !important;
  box-shadow: none !important;
}

body[data-graphics="low"] .zombie-item {
  filter: none !important;
  box-shadow: none !important;
}

body[data-graphics="low"] .falling-word {
  text-shadow: none !important;
  box-shadow: none !important;
}

/* Reduce motion requests */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* MEDIUM GRAPHICS (default) */
body[data-graphics="medium"] {
  --transition: 0.15s ease;
}

body[data-graphics="medium"] .bottom-nav {
  background: linear-gradient(
    to top,
    rgba(13, 17, 23, 0.98),
    rgba(13, 17, 23, 0.92)
  );
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

body[data-graphics="medium"] .key:active {
  box-shadow: 0 0 8px rgba(88, 166, 255, 0.3);
}

/* HIGH GRAPHICS */
body[data-graphics="high"] {
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body[data-graphics="high"] .bottom-nav {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.6);
}

body[data-graphics="high"] .key:active {
  box-shadow: 0 0 12px rgba(88, 166, 255, 0.5);
}

body[data-graphics="high"] .boss-avatar {
  filter: drop-shadow(0 0 16px rgba(220, 38, 38, 0.7));
}

/* ════════════════════════════════════════════════════════════════════
   EXTRA SMALL SCREENS (<480px)
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .bottom-nav-btn .icon {
    font-size: 20px;
  }

  .bottom-nav-btn .label {
    font-size: 0.55rem;
  }

  .bottom-nav {
    height: 56px;
  }

  .hero-title {
    font-size: 1.2rem !important;
  }

  .quick-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .qs-val {
    font-size: 1.4rem;
  }

  .classic-text-area {
    font-size: 1rem !important;
    padding: 10px 8px !important;
  }

  .mode-card {
    grid-template-columns: 36px 1fr;
    gap: 8px;
    padding: 10px;
  }

  .mc-icon {
    font-size: 1.6rem;
  }

  .mc-name {
    font-size: 0.9rem;
  }

  .mc-desc {
    font-size: 0.7rem;
  }
}

/* ════════════════════════════════════════════════════════════════════
   ZOMBIE MODE ENHANCEMENTS
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  /* Zombie элементы */
  .zombie-item {
    position: absolute;
    width: auto;
    min-width: 60px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: opacity 0.3s ease;
    will-change: left, top;
  }

  /* Zombie word styling */
  .zombie-word {
    display: flex;
    align-items: center;
    gap: 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.05em;
  }

  .zw-typed {
    color: var(--accent);
  }

  .zw-rest {
    color: var(--text2);
    opacity: 0.7;
  }

  /* Zombie типы - разные цвета */
  .zombie-item.zm-basic {
    background: rgba(100, 150, 200, 0.85);
    border: 1px solid rgba(100, 150, 200, 1);
  }

  .zombie-item.zm-runner {
    background: rgba(200, 120, 80, 0.85);
    border: 1px solid rgba(200, 120, 80, 1);
  }

  .zombie-item.zm-brute {
    background: rgba(180, 60, 60, 0.85);
    border: 1px solid rgba(180, 60, 60, 1);
  }

  .zombie-item.zm-ghost {
    background: rgba(150, 100, 200, 0.7);
    border: 1px dashed rgba(150, 100, 200, 1);
  }

  .zombie-item.zm-archer {
    background: rgba(180, 140, 60, 0.85);
    border: 1px solid rgba(180, 140, 60, 1);
  }

  .zombie-item.zm-explosive {
    background: rgba(220, 100, 60, 0.85);
    border: 1px solid rgba(220, 100, 60, 1);
  }

  .zombie-item.zm-screamer {
    background: rgba(200, 80, 80, 0.85);
    border: 1px solid rgba(200, 80, 80, 1);
  }

  .zombie-item.zm-shield {
    background: rgba(100, 180, 100, 0.85);
    border: 2px solid rgba(100, 180, 100, 1);
  }

  .zombie-item.zm-commander {
    background: rgba(220, 180, 60, 0.85);
    border: 2px solid rgba(220, 180, 60, 1);
  }

  .zombie-item.zm-necro {
    background: rgba(100, 50, 150, 0.85);
    border: 2px solid rgba(100, 50, 150, 1);
  }

  .zombie-item.zm-leaper {
    background: rgba(150, 100, 200, 0.85);
    border: 1px solid rgba(150, 100, 200, 1);
  }

  .zombie-item.zm-boss {
    background: rgba(220, 50, 50, 0.95);
    border: 3px solid rgba(220, 50, 50, 1);
  }

  /* Zombie ошибка */
  .zombie-item.zombie-error {
    background: rgba(220, 60, 60, 1) !important;
    animation: shake 0.3s ease;
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
  }

  /* Zombie мёртв */
  .zombie-item.zombie-dead {
    opacity: 0;
    pointer-events: none;
  }

  /* На LOW графике - без анимаций, плоский дизайн */
  body[data-graphics="low"] .zombie-item {
    animation: none !important;
    transition: opacity 0.2s linear !important;
    box-shadow: none !important;
    filter: none !important;
  }

  body[data-graphics="low"] .zombie-item.zombie-error {
    animation: none !important;
  }

  body[data-graphics="low"] .zombie-word {
    text-shadow: none !important;
    filter: none !important;
  }

  /* На LOW графике - убираем сложные стили */
  body[data-graphics="low"] .zombie-item.zm-ghost {
    border: 1px solid rgba(150, 100, 200, 1) !important;
  }

  body[data-graphics="low"] .zombie-item.zm-commander {
    border: 1px solid rgba(220, 180, 60, 1) !important;
  }

  body[data-graphics="low"] .zombie-item.zm-shield {
    border: 1px solid rgba(100, 180, 100, 1) !important;
  }

  body[data-graphics="low"] .zombie-item.zm-necro {
    border: 1px solid rgba(100, 50, 150, 1) !important;
  }

  body[data-graphics="low"] .zombie-item.zm-boss {
    border: 2px solid rgba(220, 50, 50, 1) !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
   ZOMBIE HUD FIX
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .zombie-hud {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px !important;
    align-items: center;
  }

  .zombie-list {
    display: flex !important;
    gap: 4px !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 !important;
  }

  .zombie-list::-webkit-scrollbar {
    height: 2px;
  }

  .zombie-list::-webkit-scrollbar-thumb {
    background: rgba(88, 166, 255, 0.3);
  }

  /* Фокусированный зомби */
  .zombie-item.typing {
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.4) !important;
    border-color: var(--accent) !important;
  }

  body[data-graphics="low"] .zombie-item.typing {
    box-shadow: none !important;
    border-color: var(--accent) !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
   MOBILE: BOTTOM NAV LABELS, LEADERBOARD, STATS TABLES
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .bottom-nav-btn { min-width: 0; }
  .bottom-nav-btn .label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.56rem;
  }

  .lb-header { padding: 20px 16px 0; }
  .lb-tabs {
    padding: 14px 16px 0;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .lb-tabs::-webkit-scrollbar { display: none; }
  .lb-tab { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px 10px; font-size: 0.82rem; }
  .lb-table-wrap { padding: 12px 8px 24px; -webkit-overflow-scrolling: touch; }
  .lb-table { font-size: 0.8rem; }
  .lb-table thead th { padding: 8px 8px; font-size: 0.65rem; letter-spacing: 0.3px; white-space: nowrap; }
  .lb-row td { padding: 10px 8px; white-space: nowrap; }
  .lb-rank { width: 32px; font-size: 1.1rem; }
  #lb-table th:nth-child(3), #lb-table td:nth-child(3),
  #lb-table th:nth-child(5), #lb-table td:nth-child(5) { display: none; }

  #top5-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  #top5-table th, #top5-table td { padding: 8px 8px; font-size: 0.8rem; }
}

@media (max-width: 767px) {
  .friends-tabs .tab-btn { min-width: 0; padding-left: 6px; padding-right: 6px; font-size: 0.82rem; white-space: nowrap; }
}

/* ════════════════════════════════════════════════════════════════════
   MOBILE: GAME SCREEN — no bottom nav, compact top bar with exit button
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  body:has(#page-game.active) .bottom-nav { display: none !important; }

  #page-game .game-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 38px;
    padding: 0 10px;
    gap: 8px;
    z-index: 300;
    background: rgba(13, 17, 23, 0.96);
    border-bottom: 1px solid var(--border);
  }
  #game-mode-title { font-size: 0.85rem; }
  #game-stop-btn { padding: 4px 12px; font-size: 0.78rem; }

  .classic-wrapper, .falling-wrapper, .zombie-wrapper, .osu-wrapper,
  .sapper-wrapper, .detective-wrapper, .boss-wrapper, .royale-wrapper, .hacker-wrapper {
    top: 38px !important;
    height: auto !important;
    bottom: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}
@media (max-width: 767px) {
  #page-game .game-topbar { box-sizing: border-box; overflow: hidden; }
  #game-mode-title {
    flex: 1 1 auto !important; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-size: 0.8rem !important; line-height: 1.2;
  }
  #game-mode-title * { display: inline !important; white-space: nowrap; }
  #game-stop-btn { height: 28px !important; min-height: 0 !important; line-height: 1 !important; padding: 0 12px !important; flex: 0 0 auto; }
  #ghost-widget { flex: 0 0 auto; }
}
@media (max-width: 767px) {
  .classic-wrapper .classic-text-area {
    flex-direction: row !important;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;
    gap: 2px 14px;
    font-size: 1.15rem !important;
    line-height: 1.75 !important;
    margin: 0 8px 8px;
  }
  .classic-stats-bar {
    flex-wrap: nowrap !important;
    justify-content: space-between;
    gap: 6px !important;
    padding: 8px !important;
  }
  .classic-stats-bar .stat-item { min-width: 0 !important; flex: 1 1 0; padding: 6px 4px !important; text-align: center; }
  .classic-stats-bar .stat-val { font-size: 1.15rem !important; }
  .classic-stats-bar .stat-lbl { font-size: 0.58rem !important; }
}
/* ════════════════════════════════════════════════════════════════════
   MOBILE: GAME FITS THE AREA ABOVE THE ON-SCREEN KEYBOARD
   (--vv-h / --vv-top and body.kb-open come from js/keyboard-viewport.js)
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  #page-game { height: var(--vv-h, 100dvh) !important; top: var(--vv-top, 0px) !important; bottom: auto !important; }
  #page-game .game-topbar { top: var(--vv-top, 0px); }
  .classic-wrapper, .falling-wrapper, .zombie-wrapper, .osu-wrapper,
  .sapper-wrapper, .detective-wrapper, .boss-wrapper, .royale-wrapper, .hacker-wrapper {
    top: calc(var(--vv-top, 0px) + 38px) !important;
    height: calc(var(--vv-h, 100dvh) - 38px) !important;
    bottom: auto !important;
  }

  /* Клавиатура открыта: оставляем только игровое поле и ввод */
  body.kb-open .zm-system-dock,
  body.kb-open .zi-label,
  body.kb-open .classic-cursor-hint,
  body.kb-open .zm-moon,
  body.kb-open .zm-embers,
  body.kb-open .zm-fog { display: none !important; }
  body.kb-open .zombie-input-row { padding: 6px 10px !important; gap: 6px !important; min-height: 0 !important; }
  body.kb-open .zombie-hud,
  body.kb-open .falling-hud,
  body.kb-open .osu-hud,
  body.kb-open .sapper-hud,
  body.kb-open .detective-hud,
  body.kb-open .boss-hud,
  body.kb-open .hacker-hud,
  body.kb-open .royale-hud { padding: 3px 6px !important; gap: 4px !important; }
  body.kb-open .classic-wrapper .classic-text-area { font-size: 1.05rem !important; line-height: 1.5 !important; }
  body.kb-open .classic-stats-bar { padding: 4px 8px !important; }
  body.kb-open .classic-stats-bar .stat-val { font-size: 1rem !important; }
}
/* ════════════════════════════════════════════════════════════════════
   MOBILE LITE: stable game height, big "tap to type" button, no clutter
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  .classic-wrapper, .falling-wrapper, .zombie-wrapper, .osu-wrapper,
  .sapper-wrapper, .detective-wrapper, .boss-wrapper, .royale-wrapper, .hacker-wrapper {
    height: calc(var(--game-h, 100dvh) - 38px) !important;
  }

  /* Место под клавиатуру: кнопка ввода внизу, пока клавиатура закрыта */
  #mobile-kb-btn {
    position: fixed !important;
    left: 12px !important; right: 12px !important; bottom: 14px !important; top: auto !important;
    width: auto !important; height: 56px !important;
    transform: none !important;
    border-radius: 14px !important;
    font-size: 1rem !important;
    z-index: 310;
  }
  body.kb-open #mobile-kb-btn { display: none !important; }

  /* Режимы, которые плохо подходят для телефона */
  .mode-card[data-mode="osu"], .mode-card[data-mode="sapper"], .mode-card[data-mode="code"],
  .mob-mode-pill[data-mode="osu"], .mob-mode-pill[data-mode="sapper"], .mob-mode-pill[data-mode="code"],
  .mode-card-large[data-mode="osu"], .mode-card-large[data-mode="sapper"] { display: none !important; }

  /* Зомби: без декораций и лишних подписей */
  .zm-moon, .zm-stars, .zm-fog, .zm-embers, .zm-backline, .zm-fence,
  .zm-system-dock, .zi-label,
  .zombie-type-label, .zombie-type-sub { display: none !important; }
  .zombie-icon { font-size: 1.6rem !important; }
  .zombie-input-row { padding: 8px 12px !important; min-height: 0 !important; }
}
/* ЗОМБИ на телефоне: счётчик волн (только цифры) справа сверху, скорость слева, остальное скрыто */
@media (max-width: 767px) {
  .zm-ico { display: none !important; }
  .zombie-hud {
    position: absolute !important;
    top: 0; left: 0; right: 0;
    z-index: 6;
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    background: none !important;
    border: 0 !important;
    padding: 8px 12px !important;
    pointer-events: none;
  }
  #zm-lives-hud, #zm-score-hud, #zm-combo-hud, .zm-ally-hud, .zm-wave-bar { display: none !important; }
  #zm-wpm-hud { order: 1; font-size: 0.8rem !important; opacity: 0.7; background: none !important; border: 0 !important; padding: 0 !important; }
  #zm-wave-hud {
    order: 2;
    background: none !important; border: 0 !important; padding: 0 !important;
    font-size: 1.1rem !important; font-weight: 700; font-family: var(--font-mono);
    display: flex; align-items: baseline; gap: 8px;
  }
  #zm-wave-hud .zm-wave-prog { font-size: 0.8rem; opacity: 0.7; font-weight: 500; }
}
/* ВСЕ РЕЖИМЫ на телефоне: HUD — тонкая строка с цифрами, без декоративных иконок */
@media (max-width: 767px) {
  .ico { display: none !important; }
  .fl-level-hud, .fl-risk, .rms-online-badge { display: none !important; }
  .falling-hud, .detective-hud, .hacker-hud, .royale-hud {
    background: none !important;
    border: 0 !important;
    box-shadow: none !important;
    justify-content: space-between !important;
    padding: 8px 14px !important;
    font-size: 0.8rem !important;
    flex-wrap: nowrap !important;
  }
  .falling-hud .hud-item, .detective-hud .hud-item, .hacker-hud .hud-item, .royale-hud .hud-item {
    background: none !important; border: 0 !important; padding: 0 !important; box-shadow: none !important;
    white-space: nowrap;
  }
  .boss-hud { background: none !important; border: 0 !important; text-align: center; font-size: 0.8rem !important; opacity: 0.8; padding: 6px !important; }
}
/* Карточка профиля на телефоне — нажимается и открывает профиль */
@media (max-width: 767px) {
  .mob-profile-card { cursor: pointer; }
  .mob-profile-card:active { transform: scale(0.99); }
  .mob-profile-score {
    background: rgba(88, 166, 255, 0.12) !important;
    color: var(--accent) !important;
    border-color: rgba(88, 166, 255, 0.25) !important;
    white-space: nowrap;
  }
}