/* Responsive game presentation. Isolated so the desktop client keeps its
   current artboard and window sizes. */

@media (max-width: 899px), (pointer: coarse) and (max-width: 1100px) {
  body.kwakencity-client .kh-client {
    --kh-shell-head: calc(58px + env(safe-area-inset-top, 0px));
  }

  body.kwakencity-client .kh-stage-wrap {
    position: relative;
    background:
      radial-gradient(ellipse at 50% 42%, rgba(41, 132, 91, .48), transparent 58%),
      radial-gradient(ellipse at 12% 80%, rgba(14, 111, 104, .34), transparent 48%),
      linear-gradient(145deg, #0c4948, #145b4d 52%, #103b38);
  }

  body.kwakencity-client .kh-topbar {
    padding-top: max(6px, env(safe-area-inset-top, 0px));
    padding-left: max(7px, env(safe-area-inset-left));
    padding-right: max(7px, env(safe-area-inset-right));
  }

  body.kwakencity-client .kh-dock {
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }

  body.kwakencity-client :is(
    .kh-dialog[open],
    .kh-drawer:not([hidden]),
    .kh-item-menu:not([hidden]),
    .kh-checkin-card,
    .kh-toast
  ) {
    --kh-window-scale: 1 !important;
  }

  body.kwakencity-client :is(.kh-dialog[open], .kh-drawer:not([hidden]), .kh-item-menu:not([hidden])) {
    --kh-titlebar-inset-top: 18px;
    --kh-titlebar-inset-inline-start: 18px;
    --kh-titlebar-inset-inline-end: 18px;
  }

  body.kwakencity-client .kh-checkin-card {
    left: 50%;
    top: 50%;
    width: min(808px, calc(100vw - 28px));
    height: auto;
    max-height: calc(100dvh - 28px);
    transform: translate(-50%, -50%) !important;
  }
}

/* Tablets keep a floating window, now at readable size and fully inside the
   usable area between the top bar and the controls. */
@media (min-width: 621px) and (max-width: 899px), (pointer: coarse) and (min-width: 621px) and (max-width: 1100px) {
  body.kwakencity-client .kh-dialog[open] {
    --kh-titlebar-inset-top: 18px;
    --kh-titlebar-inset-inline-start: 18px;
    --kh-titlebar-inset-inline-end: 18px;
    left: 50%;
    right: auto;
    top: calc(var(--kh-shell-head) + (100% - var(--kh-shell-head) - var(--kh-game-dock-height)) / 2);
    bottom: auto;
    width: min(860px, calc(100vw - 28px)) !important;
    min-width: 0;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - var(--kh-shell-head) - var(--kh-game-dock-height) - 24px) !important;
    margin: 0;
    padding: 18px;
    overflow-x: hidden;
    overflow-y: auto;
    transform: translate(-50%, -50%) !important;
  }

  body.kwakencity-client .kh-drawer:not([hidden]) {
    left: 50%;
    right: auto;
    top: calc(var(--kh-shell-head) + 8px);
    bottom: calc(var(--kh-game-dock-height) + 8px);
    width: min(900px, calc(100vw - 28px)) !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    padding: 18px;
    transform: translateX(-50%) !important;
  }

  body.kwakencity-client .kh-drawer:not([hidden]) > .kh-modal-titlebar {
    margin: -18px -18px 12px !important;
    border-radius: 17px 17px 0 0;
  }

  body.kwakencity-client .kh-item-menu:not([hidden]) {
    right: 14px;
    bottom: calc(var(--kh-game-dock-height) + 12px);
    max-width: calc(100vw - 28px);
    transform: none !important;
  }
}

/* Phones use roomy, scrollable panels instead of shrinking the entire modal
   to a tiny desktop thumbnail. The top bar and dock remain reachable. */
@media (max-width: 620px), (pointer: coarse) and (max-width: 1100px) {
  body.kwakencity-client .kh-client {
    --kh-shell-head: calc(54px + env(safe-area-inset-top, 0px));
    --kh-game-dock-height: calc(78px + env(safe-area-inset-bottom, 0px));
  }

  body.kwakencity-client :is(.kh-dialog[open], .kh-drawer:not([hidden]), .kh-item-menu:not([hidden])) {
    --kh-titlebar-inset-top: 12px;
    --kh-titlebar-inset-inline-start: 12px;
    --kh-titlebar-inset-inline-end: 12px;
  }

  body.kwakencity-client .kh-dialog[open] {
    --kh-titlebar-inset-top: 12px;
    --kh-titlebar-inset-inline-start: 12px;
    --kh-titlebar-inset-inline-end: 12px;
    left: 6px;
    right: 6px;
    top: calc(var(--kh-shell-head) + 6px);
    bottom: calc(var(--kh-game-dock-height) + 6px);
    width: auto !important;
    min-width: 0;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0;
    padding: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 18px;
    transform: none !important;
  }

  body.kwakencity-client .kh-checkin-card {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    border-radius: 18px;
  }

  body.kwakencity-client .kh-checkin h1 {
    font-size: clamp(28px, 7vw, 36px);
    white-space: normal;
  }

  body.kwakencity-client .kh-checkin input {
    min-height: 44px;
    height: auto;
    font-size: 16px;
  }

  body.kwakencity-client .kh-dialog .kh-modal-titlebar {
    min-height: 56px;
    margin: -12px -12px 10px !important;
    padding: 10px 12px;
    border-radius: 14px 14px 0 0;
  }

  body.kwakencity-client .kh-dialog .kh-modal-titlebar h2,
  body.kwakencity-client .kh-dialog > h2 {
    font-size: clamp(20px, 5.2vw, 25px);
    line-height: 1.12;
  }

  body.kwakencity-client .kh-dialog > h2 {
    margin: 6px 42px 10px 0;
    padding-bottom: 9px;
  }

  body.kwakencity-client .kh-dialog-close {
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
  }

  body.kwakencity-client .kh-drawer:not([hidden]) {
    left: 6px;
    right: 6px;
    top: calc(var(--kh-shell-head) + 6px);
    bottom: calc(var(--kh-game-dock-height) + 6px);
    width: auto !important;
    min-width: 0;
    max-width: none !important;
    height: auto !important;
    min-height: 0;
    max-height: none !important;
    margin: 0;
    padding: 12px;
    overflow: hidden;
    border-radius: 18px;
    transform: none !important;
  }

  body.kwakencity-client .kh-drawer:not([hidden]) > .kh-modal-titlebar {
    min-height: 56px;
    margin: -12px -12px 10px !important;
    padding: 10px 12px;
    border-radius: 14px 14px 0 0;
  }

  body.kwakencity-client .kh-items-drawer .kh-inventory-browser {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  body.kwakencity-client .kh-navigator[open] .kh-navigator-content {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    overflow-y: auto;
  }

  body.kwakencity-client .kh-navigator[open] .kh-public-rooms {
    max-height: none;
    padding: 10px 0 2px;
    border-top: 2px dashed var(--kh-ui-line);
    border-left: 0;
  }

  body.kwakencity-client .kh-item-menu:not([hidden]) {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(var(--kh-game-dock-height) + 8px);
    width: auto !important;
    min-width: 0;
    max-width: none !important;
    height: auto !important;
    max-height: min(230px, calc(100dvh - var(--kh-shell-head) - var(--kh-game-dock-height) - 18px)) !important;
    padding: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 16px;
    transform: none !important;
  }

  body.kwakencity-client .kh-toast {
    top: calc(var(--kh-shell-head) + 7px);
    max-width: calc(100% - 16px);
  }

  body.kwakencity-client .kh-item-menu-head > div {
    width: auto;
    max-width: calc(100% - 42px);
  }
}
