/* Live-site audit fixes, 6 Nov 2026 (phone density, pin touch targets, phone header). Loaded last on port.html. */

/* 1) Phone artwork view: keep the control stack compact under the header, the same as the 3D view,
   instead of stretching it to the bottom where Import/Export, Play and Explore met the Ship close-up / Landscape buttons. */
@media(max-width:700px){
  body[data-view] #controls,body[data-info-pilot][data-view="static"] #controls{bottom:auto!important;align-content:start;padding:0}
  body[data-view="static"] #controls{grid-template-columns:minmax(0,1fr) 58px 76px;gap:6px}
  /* Ship close-up / Landscape view: one column at the bottom right, clear of the view tools and the bottom bar. */
  body[data-info-pilot] .world-hero-bar{gap:6px}
  body[data-info-pilot] .world-hero,body[data-info-pilot] .world-hero-bar .world-silo-cut{min-height:44px}
}
/* Artwork starts below the control stack (as it already does on desktop), so the stack never covers a pin. */
@media(max-width:600px){body[data-view="static"] #static-view.static-view{top:120px}}
@media(min-width:601px) and (max-width:700px){body[data-view="static"] #static-view.static-view{top:64px}}

/* 2) Static hotspot pins: at least 44px touch targets on phones and touch screens. The visible pill grows only a little
   (34px, as on desktop) so neighbouring labels do not collide; a transparent hit area extends each pin to 46px tall.
   Pin anchor coordinates are unchanged. */
@media(max-width:700px),(pointer:coarse){
  .static-pins .static-pin,.static-pins .static-pin.static-pin--inland{min-height:34px;min-width:44px}
  .static-pins .static-pin::after{content:"";position:absolute;inset:-6px -4px;border-radius:999px}
  .static-pins .static-pin.static-pin--hit{min-height:44px;min-width:130px;padding:0}
  .static-pins .static-pin.static-pin--hit::after{inset:0}
}

/* 3) Phone header: links get a 44px tap height, tighter letter-spacing and clear space from the right edge. */
@media(max-width:600px){
  header.bar,header#site-header{padding-right:16px}
  header.bar .track{gap:16px;letter-spacing:.06em}
  header.bar .track a{min-height:44px;padding:0 2px}
}
@media(max-width:360px){
  header.bar .track{gap:12px;font-size:.68rem;letter-spacing:.04em}
}

/* 4) 2026-11-06 screen-size: phones — separate view-preset stack from View Artwork /
   zoom / home, and keep the “At the berth” tour card on screen.
   Presets stay stacked (Cut-away / Ship / Landscape / silo cut-away) with 44px targets;
   they move under the commodity chips (top-right). View tools stay bottom-left above the
   ti-bar. Tour card sits above the view tools on the left. */
@media(max-width:700px){
  body[data-info-pilot] .world-hero-bar{
    top:calc(var(--header-height) + 96px);
    right:8px;
    bottom:auto;
    left:auto;
    align-items:flex-end;
    max-height:calc(100dvh - var(--header-height) - var(--ti-bar-h,48px) - 180px);
    overflow:auto;
    overscroll-behavior:contain;
    z-index:6;
  }
  body[data-info-pilot][data-ti-sheet="open"] .world-hero-bar{display:none}
  body[data-info-pilot] #view-tools{
    top:auto;
    left:8px;
    right:auto;
    bottom:calc(var(--ti-bar-h,48px) + env(safe-area-inset-bottom,0px) + 8px);
    flex-direction:row;
    flex-wrap:wrap;
    max-width:calc(100vw - 24px);
    z-index:5;
  }
  /* Override the phone rule that hid the tour card (#terminal-tour = “At the berth”). */
  body[data-info-pilot][data-view="3d"] #terminal-tour{
    display:block;
    left:8px;
    right:auto;
    width:min(300px,calc(100vw - 16px));
    max-width:calc(100vw - 16px);
    bottom:calc(var(--ti-bar-h,48px) + env(safe-area-inset-bottom,0px) + 60px);
    padding:12px 14px;
    z-index:4;
    max-height:min(28dvh,220px);
    overflow:auto;
  }
  body[data-info-pilot][data-ti-sheet="open"] #terminal-tour,
  body[data-info-pilot][data-equipment-modal="open"] #terminal-tour{display:none}
  body[data-info-pilot][data-view="3d"] #terminal-tour #tour-help{display:none}
  body[data-info-pilot][data-view="3d"] #terminal-tour #tour-chapter{font-size:18px;min-height:22px}
  body[data-info-pilot][data-view="3d"] #terminal-tour .tour-buttons{margin-top:8px}
}

/* Short phone heights: keep the berth card above the view-tools row even when the
   viewport is under ~700px tall (e.g. landscape phone / small device). */
@media(max-width:700px) and (max-height:720px){
  body[data-info-pilot][data-view="3d"] #terminal-tour{
    bottom:calc(var(--ti-bar-h,48px) + env(safe-area-inset-bottom,0px) + 56px);
    max-height:min(24dvh,180px);
    padding:10px 12px;
  }
}

/* 5) 2026-11-06 screen-size: tablet — top commodity-chip row was flex-end + capped
   width, so the start of the row (Grain…) clipped on the left around 768–1024 px.
   Give the control strip the full top width, wrap instead of clipping, and keep the
   first chips fully visible. */
@media(min-width:701px) and (max-width:1100px){
  body[data-view] #controls,
  body[data-info-pilot] #controls,
  body[data-view="3d"] #controls{
    left:12px;
    right:12px;
    max-width:none;
    justify-content:flex-end;
    flex-wrap:wrap;
    overflow:visible;
    row-gap:8px;
  }
  body[data-info-pilot] #controls>div,
  #commodity-chips{
    flex:0 1 auto;
    max-width:100%;
  }
  #commodity-chips{
    flex-wrap:wrap;
    justify-content:flex-start;
    border-radius:18px;
  }
  #commodity-chips button{
    min-width:56px;
    padding:8px 10px;
  }
}

/* Isolated live audit: the boot still is available before the module graph. */
#viewport>#port-initial-still{position:absolute;inset:0;display:block}
#viewport>#port-initial-still img{width:100%;height:100%;object-fit:cover;object-position:center top}
/* Tablet: commodity row at the top, view tools at the lower left, stacked presets
   at the lower right. Reserve a separate footer row below the information bar. */
@media(min-width:701px) and (max-width:1100px){
  body[data-info-pilot]{--audit-footer:64px}
  body.embedded[data-info-pilot]{--audit-footer:0px}
  body[data-info-pilot] .ti-bar{bottom:var(--audit-footer)}
  body[data-info-pilot] .terminal-credit{max-width:none;width:100%;height:56px;box-sizing:border-box;justify-content:space-between;padding:4px 12px}
  body[data-info-pilot] #view-tools{top:auto;bottom:calc(var(--audit-footer) + 60px);left:12px;right:auto}
  body[data-info-pilot] .world-hero-bar{position:fixed;top:auto;bottom:calc(var(--audit-footer) + 60px);right:12px;max-height:calc(100dvh - var(--header-height) - var(--audit-footer) - 180px);overflow:auto;gap:6px}
  body[data-info-pilot] .world-hero-bar button{min-height:44px;flex-shrink:0}
  body[data-info-pilot] :is(.ti-pop,.ti-card){bottom:calc(var(--audit-footer) + 58px)}
  body[data-info-pilot][data-view="3d"] #terminal-tour{bottom:calc(var(--audit-footer) + 116px);max-width:calc(100vw - 260px)}
}
@media(min-width:701px) and (max-width:1100px) and (max-height:500px){
  body[data-info-pilot][data-view="3d"] #terminal-tour{display:none}
}
/* 320px: let the long label use its fair share and wrap instead of crowding. */
@media(max-width:360px){
  body[data-info-pilot] .ti-bar{display:grid;grid-template-columns:1fr 1.3fr .75fr .9fr 1fr;gap:2px;padding-left:4px;padding-right:4px}
  body[data-info-pilot] .ti-bar button{font-size:11px;letter-spacing:0;white-space:normal;line-height:1.15;padding:0 2px;min-height:44px}
}
