/* Public-playtest iPhone viewport, touch, and rendering hotfix. */
:root {
  --visual-viewport-height: 100svh;
  --visual-viewport-width: 100vw;
  --visual-viewport-offset-top: 0px;
  --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);
}

@supports (height: 100dvh) {
  :root { --visual-viewport-height: 100dvh; }
}

button,
input,
.telemetry-actions a {
  touch-action: manipulation;
}

button,
.telemetry-actions a {
  -webkit-tap-highlight-color: rgba(120, 210, 200, 0.18);
}

.info-modal-layer,
.telemetry-layer,
.central-consent-layer {
  pointer-events: none;
}

.info-modal-layer.is-open,
.telemetry-layer.is-open,
.central-consent-layer.is-open {
  pointer-events: auto;
}

[hidden] {
  display: none !important;
  pointer-events: none !important;
}

/* Utility controls remain full-size touch targets at every breakpoint. */
.desktop-tools button {
  min-height: 44px;
}

@media (max-width: 899px) {
  html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    position: fixed;
    top: var(--visual-viewport-offset-top);
    left: 0;
    width: 100%;
    height: var(--visual-viewport-height);
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    position: relative;
    width: min(100%, 680px);
    height: min(var(--visual-viewport-height), 940px);
    min-height: 0;
    padding:
      max(6px, var(--safe-top))
      max(6px, var(--safe-right))
      max(6px, var(--safe-bottom))
      max(6px, var(--safe-left));
  }

  .game-shell {
    min-width: 0;
    min-height: 0;
    --mobile-toolbar-top: 108px;
    --mobile-toolbar-height: 48px;
    --mobile-stage-top: 160px;
  }

  .desktop-control-panel {
    display: contents;
  }

  .desktop-tools {
    position: absolute;
    z-index: 18;
    top: var(--mobile-toolbar-top);
    right: 12px;
    left: 12px;
    height: var(--mobile-toolbar-height);
    display: grid;
    grid-template-columns: 126px 96px 126px;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 2px 4px;
    border: 1px solid rgba(205, 162, 83, 0.42);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(21, 48, 53, 0.97), rgba(7, 23, 28, 0.98));
    box-shadow: inset 0 0 0 2px rgba(4, 15, 18, 0.34);
  }

  .desktop-tools::before {
    display: none;
  }

  .sound-button,
  .info-button,
  .telemetry-button {
    position: static;
    inset: auto;
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 44px;
    transform: none;
  }

  .info-button:active:not(:disabled) {
    transform: translateY(1px);
  }

  .telemetry-button { grid-column: 1; grid-row: 1; }
  .info-button { grid-column: 2; grid-row: 1; }
  .sound-button { grid-column: 3; grid-row: 1; }

  .stage {
    top: var(--mobile-stage-top);
  }

  .main-button,
  .collect-button,
  .quick-bet,
  .bet-input,
  .sound-button,
  .info-button,
  .telemetry-button,
  .info-modal-close,
  .telemetry-close,
  .telemetry-actions a,
  .telemetry-actions button,
  .central-consent-actions button,
  .central-status-panel button {
    min-height: 44px;
  }

  .quick-bet,
  .sound-button,
  .info-modal-close,
  .telemetry-close {
    min-width: 44px;
  }

  .grain {
    display: none;
  }

  .scanlines {
    opacity: 0.045;
  }

  .altimeter,
  .info-modal-layer,
  .telemetry-layer,
  .central-consent-layer {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .info-modal-layer,
  .telemetry-layer,
  .central-consent-layer {
    top: var(--visual-viewport-offset-top);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: var(--visual-viewport-height);
    padding:
      max(6px, var(--safe-top))
      max(6px, var(--safe-right))
      max(6px, var(--safe-bottom))
      max(6px, var(--safe-left));
  }

  .info-modal,
  .telemetry-dashboard,
  .central-consent-dialog {
    max-height: 100%;
  }

  .info-modal-close,
  .telemetry-close {
    width: 44px;
    height: 44px;
  }

  .telemetry-actions a,
  .telemetry-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 599px) {
  .scanlines {
    display: none;
  }

  .game-shell {
    --mobile-toolbar-top: 70px;
    --mobile-toolbar-height: 48px;
    --mobile-stage-top: 122px;
    border-radius: 22px;
    box-shadow:
      0 0 0 4px #111a1d,
      0 0 0 6px #71542d,
      0 12px 32px rgba(0, 0, 0, 0.52);
  }

  .topbar {
    height: 68px;
    grid-template-columns: 1.28fr 0.72fr 0.92fr;
    gap: 5px;
    padding: 8px 10px;
  }

  .brand h1 {
    font-size: clamp(22px, 7vw, 29px);
  }

  .top-stat strong {
    font-size: clamp(20px, 6.5vw, 27px);
  }

  .stage {
    inset: var(--mobile-stage-top) 8px 236px;
    border-radius: 18px;
    box-shadow:
      inset 0 0 0 3px rgba(5, 14, 18, 0.6),
      inset 0 0 22px rgba(0, 0, 0, 0.36);
  }

  .desktop-tools {
    top: var(--mobile-toolbar-top);
    right: 8px;
    left: 8px;
    height: var(--mobile-toolbar-height);
    grid-template-columns: 112px 64px 44px;
  }

  .sound-button {
    width: 44px;
    min-width: 44px;
  }

  .sound-text {
    display: none;
  }

  .info-button {
    width: 64px;
    min-width: 64px;
  }

  .telemetry-button {
    width: 112px;
    min-width: 112px;
  }

  .control-deck {
    left: 8px;
    right: 8px;
    bottom: 8px;
    height: 220px;
    grid-template-columns: minmax(86px, 0.72fr) minmax(0, 1.48fr);
    grid-template-rows: 94px 52px minmax(34px, 1fr);
    gap: 6px;
    padding: 8px;
    border-radius: 17px;
    box-shadow:
      inset 0 0 0 3px rgba(4, 15, 18, 0.5),
      0 7px 20px rgba(0, 0, 0, 0.4);
  }

  .balance-readout {
    padding: 7px;
  }

  .balance-readout strong {
    font-size: clamp(18px, 5.8vw, 23px);
  }

  .bet-console {
    grid-template-columns: minmax(0, 1fr) minmax(62px, 0.54fr);
    grid-template-rows: 20px 44px;
    gap: 5px 6px;
    padding: 8px;
  }

  .quick-bets {
    grid-template-columns: repeat(4, 44px);
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .quick-bets::-webkit-scrollbar {
    display: none;
  }

  .quick-bet {
    width: 44px;
    height: 44px;
  }

  .bet-input {
    height: 44px;
    padding-inline: 7px;
    font-size: 16px;
  }

  .main-button,
  .collect-button {
    height: 52px;
    border-radius: 10px;
  }

  .history {
    min-height: 34px;
    padding: 5px 8px;
  }

  .max-win-panel {
    bottom: 9px;
  }

  .info-modal-header,
  .telemetry-header {
    padding-top: max(10px, var(--safe-top));
  }

  .central-consent-dialog {
    padding: 16px;
  }

  .central-consent-dialog h2 {
    font-size: clamp(21px, 7vw, 29px);
  }

  .central-consent-dialog p,
  .central-consent-dialog li {
    line-height: 1.45;
  }
}

/* Phone landscape: canvas on the left, compact reachable controls on the right. */
@media (max-height: 500px) and (max-width: 950px) {
  .scanlines {
    display: none;
  }

  body {
    padding: 0;
  }

  .app {
    width: 100%;
    max-width: none;
    height: var(--visual-viewport-height);
    min-height: 0;
    padding:
      max(5px, var(--safe-top))
      max(5px, var(--safe-right))
      max(5px, var(--safe-bottom))
      max(5px, var(--safe-left));
  }

  .game-shell {
    display: block;
    min-height: 0;
    padding: 0;
    border-radius: 18px;
  }

  .topbar {
    position: absolute;
    inset: 0 45% auto 0;
    height: 58px;
    padding: 6px 10px;
  }

  .brand h1 { font-size: 25px; }
  .top-stat strong { font-size: 23px; }

  .stage {
    position: absolute;
    inset: 58px 45% 8px 8px;
    width: auto;
    height: auto;
    min-height: 0;
    border-radius: 16px;
  }

  .desktop-control-panel {
    display: contents;
  }

  .desktop-tools {
    position: absolute;
    z-index: 18;
    top: 8px;
    right: 8px;
    left: auto;
    width: calc(45% - 16px);
    height: 44px;
    display: grid;
    grid-template-columns: 44px 64px minmax(112px, 1fr);
    gap: 6px;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
  }

  .desktop-tools::before {
    display: none;
  }

  .sound-button,
  .info-button,
  .telemetry-button {
    position: static;
    inset: auto;
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 44px;
    padding-inline: 6px;
    transform: none;
  }

  .sound-button { grid-column: 1; }
  .info-button { grid-column: 2; }
  .telemetry-button { grid-column: 3; }

  .sound-text { display: none; }
  .info-button:active:not(:disabled) { transform: translateY(1px); }

  .control-deck {
    position: absolute;
    top: 58px;
    right: 8px;
    bottom: 8px;
    left: auto;
    width: calc(45% - 16px);
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(84px, 0.7fr) minmax(0, 1.45fr);
    grid-template-rows: 94px 52px minmax(34px, 1fr);
    gap: 6px;
    padding: 8px;
    border-radius: 16px;
  }

  .bet-console {
    grid-template-columns: minmax(0, 1fr) minmax(62px, 0.55fr);
    grid-template-rows: 20px 44px;
    gap: 5px 6px;
    padding: 8px;
  }

  .quick-bets {
    grid-template-columns: repeat(4, 44px);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .quick-bet,
  .bet-input {
    height: 44px;
  }

  .quick-bet { width: 44px; }

  .main-button,
  .collect-button {
    height: 52px;
    border-radius: 10px;
  }

  .history {
    min-height: 34px;
    padding-block: 5px;
  }

  .desktop-guide {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
}
