/* Hide mobile dock on desktop — JS shows it on mobile */
.mobile-dock { display: none; }

/* Panel open state */
.mobile-extra-panel.open { bottom: 0 !important; }
.mobile-extra-backdrop.open { display: block !important; }

/*
 * BackWords Mobile Layout
 * Only activates on screens ≤768px
 * Desktop layout remains completely untouched
 */

@media (max-width: 768px) {
  
  /* ========================================
     GLOBAL MOBILE ADJUSTMENTS
     ======================================== */
  
  /* Game screen gets the locked viewport — everything else scrolls normally */
  #screen-game {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Lobby and other screens scroll freely */
  #screen-lobby,
  #screen-stats,
  #screen-info,
  #screen-admin {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* ========================================
     MOBILE TOP BAR - Always visible
     [Lobby] [Mini Games] [Game Info] [Shop] [Profile]
     ======================================== */
  
  #screen-game .topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #fff;
    border-bottom: 1px solid #ddd;
    padding: 8px 12px;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  /* Hide desktop nav elements */
  #screen-game .topnav .logo-sm,
  #screen-game .topnav .btn-sm:first-child {
    display: none !important;
  }

  /* Mobile top bar icons */
  #screen-game .nav-games {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: flex-start;
  }

  #screen-game .nav-games .btn-sm {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
  }

  #screen-game .nav-right {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: 0 !important;
  }

  #screen-game .nav-right .username-badge,
  #screen-game .nav-right .coin-badge {
    font-size: 11px;
    padding: 4px 6px;
    height: auto;
  }

  /* Add mobile-only icons to nav */
  #screen-game .topnav::before {
    content: "🏠";
    font-size: 20px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f2ed;
    border-radius: 8px;
    border: 1px solid #ddd;
  }

  /* Shop icon placeholder (coming soon) */
  #screen-game .nav-right::before {
    content: "🛒";
    font-size: 18px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f2ed;
    border-radius: 8px;
    border: 1px solid #ddd;
    opacity: 0.3;
    cursor: not-allowed;
  }

  /* ========================================
     HIDE DESKTOP GAME ELEMENTS
     ======================================== */
  
  #screen-game .topbar,
  #screen-game .legend,
  #screen-game .side,
  #screen-game .side-icons,
  #screen-game #saved-moves-pane {
    display: none !important;
  }

  /* ========================================
     GAME BOARD - Full screen, zoomable
     ======================================== */
  
  #screen-game .main {
    position: fixed;
    top: 52px; /* height of top bar */
    left: 0;
    right: 0;
    bottom: 180px; /* height of mobile dock */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8f7f4;
    padding: 0;
    margin: 0;
  }

  #screen-game .board-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 0;
  }

  #screen-game .board {
    /* Board will be pinch-zoomable via touch-action */
    touch-action: pinch-zoom;
    margin: 0;
    min-width: 100%;
    min-height: 100%;
  }

  /* ========================================
     MOBILE DOCK - Always visible at bottom
     ======================================== */
  
  #screen-game .mobile-dock {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 2px solid #ddd;
    z-index: 999;
    padding: 8px 12px 12px;
  }

  /* Tile rack */
  #screen-game .mobile-dock-top {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
  }

  #screen-game .mobile-dock .rack {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Last move preview under Submit */
  #screen-game .mobile-wp {
    font-size: 12px;
    text-align: center;
    color: #888;
    margin-bottom: 8px;
    min-height: 16px;
    line-height: 1.3;
    font-weight: 500;
  }

  /* Bottom action buttons */
  #screen-game .mobile-dock-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: stretch;
  }

  #screen-game .mobile-dock-actions .btn-sm,
  #screen-game .mobile-dock-actions .btn-primary {
    flex: 1;
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    padding: 0 6px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    line-height: 1;
  }

  /* Make Submit button bigger — reset btn-primary base styles that add margin/width/padding */
  #screen-game .mobile-dock-actions .btn-primary {
    flex: 2;
    background: #534AB7;
    color: #fff;
    border: none;
    font-size: 14px;
    letter-spacing: 0.5px;
    display: flex !important;
    width: auto !important;
    margin-top: 0 !important;
    padding: 0 8px !important;
  }

  /* Recall button styling */
  #screen-game .mobile-dock-actions .btn-recall {
    background: #f4f2ed;
    border-color: #ddd;
  }

  /* Emoji button styling */
  #screen-game .mobile-dock-actions button[title*="emoji"],
  #screen-game .mobile-dock-actions button[onclick*="emoji"],
  #screen-game .mobile-dock-actions .btn-emoji {
    background: #FFF3E0;
    border-color: #FFB74D;
  }

  /* Settings button styling */
  #screen-game .mobile-dock-actions button[title*="More"],
  #screen-game .mobile-dock-actions button[onclick*="Settings"],
  #screen-game .mobile-dock-actions .btn-settings {
    background: #f4f2ed;
    border-color: #ddd;
  }

  /* ========================================
     MOBILE SETTINGS/MORE MODAL
     ======================================== */
  
  #screen-game .mobile-extra-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
  }

  #screen-game .mobile-extra-backdrop.open {
    display: block;
  }

  #screen-game .mobile-extra-panel {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 16px;
    z-index: 1101;
    transition: bottom 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  }

  #screen-game .mobile-extra-panel.open {
    bottom: 0;
  }

  /* Settings panel specific */
  #mobile-settings-panel .btn-secondary {
    background: #f4f2ed;
    border: 1px solid #ddd;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    border-radius: 8px;
    text-align: center;
  }

  #mobile-settings-panel .btn-secondary:active {
    background: #e8e6e0;
  }

  /* Emoji panel specific */
  #mobile-emoji-panel .emoji-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }

  #mobile-emoji-panel .emoji-bar button {
    font-size: 28px;
    width: 56px;
    height: 56px;
    border-radius: 12px;
    border: 2px solid #ddd;
    background: #f4f2ed;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
  }

  #mobile-emoji-panel .emoji-bar button:active {
    transform: scale(0.9);
    border-color: #534AB7;
    background: #EEEDFE;
  }

  /* Game log in settings panel */
  #screen-game .mobile-extra-panel .log {
    max-height: 250px;
    overflow-y: auto;
    background: #f8f7f4;
    border-radius: 8px;
    padding: 10px;
    font-size: 12px;
    line-height: 1.5;
  }

  #screen-game .mobile-extra-panel .log > div {
    padding: 6px 0;
    border-bottom: 1px solid #e8e6e0;
  }

  #screen-game .mobile-extra-panel .log > div:last-child {
    border-bottom: none;
  }

  /* ========================================
     AUTH SCREEN MOBILE
     ======================================== */

  #screen-auth {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .auth-wrap {
    padding: 32px 20px 40px;
    justify-content: flex-start;
    padding-top: max(48px, env(safe-area-inset-top, 48px));
  }

  .auth-wrap .logo {
    font-size: 42px;
  }

  .auth-wrap .card {
    width: 100%;
    max-width: 400px;
  }

  /* ========================================
     LOBBY SCREEN MOBILE
     ======================================== */
  
  #screen-lobby .topnav {
    padding: 8px 12px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 100;
  }

  #screen-lobby .nav-games {
    order: 3;
    width: 100%;
    margin-top: 8px;
    justify-content: space-between;
  }

  #screen-lobby .nav-games .btn-sm {
    flex: 1;
    min-width: 44px;
  }

  #screen-lobby .lobby-wrap {
    padding: 12px;
    margin: 0;
    flex-direction: column;
  }

  #screen-lobby .lobby-col {
    width: 100%;
    max-width: none;
    flex: none;
  }

  /* Collapse game options on mobile */
  #screen-lobby .option-row {
    padding: 8px 0;
  }

  #screen-lobby .mode-row-sub {
    font-size: 11px;
  }

  /* ========================================
     MODAL ADJUSTMENTS
     ======================================== */
  
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
    z-index: 1200;
  }

  .modal-box {
    max-width: 100%;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  /* ========================================
     MINI GAMES MOBILE
     ======================================== */
  
  /* WordBlitz, WordStorm, WordDrift all use modals */
  /* They should be full-screen on mobile */
  .modal-box {
    font-size: 14px;
  }

  /* ========================================
     OPPONENT INFO - Always visible
     ======================================== */
  
  .mobile-scores-bar {
    display: flex !important;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    height: 44px;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid #ddd;
    z-index: 998;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .mobile-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
  }

  .mobile-score-name {
    font-size: 11px;
    color: #888;
    font-weight: 600;
    margin-bottom: 2px;
  }

  .mobile-score-pts {
    font-size: 16px;
    font-weight: 700;
    color: #333;
  }

  .mobile-score-status {
    font-size: 11px;
    color: #534AB7;
    font-weight: 700;
    padding: 4px 8px;
    background: #EEEDFE;
    border-radius: 6px;
    white-space: nowrap;
  }

  /* Adjust main game area for scores bar */
  #screen-game .main {
    top: 96px; /* topnav (52px) + scores bar (44px) */
  }

  /* This is a pseudo-element placeholder - actual implementation needs JS */
  /* Add a mobile-scores-bar div in the HTML and style it here */

  /* ========================================
     UTILITY CLASSES
     ======================================== */
  
  .mobile-only {
    display: block !important;
  }

  .desktop-only {
    display: none !important;
  }

  /* ========================================
     TOUCH INTERACTIONS
     ======================================== */
  
  /* Larger tap targets — but don't override explicit heights in the dock */
  button:not(.mobile-dock-actions button), .btn-sm:not(.mobile-dock-actions .btn-sm) {
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(83, 74, 183, 0.2);
  }
  .mobile-dock-actions button {
    -webkit-tap-highlight-color: rgba(83, 74, 183, 0.2);
  }

  /* Tile touches */
  .tile {
    -webkit-tap-highlight-color: rgba(83, 74, 183, 0.2);
  }

  /* Board cell touches */
  .cell {
    -webkit-tap-highlight-color: rgba(83, 74, 183, 0.1);
  }

  /* ========================================
     SAFE AREAS (iPhone notch, etc)
     ======================================== */
  
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    #screen-game .mobile-dock {
      padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    #screen-game .topnav {
      padding-top: calc(8px + env(safe-area-inset-top));
    }
  }

  /* ========================================
     MINI GAMES ICON MODAL
     ======================================== */
  
  /* When mini games are condensed into one icon */
  .mini-games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 12px;
  }

  .mini-game-card {
    background: #f4f2ed;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
  }

  .mini-game-card:active {
    transform: scale(0.95);
    border-color: #534AB7;
  }

  .mini-game-card .icon {
    font-size: 32px;
    margin-bottom: 8px;
  }

  .mini-game-card .title {
    font-size: 13px;
    font-weight: 700;
    color: #333;
  }

  /* ========================================
     PERFORMANCE OPTIMIZATIONS
     ======================================== */
  
  /* Hardware acceleration for smooth animations — game screen only */
  #screen-game .board,
  #screen-game .mobile-dock,
  #screen-game .mobile-extra-panel,
  #screen-game .topnav {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  /* Reduce animations on low-end devices */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation: none !important;
      transition: none !important;
    }
  }

  /* ========================================
     LANDSCAPE ORIENTATION
     ======================================== */
  
  @media (max-width: 768px) and (orientation: landscape) {
    #screen-game .main {
      bottom: 140px; /* Shorter dock in landscape */
    }

    #screen-game .mobile-dock {
      padding: 6px 12px 8px;
    }

    #screen-game .mobile-wp {
      font-size: 11px;
      margin-bottom: 4px;
    }

    #screen-game .mobile-dock-actions .btn-sm,
    #screen-game .mobile-dock-actions .btn-primary {
      font-size: 12px;
      height: 38px !important;
      min-height: 38px !important;
      max-height: 38px !important;
    }
  }

  /* ========================================
     SMALL PHONES (≤480px)
     ======================================== */
  
  @media (max-width: 480px) {
    #screen-game .topnav {
      padding: 6px 8px;
    }

    #screen-game .nav-games .btn-sm {
      width: 32px;
      height: 32px;
      font-size: 16px;
    }

    #screen-game .mobile-dock-actions {
      gap: 4px;
    }

    #screen-game .mobile-dock-actions .btn-sm,
    #screen-game .mobile-dock-actions .btn-primary {
      font-size: 12px;
    }

  }
}

/* ── Must-use tile glow (Hit Me / Gambler's Draw) ── */
.tile.must-use {
  box-shadow: 0 0 0 2px #EF9F27, 0 0 10px 3px rgba(239,159,39,0.55);
  border-color: #EF9F27 !important;
  animation: must-use-pulse 1.4s ease-in-out infinite;
}
@keyframes must-use-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #EF9F27, 0 0 10px 3px rgba(239,159,39,0.45); }
  50%       { box-shadow: 0 0 0 2px #EF9F27, 0 0 16px 6px rgba(239,159,39,0.75); }
}

/* ── Tile on Lurker-eaten cell: regular tile + gold dashed border ── */
.cell.chaos-broken-played::after {
  content: '';
  position: absolute; inset: 1px;
  border: 2px dashed #EF9F27;
  border-radius: 3px;
  pointer-events: none;
  z-index: 3;
}
