/* KwakenCity game: use the browser viewport as the game frame. */
html:has(body.kwakencity-client),
body.kwakencity-client {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0 !important;
  overflow: hidden !important;
  overscroll-behavior: none;
  background: #073f49;
}

body.kwakencity-client {
  display: block;
}

body.kwakencity-client .kh-client {
  --kh-shell-head: clamp(58px, 7.2vh, 78px);
  /* 38px chat + 44px buttons + 4px gap + 8px padding + 3px border. */
  --kh-game-dock-content-height: 98px;
  --kh-game-dock-bottom-gap: calc(12px + env(safe-area-inset-bottom, 0px));
  /* This is the full reserved footer, also used by modal/drawer offsets.
     Keep later responsive rules from counting the safe area a second time. */
  --kh-game-dock-height: calc(var(--kh-game-dock-content-height) + var(--kh-game-dock-bottom-gap)) !important;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--kh-shell-head) minmax(0, 1fr) var(--kh-game-dock-height);
  overflow: hidden;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.kwakencity-client .kh-topbar {
  grid-row: 1;
  grid-column: 1;
  width: 100%;
  min-width: 0;
  min-height: var(--kh-shell-head);
  height: var(--kh-shell-head);
  padding-block: 6px;
}

body.kwakencity-client .kh-stage-wrap {
  grid-row: 2;
  grid-column: 1;
  display: block;
  container: stage-viewport / size;
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: #0b100d;
}

/* Legacy fullscreen rules fit the world to a fixed 84:53 panel and center it.
   The viewport layout owns the whole middle grid row, so keep that row filled. */
body.kwakencity-client .kh-client.is-fullscreen .kh-stage-wrap {
  container: stage-viewport / size;
  width: 100%;
  height: 100%;
  min-height: 0;
  align-self: stretch;
  justify-self: stretch;
}

/* Keep small world props proportional to the game canvas at larger resolutions. */
body.kwakencity-client .kh-world-hotspot > .kh-door-arrow-icon,
body.kwakencity-client .kh-world-hotspot > .kh-door-arrow-icon img,
body.kwakencity-client .kh-gamehall-door > .kh-door-arrow-icon img,
body.kwakencity-client .kh-public-exit > .kh-door-arrow-icon img {
  width: clamp(22px, 2.45cqw, 46px);
  height: auto;
  aspect-ratio: 26 / 15;
}

body.kwakencity-client .kh-news-mailbox {
  width: clamp(66px, 7.9cqw, 140px);
  height: clamp(82px, 9.7cqw, 166px);
}

body.kwakencity-client .kh-news-mailbox-art { inset: 0 0 clamp(10px, 1.3cqw, 18px); }
body.kwakencity-client .kh-news-mailbox-art img {
  width: clamp(66px, 7.9cqw, 140px);
  height: auto;
  aspect-ratio: 1;
}

body.kwakencity-client .kh-news-mailbox-flag {
  top: 1.6cqw;
  left: .38cqw;
  width: 2.16cqw;
  height: 3cqw;
}

body.kwakencity-client .kh-news-mailbox-flag i {
  left: .19cqw;
  bottom: .19cqw;
  width: .56cqw;
  height: 2.54cqw;
  border-width: .19cqw;
}

body.kwakencity-client .kh-news-mailbox-flag b {
  left: .47cqw;
  width: 1.6cqw;
  height: 1.22cqw;
  border-width: .19cqw;
}

body.kwakencity-client .kh-news-mailbox-label {
  min-width: 5.8cqw;
  padding: .28cqw .66cqw;
  border-width: .19cqw;
  font-size: clamp(8px, .75cqw, 13px);
}

body.kwakencity-client .kh-news-mailbox > strong {
  top: .28cqw;
  right: -.19cqw;
  min-width: 1.7cqw;
  height: 1.7cqw;
  padding-inline: .38cqw;
  border-width: .19cqw;
  font-size: clamp(8px, .85cqw, 14px);
}

body.kwakencity-client .kh-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100cqw, calc(100cqh * 84 / 53));
  height: min(100cqh, calc(100cqw * 53 / 84));
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  aspect-ratio: 84 / 53;
  container: game-world / inline-size;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.kwakencity-client .kh-world-camera {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: visible;
  transform-origin: 50% 50%;
  will-change: auto;
}

body.kwakencity-client .kh-room-camera-controls {
  position: absolute;
  z-index: 120;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border: 2px solid rgba(243, 255, 223, .9);
  border-radius: 12px;
  background: rgba(14, 43, 29, .88);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .32);
  color: #fffde8;
  backdrop-filter: blur(5px);
}

body.kwakencity-client .kh-room-camera-controls[hidden] { display: none !important; }
body.kwakencity-client .kh-room-camera-controls button {
  display: grid;
  place-items: center;
  width: 30px;
  min-width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid #b6da83;
  border-radius: 8px;
  background: linear-gradient(#f9ffe9, #dceebc);
  color: #235b32;
  font: inherit;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}
body.kwakencity-client .kh-room-camera-controls button:not(:disabled):hover,
body.kwakencity-client .kh-room-camera-controls button:focus-visible {
  outline: 2px solid #ffdc52;
  outline-offset: 1px;
  filter: brightness(1.06);
}
body.kwakencity-client .kh-room-camera-controls button:disabled {
  opacity: .48;
  cursor: default;
  filter: saturate(.55);
}
body.kwakencity-client .kh-room-camera-controls output {
  min-width: 44px;
  padding: 0 3px;
  color: #fffde8;
  font-size: 10px;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 620px) {
  body.kwakencity-client .kh-room-camera-controls { top: 7px; right: 7px; gap: 3px; padding: 4px; }
  body.kwakencity-client .kh-room-camera-controls button { width: 27px; min-width: 27px; height: 27px; font-size: 18px; }
}

body.kwakencity-client .kh-lobby-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

body.kwakencity-client .kh-game-loader {
  background: radial-gradient(circle at 50% 42%, #176b53, #073f49 72%);
}

body.kwakencity-client .kh-game-loader-logo {
  width: min(360px, 76vw);
  max-height: 140px;
  filter: brightness(0) invert(1) drop-shadow(0 8px 18px rgba(0, 0, 0, .24));
}

body.kwakencity-client .kh-game-loader-track {
  height: 8px;
  border-color: rgba(255, 255, 255, .66);
  border-radius: 999px;
  background: rgba(3, 37, 40, .65);
}

body.kwakencity-client .kh-game-loader-track > span { border-radius: inherit; }

body.kwakencity-client .kh-dock {
  position: relative;
  z-index: 9000;
  grid-row: 3;
  grid-column: 1;
  left: auto;
  right: auto;
  bottom: auto;
  justify-self: stretch;
  align-self: start;
  width: 100%;
  height: var(--kh-game-dock-content-height);
  min-height: 0;
  padding: 4px 10px;
  padding-bottom: 4px !important;
  transform: none;
  border: 0;
  border-top: 3px solid #2e791d;
  border-radius: 0;
  background: #56aa23;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2);
}

body.kwakencity-client .kh-maintenance-screen {
  position: absolute;
  inset: 0;
  padding: 18px;
  background: rgba(9, 47, 37, .66);
  backdrop-filter: blur(5px) saturate(.84);
}

body.kwakencity-client .kh-maintenance-card {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  width: min(520px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  padding: clamp(22px, 4vw, 34px);
  border-radius: 22px;
  text-align: center;
}

body.kwakencity-client .kh-maintenance-copy {
  justify-items: center;
  width: 100%;
}

body.kwakencity-client .kh-maintenance-phase {
  margin-top: 13px;
}

body.kwakencity-client .kh-maintenance-card h2,
body.kwakencity-client .kh-maintenance-card p,
body.kwakencity-client .kh-maintenance-card small {
  max-width: 42ch;
}

body.kwakencity-client .kh-maintenance-card h2 {
  font-size: clamp(24px, 3.2vw, 32px);
  line-height: 1.12;
}

body.kwakencity-client .kh-maintenance-card p {
  margin: 10px 0 18px;
}

@media (max-width: 900px), (pointer: coarse) and (max-width: 1100px) {
  body.kwakencity-client .kh-client {
    --kh-shell-head: 58px;
    /* The 30px icons and 4px button padding need a 38px second row. */
    --kh-game-dock-content-height: 86px;
    --kh-game-dock-bottom-gap: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  body.kwakencity-client .kh-topbar {
    grid-template-columns: 38px minmax(100px, 1fr) minmax(190px, 250px) auto;
    gap: 8px;
    padding-inline: 10px;
  }

  body.kwakencity-client .kh-brand {
    width: 36px;
    min-width: 36px;
    height: 36px;
  }

  body.kwakencity-client .kh-brand-wordmark { display: none; }
  body.kwakencity-client .kh-room-title { min-width: 0; max-width: none; padding-inline: 8px; }
  body.kwakencity-client .kh-room-title-subtitle { display: none; }

  body.kwakencity-client .kh-top-balances {
    display: flex;
    width: 100%;
    max-width: 250px;
    gap: 0;
    overflow: hidden;
  }

  body.kwakencity-client .kh-top-balances > button {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 3px;
  }

  body.kwakencity-client .kh-topbar-tools { gap: 0; }
  body.kwakencity-client .kh-connection { display: none; }

  body.kwakencity-client .kh-dock {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: 34px minmax(34px, 1fr);
    gap: 3px;
    padding: 4px 7px;
  }

  body.kwakencity-client .kh-chat,
  body.kwakencity-client .kh-chat input,
  body.kwakencity-client .kh-chat button {
    min-height: 34px;
    height: 34px;
  }
}

@media (max-width: 620px), (pointer: coarse) and (max-width: 1100px) {
  body.kwakencity-client .kh-client {
    --kh-shell-head: 54px;
    --kh-game-dock-content-height: 78px;
  }

  body.kwakencity-client .kh-topbar {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 6px;
    padding-inline: 7px;
  }

  body.kwakencity-client .kh-brand {
    width: 32px;
    min-width: 32px;
    height: 32px;
  }

  body.kwakencity-client .kh-room-title { display: none; }
  /* On narrow screens keep the balances readable without reviving the old
     joined, segmented wallet bar. The colored Font Awesome symbols carry
     the currency identity while the amounts stay compact beside them. */
  body.kwakencity-client .kh-top-balances {
    display: flex;
    justify-self: center;
    align-items: center;
    gap: 2px;
    width: min(100%, 226px);
    max-width: 226px;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  body.kwakencity-client .kh-top-balances > :is(.kh-top-leaves, .kh-top-wallet, .kh-top-quacks, .kh-top-club) {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: auto;
    min-width: 0;
    min-height: 32px;
    height: 32px;
    padding: 2px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    box-shadow: none;
  }
  body.kwakencity-client .kh-top-balances > button + button { border-left: 0; }
  body.kwakencity-client .kh-top-balances > button > .kh-currency-icon,
  body.kwakencity-client .kh-top-balances > .kh-top-club > .kh-top-club-icon {
    flex: 0 0 17px;
    width: 17px;
    min-width: 17px;
    height: 17px;
    min-height: 17px;
  }
  body.kwakencity-client .kh-top-balances > button > .kh-top-balance-copy,
  body.kwakencity-client .kh-top-balances > .kh-top-club > .kh-top-club-copy {
    display: flex;
    flex: 0 1 auto;
    align-items: center;
    width: auto;
    min-width: 0;
    height: auto;
    overflow: hidden;
  }
  body.kwakencity-client .kh-top-balances .kh-top-balance-copy > small,
  body.kwakencity-client .kh-top-balances .kh-top-balance-label,
  body.kwakencity-client .kh-top-balances .kh-top-club-value > small { display: none; }
  body.kwakencity-client .kh-top-balances > button strong,
  body.kwakencity-client .kh-top-balances .kh-top-club-value strong {
    display: block;
    min-width: 0;
    overflow: hidden;
    color: #fffde9;
    font-size: 9px;
    line-height: 1;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.kwakencity-client .kh-top-balances > button { min-height: 32px; height: 32px; }
  body.kwakencity-client .kh-topbar-tools { width: 32px; }
  body.kwakencity-client .kh-fullscreen-toggle { width: 32px; height: 32px; padding: 5px; }

  body.kwakencity-client .kh-dock {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: 32px minmax(30px, 1fr);
    gap: 3px;
    padding: 3px 5px;
    padding-bottom: 3px !important;
  }

  body.kwakencity-client .kh-chat,
  body.kwakencity-client .kh-chat input,
  body.kwakencity-client .kh-chat button {
    min-height: 32px;
    height: 32px;
  }

  body.kwakencity-client .kh-maintenance-screen { padding: 10px; }
  body.kwakencity-client .kh-maintenance-card { width: 100%; padding: 22px 17px; }
  body.kwakencity-client .kh-maintenance-card h2 { font-size: clamp(23px, 7vw, 30px); }
  body.kwakencity-client .kh-maintenance-card p { font-size: 13px; }
  body.kwakencity-client .kh-game-loader-logo { width: min(300px, 80vw); }
}

/* Keep the balance row readable on desktop and let it grow with wide screens. */
@container kwaak-shell (min-width: 901px) {
  body.kwakencity-client .kh-top-balances > button > .kh-currency-icon,
  body.kwakencity-client .kh-top-balances > .kh-top-club > .kh-top-club-badge {
    flex-basis: clamp(24px, 1.6cqw, 34px);
    width: clamp(24px, 1.6cqw, 34px);
    min-width: clamp(24px, 1.6cqw, 34px);
    height: clamp(24px, 1.6cqw, 34px);
    min-height: clamp(24px, 1.6cqw, 34px);
  }

  body.kwakencity-client .kh-top-balances > button > .kh-top-balance-copy strong,
  body.kwakencity-client .kh-top-balances > .kh-top-club .kh-top-club-value strong,
  body.kwakencity-client .kh-top-balances > .kh-top-club .kh-top-club-value small {
    font-size: clamp(13px, .85cqw, 17px);
  }
}

/* Some Android foldables keep a desktop-sized CSS viewport even while held as
   touch devices. Keep the compact game header and dock on those screens too. */
@media (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-content-height: 78px;
  }

  body.kwakencity-client .kh-topbar {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 6px;
    padding-inline: max(7px, env(safe-area-inset-left)) max(7px, env(safe-area-inset-right));
  }

  body.kwakencity-client .kh-brand { width: 32px; min-width: 32px; height: 32px; }
  body.kwakencity-client .kh-brand-wordmark,
  body.kwakencity-client .kh-room-title { display: none; }

  body.kwakencity-client .kh-top-balances {
    justify-self: center;
    width: min(100%, 320px);
    max-width: 320px;
  }

  body.kwakencity-client .kh-top-balances > button > .kh-currency-icon,
  body.kwakencity-client .kh-top-balances > .kh-top-club > .kh-top-club-icon {
    flex-basis: 17px;
    width: 17px;
    min-width: 17px;
    height: 17px;
    min-height: 17px;
  }

  body.kwakencity-client .kh-top-balances > button > .kh-top-balance-copy strong,
  body.kwakencity-client .kh-top-balances > .kh-top-club .kh-top-club-value strong,
  body.kwakencity-client .kh-top-balances > .kh-top-club .kh-top-club-value small {
    font-size: 10px;
  }

}

/* Give the navigator's gold title strip a little air from the modal's top edge. */
@media (min-width: 900px) {
  body.kwakencity-client .kh-navigator[open] .kh-navigator-hero.kh-modal-titlebar {
    margin: -8px -8px 8px;
    padding-top: 12px;
    border-radius: 16px;
  }
}

/* Keep the navigator heading aligned cleanly after removing the decorative compass. */
body.kwakencity-client .kh-navigator-hero,
body.kwakencity-client .kh-navigator[open] .kh-navigator-hero {
  grid-template-columns: minmax(0, 1fr) auto;
}

/* Official rooms use the same visitor count and green entry action as busy Nests. */
body.kwakencity-client .kh-official-room-list > button,
body.kwakencity-client .kh-navigator-room-list > button.kh-room-is-official {
  grid-template-columns: 62px minmax(0, 1fr) auto auto;
  padding-left: 4px;
}

body.kwakencity-client .kh-room-preview i { display: none; }

/* Make visitor counts and the room entry action easy to spot in every Nest list. */
body.kwakencity-client .kh-navigator-room-list:not(.kh-official-room-list) > button {
  grid-template-columns: 62px minmax(0, 1fr) auto auto auto;
}

body.kwakencity-client .kh-navigator-room-list:not(.kh-official-room-list) > button.kh-room-is-official {
  grid-template-columns: 62px minmax(0, 1fr) auto auto;
}

body.kwakencity-client .kh-room-visitors {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  min-width: 90px;
  min-height: 27px;
  padding: 5px 9px;
  box-sizing: border-box;
  font-size: 12px;
  font-weight: 950;
  line-height: 1;
  white-space: nowrap;
}

@media (max-width: 520px) {
  body.kwakencity-client .kh-room-visitors {
    width: 82px;
    min-width: 82px;
    padding-inline: 5px;
    font-size: 10px;
  }
}

body.kwakencity-client .kh-room-visit-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 28px;
  padding: 0 9px;
  border: 2px solid #1b7535;
  border-radius: 9px;
  background: linear-gradient(#4aba3b, #268535);
  box-shadow: 0 2px 0 #1b602e;
  color: #fffef0;
  font-size: 10px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
}

body.kwakencity-client .kh-navigator-room-list > button:disabled .kh-room-visit-action {
  border-color: #9aa995;
  background: #e7ecdf;
  box-shadow: none;
  color: #657265;
}

/* Center the desktop market in the usable space above the complete footer.
   Compact/touch positioning stays with the responsive panel rules. */
@media (min-width: 900px) and (pointer: fine) {
  body.kwakencity-client .kh-marketplace-drawer:not([hidden]) {
    top: calc(var(--kh-shell-head) + (100dvh - var(--kh-shell-head) - var(--kh-game-dock-height)) / 2);
    bottom: auto;
    height: min(760px, calc(100dvh - var(--kh-shell-head) - var(--kh-game-dock-height) - 20px));
    max-height: calc(100dvh - var(--kh-shell-head) - var(--kh-game-dock-height) - 20px);
  }
}
