/* =========================================================================
   CHESS WEB3 - MOBILE RESPONSIVE OVERRIDES
   =========================================================================
   This file contains ONLY @media queries for mobile/tablet.
   Desktop styles remain untouched in style.css.
   Load AFTER style.css:  <link rel="stylesheet" href="mobile.css">
   ========================================================================= */

/* ===== GLOBAL MOBILE OVERRIDES ===== */
@media (max-width: 768px) {

  /* Allow scrolling on mobile */
  body {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100vh;
  }

  /* ===== HEADER ===== */
  .top-bar {
    height: 50px;
    padding: 0 10px;
  }

  .header-left {
    left: 10px !important;
  }

  /* Remove absurd logo scaling */
  .logo-img {
    transform: scale(2.5);
    transform-origin: left center;
    margin-left: 10px;
    margin-top: 5px;
    height: 35px;
  }

  /* Hide desktop nav links — replaced by hamburger */
  .header-right .history-link,
  .header-right .history-dropdown {
    display: none;
  }

  /* Keep settings + user avatar visible but compact */
  .header-right {
    right: 10px;
    gap: 6px;
  }

  .header-center-grid {
    display: none;
  }

  /* ===== MOBILE STAT BAR (below header) ===== */
  .mobile-stats-bar {
    display: flex !important;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
  }

  .mobile-stats-bar .stat-box {
    min-width: auto;
    padding: 4px 10px;
    font-size: 0.8rem;
  }

  .mobile-stats-bar .stat-label {
    display: none;
  }

  /* ===== HAMBURGER BUTTON ===== */
  .hamburger-btn {
    display: flex !important;
  }

  /* ===== MOBILE DRAWER ===== */
  .mobile-drawer {
    display: block !important;
  }

  .mobile-drawer.open {
    transform: translateX(0);
  }

  .drawer-overlay.open {
    display: block !important;
    opacity: 1;
  }

  /* ===== GAME AREA — SINGLE COLUMN ===== */
  .main-container {
    padding: 10px;
    align-items: flex-start;
  }

  .game-area {
    /* Critical fix: minmax(0, 1fr) prevents the grid from expanding past 
       the viewport when chessboardjs sets a fixed pixel width internally */
    grid-template-columns: minmax(0, 1fr);
    grid-gap: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .board-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  /* Center the inner chessboardjs elements to distribute remaining rounding pixels evenly */
  #board > div {
    margin: 0 auto;
  }

  /* Board fills available width */
  :root {
    --board-size: 100%;
  }

  #board {
    border-radius: 2px;
  }

  /* ===== SIDEBAR → BELOW BOARD ===== */
  .sidebar-wrapper {
    width: 100%;
    height: auto;
    min-height: 0;
  }

  /* Player bars — compact horizontal */
  .player-status {
    padding: 6px 10px;
  }

  .player-info .name {
    font-size: 0.95rem;
  }

  .rating-inline {
    font-size: 0.8rem;
  }

  .timer-tab {
    font-size: 1.3rem;
    padding: 6px 10px;
    min-width: 75px;
  }

  /* ===== SIDEBAR CONTENT ===== */
  .sidebar-main {
    margin: 5px 0;
  }

  /* Lobby controls */
  .lobby-controls {
    padding: 10px;
    gap: 8px;
  }

  .primary-btn {
    padding: 12px;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  .secondary-btn {
    padding: 10px;
    font-size: 0.85rem;
  }

  /* Moves container — limited height on mobile */
  .moves-container {
    max-height: 150px;
  }

  .move-history-content {
    max-height: 120px;
  }

  /* Game controls — horizontal */
  .game-controls {
    padding: 10px;
    gap: 8px;
  }

  .action-buttons {
    gap: 8px;
  }

  .icon-btn {
    padding: 10px;
    font-size: 1rem;
    min-height: 44px;
  }

  /* ===== MODALS ===== */
  .modal-content {
    padding: 25px 20px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-title {
    font-size: 1.4rem;
  }

  .modal-text {
    font-size: 0.95rem;
  }

  .modal-content.wide {
    max-width: 100% !important;
    width: 95% !important;
  }

  /* Withdrawal modal */
  .withdrawal-form {
    max-width: 100% !important;
  }

  /* Rewards modal */
  #rewards-modal .modal-content {
    padding: 25px 15px;
    max-width: 95%;
  }

  .accordion-header {
    padding: 14px 15px;
    font-size: 1rem;
  }

  .inner-content {
    padding: 0 15px 15px 15px;
    font-size: 0.9rem;
  }

  /* Friend modal */
  .friend-modal-content {
    width: 95% !important;
  }

  .friends-list-container {
    max-height: 300px;
  }

  /* ===== TOUCH TARGETS ===== */
  button,
  .btn-small,
  .btn-start,
  .dropdown-item,
  .time-btn,
  .tab-btn,
  .friend-tab {
    min-height: 44px;
  }

  /* Active states for touch feedback (hover doesn't work on touch) */
  .primary-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  .secondary-btn:active {
    background: rgba(139, 92, 246, 0.25);
  }

  .icon-btn:active {
    background: #555;
  }

  .dropdown-item:active {
    background: rgba(255, 255, 255, 0.08);
  }

  /* Prevent double-tap zoom on interactive elements */
  .board-container,
  button,
  a,
  input,
  select {
    touch-action: manipulation;
  }

  /* ===== LEADERBOARD PAGE ===== */
  .leaderboard-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    max-width: 100vw;
    gap: 15px;
  }

  .sidebar-right {
    order: 2;
  }

  .tabs-container {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 8px;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
  }

  .tabs-container .tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .lb-header {
    flex-direction: column;
    gap: 10px;
    padding: 15px;
  }

  .lb-header h2 {
    font-size: 1.1rem;
  }

  .leaderboard-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .leaderboard-table-container table {
    min-width: 500px;
  }

  .countdown {
    font-size: 2rem;
  }

  /* ===== HISTORY PAGE ===== */
  .history-container {
    margin: 15px auto;
    padding: 0 10px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .page-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .page-icon {
    font-size: 2rem;
  }

  .page-title h1 {
    font-size: 1.3rem;
  }

  .history-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .history-table {
    min-width: 600px;
  }

  .history-table th,
  .history-table td {
    padding: 10px 8px;
    font-size: 0.8rem;
  }

  .page-btn {
    width: 40px;
    height: 40px;
  }

  /* ===== TOURNAMENT PAGE ===== */
  .tournament-grid,
  .tournaments-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    max-width: 100vw;
  }

  /* ===== SCROLLBAR ===== */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
}

/* ===== SMALL PHONES (iPhone SE, etc) ===== */
@media (max-width: 480px) {

  .logo-img {
    transform: scale(2);
    margin-left: 5px;
  }

  .timer-tab {
    font-size: 1.1rem;
    padding: 5px 8px;
    min-width: 65px;
  }

  .player-info .name {
    font-size: 0.85rem;
  }

  /* Hide non-essential columns in history */
  .col-precision,
  .col-moves {
    display: none;
  }

  .modal-content {
    padding: 20px 15px;
  }

  .modal-title {
    font-size: 1.2rem;
  }

  /* Even more compact stat boxes */
  .mobile-stats-bar .stat-box {
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  .stat-icon {
    font-size: 0.8rem;
  }
}

/* ===== ELEMENTS HIDDEN BY DEFAULT (shown only on mobile) ===== */
/* These are created in HTML but hidden on desktop */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.hamburger-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

.mobile-stats-bar {
  display: none;
}

/* ===== MOBILE DRAWER ===== */
.mobile-drawer {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  z-index: 10000;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3 {
  color: var(--text-bright);
  font-size: 1.1rem;
  margin: 0;
}

.drawer-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.drawer-close:active {
  background: rgba(255, 255, 255, 0.1);
}

.drawer-nav {
  padding: 10px 0;
}

.drawer-nav a,
.drawer-nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}

.drawer-nav a:active,
.drawer-nav button:active {
  background: rgba(255, 255, 255, 0.05);
}

.drawer-divider {
  height: 1px;
  background: var(--border-color);
  margin: 8px 0;
}

/* Drawer overlay */
.drawer-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s;
}
