/* ════════════════════════════════════════════════════════════════════
   TypeArena — ULTRA POLISH v5
   Суперполировка: анимации, переходы, звуки, визуалы
   ════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  /* ─────── PAGE TRANSITIONS ─────── */
  .page {
    animation: pageEnter 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  }

  @keyframes pageEnter {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ─────── BUTTONS WITH RIPPLE ─────── */
  button {
    position: relative;
    overflow: hidden;
  }

  button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    pointer-events: none;
  }

  button:active::before {
    animation: ripple 0.6s ease-out;
  }

  @keyframes ripple {
    to {
      width: 300px;
      height: 300px;
      opacity: 0;
    }
  }

  /* ─────── SMOOTH SCROLLING ─────── */
  html {
    scroll-behavior: smooth;
  }

  .main-content,
  .classic-text-area,
  .falling-field,
  .zombie-list,
  .sapper-board,
  .royale-text-area {
    scroll-behavior: smooth;
  }

  /* ─────── TOUCH FEEDBACK ─────── */
  .btn-play-mode,
  .btn-buy,
  .fi-action,
  .shop-item,
  .mode-card-large,
  .filter-btn,
  .cat-btn,
  .tab-btn {
    transform: translateZ(0);
    will-change: transform, opacity;
    backface-visibility: hidden;
  }

  .btn-play-mode:active,
  .btn-buy:active,
  .fi-action:active,
  .shop-item:active,
  .mode-card-large:active,
  .filter-btn:active,
  .cat-btn:active,
  .tab-btn:active {
    transform: scale(0.97);
  }

  /* ─────── LOADING ANIMATION ─────── */
  .loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(88, 166, 255, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  .loading-skeleton {
    background: linear-gradient(
      90deg,
      var(--bg2) 0%,
      var(--bg3) 50%,
      var(--bg2) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
  }

  @keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }

  /* ─────── MODAL / DIALOG ─────── */
  /* Only style overlays that are actually open — plain .modal-overlay must stay display:none */
  .modal-overlay.visible {
    align-items: flex-end;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .modal {
    width: 100%;
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    padding: 16px;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 80vh;
    overflow-y: auto;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
  }

  /* ─────── BADGE ANIMATIONS ─────── */
  .stat-badge,
  .mc-tag,
  .qs-item {
    animation: badgeEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  @keyframes badgeEnter {
    from {
      opacity: 0;
      transform: scale(0.8) translateY(8px);
    }
    to {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }

  /* ─────── PROFILE CARD IMPROVEMENTS ─────── */
  .profile-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(135deg, rgba(88, 166, 255, 0.1), rgba(88, 166, 255, 0.05));
    border-radius: 12px;
    border: 2px solid rgba(88, 166, 255, 0.2);
    margin-bottom: 16px;
  }

  .profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), rgba(88, 166, 255, 0.6));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4rem;
    font-weight: 900;
    color: white;
    margin: 0 auto;
    box-shadow: 0 4px 16px rgba(88, 166, 255, 0.3);
  }

  .profile-info-large {
    text-align: center;
  }

  .profile-name-large {
    font-size: 1.2rem;
    font-weight: 900;
    color: var(--text);
    margin: 8px 0 4px;
  }

  .profile-level-large {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 700;
  }

  .profile-badges {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 8px;
  }

  .profile-badge {
    padding: 4px 8px;
    background: rgba(88, 166, 255, 0.2);
    border: 1px solid rgba(88, 166, 255, 0.4);
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--accent);
  }

  /* ─────── PROGRESS BARS ─────── */
  .progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg3);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
  }

  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #58a6ff);
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.4);
  }

  .progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text2);
  }

  .progress-container {
    margin: 12px 0;
  }

  /* ─────── ACHIEVEMENT UNLOCKED ─────── */
  .achievement-popup {
    position: fixed;
    bottom: 80px;
    right: 16px;
    background: var(--bg2);
    border: 2px solid var(--accent);
    border-radius: 12px;
    padding: 12px 16px;
    z-index: 250;
    animation: achievementSlideIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 8px 24px rgba(88, 166, 255, 0.2);
  }

  @keyframes achievementSlideIn {
    from {
      opacity: 0;
      transform: translateX(200px) translateY(200px);
    }
    to {
      opacity: 1;
      transform: translateX(0) translateY(0);
    }
  }

  .ach-popup-icon {
    font-size: 1.8rem;
    margin-bottom: 4px;
  }

  .ach-popup-text {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
  }

  /* ─────── STATS CARDS ─────── */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .stat-card {
    padding: 12px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s;
  }

  .stat-card:hover,
  .stat-card:active {
    border-color: var(--accent);
    background: rgba(88, 166, 255, 0.08);
  }

  .stat-card-icon {
    font-size: 1.6rem;
    margin-bottom: 4px;
  }

  .stat-card-value {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--accent);
  }

  .stat-card-label {
    font-size: 0.7rem;
    color: var(--text2);
    font-weight: 600;
    margin-top: 2px;
  }

  /* ─────── DAILY CHALLENGE ─────── */
  .daily-challenge {
    padding: 12px;
    background: linear-gradient(135deg, rgba(255, 200, 50, 0.15), rgba(255, 200, 50, 0.05));
    border: 2px solid rgba(255, 200, 50, 0.3);
    border-radius: 12px;
    margin-bottom: 12px;
  }

  .challenge-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .challenge-icon {
    font-size: 1.4rem;
  }

  .challenge-title {
    font-size: 1rem;
    font-weight: 800;
    color: #ffc832;
  }

  .challenge-desc {
    font-size: 0.8rem;
    color: var(--text2);
    line-height: 1.4;
    margin-bottom: 8px;
  }

  .challenge-reward {
    display: flex;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
  }

  .challenge-button {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #ffc832, #ffb300);
    color: #000;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
  }

  .challenge-button:active {
    transform: scale(0.98);
  }

  /* ─────── LEADERBOARD HIGHLIGHTS ─────── */
  .leaderboard-row {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 6px;
  }

  .lb-rank {
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--accent);
    text-align: center;
  }

  .lb-rank.top-1 { color: #ffd700; font-size: 1.3rem; }
  .lb-rank.top-2 { color: #c0c0c0; font-size: 1.2rem; }
  .lb-rank.top-3 { color: #cd7f32; font-size: 1.1rem; }

  .lb-player {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .lb-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
  }

  .lb-score {
    font-size: 0.8rem;
    color: var(--text2);
  }

  .lb-medals {
    display: flex;
    gap: 4px;
    font-size: 1rem;
  }

  /* ─────── FLOATING ACTION BUTTON ─────── */
  .fab {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), rgba(88, 166, 255, 0.6));
    border: none;
    color: white;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.4);
    z-index: 100;
    transition: all 0.3s;
  }

  .fab:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
  }

  /* ─────── TOOLTIP ─────── */
  [data-tooltip] {
    position: relative;
  }

  [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg3);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  [data-tooltip]:hover::after {
    opacity: 1;
  }

  /* ─────── CONFETTI ANIMATION ─────── */
  .confetti-piece {
    position: fixed;
    pointer-events: none;
    animation: confettiFall 3s ease-in forwards;
  }

  @keyframes confettiFall {
    to {
      transform: translateY(100vh) rotate(720deg);
      opacity: 0;
    }
  }

  /* ─────── GRADIENT TEXT ─────── */
  .gradient-text {
    background: linear-gradient(135deg, var(--accent), #58a6ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 900;
  }

  /* ─────── OPTIMIZATIONS FOR LOW GRAPHICS ─────── */
  body[data-graphics="low"] .modal-overlay {
    backdrop-filter: none;
  }

  body[data-graphics="low"] button::before {
    display: none;
  }

  body[data-graphics="low"] .progress-fill {
    box-shadow: none;
  }

  body[data-graphics="low"] .achievement-popup {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  body[data-graphics="low"] .fab {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  }

  /* ─────── ANIMATIONS FOR HIGH GRAPHICS ─────── */
  body[data-graphics="high"] .progress-fill {
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.6),
                inset 0 0 6px rgba(255, 255, 255, 0.2);
  }

  body[data-graphics="high"] .fab {
    box-shadow: 0 6px 20px rgba(88, 166, 255, 0.5);
  }

  body[data-graphics="high"] .profile-avatar-large {
    box-shadow: 0 6px 24px rgba(88, 166, 255, 0.4),
                inset 0 0 16px rgba(255, 255, 255, 0.2);
  }

  /* ─────── STAGGER ANIMATIONS ─────── */
  .mode-card-large:nth-child(1) { animation-delay: 0s; }
  .mode-card-large:nth-child(2) { animation-delay: 0.1s; }
  .mode-card-large:nth-child(3) { animation-delay: 0.2s; }
  .mode-card-large:nth-child(4) { animation-delay: 0.3s; }
  .mode-card-large:nth-child(5) { animation-delay: 0.4s; }
  .mode-card-large:nth-child(n+6) { animation-delay: 0.5s; }

  .shop-item:nth-child(1) { animation-delay: 0s; }
  .shop-item:nth-child(2) { animation-delay: 0.1s; }
  .shop-item:nth-child(3) { animation-delay: 0.2s; }
  .shop-item:nth-child(4) { animation-delay: 0.3s; }
  .shop-item:nth-child(n+5) { animation-delay: 0.4s; }

  .stat-card:nth-child(1) { animation-delay: 0s; }
  .stat-card:nth-child(2) { animation-delay: 0.1s; }
  .stat-card:nth-child(3) { animation-delay: 0.2s; }
  .stat-card:nth-child(4) { animation-delay: 0.3s; }

  /* ─────── PULSE EFFECT ─────── */
  .pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
  }

  /* ─────── SHAKE EFFECT ─────── */
  .shake {
    animation: shake 0.4s ease-in-out;
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
  }

  /* ─────── BOUNCE EFFECT ─────── */
  .bounce {
    animation: bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  }

  @keyframes bounce {
    0% { transform: translateY(-8px); opacity: 0; }
    50% { transform: translateY(-4px); }
    100% { transform: translateY(0); opacity: 1; }
  }
}
