/* Keep the cabinet in the visual viewport. Only the content of an open station
   can overflow, so a wheel or a swipe cannot displace its menu or the shop tabs. */
html { height:100%; overflow:clip; overscroll-behavior:none; }
body {
  height:100vh; height:100dvh; min-height:0; overflow:clip;
  display:grid; grid-template-rows:auto minmax(0,1fr);
}
main {
  min-height:0; display:grid; grid-template-rows:auto minmax(0,1fr) auto;
  padding-top:clamp(8px,1.8vh,22px); padding-bottom:max(3px,env(safe-area-inset-bottom));
}
.mast-inner { min-height:62px; gap:clamp(16px,5vw,80px); }
.mast-tools .nav-btn { padding:0; }
.mast-tools .nav-btn i { display:inline-flex; }
.stations { gap:4px; }
.station-link {
  display:inline-flex; justify-content:center; align-items:center; gap:7px;
  min-height:38px; padding:5px 11px; border:2px solid transparent;
  font-size:19px; color:#ebd8b4; text-shadow:2px 2px #312322;
}
.station-link[aria-pressed="true"] {
  color:#ffe2a0; background:#3c2e2a; border-color:#291e21;
  box-shadow:inset 0 2px #966e4a,inset 2px 0 #71553f,inset -2px -2px #59402f;
}
.station-link:hover { color:#fff3d7; background-color:#604435; }
.compact-link { display:none; }
.heading { margin-bottom:clamp(7px,1.25vh,16px); }
.heading h1 { font-size:clamp(29px,3vw,45px); }
.playgrid { min-height:0; grid-template-rows:minmax(0,1fr); align-items:stretch; }
.operations {
  display:grid; min-height:0; grid-template-rows:minmax(0,1fr) auto;
  gap:clamp(6px,1.1vh,14px);
}
.operations.with-station { grid-template-rows:minmax(0,.95fr) minmax(0,1fr); }
.operations.full-station { grid-template-rows:minmax(0,1fr); }
.field-row,.field-row>.panel,.station-panel,.management { min-height:0; }
.field-row { min-width:0; }
.field-row .ore-hit,.field-row .landscape { min-height:0; aspect-ratio:auto; }
.field-row .charge-line,.field-row .mine-console { min-height:44px; }
.field-row .panel-title { min-height:35px; }
.field-row .mine-console .activity { flex-wrap:wrap; }
.logistics,.shipment,.workings,.management { margin-top:0; }
.shipment { margin-top:6px; }
#reserve-cage:not([hidden]) { display:block; width:100%; margin-top:4px; font-size:16px; }
#reserve-cage[hidden] { display:none; }
#supply-panel {
  min-width:0; min-height:0; max-height:min(40dvh,315px);
  overflow:auto; overscroll-behavior:contain;
}
.stock { grid-template-columns:repeat(2,minmax(0,1fr)); }
.shop,.station-panel {
  display:grid; overflow:hidden; align-self:stretch;
  grid-template-rows:auto minmax(0,1fr); background-color:#6c4935;
}
.shop { grid-template-rows:auto auto minmax(0,1fr); }
.station-scroll {
  min-height:0; min-width:0; overflow-y:auto; overflow-x:hidden;
  overscroll-behavior:contain; touch-action:pan-y;
  scrollbar-color:#a58864 #262832;
}
.station-scroll:focus-visible,#supply-panel:focus-visible {
  outline:2px solid #b5d7b2; outline-offset:-3px;
}
#tab-content { scrollbar-gutter:stable; }
.shop .cards { grid-template-columns:minmax(0,1fr); }
.station-panel .work-tabs { flex-wrap:wrap; }
#guild-content,#flood-content { background:var(--panel); }
.deep-panel { grid-template-rows:minmax(0,1fr); }
.playgrid [data-pane][hidden] { display:none; }
.playgrid.voyage-view { grid-template-columns:minmax(0,1fr); }
main:has(.voyage-view) { grid-template-rows:minmax(0,1fr) auto; }
main:has(.voyage-view) > .heading { display:none; }
footer { padding:clamp(4px,.8vh,10px) 0 2px; }
dialog[open] {
  display:grid; grid-template-rows:auto minmax(0,1fr); max-height:88dvh; overflow:hidden;
}
#dialog-body { min-height:0; overflow:auto; overscroll-behavior:contain; }

@media(max-height:760px) and (min-width:971px) {
  .mast-inner { min-height:50px; }
  .brand-mark { height:38px; width:38px; }
  .brand-mark canvas { width:32px; height:32px; }
  .brand small { font-size:11px; } .brand b { font-size:26px; }
  main { padding-top:8px; } .heading h1 { font-size:32px; }
  .panel-body { padding:8px 10px; gap:5px; }
  .panel-title { min-height:32px; }
  .shop-sign { min-height:44px; }
  .tab { min-height:40px; }
}

/* Portable cabinet: every destination gets the whole area below the HUD.
   Keep this condition in sync with viewport.js, including short landscape. */
@media(max-width:970px),(max-height:610px) {
  .compact-link { display:inline-flex; }
  .playgrid,.operations,.operations.with-station {
    grid-template: minmax(0,1fr) / minmax(0,1fr);
  }
  .playgrid.shop-alone .operations { display:none; }
  .station-link { min-height:34px; padding:3px 6px; font-size:17px; gap:4px; }
  .mast-inner { gap:12px; }
  .stations { gap:1px; }
  #supply-panel { max-height:none; }
  .shop .cards { grid-template-columns:repeat(auto-fit,minmax(min(245px,100%),1fr)); }
  .shop .card { align-content:start; }
  .shop .tabs { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); }
}
@media(max-width:780px) and (min-height:451px) {
  .mast-inner { display:grid; grid-template-columns:auto minmax(0,1fr); gap:4px; padding-top:4px; }
  .mast-tools { grid-column:2; grid-row:1; justify-self:end; }
  .stations { grid-column:1/-1; grid-row:2; display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); }
  .station-link { gap:4px; padding:4px 2px; }
}
@media(max-width:650px) and (min-height:451px) {
  .brand-mark { width:29px; height:29px; }
  .brand-mark canvas { width:23px; height:23px; }
  .brand small { font-size:9px; } .brand b { font-size:18px; }
  .station-link { flex-direction:column; gap:2px; min-width:0; padding:3px 1px; font-size:15px; }
  .station-link canvas { width:18px; height:18px; }
  .mast-tools .square { min-height:30px; width:32px; height:30px; }
  main { padding-top:7px; }
  .heading h1 { font-size:clamp(24px,6vw,30px); }
  .heading { margin-bottom:6px; }
  .shop .cards { grid-template-columns:minmax(0,1fr); }
}
@media(max-width:970px) and (max-aspect-ratio:1/1) {
  .field-row { grid-template: minmax(0,0.77fr) minmax(0,1.23fr) / minmax(0,1fr); }
  .seam {
    display:grid; grid-template-columns:minmax(0,1.35fr) minmax(105px,1fr);
    grid-template-rows:1fr 1fr; background:#27323c;
  }
  .seam .ore-hit { grid-column:1; grid-row:1/3; }
  .seam .charge-line,.seam .panel-title { grid-column:2; align-items:flex-start; justify-content:center; flex-direction:column; gap:6px; padding:8px; }
  .seam .panel-title { grid-row:1; } .seam .charge-line { grid-row:2; }
  .field-row .landscape { flex:1; }
  .field-row .charges { gap:4px; }
  .field-row .charges i { width:10px; height:16px; }
  .field-row .landscape canvas { object-fit:contain; }
}
@media(max-width:400px) and (min-height:451px) {
  .station-link { font-size:clamp(12px,3.45vw,14px); }
}
@media(max-height:450px) {
  .mast-inner { min-height:34px; gap:7px; } .mast { border-width:2px 0 3px; }
  .mast-tools { gap:3px; } .mast-tools .square { min-height:28px; height:28px; width:28px; }
  .mast .brand-mark { display:none; } .mast .brand small { display:none; } .mast .brand b { font-size:22px; }
  .station-link { min-height:29px; padding:2px 4px; font-size:15px; }
  .station-link i { display:none; } .stations { gap:1px; }
  main { padding-top:4px; } .heading { margin-bottom:4px; }
  .heading h1 { font-size:22px; } .location { font-size:13px; }
  .purse>div { min-width:50px; padding:2px 5px; } .purse b { font-size:16px; }
  .purse small { display:none; } .purse canvas { width:19px; height:19px; }
  .field-row .charge-line,.field-row .mine-console { min-height:30px; padding:3px 6px; }
  .field-row .panel-title,.shop-sign { min-height:31px; }
  .shop-sign h2 { font-size:20px; }
  .tab { min-height:30px; flex-direction:row; } .tabs { padding-top:2px; }
  footer { display:none; }
}
@media(max-height:450px) and (max-width:650px) {
  .mast-inner { display:grid; grid-template-columns:auto 1fr; padding-top:2px; }
  .mast-tools { grid-column:2; grid-row:1; justify-self:end; }
  .stations { grid-column:1/-1; display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); }
  .station-link { padding:1px; font-size:14px; }
}
