/* pvpTD — Mobile-specific Responsive Styles */

/* Phone portrait */
@media (max-width: 640px) {
  .hud-top-bar {
    padding: 4px 8px;
  }
  .hud-gold {
    font-size: 13px;
    min-width: 70px;
  }
  .hud-center {
    gap: 12px;
    font-size: 13px;
  }
  .hud-timer {
    font-size: 15px;
  }

  .build-bar {
    bottom: 4px;
    padding: 6px 8px;
    gap: 5px;
    max-width: 100vw;
    overflow-x: auto;
    border-radius: 12px;
  }
  .tower-card {
    width: 64px;
    min-width: 64px;
    height: 90px;
    padding: 4px 3px;
  }
  .tower-card .tower-icon {
    width: 28px;
    height: 28px;
  }
  .tower-card .tower-name {
    font-size: 8px;
  }
  .tower-card .tower-cost {
    font-size: 9px;
  }

  .send-bar {
    bottom: 4px;
    padding: 6px 6px;
    gap: 4px;
    max-width: 100vw;
    max-height: 45vh;
  }
  .mob-card {
    width: 58px;
    min-width: 58px;
    height: 82px;
    padding: 4px 2px;
  }
  .mob-card .mob-icon {
    width: 22px;
    height: 22px;
  }
  .mob-card .mob-name {
    font-size: 8px;
  }
  .mob-card .mob-cost {
    font-size: 9px;
  }

  .upgrade-panel {
    left: 50% !important;
    transform: translateX(-50%);
    bottom: 60px !important;
    top: auto !important;
    min-width: 200px;
  }

  .kill-feed {
    display: none;
  }

  .screen-content {
    padding: 20px 16px;
  }
  .screen-title {
    font-size: 24px;
  }

  .role-select {
    flex-direction: column;
    gap: 10px;
  }
  .role-card {
    padding: 12px;
  }
  .role-card .role-name {
    font-size: 15px;
  }

  .results-stats {
    grid-template-columns: 1fr;
  }

  .results-winner {
    font-size: 32px;
  }

  .profile-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quest-tracker {
    display: none;
  }

  /* Daily-quest chips: min-width:150px forced 3 chips wider than the narrow
     menu, clipping the last one. Stack them full-width instead. */
  .lobby-quests {
    grid-template-columns: 1fr;
  }
  .lobby-quest-chip {
    min-width: 0;
  }

  /* Map grid single column on mobile */
  .map-grid {
    grid-template-columns: 1fr;
  }

  /* Achievement grid smaller on mobile */
  .achievement-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Results stats 2 columns on mobile */
  .results-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Hide hotkey badges on mobile */
  .tower-card .hotkey, .mob-card .hotkey { display: none; }

  /* Upgrade tree centered on mobile */
  .upgrade-tree-panel {
    left: 50% !important;
    transform: translateX(-50%);
    bottom: 110px !important;
    top: auto !important;
    max-width: 95vw;
    max-height: 50vh;
    overflow-y: auto;
  }
  .utp-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .utp-card-row {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Chat smaller on mobile */
  .chat-panel {
    width: 200px;
    bottom: 4px;
    left: 4px;
  }
  .chat-messages {
    height: 100px;
  }

  /* Emote panel */
  .emote-panel {
    bottom: 52px;
    right: 4px;
  }
  .emote-wheel {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Side select stacks on phones */
  .side-pick {
    grid-template-columns: 1fr;
  }

  /* Lobby nav wraps */
  .lobby-nav {
    gap: 4px;
  }
  .lobby-nav-btn {
    height: 54px;
    font-size: 9px;
  }
  .lobby-nav-btn .nav-glyph {
    width: 22px;
    height: 22px;
  }

  /* Skin grid */
  .skin-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablet */
@media (min-width: 641px) and (max-width: 1024px) {
  .build-bar {
    max-width: 90vw;
  }
  .send-bar {
    max-width: 90vw;
  }

  .screen-content {
    max-width: 500px;
  }
}

/* Touch device specific */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
    min-width: 44px;
  }

  .tower-card {
    min-height: 80px;
  }

  .mob-card {
    min-height: 72px;
  }

  .utp-upgrade-card,
  .utp-sell-btn {
    min-height: 44px;
  }

  /* Hide hotkey badges on touch */
  .tower-card .hotkey, .mob-card .hotkey { display: none; }

  .utp-close {
    min-width: 44px;
    min-height: 44px;
  }

  /* Prevent double-tap zoom */
  * {
    touch-action: manipulation;
  }
}

/* Short viewports (e.g. 768px height) — compress lobby to fit */
@media (max-height: 768px) {
  .screen-content {
    padding: 16px 20px;
  }
  .screen-title {
    font-size: 24px;
    margin-bottom: 4px;
  }
  .screen-subtitle {
    margin-bottom: 10px;
    font-size: 12px;
  }
  .role-select {
    margin: 8px 0;
  }
  .role-card {
    padding: 10px 12px;
  }
  .role-card .role-name {
    font-size: 16px;
    margin-bottom: 2px;
  }
  .role-card .role-desc {
    font-size: 10px;
  }
  .role-card .role-icon svg {
    width: 32px;
    height: 32px;
  }
  .role-card .role-icon {
    margin-bottom: 4px;
  }
  .role-ready-indicator {
    margin: 4px auto 0;
  }
  .ready-status {
    margin-top: 6px;
  }
  .ready-dot {
    font-size: 12px;
  }
  .lobby-ready-btn {
    margin-top: 10px;
    padding: 8px 32px;
    font-size: 15px;
  }
  .lobby-nav {
    margin-top: 12px;
    padding-top: 10px;
  }
  .lobby-nav-btn {
    height: 58px;
    font-size: 9px;
  }
  .lobby-nav-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* Landscape on phones */
@media (max-height: 480px) and (orientation: landscape) {
  .hud-top-bar {
    padding: 2px 8px;
  }
  .hud-gold {
    font-size: 12px;
  }
  .hud-center {
    font-size: 12px;
    gap: 10px;
  }

  .build-bar, .send-bar {
    bottom: 2px;
    padding: 4px 6px;
    max-width: 100vw;
  }
  .send-bar {
    max-height: 40vh;
  }
  .tower-card {
    width: 52px;
    min-width: 52px;
    height: 72px;
    padding: 3px 2px;
  }
  .tower-card .tower-name,
  .tower-card .tower-cost {
    font-size: 8px;
  }
  .tower-card .tower-icon {
    width: 22px;
    height: 22px;
  }
  .mob-card {
    width: 48px;
    min-width: 48px;
    height: 68px;
  }

  /* Hide hotkey badges in landscape */
  .tower-card .hotkey, .mob-card .hotkey { display: none; }

  .upgrade-tree-panel {
    bottom: 76px !important;
    max-height: 45vh;
    overflow-y: auto;
  }
}

/* --- Safe-area compliance (M4.1 — Discord Activities / notched phones) --- */
.hud-top {
  padding-top: max(8px, env(safe-area-inset-top));
}
.build-bar, .send-bar {
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.ability-bar {
  left: max(12px, env(safe-area-inset-left));
}
.chat-panel {
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- Rotate-to-landscape prompt (job 030) ----------------------------------
   Hidden by default. Only a phone-width portrait viewport DURING A MATCH gets
   it (body.in-match, set by UIManager.hideAllScreens); menus stay usable in
   portrait, and it auto-clears the instant the device turns landscape. The
   game's fixed 4:3 field can't be reflowed to portrait without a full render
   refactor (backlog job 033) — so we ask for a rotate, matching the landscape
   manifest, rather than ship a stretched, HUD-collided board. */
#rotate-prompt { display: none; }
@media (orientation: portrait) and (max-width: 640px) {
  body.in-match #rotate-prompt {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 100000;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #1a1330 0%, #0b0816 78%);
    pointer-events: auto;
    padding: 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}
.rotate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.rotate-phone {
  width: 52px;
  height: 92px;
  border-radius: 12px;
  border: 3px solid var(--color-secondary, #f0c040);
  box-shadow: 0 0 22px rgba(240, 192, 64, 0.35), inset 0 0 0 3px rgba(240, 192, 64, 0.12);
  transform-origin: center;
  animation: rotate-hint 2.4s ease-in-out infinite;
}
.rotate-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--color-secondary, #f0c040);
}
.rotate-sub {
  font-size: 13px;
  color: var(--color-text-dim, #9a90b0);
}
@keyframes rotate-hint {
  0%, 22% { transform: rotate(0deg); }
  48%, 82% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rotate-phone { animation: none; }
}
