/* ============================================================
   GIRI GAMES — Mobile Optimizations
   Target: 320px–480px viewport width
   Overrides games-main.css & games-common.css
   ============================================================ */

/* ==========================================================
   GENERAL MOBILE GAME UTILITIES
   ========================================================== */

@media (max-width: 768px) {
  /* Prevent pull-to-refresh during gameplay */
  #view-games {
    overscroll-behavior: contain;
  }
  .game-play-area {
    overscroll-behavior: contain;
  }

  /* Hide desktop-only hint text (e.g. "Use arrow keys") */
  .desktop-hint {
    display: none;
  }
}

/* Hide touch controls on desktop */
@media (min-width: 481px) {
  .snake-dpad,
  .tetris-touch-controls {
    display: none !important;
  }
}

/* ==========================================================
   HOME PAGE (games-main.css overrides)
   ========================================================== */

@media (max-width: 480px) {
  /* -- Home container -- */
  .games-home {
    padding: 12px 8px;
  }

  /* -- Header: stack vertically, smaller title -- */
  .games-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }
  .games-header h1,
  .games-header-title {
    font-size: 20px;
  }
  .games-header-subtitle {
    font-size: 12px;
  }

  /* -- Player bar: compact, stack stats below -- */
  .games-player-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .games-player-info {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .games-player-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: space-between;
  }
  .games-player-stat {
    font-size: 12px;
    min-width: 0;
  }

  /* -- Daily challenge: stack vertically -- */
  .games-daily-challenge {
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
  }
  .games-daily-icon {
    font-size: 28px;
  }
  .games-daily-title {
    font-size: 14px;
  }
  .games-daily-desc {
    font-size: 12px;
  }

  /* -- Game grid: tighten gap -- */
  .games-grid {
    gap: 10px;
    padding: 0;
  }

  /* -- Game card: smaller padding and icon -- */
  .game-card {
    padding: 12px;
    border-radius: 12px;
  }
  .game-card-icon {
    font-size: 32px;
    width: 48px;
    height: 48px;
  }
  .game-card-title {
    font-size: 14px;
  }
  .game-card-desc {
    font-size: 11px;
    -webkit-line-clamp: 2;
  }
  .game-card-xp {
    font-size: 11px;
  }

  /* -- Game topbar -- */
  .game-topbar {
    padding: 8px 10px;
    gap: 8px;
  }
  .game-topbar-title {
    font-size: 14px;
  }
  .game-topbar-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  /* -- Play area -- */
  .game-play-area {
    padding: 10px 8px;
  }

  /* -- Finish overlay -- */
  .game-finish-overlay {
    padding: 16px;
  }
  .game-finish-title {
    font-size: 22px;
  }
  .game-finish-subtitle {
    font-size: 14px;
  }
  .game-finish-stats {
    gap: 8px;
  }
  .game-finish-stat {
    padding: 8px 10px;
    font-size: 12px;
  }
  .game-finish-stat-value {
    font-size: 20px;
  }
  .game-finish-actions {
    flex-direction: column;
    gap: 8px;
  }
  .game-finish-btn {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
  }

  /* -- Modal: full-width, less border-radius -- */
  .games-modal-content,
  .game-modal-content {
    width: calc(100vw - 24px);
    max-width: 100%;
    border-radius: 14px;
    padding: 16px;
    margin: 12px;
  }
  .games-modal-title,
  .game-modal-title {
    font-size: 18px;
  }

  /* -- Leaderboard rows -- */
  .leaderboard-row {
    padding: 8px 10px;
    gap: 8px;
  }
  .leaderboard-rank {
    font-size: 13px;
    min-width: 28px;
  }
  .leaderboard-name {
    font-size: 13px;
  }
  .leaderboard-score {
    font-size: 13px;
  }

  /* -- Profile modal: compact stats -- */
  .games-profile-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .games-profile-stat {
    padding: 8px;
    font-size: 12px;
  }
  .games-profile-stat-value {
    font-size: 18px;
  }
}

/* ==========================================================
   CHESS
   ========================================================== */

@media (max-width: 480px) {
  .chess-wrapper {
    flex-direction: column;
    gap: 12px;
    padding: 8px;
  }
  .chess-board {
    width: min(480px, calc(100vw - 32px));
    height: auto;
    aspect-ratio: 1;
  }
  .chess-right {
    max-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .chess-moves-list {
    max-height: 120px;
  }
  .chess-player {
    padding: 6px 8px;
    font-size: 13px;
  }
  .chess-clock {
    font-size: 15px;
    padding: 3px 8px;
  }
  .chess-overlay-msg {
    font-size: 18px;
  }
  .chess-info-panel {
    width: 100%;
  }
  .chess-controls {
    flex-wrap: wrap;
    gap: 6px;
  }
  .chess-controls button {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* ==========================================================
   SUDOKU
   ========================================================== */

@media (max-width: 480px) {
  .sudoku-numpad {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .sudoku-num-btn {
    font-size: 16px;
    padding: 10px 6px;
  }
  .sudoku-board {
    width: min(360px, calc(100vw - 32px));
  }
  .sudoku-cell {
    font-size: 16px;
  }
  .sudoku-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .sudoku-actions button {
    font-size: 12px;
    padding: 6px 10px;
  }
}

/* ==========================================================
   MINESWEEPER
   ========================================================== */

@media (max-width: 480px) {
  /* Scale cells down on mobile */
  .mine-cell {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  /* Medium difficulty — even smaller */
  .mines-grid.mines-medium .mine-cell {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  /* Hard/expert — allow horizontal scroll */
  .mines-board {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mines-stats {
    flex-wrap: wrap;
    gap: 6px;
  }
  .mines-stat-box {
    min-width: 60px;
    padding: 6px 10px;
  }
  .mines-stat-value {
    font-size: 16px;
  }
  .mines-stat-label {
    font-size: 10px;
  }
}

/* ==========================================================
   MEMORY
   ========================================================== */

@media (max-width: 480px) {
  .memory-card {
    width: 60px;
    height: 60px;
  }
  .memory-card-face {
    font-size: 22px;
    border-radius: 10px;
  }
  .memory-stats {
    gap: 12px;
    padding: 8px 14px;
    flex-wrap: wrap;
  }
  .memory-stat {
    font-size: 12px;
  }
  .memory-stat-value {
    font-size: 16px;
  }
  .memory-grid {
    gap: 6px;
  }
}

/* ==========================================================
   2048
   ========================================================== */

@media (max-width: 480px) {
  .g2048-board {
    gap: 6px;
    padding: 8px;
    border-radius: 12px;
  }
  .g2048-tile {
    border-radius: 6px;
    font-size: 20px;
  }
  .g2048-score-box {
    padding: 6px 12px;
  }
  .g2048-score-value {
    font-size: 18px;
  }
}

/* ==========================================================
   SNAKE — D-Pad Touch Controls
   ========================================================== */

@media (max-width: 480px) {
  .snake-canvas {
    border-radius: 8px;
  }

  /* D-pad grid layout for touch buttons */
  .snake-dpad {
    display: grid;
    grid-template-areas:
      ".    up   ."
      "left .    right"
      ".    down .";
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 52px 52px 52px;
    gap: 4px;
    margin: 12px auto 0;
  }
  .snake-dpad-btn {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #e2e8f0);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background 0.1s;
  }
  .snake-dpad-btn:active {
    background: rgba(34, 197, 94, 0.3);
  }
  .snake-dpad-btn[data-dir="up"]    { grid-area: up; }
  .snake-dpad-btn[data-dir="down"]  { grid-area: down; }
  .snake-dpad-btn[data-dir="left"]  { grid-area: left; }
  .snake-dpad-btn[data-dir="right"] { grid-area: right; }

  .snake-score {
    font-size: 14px;
  }
}

/* ==========================================================
   TETRIS — Layout + Touch Controls
   ========================================================== */

@media (max-width: 480px) {
  .tetris-wrapper {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }
  .tetris-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    min-width: unset;
    width: 100%;
  }
  .tetris-panel {
    padding: 8px;
    min-width: 80px;
  }
  .tetris-panel-value {
    font-size: 18px;
  }
  .tetris-panel-label {
    font-size: 10px;
  }

  /* Touch controls */
  .tetris-touch-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    padding: 8px 0;
    flex-wrap: wrap;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
  }
  .tetris-touch-btn {
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text, #e2e8f0);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background 0.1s;
  }
  .tetris-touch-btn:active {
    background: rgba(124, 58, 237, 0.3);
  }
  .tetris-touch-btn.primary {
    background: rgba(124, 58, 237, 0.2);
    border: 1px solid rgba(124, 58, 237, 0.4);
  }
  .tetris-touch-btn.wide {
    width: 100px;
  }
}

/* ==========================================================
   GIMOTS (Wordle)
   ========================================================== */

@media (max-width: 380px) {
  .gimots-cell {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  .gimots-key {
    min-width: 24px;
    height: 38px;
    font-size: 11px;
    padding: 0 4px;
  }
  .gimots-key.wide {
    min-width: 44px;
  }
  .gimots-row {
    gap: 4px;
  }
  .gimots-keyboard-row {
    gap: 3px;
  }
}

/* ==========================================================
   TYPERACE
   ========================================================== */

@media (max-width: 480px) {
  .tr-wrapper {
    padding: 12px 10px 24px;
    gap: 12px;
  }
  .tr-logo-text {
    font-size: 18px;
  }
  .tr-logo-icon {
    font-size: 26px;
  }
  .tr-text-display {
    font-size: 16px;
    line-height: 1.8;
    padding: 14px 12px;
  }
  .tr-arena {
    padding: 16px 12px;
    border-radius: 14px;
  }
  .tr-stats {
    flex-wrap: wrap;
    gap: 6px;
  }
  .tr-stat-card {
    min-width: 70px;
    padding: 10px 8px;
  }
  .tr-stat-main {
    font-size: 18px;
  }
  .tr-stat-label {
    font-size: 10px;
  }
  .tr-level-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
  .tr-finish-box {
    padding: 24px 18px;
  }
  .tr-finish-val {
    font-size: 20px;
  }
  .tr-finish-stat {
    padding: 8px 10px;
    min-width: 55px;
  }
  .tr-hm-key {
    min-width: 22px;
    height: 22px;
    font-size: 9px;
  }
  .tr-input-area {
    font-size: 15px;
  }
}

/* ==========================================================
   LETTRE FLASH
   ========================================================== */

@media (max-width: 480px) {
  .lf-letter-display {
    font-size: 90px;
    line-height: 1.1;
  }
  .lf-kb-key {
    width: 30px;
    height: 30px;
    font-size: 11px;
  }
  .lf-arena {
    padding: 20px 12px 16px;
    min-height: 180px;
  }
  .lf-keyboard-row {
    gap: 3px;
  }
  .lf-stats {
    flex-wrap: wrap;
    gap: 6px;
  }
  .lf-stat {
    font-size: 12px;
    padding: 4px 8px;
  }
}

/* ==========================================================
   EXTRA SMALL SCREENS (320px)
   ========================================================== */

@media (max-width: 360px) {
  .games-grid {
    grid-template-columns: 1fr;
  }
  .game-card {
    padding: 10px;
  }
  .chess-board {
    width: calc(100vw - 20px);
  }
  .memory-card {
    width: 50px;
    height: 50px;
  }
  .memory-card-face {
    font-size: 18px;
  }
  .snake-dpad {
    grid-template-columns: 52px 52px 52px;
    grid-template-rows: 46px 46px 46px;
  }
  .tetris-touch-btn {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }
  .mine-cell {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
}
