/* ══════════════════════════════════════════════════════════════
   mobile.css — Camada mobile isolada
   Usa pointer:coarse para nunca afetar desktop.
   REGRA: não bloquear overflow ou touch no body globalmente.
══════════════════════════════════════════════════════════════ */

/* ── 1. Base: qualquer dispositivo touch ─────────────────────── */
@media (pointer: coarse) {
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  input, textarea, [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
  }

  /* touch-action: manipulation em botões previne zoom por duplo-toque
     SEM bloquear o evento de click — seguro para todos os botões */
  button, a, [role="button"], label,
  .inventory-slot, .menu-option, .sd-btn, .gold-button,
  .dpad-up, .dpad-left, .dpad-down, .dpad-right,
  .book-tab, .pixel-side-button {
    touch-action: manipulation;
  }

  /* Tamanho mínimo confortável para toque */
  button, .inventory-slot, .menu-option, .sd-btn, .gold-button {
    min-height: 44px;
  }
}

/* ── 2. Overlay de rotação ───────────────────────────────────── */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background:
    radial-gradient(ellipse at 50% 65%, rgba(58, 38, 16, .88), rgba(12, 5, 2, .97)),
    url("../assets/backgrounds/farm_bg.png") center / cover no-repeat;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.rotate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 32px 24px;
  border: 5px solid #f0c840;
  background: rgba(43, 21, 8, .90);
  box-shadow: 6px 6px 0 rgba(0,0,0,.42), 0 0 28px rgba(240,200,64,.20);
  max-width: 280px;
  text-align: center;
}

.rotate-phone {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: mobRotatePhone 2.4s ease-in-out infinite;
}

.rotate-phone__body {
  width: 24px;
  height: 40px;
  border: 4px solid #f0c840;
  border-radius: 5px;
  position: relative;
  box-shadow: 0 0 14px rgba(240,200,64,.5);
}

.rotate-phone__body::before {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 3px;
  border-radius: 2px;
  background: #f0c840;
  opacity: .8;
}

.rotate-phone__body::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 2px;
  border-radius: 2px;
  background: #f0c840;
  opacity: .5;
}

@keyframes mobRotatePhone {
  0%, 30%  { transform: rotate(0deg);  opacity: 1; }
  55%      { transform: rotate(90deg); opacity: .7; }
  65%, 90% { transform: rotate(90deg); opacity: 1; }
  100%     { transform: rotate(0deg);  opacity: 1; }
}

.rotate-title {
  margin: 0;
  color: #f0c840;
  font-family: "VT323", monospace;
  font-size: 30px;
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(0,0,0,.55);
}

.rotate-subtitle {
  margin: 0;
  color: #f7e6bb;
  font-family: "VT323", monospace;
  font-size: 20px;
  line-height: 1.35;
  opacity: .85;
}

/* ── 3. Mobile portrait — esconde jogo, mostra overlay ──────── */
@media (pointer: coarse) and (orientation: portrait) {
  #rotate-overlay { display: flex; }

  #topbar, .quick-actions, #app, #background, #ambience, #toast {
    visibility: hidden;
    pointer-events: none;
  }
}

/* ══════════════════════════════════════════════════════════════
   4. Mobile landscape — telefones deitados
   pointer:coarse + landscape + altura ≤ 520px
   NÃO toca em overflow/touch-action do body — quebra screens.
══════════════════════════════════════════════════════════════ */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {

  /* 4.0 Variáveis reduzidas */
  :root {
    --topbar-h: 28px;
    --mob-bottom-bar: 68px;
  }

  /* Previne pull-to-refresh sem bloquear scroll de conteúdo */
  body {
    overscroll-behavior: none;
  }

  /* 4.1 Topbar compacta */
  .topbar {
    height: 28px;
    font-size: 13px;
    padding: 0 8px;
  }

  .topbar__icon { width: 18px; height: 18px; }
  #farm-date, #farm-clock { font-size: 14px; line-height: 1; }
  .topbar__center { display: none; }

  /* 4.2 Quick-actions compactas */
  .quick-actions {
    top: auto;
    bottom: 6px;
    right: 6px;
    gap: 3px;
  }

  .pixel-side-button {
    padding: 3px 7px;
    font-size: 13px;
    min-height: 30px;
  }

  #help-button { display: none; }

  /* ══ 4.3 FARM ═══════════════════════════════════════════════ */

  /* Stage ocupa tela toda: só o farm usa position fixed */
  .screen--farm {
    display: block;
    position: fixed;
    inset: 0;
    top: var(--topbar-h, 28px);
    padding: 0;
    overflow: hidden;
    touch-action: none; /* OK aqui pois o farm usa click no stage */
  }

  .farm-layout {
    position: absolute;
    inset: 0;
    bottom: var(--mob-bottom-bar, 68px);
  }

  .farm-stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    border-width: 3px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Barra de controles fixa no rodapé */
  .farm-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    margin: 0;
    width: 100%;
    max-width: none;
    padding: 6px 12px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: rgba(18, 8, 6, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 3px solid #2b1508;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .dpad { gap: 3px; flex-shrink: 0; }

  .dpad-up, .dpad-left, .dpad-down, .dpad-right {
    width: 50px;
    height: 50px;
    font-size: 18px;
    border-width: 3px;
    padding: 0;
    display: grid;
    place-items: center;
  }

  .farm-main-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 5px;
    flex: 1;
    justify-content: center;
  }

  .farm-main-actions button {
    min-height: 44px;
    font-size: 16px;
    padding: 4px 12px;
    border-width: 3px;
    flex: 1;
    min-width: 90px;
    max-width: 150px;
  }

  /* Inventory: barra lateral direita */
  .inventory-bar {
    position: fixed;
    right: 6px;
    top: calc(var(--topbar-h, 28px) + 4px);
    margin: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    width: auto;
    max-width: none;
    max-height: calc(100dvh - var(--topbar-h, 28px) - var(--mob-bottom-bar, 68px) - 10px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border-width: 3px;
    padding: 4px 3px;
    z-index: 40;
    gap: 3px;
    background: rgba(58, 38, 16, .88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .inventory-slot {
    width: 50px;
    min-height: 50px;
    height: 50px;
    padding: 4px 2px;
    flex-direction: column;
  }

  .inventory-slot__label { display: none; }

  .inventory-slot__tip {
    right: calc(100% + 8px);
    left: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%) translateX(4px);
    white-space: nowrap;
  }

  .inventory-slot:not(.is-locked):hover .inventory-slot__tip,
  .inventory-slot:not(.is-locked):focus-visible .inventory-slot__tip {
    transform: translateY(-50%) translateX(0);
  }

  .farm-dialogue-strip,
  .farm-objective-chip { font-size: 14px; padding: 4px 8px; }

  /* ══ 4.4 MENU HUB ════════════════════════════════════════════ */

  .screen--menu-hub,
  .screen--menu-detail {
    padding: 4px 6px 8px;
    align-items: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100dvh - var(--topbar-h, 28px));
  }

  .menu-panel--hub {
    width: 100%;
    max-height: none;
    padding: 6px;
  }

  .menu-panel--hub::before,
  .menu-panel--hub::after { display: none; }

  .menu-hub-header {
    grid-template-columns: 1fr auto;
    margin-bottom: 6px;
    gap: 6px;
  }

  .menu-title { font-size: clamp(20px, 5vw, 32px); }
  .menu-hub-kicker { font-size: 16px; margin-bottom: 2px; }

  .menu-hub-progress {
    min-width: 90px;
    padding: 4px 7px;
  }

  .menu-hub-progress small { font-size: 13px; }

  .menu-saveload {
    margin-bottom: 6px;
    padding: 4px 8px;
    border-radius: 6px;
  }

  .menu-saveload__label { font-size: 12px; }
  .menu-saveload__pct   { font-size: 14px; }

  .menu-grid--hub {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
  }

  .menu-option--button {
    min-height: 60px;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    padding-left: 10px;
  }

  .menu-option--button .menu-option__icon { width: 34px; height: 34px; }
  .menu-option--button .menu-option__icon img { width: 26px; height: 26px; }
  .menu-option__copy strong { font-size: 17px; line-height: 1; }
  .menu-option__copy span   { font-size: 14px; }
  .menu-option__badge       { font-size: 15px; min-width: 34px; padding: 3px 4px; }
  .menu-option__check       { width: 18px; height: 18px; font-size: 11px; }

  .save-tip { font-size: 14px; margin-top: 4px; }

  /* ══ 4.5 LAGO (Phaser 960×540) ══════════════════════════════ */

  .lake-screen {
    height: calc(100dvh - var(--topbar-h, 28px));
    padding: 4px 6px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .lake-layout {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .lake-side {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 4px 6px;
  }

  .lake-side-card {
    max-height: 100px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .lake-categories { font-size: 16px; gap: 4px; }

  #lake-pull {
    min-height: 56px;
    min-width: 86px;
    font-size: 19px;
    padding: 8px 12px;
  }

  #lake-status { font-size: 16px; }
  .lake-tutorial p      { font-size: 17px; line-height: 1.3; }
  .lake-tutorial strong { font-size: 20px; }
  #lake-start { min-height: 48px; font-size: 20px; }

  /* ══ 4.6 BATALHA ═════════════════════════════════════════════ */

  .pokemon-battle {
    width: 100%;
    max-width: none;
    border-width: 3px;
    outline: none;
  }

  .pokemon-field {
    height: clamp(140px, 38dvh, 220px);
    min-height: 140px;
  }

  .pokemon-bottom {
    grid-template-columns: 1fr minmax(200px, 36%);
    padding: 6px;
    gap: 6px;
  }

  .pokemon-textbox {
    min-height: 70px;
    font-size: 18px;
    padding: 7px 10px;
  }

  .pokemon-attack { min-height: 44px; gap: 5px; padding: 4px 6px; }
  .pokemon-attack strong { font-size: 16px; }
  .pokemon-attack span   { font-size: 13px; }

  .skill-check {
    bottom: 8px;
    width: min(420px, calc(100% - 24px));
    font-size: 18px;
  }

  .pokemon-hud { width: min(280px, 40%); }
  .pokemon-hp__bar  { height: 14px; }
  .pokemon-hud__name { font-size: 18px; }
  .pokemon-hp__text  { font-size: 14px; }

  /* ══ 4.7 CARTA ═══════════════════════════════════════════════ */

  .screen--letter,
  .letter-screen,
  .letter-panel {
    overflow-y: auto;
    max-height: calc(100dvh - var(--topbar-h, 28px));
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px;
  }

  /* ══ 4.8 CROPS ═══════════════════════════════════════════════ */

  .screen--crops,
  .screen--crops-overcooked {
    position: fixed;
    inset: 0;
    top: var(--topbar-h, 28px);
    padding: 0;
    overflow: hidden;
    touch-action: none;
  }

  .crops-panel--map {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .crops-header { padding: 3px 8px; flex-shrink: 0; font-size: 15px; }
  .crops-map-stage { flex: 1; min-height: 0; }

  /* ══ 4.9 CONTEÚDO: Memórias, Livro, Loja, Final ═════════════ */

  .memories-screen,
  .book-screen,
  .shop-screen,
  .finale-screen {
    height: calc(100dvh - var(--topbar-h, 28px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .memories-page,
  .finale-panel,
  .shop-panel,
  .content-wrap { max-width: 100%; padding: 6px 8px; }

  .shop-grid { grid-template-columns: 1fr; gap: 8px; }

  .shop-item {
    grid-template-columns: 48px 1fr auto;
    padding: 8px;
  }

  .shop-item button { min-height: 44px; font-size: 16px; }

  .book-tabs { flex-wrap: wrap; gap: 4px; }
  .book-tab  { font-size: 16px; padding: 5px 8px; min-height: 40px; }

  /* Tela inicial / senha */
  .screen--save-found {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100dvh - var(--topbar-h, 28px));
  }

  /* Toast sobe acima dos controles do farm */
  #toast {
    bottom: calc(var(--mob-bottom-bar, 68px) + 8px);
    font-size: 16px;
  }
}

/* ── 5. Tablets landscape (altura > 520px, touch) ────────────── */
@media (pointer: coarse) and (orientation: landscape) and (min-height: 521px) {
  :root { --topbar-h: 32px; }
  .topbar { height: 32px; }
  #help-button { display: none; }

  button, .inventory-slot, .menu-option, .sd-btn, .gold-button {
    min-height: 44px;
  }
}
