/* The illustrated game keeps its existing gutters inside the device's usable
   viewport. The optional 3D world and atlas own their own viewport geometry. */
:root {
  --fc-safe-top: env(safe-area-inset-top, 0px);
  --fc-safe-right: env(safe-area-inset-right, 0px);
  --fc-safe-bottom: env(safe-area-inset-bottom, 0px);
  --fc-safe-left: env(safe-area-inset-left, 0px);
}

body:not(.world-scene-active):not([data-campaign-diorama="active"]) .app-shell {
  --fc-shell-gutter: clamp(16px, 3vw, 40px);
  padding-top: var(--fc-safe-top);
  padding-right: calc(var(--fc-shell-gutter) + var(--fc-safe-right));
  padding-left: calc(var(--fc-shell-gutter) + var(--fc-safe-left));
}

/* Adventure clearance already includes the measured dock and its bottom inset. */
body[data-screen="home"]:not(.world-scene-active):not([data-campaign-diorama="active"]) .app-shell {
  padding-bottom: var(--fc-safe-bottom);
}

@media (max-width: 480px), (max-height: 560px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) .app-shell {
    --fc-shell-gutter: 12px;
  }
}

@media (max-width: 640px) {
  body[data-screen]:not(.world-scene-active):not([data-campaign-diorama="active"]) .app-shell {
    --fc-shell-gutter: 12px;
  }
  /* This dock is fixed to the viewport, outside the shell's safe side gutters.
     Its existing bottom padding remains the single home-indicator allowance. */
  body[data-screen="adventure"]:not(.world-scene-active):not([data-campaign-diorama="active"]) #action-dock {
    padding-left: calc(12px + var(--fc-safe-left));
    padding-right: calc(12px + var(--fc-safe-right));
  }
}

@media (max-width: 600px) {
  body[data-home="camp"]:not(.world-scene-active):not([data-campaign-diorama="active"]) .app-shell {
    --fc-shell-gutter: 12px;
  }
}

/* Keep each dialog's existing width and internal padding. Limit its outside
   box, and center it between the safe edges, including an asymmetric notch.
   These properties also update when the dynamic viewport changes on rotation. */
body:not(.world-scene-active):not([data-campaign-diorama="active"]) :is(dialog.game-dialog, dialog.fbs-settings) {
  --fc-dialog-inline-gap: 32px;
  --fc-dialog-block-gap: 40px;
  inset: var(--fc-safe-top) var(--fc-safe-right) var(--fc-safe-bottom) var(--fc-safe-left);
  max-width: calc(100vw - var(--fc-safe-left) - var(--fc-safe-right) - var(--fc-dialog-inline-gap));
  max-height: calc(100vh - var(--fc-safe-top) - var(--fc-safe-bottom) - var(--fc-dialog-block-gap));
  max-height: calc(100dvh - var(--fc-safe-top) - var(--fc-safe-bottom) - var(--fc-dialog-block-gap));
}

@media (max-width: 680px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.game-dialog {
    --fc-dialog-block-gap: 28px;
  }
}

@media (max-width: 480px), (max-height: 560px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.game-dialog {
    --fc-dialog-block-gap: 16px;
  }
}

body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.story-dialog {
  --fc-dialog-inline-gap: 28px;
  --fc-dialog-block-gap: 26px;
}

body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.journal-dialog {
  --fc-dialog-inline-gap: 28px;
  --fc-dialog-block-gap: 30px;
}

body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.campaign-replay-dialog {
  --fc-dialog-inline-gap: 28px;
  --fc-dialog-block-gap: 32px;
}

@media (max-width: 560px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.story-dialog {
    --fc-dialog-inline-gap: 14px;
    --fc-dialog-block-gap: 16px;
  }
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.journal-dialog {
    --fc-dialog-inline-gap: 16px;
    --fc-dialog-block-gap: 20px;
  }
}

body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.fbs-settings {
  --fc-dialog-block-gap: 36px;
}

@media (max-width: 740px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.fbs-settings {
    --fc-dialog-inline-gap: 20px;
    --fc-dialog-block-gap: 20px;
  }
}

@media (max-width: 440px) {
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.fbs-settings {
    --fc-dialog-inline-gap: 12px;
    --fc-dialog-block-gap: 12px;
  }
}

@media (max-height: 520px) {
  /* The outer settings box now clears the bottom inset. Keep only its normal
     footer spacing instead of applying that same inset a second time. */
  body:not(.world-scene-active):not([data-campaign-diorama="active"]) dialog.fbs-settings .fbs-footer {
    padding-bottom: 12px;
  }
}
