/**
 * TypeRush - Mobile & Responsive Stylesheet
 * Phase 12: Mobile Responsiveness & Layout Adaptations
 *
 * Breakpoints:
 * - 1024px: Laptops / Tablets Landscape
 * - 768px:  Tablets Portrait / iPads
 * - 480px:  Mobile Phones
 * - 360px:  Small Phones
 *
 * @package TypeRush
 */

/* ════════════════════════════════════════════════════════════
   1. TABLETS & SMALL LAPTOPS (<= 1024px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .site-header .header-container,
  .site-footer .footer-container,
  .test-wrapper,
  .profile-container,
  .leaderboard-container {
    padding-left: 20px;
    padding-right: 20px;
  }

  .test-config-bar {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
  }

  .test-config-bar::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
  }

  .results-hero {
    gap: 20px;
  }
}

/* ════════════════════════════════════════════════════════════
   2. TABLETS PORTRAIT (<= 768px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Site Layout */
  .typerush-app {
    padding: 12px 14px;
    min-height: 100vh;
  }

  /* Header */
  .site-header {
    margin-bottom: 24px;
  }

  .site-header .header-container {
    padding: 0;
  }

  .brand-title {
    font-size: 1.35rem !important;
  }

  .header-nav {
    gap: 8px !important;
  }

  .nav-icon-btn {
    padding: 8px 10px !important;
    min-width: 38px;
    min-height: 38px;
  }

  .user-display-name {
    display: none; /* Hide username text to save header space */
  }

  /* Config Bar on Tablet */
  .test-config-bar {
    display: flex;
    align-items: center;
    background-color: var(--sub-alt-color, #2c2e31);
    padding: 6px 10px;
    border-radius: 10px;
    margin-bottom: 28px;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .config-group {
    flex-shrink: 0;
  }

  .config-btn {
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
    min-height: 36px;
  }

  /* Core Typing Area */
  .words-wrapper {
    font-size: 1.35rem !important;
    line-height: 1.65 !important;
    min-height: 120px !important;
    max-height: 135px !important;
  }

  .words-container {
    column-gap: 0.5em !important;
  }

  /* Hide Virtual Keymap on touch/mobile screens — no physical room */
  #keymap-container,
  .keymap-container {
    display: none !important;
  }

  /* Footer adaptations */
  .keyboard-hints {
    display: none !important; /* Touch devices have no physical tab/enter */
  }

  .site-footer .footer-container {
    flex-direction: column-reverse;
    gap: 16px;
    align-items: center;
    text-align: center;
    padding: 16px 0;
  }

  .footer-left {
    justify-content: center;
    flex-wrap: wrap;
    gap: 16px;
  }

  .footer-right {
    justify-content: center;
  }

  /* Settings Panel Drawer becomes Full-Screen */
  .settings-drawer {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
  }

  .settings-drawer .drawer-header {
    padding: 18px 20px;
  }

  .settings-drawer .drawer-body {
    padding: 16px 18px 40px;
  }

  /* Result Screen */
  .results-hero {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
  }

  .hero-stat .stat-value {
    font-size: 2.8rem !important;
  }

  .results-chart-box {
    height: 200px !important;
    margin: 20px 0 !important;
  }

  .results-substats-row {
    flex-wrap: wrap;
    gap: 12px;
  }

  .substat-card {
    flex: 1 1 calc(50% - 12px);
    min-width: 130px;
  }

  .results-actions {
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
  }

  .results-actions button {
    flex: 1 1 calc(50% - 10px);
    min-height: 44px;
    justify-content: center;
  }

  /* Tables horizontal scroll */
  .table-responsive-wrapper,
  .history-table-container,
  .leaderboard-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .history-table,
  .leaderboard-table {
    min-width: 580px;
  }
}

/* ════════════════════════════════════════════════════════════
   3. MOBILE PHONES (<= 480px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* Layout */
  .typerush-app {
    padding: 8px 10px;
  }

  /* Site Branding */
  .brand-title {
    font-size: 1.15rem !important;
  }

  .brand-icon {
    font-size: 1.15rem;
  }

  /* Header Nav */
  .header-nav {
    gap: 4px !important;
  }

  .nav-icon-btn {
    padding: 6px 8px !important;
    min-width: 34px;
    min-height: 34px;
    font-size: 0.95rem;
  }

  /* Config Bar */
  .test-config-bar {
    padding: 5px 8px;
    gap: 6px;
    border-radius: 8px;
    margin-bottom: 20px;
  }

  .config-btn {
    padding: 6px 10px !important;
    font-size: 0.78rem !important;
    min-height: 34px;
  }

  .config-btn i {
    font-size: 0.8rem;
  }

  .config-divider {
    height: 16px;
    margin: 0 4px;
  }

  /* Words Area on Phones */
  .words-wrapper {
    font-size: 1.18rem !important;
    line-height: 1.6 !important;
    min-height: 105px !important;
    max-height: 115px !important;
  }

  .words-container {
    column-gap: 0.45em !important;
    row-gap: 0.15em !important;
  }

  .live-stats-bar {
    font-size: 1.6rem !important;
    margin-bottom: 12px;
  }

  /* Out of focus overlay on phones */
  .focus-notice {
    font-size: 0.88rem !important;
    padding: 10px 16px !important;
  }

  /* Restart button touch target */
  .restart-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }

  /* Result screen mobile hero */
  .results-hero {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
    padding: 16px 12px !important;
  }

  .hero-stat .stat-value {
    font-size: 2.2rem !important;
  }

  .hero-stat .stat-label {
    font-size: 0.75rem !important;
  }

  .results-chart-box {
    height: 170px !important;
    margin: 14px 0 !important;
  }

  .substat-card {
    flex: 1 1 100%;
    padding: 10px 14px;
  }

  .results-actions button {
    flex: 1 1 100%;
    font-size: 0.85rem;
  }

  /* Modals */
  .tr-modal-dialog,
  .command-palette-container,
  .auth-modal-box {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    padding: 18px 16px !important;
    margin: 10px !important;
  }

  .command-palette-input {
    font-size: 1rem !important;
  }

  /* Profile & Leaderboard cards */
  .profile-stats-grid,
  .leaderboard-filters-bar {
    grid-template-columns: 1fr !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .history-table,
  .leaderboard-table {
    font-size: 0.8rem;
  }

  /* Input zoom prevention on iOS */
  .words-input {
    font-size: 16px !important; /* Prevents auto-zoom in Safari iOS */
  }
}

/* ════════════════════════════════════════════════════════════
   4. EXTRA SMALL PHONES (<= 360px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 360px) {
  .brand-title {
    font-size: 1rem !important;
  }

  .words-wrapper {
    font-size: 1.05rem !important;
    line-height: 1.5 !important;
  }

  .hero-stat .stat-value {
    font-size: 1.85rem !important;
  }

  .config-btn span {
    display: none; /* Icon-only on ultra compact screens */
  }

  .config-btn {
    padding: 6px 8px !important;
  }
}
