/* ========================================
   MOBILE - Styles spécifiques mobile
   ======================================== */

@media (max-width: 768px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
    font-size: 14px;
    -webkit-overflow-scrolling: touch;
    height: auto;
    min-height: 100vh;
  }

  /* Permettre le scroll sur tous les écrans */
  .screen {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto;
    min-height: 100vh;
    -webkit-overflow-scrolling: touch;
  }

  #game-screen {
    display: flex !important;
    height: auto !important;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* ====== AUTH SCREENS ====== */
  .auth-container {
    padding: 15px;
    max-width: 95%;
    margin: 0 auto;
  }

  .auth-container h1 {
    font-size: 1.8em;
    margin-bottom: 20px;
  }

  .auth-form input {
    padding: 12px;
    font-size: 16px;
  }

  .auth-form button {
    padding: 14px;
    font-size: 16px;
  }

  /* ====== LOBBY ====== */
  .lobby-container,
  .waiting-room-container {
    padding: 15px;
    max-width: 95%;
    margin: 0 auto;
  }

  .lobby-container h1 {
    font-size: 1.8em;
  }

  .lobby-buttons {
    flex-direction: column;
    gap: 10px;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    padding: 14px;
    font-size: 16px;
  }

  .join-room {
    width: 100%;
  }

  .join-room input {
    font-size: 16px;
    padding: 12px;
  }

  /* Room settings */
  .game-settings,
  .map-selection {
    padding: 15px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .setting-item label {
    font-size: 14px;
  }

  .setting-item input,
  .setting-item select {
    font-size: 16px;
    padding: 10px;
  }

  /* ====== GAME LAYOUT ====== */
  /* Structure verticale complète */
  .game-wrapper {
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    overflow: visible;
    height: auto;
    min-height: auto;
  }

  /* Top panel - Sticky en haut avec toutes les stats et boutons */
  .top-panel {
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
    justify-content: center;
    background: #16213e;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    order: 1;
    width: 100%;
  }

  .stat-item {
    font-size: 11px;
    padding: 6px 10px;
    flex: 0 1 auto;
    min-width: 85px;
    text-align: center;
  }

  .stat-icon {
    font-size: 16px;
  }

  .stat-value {
    font-size: 14px;
    font-weight: bold;
  }

  .stat-label {
    font-size: 10px;
  }

  .btn-research-toggle,
  .btn-skill,
  .btn-aura-toggle,
  .btn-quit {
    font-size: 11px;
    padding: 8px 12px;
    flex: 0 1 auto;
    min-width: 85px;
    margin: 0;
  }

  /* Game center - Canvas du jeu en order: 2 */
  .game-center {
    order: 2;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  #game-container {
    width: 100%;
    height: 450px;
    min-height: 400px;
    max-height: 500px;
    border-width: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a1a2e;
    border-radius: 8px;
    overflow: hidden;
  }

  #game-container canvas {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* Left panel - Tours en order: 3 */
  .left-panel {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    order: 3;
    height: auto;
    max-height: none;
  }

  /* Right panel - Classement + Monstres en order: 4 */
  .right-panel {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    order: 4;
    height: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
  }

  .right-section {
    width: 100%;
  }

  .panel-divider {
    height: 2px;
    background: #0f3460;
    margin: 10px 0;
  }

  /* ====== PANELS ====== */
  .game-panel {
    padding: 12px;
    gap: 10px;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .game-panel h3 {
    font-size: 16px;
    padding-bottom: 8px;
    text-align: center;
    margin: 0;
  }

  /* ====== TOWER SHOP ====== */
  .tower-shop {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    overflow: visible;
    max-height: none;
    padding: 5px;
  }

  .tower-btn {
    padding: 8px;
    font-size: 10px;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
  }

  .tower-icon {
    font-size: 24px;
    margin-bottom: 4px;
  }

  .tower-name {
    font-size: 10px;
    margin: 4px 0;
    font-weight: bold;
  }

  .tower-stats {
    font-size: 8px;
    line-height: 1.3;
  }

  .cost {
    font-size: 9px;
    padding: 3px 6px;
    margin-top: 4px;
  }

  .btn-towers-header {
    font-size: 0.9em;
    padding: 10px;
    width: 100%;
    margin-bottom: 8px;
  }

  #tower-count {
    font-size: 12px;
    text-align: center;
    padding: 8px;
    margin: 8px 0;
  }

  /* ====== MONSTER SHOP ====== */
  .monster-shop {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    overflow: visible;
    max-height: none;
    padding: 5px;
  }

  .monster-btn {
    padding: 8px;
    font-size: 10px;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
  }

  .monster-icon {
    font-size: 24px;
    margin-bottom: 4px;
  }

  .monster-name {
    font-size: 10px;
    margin: 4px 0;
    font-weight: bold;
  }

  .monster-stats {
    font-size: 8px;
    line-height: 1.3;
  }

  .target-select {
    font-size: 12px;
    padding: 8px;
    margin-bottom: 10px;
    width: 100%;
    background: #16213e;
    color: #e94560;
    border: 2px solid #e94560;
    border-radius: 6px;
  }

  .target-label {
    font-size: 12px;
    display: block;
    margin-bottom: 5px;
    text-align: center;
    color: #e94560;
    font-weight: bold;
  }

  /* ====== LEADERBOARD ====== */
  .leaderboard {
    max-height: none;
    height: auto;
    overflow: visible;
  }

  .leaderboard-content {
    max-height: none;
    overflow: visible;
  }

  .leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .player-item {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .player-name {
    font-size: 13px;
    font-weight: bold;
  }

  .player-status,
  .player-wave {
    font-size: 11px;
  }

  .player-health {
    font-size: 13px;
    font-weight: bold;
  }

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

  .research-modal h2 {
    font-size: 1.5em;
    margin-bottom: 15px;
  }

  .research-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .research-item {
    padding: 12px;
  }

  .research-header {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .research-name {
    font-size: 14px;
  }

  .research-level {
    font-size: 12px;
  }

  .research-stats {
    font-size: 11px;
  }

  .btn-research {
    font-size: 12px;
    padding: 10px;
    width: 100%;
    margin-top: 8px;
  }

  /* Towers Modal */
  .towers-modal .modal-content {
    width: 95%;
    max-width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 15px;
  }

  .towers-modal h2 {
    font-size: 1.5em;
    margin-bottom: 15px;
  }

  .towers-table-container {
    overflow-x: auto;
  }

  .towers-table {
    font-size: 11px;
  }

  .towers-table th,
  .towers-table td {
    padding: 8px 4px;
  }

  .btn-upgrade-list,
  .btn-sell {
    font-size: 10px;
    padding: 6px 10px;
    margin: 2px;
  }

  .target-mode-select {
    font-size: 11px;
    padding: 4px;
  }

  /* Spectator Modal */
  .spectator-modal-content {
    width: 95%;
    max-width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 15px;
  }

  .spectator-modal-content h2 {
    font-size: 1.5em;
    margin-bottom: 15px;
  }

  #spectator-canvas {
    width: 100%;
    height: 250px;
    max-height: 250px;
  }

  .spectator-stats {
    flex-direction: column;
    gap: 8px;
  }

  .spectator-stat {
    font-size: 12px;
  }

  /* Game Over Modal */
  #game-over-modal .modal-content {
    width: 95%;
    max-width: 95%;
    padding: 20px;
  }

  #game-over-modal h2 {
    font-size: 2em;
    margin-bottom: 15px;
  }

  #game-over-message {
    font-size: 1.1em;
    margin-bottom: 20px;
  }

  #final-stats {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 20px;
  }

  .stat-box {
    padding: 12px;
  }

  .stat-box h3 {
    font-size: 1em;
  }

  .stat-box p {
    font-size: 1.3em;
  }

  #btn-return-lobby {
    font-size: 16px;
    padding: 14px 24px;
  }

  /* ====== WAVE INFO ====== */
  .wave-info {
    font-size: 14px;
    padding: 8px;
    margin-bottom: 8px;
  }

  /* ====== TOOLTIPS ====== */
  .tooltip {
    display: none !important;
  }

  /* ====== BUTTONS ====== */
  button,
  .btn,
  .tower-btn,
  .monster-btn {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

/* ====== PORTRAIT MODE ====== */
@media (max-width: 768px) and (orientation: portrait) {
  #game-container {
    height: 420px;
    min-height: 380px;
  }

  .tower-shop,
  .monster-shop {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ====== LANDSCAPE MODE ====== */
@media (max-width: 768px) and (orientation: landscape) {
  #game-container {
    height: 280px;
    min-height: 250px;
    max-height: 320px;
  }

  .tower-shop,
  .monster-shop {
    grid-template-columns: repeat(4, 1fr);
  }

  .top-panel {
    padding: 6px;
    gap: 4px;
  }

  .stat-item,
  .btn-research-toggle,
  .btn-skill,
  .btn-aura-toggle,
  .btn-quit {
    min-width: 70px;
    font-size: 10px;
    padding: 5px 8px;
  }
}

/* ====== VERY SMALL SCREENS ====== */
@media (max-width: 480px) {
  .auth-container h1 {
    font-size: 1.5em;
  }

  .lobby-container h1 {
    font-size: 1.5em;
  }

  #game-container {
    height: 380px;
    min-height: 350px;
  }

  .game-panel h3 {
    font-size: 14px;
  }

  .tower-shop,
  .monster-shop {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-item {
    min-width: 75px;
    font-size: 10px;
  }

  .btn-research-toggle,
  .btn-skill,
  .btn-aura-toggle,
  .btn-quit {
    min-width: 75px;
    font-size: 10px;
    padding: 6px 8px;
  }
}
