/* Shared phone / tablet layout for v3719 game hub + games */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --touch-min: 44px;
}

html.is-touch,
html.is-touch body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

html.is-touch body.game-page,
html.is-touch #game-root {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-touch #game-canvas {
  touch-action: none;
}

/* Hub — also apply on narrow screens without touch class */
@media (max-width: 640px) {
  .shell {
    justify-content: flex-start;
    padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1.25rem, var(--safe-bottom)) max(1rem, var(--safe-left));
  }
  .paywall {
    padding: max(1rem, var(--safe-top)) max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left));
  }
  .pay-row, .code-row, .invite-box { flex-direction: column; }
  .controls { grid-template-columns: 1fr !important; }
  .game-meta { flex-wrap: wrap; }
}

/* Hub */
html.is-touch .shell {
  justify-content: flex-start;
  padding:
    max(1rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(1.25rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
}

html.is-touch .paywall {
  padding:
    max(1rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(1rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
  -webkit-overflow-scrolling: touch;
}

html.is-touch .pay-row,
html.is-touch .code-row,
html.is-touch .invite-box {
  flex-direction: column;
}

html.is-touch .cta,
html.is-touch .game-link,
html.is-touch .featured-play,
html.is-touch .lock-btn,
html.is-touch button {
  min-height: var(--touch-min);
}

html.is-touch .game-meta {
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}

html.is-touch .controls {
  grid-template-columns: 1fr !important;
}

/* Touch control overlay */
#ash-mobile-controls {
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  display: none;
}

html.is-touch #ash-mobile-controls {
  display: block;
}

#ash-mobile-controls .ash-zone {
  position: absolute;
  pointer-events: auto;
}

#ash-joy-base {
  left: max(0.85rem, var(--safe-left));
  bottom: max(0.85rem, var(--safe-bottom));
  width: 7.5rem;
  height: 7.5rem;
  border-radius: 50%;
  background: rgba(12, 16, 14, 0.42);
  border: 2px solid rgba(255, 255, 255, 0.14);
}

#ash-joy-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.75rem;
  height: 2.75rem;
  margin: -1.375rem 0 0 -1.375rem;
  border-radius: 50%;
  background: rgba(232, 163, 23, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

#ash-look-pad {
  right: 0;
  top: 0;
  width: 46%;
  height: 100%;
  background: transparent;
}

#ash-actions {
  right: max(0.85rem, var(--safe-right));
  bottom: max(0.85rem, var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
  max-width: 42%;
}

.ash-btn {
  pointer-events: auto;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(12, 16, 14, 0.72);
  color: #e8efe4;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  user-select: none;
  touch-action: none;
}

.ash-btn.primary {
  background: rgba(232, 163, 23, 0.88);
  color: #1a1205;
  border-color: rgba(255, 184, 46, 0.65);
  min-width: 3.6rem;
  min-height: 3.6rem;
  border-radius: 50%;
  font-size: 0.68rem;
}

.ash-btn.pressed {
  transform: scale(0.94);
  filter: brightness(1.08);
}

/* HUD compaction on phones */
@media (max-width: 640px) {
  html.is-touch #hint-bar,
  html.is-touch .hint,
  html.is-touch #reload-hint {
    display: none !important;
  }

  html.is-touch .hud-top {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem !important;
  }

  html.is-touch .hud-bottom {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.35rem;
    padding: 0.65rem 0.75rem !important;
  }

  html.is-touch .hud-dir {
    top: max(0.5rem, var(--safe-top)) !important;
    font-size: 0.62rem !important;
    padding: 0.35rem 0.55rem !important;
  }

  html.is-touch #speed-val {
    font-size: 2.6rem !important;
  }

  html.is-touch #speed-cluster {
    bottom: max(5.5rem, calc(var(--safe-bottom) + 4.5rem)) !important;
    right: max(0.75rem, var(--safe-right)) !important;
  }

  html.is-touch #minimap {
    width: 5.5rem !important;
    height: 5.5rem !important;
    bottom: max(5.5rem, calc(var(--safe-bottom) + 4.5rem)) !important;
    left: max(0.75rem, var(--safe-left)) !important;
  }

  html.is-touch #nitro-bar {
    bottom: max(4.8rem, calc(var(--safe-bottom) + 3.8rem)) !important;
    width: 10rem !important;
  }

  html.is-touch #race-info,
  html.is-touch #hype-cluster {
    transform: scale(0.88);
    transform-origin: top left;
  }

  html.is-touch #position-badge {
    font-size: 2rem !important;
    top: max(0.65rem, var(--safe-top)) !important;
    right: max(0.65rem, var(--safe-right)) !important;
  }

  html.is-touch .kill-feed {
    display: none !important;
  }

  html.is-touch .overlay .menu-content {
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1rem;
  }

  html.is-touch .car-pick,
  html.is-touch .house-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  html.is-touch .panel input,
  html.is-touch .pay-field input {
    font-size: 16px !important;
  }
}

@media (max-width: 380px) {
  html.is-touch .car-pick,
  html.is-touch .house-grid {
    grid-template-columns: 1fr !important;
  }

  html.is-touch #ash-joy-base {
    width: 6.5rem;
    height: 6.5rem;
  }
}
