/* ==========================================================
   Chawwa Ashta - Mobile layout overrides
   Load AFTER style.css. Only applies on screens <= 768px wide.
   ========================================================== */

html { -webkit-text-size-adjust: 100%; }

body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom delay */
}

@media (max-width: 768px) {

  body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* ---------- Header: slim one-row bar ---------- */
  .app-header {
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
    position: sticky;
    top: 0;
  }
  .logo-icon { font-size: 22px; }
  .title-wrap h1 { font-size: 15px; letter-spacing: 1px; }
  .title-wrap .sub-title { display: none; }
  .header-actions { gap: 6px; }
  .wallet-badge { padding: 7px 10px; font-size: 13px; gap: 6px; min-height: 36px; }
  .btn-icon { padding: 8px 10px; min-height: 36px; }
  .btn-icon span.text { display: none; }

  .main-content { padding: 8px; align-items: flex-start; }

  /* ---------- Lobby ---------- */
  .lobby-screen { padding: 16px 12px; border-radius: 14px; }
  .lobby-screen h2 { font-size: 22px; }
  .lobby-section { margin-bottom: 16px; }

  /* 4 game modes become a 2x2 grid of big tap targets */
  .lobby-section .choice-row { flex-wrap: wrap; }
  .choice-btn { min-height: 56px; padding: 10px 8px; }
  .mode-choice-btn { flex: 1 1 calc(50% - 6px); }
  .count-choice-btn { min-height: 48px; }

  .bot-level-grid { grid-template-columns: 1fr; }
  .bot-level-card { padding: 12px; }

  .skin-dialogue-grid { gap: 8px; }
  .skin-card-box { width: calc(33.33% - 6px); min-width: 92px; height: 92px; }

  .player-skin-tab-btn { padding: 10px 12px; min-height: 44px; }

  .lobby-wallet-card { flex-direction: column; align-items: stretch; gap: 10px; }
  .lobby-wallet-card > div:last-child { width: 100%; }
  .lobby-wallet-card .btn-watch-ad,
  .lobby-wallet-card .btn-open-wallet { flex: 1; min-height: 46px; justify-content: center; }

  .btn-start-game {
    min-height: 58px;
    font-size: 17px;
    position: sticky;
    bottom: calc(var(--ad-dock-height) + 8px + env(safe-area-inset-bottom));
    z-index: 10;
  }

  /* ---------- In-game: board first, controls right under it ---------- */
  .game-play-area {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  /* Let sidebar children be ordered individually */
  .game-sidebar { display: contents; }

  .turn-banner          { order: 0; padding: 8px 10px; }
  .board-container-wrap { order: 1; padding: 0; }
  .game-controls-tray   { order: 2; width: 100%; max-width: none; gap: 8px; }
  .players-status-list  { order: 3; }
  .commentary-box       { order: 4; height: 110px; }

  .turn-banner .current-player-name { font-size: 16px; margin-top: 2px; }
  .turn-banner .turn-tag { font-size: 9px; }

  /* Board fills the screen width exactly (works from 320px up) */
  .board-outer-frame {
    padding: 6px;
    border-width: 4px;
    border-radius: 12px;
    max-width: 100%;
  }
  .corner-ornament { display: none; }
  .board-grid {
    gap: 3px;
    padding: 3px;
    grid-template-columns: repeat(5, calc((100vw - 16px - 20px - 6px - 12px) / 5));
    grid-template-rows: repeat(5, calc((100vw - 16px - 20px - 6px - 12px) / 5));
  }
  /* Cap on large phones / small tablets */
  @supports (width: min(1px, 2px)) {
    .board-grid {
      grid-template-columns: repeat(5, min(86px, calc((100vw - 54px) / 5)));
      grid-template-rows: repeat(5, min(86px, calc((100vw - 54px) / 5)));
    }
  }

  /* Pawns scale with the cell so they never overflow */
  .pawns-cluster[data-count="1"] .pawn-container { width: 70%; height: 70%; }
  .pawns-cluster[data-count="1"] .pawn-goti { width: 94%; height: 94%; }

  /* ---------- Shells + Roll button ---------- */
  .kaudya-tray-card { padding: 10px; border-radius: 14px; }
  .kaudya-tray-header { display: none; }
  .kaudya-board { min-height: 74px; padding: 8px 6px; margin-bottom: 8px; }
  .cowrie-wrapper { width: 34px; height: 52px; }
  .roll-result-badge { min-height: 34px; padding: 6px 8px; margin-bottom: 8px; }
  .roll-result-text { font-size: 14px; }

  .btn-roll-kaudya {
    min-height: 56px;
    font-size: 17px;
  }
  .btn-jugda-action { min-height: 50px; }

  /* Hint + New Match sit side by side */
  .game-controls-tray { display: grid; grid-template-columns: 1fr 1fr; }
  .kaudya-tray-card { grid-column: 1 / -1; }
  .btn-hint { min-height: 48px; }
  .quick-controls .btn-secondary { min-height: 48px; font-size: 13px; }
  .btn-hint[style*="display: none"] + .quick-controls { grid-column: 1 / -1; }

  .game-play-area .online-chat-panel {
    position: fixed;
    z-index: 90;
    left: 10px;
    right: 10px;
    bottom: calc(var(--ad-dock-height, 0px) + 10px + env(safe-area-inset-bottom));
    width: auto;
    min-width: 0;
    height: min(72dvh, 560px);
    max-height: calc(100dvh - 90px - var(--ad-dock-height, 0px) - env(safe-area-inset-bottom));
    flex-basis: auto;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.85);
    animation: online-chat-slide-up 0.22s ease-out;
  }
  .game-play-area .online-chat-close { display: block; min-width: 40px; min-height: 40px; }
  .game-play-area .online-chat-toggle {
    position: fixed;
    z-index: 85;
    right: 14px;
    bottom: calc(var(--ad-dock-height, 0px) + 12px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 46px;
    padding: 0 14px;
    border: 1px solid var(--gold-accent);
    border-radius: 24px;
    background: linear-gradient(135deg, #5c3818, #2c1a0e);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    color: #fff1c5;
    font-weight: 700;
    cursor: pointer;
  }
  .online-chat-unread {
    min-width: 19px;
    height: 19px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border-radius: 10px;
    background: #d32f2f;
    color: white;
    font-size: 11px;
  }

  .player-status-card { padding: 8px 10px; }
  .player-status-card.active-turn { transform: none; }

  /* ---------- Modals: bottom-sheet style ---------- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-card {
    max-width: 100% !important;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    display: flex;
    flex-direction: column;
  }
  .modal-body {
    max-height: none;
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }
  .modal-close-btn { font-size: 30px; padding: 4px 10px; min-width: 44px; min-height: 44px; }

  /* Confirm dialog stays centred, it is small */
  #purchase-confirm-modal { align-items: center; padding: 16px; }
  #purchase-confirm-modal .modal-card { border-radius: 16px; }

  .wallet-tabs { overflow-x: auto; }
  .wallet-tab-btn { min-height: 44px; white-space: nowrap; padding: 8px 12px; }
  .themes-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .blueprint-grid { grid-template-columns: 1fr; }
  .reward-ad-card { flex-direction: column; align-items: stretch; }
  .reward-ad-card .btn-watch-ad { min-height: 48px; justify-content: center; }
  .btn-stepper { width: 48px; height: 48px; }
  .btn-pay-now, .btn-confirm-pay, .btn-confirm-cancel { min-height: 48px; }

  /* Toasts at the top so they never cover the Roll button */
  .chawwa-toast-container {
    top: calc(64px + env(safe-area-inset-top));
    bottom: auto;
    left: 10px;
    right: 10px;
    max-width: none;
  }

  /* 16px inputs stop iOS from zooming the page on focus */
  input, select, textarea,
  .room-code-input, .monetag-input {
    font-size: 16px;
    user-select: text;
    -webkit-user-select: text;
  }
}

@keyframes online-chat-slide-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Very small phones */
@media (max-width: 360px) {
  .title-wrap h1 { font-size: 13px; }
  .skin-card-box { min-width: 84px; height: 86px; }
  .skin-card-label { font-size: 11.5px; }
}

/* Landscape phones: put board and controls side by side */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .game-play-area { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .turn-banner { order: 0; flex: 1 1 100%; }
  .board-container-wrap { order: 1; flex: 0 0 auto; }
  .game-controls-tray { order: 2; flex: 1 1 220px; max-width: 280px; display: flex; }
  .board-grid {
    grid-template-columns: repeat(5, min(60px, calc((100vh - 130px) / 5)));
    grid-template-rows: repeat(5, min(60px, calc((100vh - 130px) / 5)));
  }
  .players-status-list, .commentary-box { display: none; }
}
