.rotate-device-hint {
  display: none;
}

/* На телефоне карточки не растягиваются на всю ширину панели. */
@media (hover: none), (pointer: coarse), (max-width: 900px) {
  .home-screen:not(.is-open),
  .story-intro:not(.is-open) {
    display: none;
  }

  .home-screen.is-open,
  .story-intro.is-open {
    display: grid;
  }

  .game-stage:not(.home-screen-active) .quest-alert-button,
  .game-stage:not(.home-screen-active) .daily-quest-button {
    animation: none;
    filter: none;
  }

  body.mobile-game-ui-blocked .hud {
    visibility: hidden;
    opacity: 0;
  }

  .shop-content {
    grid-template-columns: repeat(auto-fill, minmax(96px, 112px));
    justify-content: start;
  }

  .shop-item {
    max-width: 112px;
  }

  .inventory-section.is-active {
    grid-template-columns: repeat(auto-fill, minmax(76px, 96px));
    justify-content: start;
  }

  .inventory-item,
  .potion-inventory-item {
    max-width: 96px;
    min-height: 92px;
  }

  .inventory-item img,
  .potion-inventory-item img {
    max-height: 64px;
  }

  #inventoryBootsItem,
  #inventoryCollarItem,
  #inventoryJacketItem,
  #inventoryFlashlightItem,
  #inventoryBeachOutfitItem,
  #inventoryPirateOutfitItem {
    grid-column: auto;
  }
}

/* Портрет оставляем для главного экрана. После старта просим повернуть телефон. */
@media (orientation: portrait) and (max-width: 600px) {
  .game-stage:not(.home-screen-active) .rotate-device-hint {
    position: fixed;
    z-index: 90;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    padding:
      max(24px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(24px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    background: linear-gradient(180deg, #9eddf4 0 48%, #7fc867 48% 100%);
    color: #263f44;
    text-align: center;
  }

  .rotate-device-icon {
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    border: 4px solid rgba(255, 255, 255, 0.9);
    border-radius: 26px;
    background: rgba(255, 248, 219, 0.92);
    color: #b96520;
    font-size: 58px;
    line-height: 1;
    box-shadow: 0 14px 32px rgba(31, 35, 40, 0.18);
    transform: rotate(-35deg);
  }

  .rotate-device-hint strong {
    margin-top: 8px;
    font-size: clamp(24px, 7vw, 32px);
  }

  .rotate-device-hint small {
    max-width: 280px;
    font-size: 15px;
    font-weight: 800;
  }
}

/* Игровой режим телефона: поле занимает всю доступную высоту. */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1024px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #10171b;
  }

  body {
    display: block;
    min-height: 100dvh;
    padding: 0;
    overscroll-behavior: none;
  }

  .game-shell,
  .game-stage {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    margin: 0;
  }

  .game-shell {
    overflow: hidden;
  }

  .topbar,
  .controls {
    display: none;
  }

  .game-stage {
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #10171b;
    touch-action: none;
  }

  canvas {
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    touch-action: none;
  }

  .save-status {
    position: fixed;
    z-index: 34;
    right: auto;
    bottom: max(44px, calc(env(safe-area-inset-bottom) + 44px));
    left: 50%;
    transform: translateX(-50%);
  }

  .hud {
    position: fixed;
    z-index: 31;
    top: max(5px, env(safe-area-inset-top));
    left: 50%;
    display: flex;
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 3px 6px;
    gap: 5px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.88);
    font-size: 10px;
    box-shadow: 0 5px 16px rgba(31, 35, 40, 0.2);
    transform: translateX(-50%);
  }

  .hud .age-score,
  .hud #statusText,
  .hud .bone-hint {
    display: none;
  }

  .hud .bone-score img {
    width: 20px;
    height: 20px;
  }

  .hud .coin-icon,
  .hud .diamond-icon {
    width: 16px;
    height: 16px;
  }

  .hud .hp-meter,
  .hud .hp-ring {
    width: 26px;
    height: 26px;
    min-width: 26px;
  }

  .side-actions {
    position: fixed;
    z-index: 32;
    top: max(7px, env(safe-area-inset-top));
    left: max(7px, env(safe-area-inset-left));
    gap: 4px;
  }

  .shop-button,
  .inventory-button,
  .settings-button {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }

  .shop-button-icon,
  .inventory-button-icon,
  .settings-button-icon {
    width: 30px;
    height: 30px;
  }

  .quest-alert-button,
  .daily-quest-button {
    position: fixed;
    z-index: 32;
    top: max(7px, env(safe-area-inset-top));
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-width: 2px;
    font-size: 21px;
  }

  .quest-alert-button {
    right: max(7px, env(safe-area-inset-right));
  }

  .daily-quest-button {
    right: max(45px, calc(env(safe-area-inset-right) + 45px));
  }

  .boss-hud {
    position: fixed;
    top: max(48px, calc(env(safe-area-inset-top) + 48px));
    width: min(360px, 52vw);
  }

  .quickbar {
    position: fixed;
    z-index: 31;
    top: auto;
    bottom: max(5px, env(safe-area-inset-bottom));
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-auto-columns: 30px;
    gap: 2px;
    width: auto;
    padding: 3px;
  }

  .quickbar:not(.has-items),
  .quickbar-slot.is-empty {
    display: none;
  }

  .experience-meter {
    display: none;
  }

  .quickbar-slot {
    width: 30px;
    height: 30px;
    min-width: 30px;
  }

  .quickbar-slot img {
    width: 26px;
    height: 26px;
  }

  .touch-controls {
    position: fixed;
    z-index: 30;
    padding:
      5px
      max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .touch-control {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-width: 2px;
    font-size: 23px;
    opacity: 0.72;
  }

  .touch-control.is-pressed {
    opacity: 1;
  }

  .touch-jump-control {
    width: 52px;
    height: 52px;
    min-width: 52px;
  }

  .touch-jump-control small {
    display: none;
  }

  .shop-panel,
  .inventory-panel,
  .settings-panel,
  .quest-panel,
  .daily-quest-panel {
    position: fixed;
    z-index: 80;
    inset:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    width: auto;
    min-height: 0;
    max-height: none;
    padding: 8px;
    border-radius: 12px;
  }

  .shop-header {
    gap: 6px;
  }

  .shop-title h2 {
    font-size: 18px;
  }

  .shop-panel-icon,
  .inventory-panel-icon,
  .settings-panel-icon {
    width: 28px;
    height: 28px;
  }

  .shop-close {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }

  .shop-wallet,
  .shop-tabs,
  .inventory-tabs,
  .shop-content,
  .inventory-content {
    margin-top: 6px;
  }

  .shop-tab,
  .inventory-tab {
    width: auto;
    padding: 5px 8px;
    font-size: 12px;
  }

  .shop-content,
  .inventory-content {
    padding: 6px;
  }

  .shop-item {
    grid-template-rows: 58px auto;
    min-height: 96px;
    padding: 5px;
  }

  .potion-shop-item {
    grid-template-rows: 54px auto auto;
  }

  .shop-item-image {
    min-height: 54px;
  }

  .shop-item-image img {
    max-height: 58px;
  }

  .shop-price {
    min-height: 27px;
    padding: 3px 6px;
  }

  .inventory-item,
  .potion-inventory-item {
    min-height: 82px;
    padding: 5px;
  }
}
