/* Phone layouts for the floor and Preview city views. Keep Real city HUD ownership
   with the city-layer workstream; the landscape exception covers 844×390. */
@media (max-width: 820px) {
  .topbar {
    left: 8px;
    right: 8px;
    top: 8px;
    min-height: 52px;
    height: auto;
    flex-wrap: wrap;
    gap: 5px 8px;
    padding: 6px 8px;
  }

  .brand small { display: none; }
  .top-mid { order: 3; width: 100%; min-height: 22px; overflow: hidden; }
  .chip.paper { font-size: 0; padding: 5px 9px; }
  .chip.paper::after { content: "Paper"; font-size: 11px; }
  .clock { margin-left: auto; gap: 5px; }
  .clock b { font-size: 14px; min-width: 42px; }
  .mode-switch button { padding: 5px 7px; }
  .speed button { padding: 5px 6px; }
  .topbar button, .topbar select { min-height: 40px; }

  /* Keep the showcase roster readable while leaving the scene clear. */
  #labels .tag:nth-child(n+5) { display: none; }
  .dock {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(32vh, 250px);
    overflow: hidden;
  }
  .inspector {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(32vh, 250px);
  }
  .inspector:empty { display: none; }
  .inspector:not(:empty) ~ .dock { display: none; }
  .tab-body { max-height: min(24vh, 178px); overflow: auto; }
  .tabs button, .inspector button, body:not(.city-level) #real-hud button { min-height: 40px; }
  .inspector select { min-height: 40px; }
  [data-mode="preview"] body.city-level #city-ui .c-controls button,
  [data-mode="preview"] body.city-level #city-ui .c-tabs button { min-height: 40px; }
  .hw-panel button { min-height: 40px; }
  .tab-body table { width: max-content; min-width: 100%; }

  /* Preview floor: sheet, Home + Work strip, then the KPI strip. */
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) #world-actions {
    position: absolute;
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(min(32vh, 250px) + 14px);
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
    padding: 4px;
    gap: 4px;
    max-height: 42px;
  }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) #world-actions::-webkit-scrollbar { display: none; }
  body:not(.city-level) #world-actions span { display: none; }
  body:not(.city-level) #world-actions button, body:not(.city-level) #world-actions summary { min-height: 40px; padding: 7px 9px; flex: 0 0 auto; }
  body:not(.city-level) #journey-rec,
  body:not(.city-level) #cubicle-rec,
  body:not(.city-level) #world-designs { display: none !important; }

  [data-mode="preview"] body:not(.city-level):not(.home-work-active) .kpis {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: calc(min(32vh, 250px) + 62px);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px;
  }
  .kpis::-webkit-scrollbar { display: none; }
  .kpi { flex: 0 0 132px; min-width: 132px; padding: 7px 9px; }
  .kpi button { min-height: 40px; }
  .kpi b { font-size: 15px; }
  .kpi .link { font-size: 10px; }

  /* Real floor remains scoped to its own HUD. */
  [data-mode="real"] body:not(.city-level):not(.home-work-active) #world-actions {
    top: 104px;
    bottom: auto;
    left: 8px;
    right: 8px;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  [data-mode="real"] body:not(.city-level):not(.home-work-active) #real-hud {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(31vh, 245px);
    overflow: auto;
    padding: 8px;
  }

  /* Preview city map uses its own sheet; Real city HUD stays with PR #65. */
  [data-mode="preview"] body.city-level #world-actions {
    top: 142px;
    bottom: auto;
    left: 8px;
    right: 8px;
    max-width: none;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    scrollbar-width: none;
  }
  [data-mode="preview"] body.city-level .topbar { z-index: 20; }
  [data-mode="preview"] body.city-level #world-actions span { display: none; }
  [data-mode="preview"] body.city-level #world-actions button,
  [data-mode="preview"] body.city-level #world-actions summary {
    min-height: 40px;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  [data-mode="preview"] body.city-level #world-actions button,
  [data-mode="preview"] body.city-level #world-actions summary,
  [data-mode="preview"] body.city-level #city-ui button { min-height: 40px; }
  [data-mode="preview"] body.city-level #journey-rec,
  [data-mode="preview"] body.city-level #cubicle-rec,
  [data-mode="preview"] body.city-level #world-designs { display: none !important; }
}

/* The brief requires 844×390, just beyond its 820px portrait breakpoint.
   This narrow, height-scoped landscape rule is the smallest exception. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topbar {
    top: 6px;
    left: 8px;
    right: 8px;
    min-height: 48px;
    height: 48px;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 4px 7px;
  }
  .brand { flex: 0 0 auto; }
  .brand small { display: none; }
  .top-mid { order: 0; width: auto; min-height: 0; flex: 0 1 auto; }
  .chip.paper { font-size: 0; padding: 5px 8px; }
  .chip.paper::after { content: "Paper"; font-size: 11px; }
  #tour-time, #tour-rec, #clock-day { display: none; }
  .clock { flex: 0 0 auto; gap: 4px; }
  .clock b { min-width: 36px; font-size: 12px; }
  .mode-switch button { padding: 5px 6px; font-size: 11px; }
  .speed button { padding: 4px 5px; }
  .tour-btns #tour-play { width: 26px; height: 26px; }
  .topbar button, .topbar select, .tabs button, .inspector button,
  body:not(.city-level) #real-hud button,
  body:not(.city-level) #world-actions button,
  body:not(.city-level) #world-actions summary,
  .kpi button { min-height: 40px; }
  .hw-panel button { min-height: 40px; }

  [data-mode="preview"] body:not(.city-level):not(.home-work-active) .kpis {
    top: 62px;
    left: 8px;
    right: auto;
    bottom: auto;
    width: 46%;
    display: flex;
    gap: 4px;
    overflow-x: auto;
  }
  .kpi { flex: 0 0 116px; min-width: 116px; padding: 5px 7px; }
  .kpi span { font-size: 10px; }
  .kpi b { font-size: 13px; }
  .kpi small, .kpi .link { display: none; }

  [data-mode="preview"] body:not(.city-level):not(.home-work-active) #world-actions {
    top: 134px;
    left: 8px;
    right: auto;
    bottom: auto;
    width: 46%;
    height: 44px;
    max-height: 44px;
    gap: 3px;
    padding: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
    white-space: nowrap;
    justify-content: flex-start;
  }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) #world-actions::-webkit-scrollbar { display: none; }
  [data-mode="preview"] body.city-level #world-actions {
    top: 124px;
    left: 8px;
    right: auto;
    bottom: auto;
    width: 46%;
    max-width: none;
    max-height: 44px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
    white-space: nowrap;
  }
  [data-mode="preview"] body.city-level .topbar { z-index: 20; }
  [data-mode="preview"] body.city-level #world-actions::-webkit-scrollbar { display: none; }
  [data-mode="preview"] body.city-level #world-actions button,
  [data-mode="preview"] body.city-level #world-actions summary { min-height: 40px; padding: 5px; font-size: 9px; }
  [data-mode="preview"] body.city-level #city-ui button { min-height: 40px; }
  [data-mode="preview"] body.city-level #journey-rec,
  [data-mode="preview"] body.city-level #cubicle-rec,
  [data-mode="preview"] body.city-level #world-designs { display: none !important; }
  body:not(.city-level) #world-actions span { display: none; }
  body:not(.city-level) #world-actions button, body:not(.city-level) #world-actions summary { min-height: 40px; padding: 5px 5px; font-size: 9px; flex: 0 0 auto; white-space: nowrap; }
  body:not(.city-level) #journey-rec,
  body:not(.city-level) #cubicle-rec,
  body:not(.city-level) #world-designs { display: none !important; }
  [data-mode="preview"] body.city-level #city-ui .c-controls {
    top: auto;
    bottom: 94px;
    left: 8px;
    flex-direction: row;
  }
  [data-mode="preview"] body.city-level #city-ui .c-controls .sep {
    width: 1px;
    height: auto;
    margin: 4px 2px;
  }
  [data-mode="preview"] body.city-level #city-ui:has(.c-panel:not([hidden])) :is(.c-controls, .c-tabs, .c-hint) { visibility: hidden; }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) .dock {
    left: 8px;
    right: auto;
    bottom: 8px;
    top: 180px;
    width: 46%;
    max-height: none;
    overflow: auto;
  }
  .tab-body { max-height: 28vh; }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) .inspector {
    left: 8px;
    right: auto;
    bottom: 8px;
    top: 180px;
    width: 46%;
    max-height: none;
  }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) .inspector:not(:empty) ~ .dock { display: none; }
  [data-mode="preview"] body:not(.city-level):not(.home-work-active) #labels .tag:nth-child(n+4) { display: none; }

  [data-mode="real"] body:not(.city-level):not(.home-work-active) #world-actions {
    top: 62px;
    left: 8px;
    right: auto;
    width: 46%;
    bottom: auto;
  }
  [data-mode="real"] body:not(.city-level):not(.home-work-active) #real-hud {
    left: 8px;
    right: auto;
    bottom: 8px;
    width: 46%;
    max-height: 58vh;
    overflow: auto;
    padding: 7px;
  }
  [data-mode="real"] body:not(.city-level):not(.home-work-active) #real-hud .rh-log,
  [data-mode="real"] body:not(.city-level):not(.home-work-active) #real-hud .hint { display: none; }
}
