/* Phone HUD: preserve readable information while opening the road ahead. */
.compact-label,
.action-icon,
.destination #distance-compact {
  display: none;
}

@media (max-width: 600px), (max-width: 1000px) and (max-height: 600px) {
  #game {
    min-height: 0;
  }

  .game-active .wordmark {
    display: none;
  }

  .game-active .topbar {
    top: max(8px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    justify-content: flex-end;
  }

  .top-actions {
    gap: 4px;
  }

  .top-actions button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 10px;
    font-size: 18px;
    background: rgba(20, 39, 51, .78);
  }

  .action-label {
    display: none;
  }

  .action-icon {
    display: block;
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  #sound[aria-pressed="false"] .sound-waves,
  #sound[aria-pressed="true"] .sound-muted {
    display: none;
  }

  .stats {
    top: max(8px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
    transform: none;
    width: calc(100% - 180px);
    max-width: 246px;
    padding: 6px 0;
    border-radius: 8px;
    box-shadow: 0 3px 12px #10202c22;
  }

  .stat {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 0 7px;
    gap: 2px;
  }

  .stat > span {
    margin: 0;
    font-size: .75rem;
    letter-spacing: .025em;
    line-height: 1;
    white-space: nowrap;
  }

  .stat .full-label {
    display: none;
  }

  .stat .compact-label {
    display: inline;
  }

  .stat strong {
    font-size: 1.125rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  .stat small {
    font-size: .875rem;
  }

  .destination {
    top: calc(max(8px, env(safe-area-inset-top)) + 54px);
    left: max(14px, env(safe-area-inset-left));
    width: fit-content;
    max-width: min(230px, calc(100% - 112px));
    min-height: 42px;
    padding: 6px 10px 6px 7px;
    gap: 8px;
    border-left-width: 2px;
    border-radius: 4px 7px 7px 4px;
    pointer-events: none;
  }

  .destination-icon {
    width: 22px;
    flex: 0 0 22px;
    font-size: 25px;
  }

  .destination > div {
    min-width: 0;
  }

  .destination #objective-label,
  .destination #distance {
    display: none;
  }

  .destination strong {
    margin: 0;
    font-size: .875rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .destination #distance-compact {
    display: block;
    margin-top: 2px;
    color: var(--yellow);
    font-size: .75rem;
    font-weight: 500;
    line-height: 1.15;
    letter-spacing: 0;
  }

  .speedometer {
    top: auto;
    right: auto;
    bottom: max(26px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    display: flex;
    align-items: baseline;
    gap: 4px;
    pointer-events: none;
  }

  .speedometer strong {
    font-size: 1.5rem;
    line-height: 1;
  }

  .speedometer > span {
    margin: 0;
    font-size: .75rem;
    letter-spacing: 0;
  }

  .speed-track {
    display: none;
  }

  .rescue {
    left: max(14px, env(safe-area-inset-left));
    right: auto;
    bottom: calc(max(25px, env(safe-area-inset-bottom)) + 75px);
    min-height: 44px;
    padding: 8px 10px;
    font-size: .75rem;
  }

  .toast {
    top: 44%;
    max-width: min(340px, 75%);
    padding: 9px 14px;
    font-size: .875rem;
  }
}

@media (min-width: 600px) and (max-width: 1000px) and (max-height: 600px) {
  .stats {
    width: auto;
    max-width: calc(100% - 226px);
    min-height: 34px;
    padding: 6px 2px;
  }

  .stat {
    flex: 0 1 auto;
    flex-direction: row;
    padding: 0 9px;
    gap: 6px;
  }

  .destination {
    top: calc(max(8px, env(safe-area-inset-top)) + 42px);
    max-width: 230px;
  }

  .minimap {
    top: calc(max(8px, env(safe-area-inset-top)) + 50px);
    right: max(14px, env(safe-area-inset-right));
    bottom: auto;
    width: 74px;
    padding: 4px;
    border-radius: 8px;
    pointer-events: none;
  }

  .minimap canvas {
    width: 64px;
    height: 64px;
  }

  .speedometer {
    bottom: max(22px, env(safe-area-inset-bottom));
  }

  .rescue {
    bottom: calc(max(20px, env(safe-area-inset-bottom)) + 70px);
  }
}

/* Keep the exit control reachable on pause/results screens as well. */
.topbar {
  z-index: 20;
}

.toast {
  z-index: 30;
}

.top-actions #fullscreen {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  flex-shrink: 0;
}

.fullscreen-icon {
  display: block;
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fullscreen[aria-pressed="false"] .fullscreen-collapse,
#fullscreen[aria-pressed="true"] .fullscreen-expand {
  display: none;
}

#fullscreen[aria-pressed="true"] {
  color: var(--yellow);
  border-color: var(--yellow);
}

#game:fullscreen {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--ink);
}

#game:-webkit-full-screen {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--ink);
}

#game::backdrop {
  background: var(--ink);
}

/* Leave the existing three-button/counter row intact on narrow phones. */
@media (max-width: 599px) {
  .top-actions #fullscreen {
    position: absolute;
    top: 54px;
    right: 0;
  }
}

/* With browser chrome expanded, very short windows need the road most. */
@media (min-width: 600px) and (max-width: 1000px) and (max-height: 275px) {
  .minimap {
    display: none;
  }
}

/* Large touch tablets can report a desktop-sized viewport while still showing
   the driving controls. Keep recovery on the quiet left side, above steering,
   and leave the minimap / slide / pedals as one clean stack on the right. */
@media (pointer: coarse) and (orientation: landscape) {
  .rescue {
    right: auto;
    left: max(18px, env(safe-area-inset-left));
    bottom: calc(max(25px, env(safe-area-inset-bottom)) + 78px);
    z-index: 4;
    width: 135px;
    min-height: 32px;
    padding: 7px 10px;
    font-size: .75rem;
    white-space: nowrap;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-width: 760px) {
  .rescue {
    left: max(12px, env(safe-area-inset-left));
    width: 115px;
  }
}
