/* Top bar (#hud): the fold button (js/hud.js) and the one-line bar of low screens - a phone on its side,
   a TV showing a Mac or an iPhone through AirPlay. Loaded last: these rules win over the modules' own. */

/* the fold button: top right corner of the bar; the district line steps aside for it */
#hud #hudTog { position: absolute; top: 6px; right: 6px; width: 24px; height: 22px; padding: 0; display: grid; place-items: center; }
#hudTog svg { display: block; image-rendering: pixelated; }
#hud .lbl-where { right: 38px; }
/* walking / driving fold the bar to one row (narrow or touch screens): the button keeps a place at its end */
@media (max-width: 600px), (pointer: coarse) {
  body.walking #hud, body.driving #hud { padding-right: 38px; }
  body.walking #hud #hudTog, body.driving #hud #hudTog { top: 50%; margin-top: -11px; }
}
/* phone: the open search field takes the whole title line */
@media (max-width: 600px) { #hud.finding #hudTog { display: none; } }

/* folded: only the button stays, small and quiet in the corner (full strength on hover / focus) */
#hud.hud-off { padding: 0 !important; right: auto !important; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); opacity: .72; }
#hud.hud-off > :not(#hudTog) { display: none !important; }
#hud.hud-off #hudTog { position: static; display: grid; margin: 0; width: 32px; height: 28px; border: 0; background: var(--paper); }
#hud.hud-off:hover, #hud.hud-off:focus-within { opacity: 1; }

/* low screens: one line - title, district, magnifier, controls, mode buttons as icons, fold button */
@media (min-width: 601px) and (max-height: 600px), (min-aspect-ratio: 3/2) and (max-height: 600px) {
  #hud { top: 6px; left: max(6px, env(safe-area-inset-left, 0px)); right: auto; display: flex; align-items: center; gap: 6px;
    padding: 3px 5px; border-width: 2px; box-shadow: 3px 3px 0 var(--ink);
    max-width: calc(100vw - 12px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)); }
  #hud .title { flex: 0 0 auto; font-size: 14px; letter-spacing: .5px; white-space: nowrap; }
  #hud .lbl-where { position: static; order: 1; flex: 0 1 auto; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
  #hud .lbl-where::before { margin-left: 2px; }
  #pkFind { order: 2; margin-left: 0; flex: 0 0 auto; }
  #hud .row { order: 3; flex: 1 1 auto; min-width: 0; margin-top: 0; flex-wrap: nowrap; gap: 4px; }
  #hud #hudTog { order: 4; position: static; flex: 0 0 auto; margin: 0; }
  #hud button { height: 26px; }
  #hud .row > button:not(.tour-btn) { width: 28px; font-size: 14px; }
  #hud .row > .tour-btn { padding: 0 5px; margin-left: 0; }
  #hud .row > #time { flex: 1 1 80px; min-width: 56px; width: auto; }
  #clock { min-width: 40px; font-size: 12px; }
  /* the mode buttons keep their icon, the word goes to the tooltip (walking / driving keep the words) */
  body:not(.walking):not(.driving) #hud .row > .tour-btn > span:not(.mp-n) { display: none; }
  body:not(.walking):not(.driving) #hud .row > .tour-btn { gap: 0; }
  /* walking / driving: the bar folds to their own buttons, as on a phone */
  body.walking #hud .title, body.walking #hud .lbl-where, body.walking #pkFind,
  body.walking #hud .row > :not(#walkBtn):not(#okBtn):not(#povBtn):not(#godBtn):not(#mpBtn),
  body.driving #hud .title, body.driving #hud .lbl-where, body.driving #pkFind,
  body.driving #hud .row > :not(#driveBtn):not(#driveCamBtn):not(#driveOutBtn) { display: none; }
  body.walking #hud, body.driving #hud { padding: 3px 5px; }
  body.walking #hud #hudTog, body.driving #hud #hudTog { margin-top: 0; }
  /* search: the magnifier is a button; a tap swaps the title and the district for the field */
  #hud:not(.finding) #pkFind input, #hud:not(.finding) #pkFindClear { display: none; }
  #hud:not(.finding) #pkFindOpen { position: static; width: 28px; height: 24px; border: 2px solid var(--ink); background: #fff;
    pointer-events: auto; cursor: pointer; }
  #hud.finding .title, #hud.finding .lbl-where { display: none; }
  #hud.finding #pkFind input { width: 240px; height: 26px; font-size: 16px; }
  #hud.finding #pkFindOpen { top: 0; }
  #hud.finding #pkFindClear { top: 2px; }
  #pkFindList { max-height: calc(100vh - var(--pk-hud-b, 48px) - 16px); }
  /* the Odkryj panel starts under the bar, not at a fixed 128 px */
  .ok-panel { top: calc(var(--pk-hud-b, 48px) + 8px); max-height: calc(100vh - var(--pk-hud-b, 48px) - 24px); }
}
/* low and narrow (a small phone on its side, 640-760 px): no district, tighter buttons; what still does not
   fit scrolls sideways inside the row instead of sliding under the fold button */
@media (min-width: 601px) and (max-width: 760px) and (max-height: 600px), (min-aspect-ratio: 3/2) and (max-width: 760px) and (max-height: 600px) {
  #hud { gap: 4px; }
  #hud .lbl-where { display: none; }
  #hud .title { font-size: 13px; letter-spacing: 0; }
  #hud .row { gap: 3px; overflow-x: auto; scrollbar-width: none; }
  #hud .row::-webkit-scrollbar { display: none; }
  #hud .row > button:not(.tour-btn) { width: 26px; }
  #hud .row > .tour-btn { padding: 0 3px; }
  #hud .row > #time { min-width: 44px; }
}
/* the tour / retro card on the right: under the bar wherever the bar reaches that far (the one-line bar of a
   low screen spans the width; the full bar is ~960 px wide, so below ~1380 px it meets the card) */
@media (min-width: 601px) and (max-width: 1380px), (min-width: 601px) and (max-height: 600px) {
  .tour-card { top: calc(var(--pk-hud-b, 96px) + 8px); height: min(560px, calc(100vh - var(--pk-hud-b, 96px) - 24px)); }
}
