/* Window-only limits use actual HUD units; canvas, HUD pads and rotation gating are unchanged. */
.window.ui-window-safe {
  box-sizing: border-box;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: var(--ui-window-max-w, 100vw) !important;
  max-height: var(--ui-window-max-h, 100vh) !important;
}
.window.ui-window-safe > .win-title { flex-shrink: 0; min-width: 0; }
.window.ui-window-safe > .win-title > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.window.ui-window-safe .win-body {
  min-width: 0;
  min-height: 0;
  max-height: none !important;
  overflow: auto;
  overscroll-behavior: contain;
}
body.touch .window.ui-window-safe > .win-title { min-height: var(--ui-window-touch-target, 44px); }
body.touch .window.ui-window-safe > .win-title .win-close {
  box-sizing: border-box;
  flex: 0 0 var(--ui-window-touch-target, 44px);
  width: var(--ui-window-touch-target, 44px);
  min-width: var(--ui-window-touch-target, 44px);
  height: var(--ui-window-touch-target, 44px);
  min-height: var(--ui-window-touch-target, 44px);
  padding: 0;
}
/* Prevent long control rows from forcing a common settings window wider than its body. */
.window.ui-window-safe .set-row { flex-wrap: wrap; min-width: 0; }
.window.ui-window-safe .set-row > input[type="range"] { min-width: 0; max-width: 100%; }

/* Keep native NPC choices/paging visible when one whole paragraph exceeds the remaining room. */
#dialogWindow.window.ui-window-safe > .win-body { display: flex; flex-direction: column; }
#dialogWindow.window.ui-window-safe .dialog-lines { min-height: 0; overflow: auto; flex: 1 1 auto; }
#dialogWindow.window.ui-window-safe .dialog-actions { flex: 0 0 auto; }

/* Only while the native NPC pager measures whole paragraphs; restored in finally. */
.window.ui-window-safe.ui-dialogue-measuring { height: auto !important; max-height: none !important; }
.window.ui-window-safe.ui-dialogue-measuring > .win-body {
  flex: 0 0 auto;
  height: auto !important;
  max-height: none !important;
}
#dialogWindow.window.ui-window-safe.ui-dialogue-measuring .dialog-lines { flex: 0 0 auto; overflow: visible; }
.window.ui-window-safe.ui-dialogue-measuring::after {
  content: '';
  display: block;
  flex: 0 0 var(--ui-dialogue-measure-extra, 0px);
  height: var(--ui-dialogue-measure-extra, 0px);
}

/* Fish-card actions stay beside the complete card on landscape screens. */
.fish-card-view.ui-window-overlay-safe .fcv-wrap {
  display: grid;
  grid-template-columns: var(--ui-fcv-card-w, 270px) minmax(0, 330px);
  grid-template-rows: auto auto;
  align-items: center;
  align-content: center;
  column-gap: 16px;
  row-gap: 12px;
  box-sizing: border-box;
  max-width: var(--ui-window-max-w, calc(100vw - 16px));
  max-height: var(--ui-window-max-h, calc(100vh - 16px));
  overflow: auto;
  overscroll-behavior: contain;
}
.fish-card-view.ui-window-overlay-safe .fcv-card {
  grid-column: 1;
  grid-row: 1 / 3;
  width: var(--ui-fcv-card-w, 270px);
  height: var(--ui-fcv-card-h, 360px);
}
.fish-card-view.ui-window-overlay-safe .fcv-info {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  align-self: end;
  box-sizing: border-box;
  padding: 10px;
  border-radius: 8px;
  background: rgba(17, 25, 38, .94);
  color: #f8fafc;
  font-size: max(12px, calc(var(--ui-window-touch-target, 44px) / 3.3846));
}
.fish-card-view.ui-window-overlay-safe .fcv-btns {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
  align-self: start;
}
body.touch .fish-card-view.ui-window-overlay-safe .fcv-btns > button {
  min-height: var(--ui-window-touch-target, 44px);
  min-width: var(--ui-window-touch-target, 44px);
  max-width: 100%;
  white-space: normal;
}
