/* Compact race instruments keep one header row in either phone orientation. */
@media (pointer: coarse), (max-width: 760px), (orientation: landscape) and (max-height: 560px) {
  #hud.hud .hud-top {
    display: grid; grid-template-columns: max-content max-content minmax(0, 1fr) max-content;
    grid-template-areas: 'position lap time actions'; grid-template-rows: 44px;
    align-items: stretch; gap: 4px; height: 44px;
    top: calc(4px + var(--safe-top)); left: calc(6px + var(--safe-left)); right: calc(6px + var(--safe-right));
  }
  #hud.hud .hud-top > * { grid-row: 1; height: 44px; min-height: 0; min-width: 0; margin: 0; border-image-width: 7px; }
  #hud.hud .race-place { grid-area: position; padding: 3px 6px 3px 3px; gap: 5px; border-width: 2px; }
  #hud.hud .driver-portrait { width: 26px; height: 26px; flex: 0 0 26px; border-width: 2px; }
  #hud.hud .position-copy { gap: 3px; align-items: baseline; }
  #hud.hud .position-copy > span { font-size: 23px; }
  #hud.hud .position-copy small { font-size: 10px; padding: 0; white-space: nowrap; }
  #hud.hud .position-copy b { display: none; }
  #hud.hud .hud-lap { grid-area: lap; padding: 3px 6px; gap: 2px; justify-content: center; }
  #hud.hud .hud-lap > span { font-size: 8px; line-height: 10px; letter-spacing: .3px; }
  #hud.hud .hud-lap strong { display: flex; align-items: baseline; gap: 1px; white-space: nowrap; font-size: 18px; }
  #hud.hud .hud-lap strong > small { font-size: 10px; }
  #hud.hud .hud-timing { grid-area: time; padding: 3px 8px; gap: 12px; flex-direction: row; justify-content: space-around; align-items: center; }
  #hud.hud .hud-timing > div { flex-direction: column; align-items: flex-start; gap: 3px; }
  #hud.hud .hud-timing span { font-size: 8px; line-height: 9px; letter-spacing: .2px; white-space: nowrap; }
  #hud.hud .hud-timing strong { font-size: 13px; line-height: 14px; white-space: nowrap; }
  #hud.hud .hud-top-right { grid-area: actions; gap: 3px; padding: 0 3px; border-width: 0; }
  #hud.hud .hud-top-right > span { display: none; }
  #hud.hud .hud-top-right .icon-button { flex: 0 0 44px; width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  #hud.hud .hud-top-right .icon { width: 20px; height: 20px; }
  #hud.hud .hud-gold { gap: 3px; max-width: 67px; font-size: 12px; }
  #hud.hud .hud-gold .gold-icon { width: 19px; height: 19px; flex: 0 0 19px; }
  #hud.hud .hud-gold strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  #hud.hud .minimap-panel { top: calc(56px + var(--safe-top)); }
  #hud.hud .minimap-heading { height: 20px; padding: 2px 4px; gap: 3px; font-size: 9px; }
  #hud.hud #minimap-zone { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #hud.hud #minimap-clock { flex: none; font-size: 9px; }
  #hud.hud .active-effects { top: calc(56px + var(--safe-top)); }
  #hud.hud .active-effect {
    width: 36px; min-width: 36px; height: 44px; padding: 2px; gap: 2px;
    grid-template-columns: 1fr; grid-template-rows: 22px 10px; justify-items: center;
  }
  #hud.hud .active-effect img, #hud.hud .active-effect > .icon { width: 22px; height: 22px; grid-column: 1; grid-row: 1; }
  #hud.hud .active-effect strong { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #hud.hud .active-effect .effect-time { grid-column: 1; grid-row: 2; font-size: 10px; line-height: 10px; }
  #hud.hud .race-center {
    left: 50%; right: auto; transform: translateX(-50%); width: max-content;
    max-width: min(270px, calc(100vw - 32px)); display: block; pointer-events: none;
  }
  #hud.hud .race-notice, #hud.hud .wrong-way {
    margin: 0; padding: 5px 9px; min-width: 0; font-size: 11px; line-height: 1.25;
    border-width: 2px; border-image-width: 7px; white-space: normal; text-wrap: balance;
  }
  #hud.hud .wrong-way small { margin-top: 2px; font-size: 8px; line-height: 10px; }
  #hud.hud .countdown { font-size: 64px; }
  #hud.hud .countdown.go { font-size: 52px; }
  #hud.hud .countdown.waiting { font-size: 25px; }
}

@media (max-width: 600px) {
  /* The current lap/distance is already beside the timer. Secondary best-lap /
     remaining-distance detail yields its space to one readable header row. */
  #hud.hud .hud-timing > div:last-child { display: none; }
  #hud.hud .hud-timing { justify-content: center; padding-inline: 5px; }
  #hud.hud .hud-timing strong { font-size: 11px; }
  #hud.hud .hud-gold { max-width: 54px; font-size: 11px; }
  #hud.hud .hud-gold .gold-icon { width: 17px; height: 17px; flex-basis: 17px; }
}

@media (max-width: 760px) and (orientation: portrait) {
  #hud.hud .minimap-panel { width: 112px; }
  #hud.hud .active-effects, #hud.hud .active-effects:has(.active-effect:nth-child(7)) {
    display: grid; grid-template-columns: repeat(4, 36px); gap: 4px;
    left: calc(10px + var(--safe-left)); right: auto; max-width: 156px;
  }
  #hud.hud .race-center, #hud.hud:has(.active-effects .active-effect:nth-child(9)) .race-center { top: calc(204px + var(--safe-top)); }
  #hud.hud .fps-counter { top: auto; bottom: calc(116px + var(--safe-bottom)); }
}

@media (orientation: landscape) and (max-height: 560px) {
  #hud.hud .active-effects, #hud.hud .active-effects:has(.active-effect:nth-child(7)) {
    left: calc(124px + var(--safe-left)); right: calc(164px + var(--safe-right));
    display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: none;
  }
  #hud.hud .race-center { top: calc(108px + var(--safe-top)); max-width: min(260px, calc(100vw - 290px)); }
}

@media (orientation: landscape) and (max-height: 560px) and (max-width: 770px) {
  #hud.hud:has(.active-effects .active-effect:nth-child(11)) .race-center { top: calc(156px + var(--safe-top)); }
}
