/* Isolate the modular rig from the complete legacy skin sheets. */
/* Rasterize standing world sprites at their final perspective size, as in
   the info stand. Scaling an already rasterized sprite softened its ink. */
body .kh-guest:not(.is-sitting) {
  width: calc(7cqw * var(--guest-scale, 1));
  transform: translate(-50%, -100%);
  will-change: auto;
  transition: left var(--walk-time, 1600ms) linear,
    top var(--walk-time, 1600ms) linear, width var(--walk-time, 1600ms) linear;
}
[data-avatar-renderer="modular"] { overflow: visible; }
body [data-avatar-renderer="modular"] > .kh-sprite-flip { visibility: hidden !important; animation: none !important; }
body [data-avatar-pending="true"] > .kh-sprite-flip { visibility: hidden !important; }
/* Once a modular preview is requested, its old complete skin is not a valid
   placeholder. Keep an already decoded modular sheet visible during retries. */
body [data-clothing-preview][data-avatar-load="loading"] > .kh-sprite-flip,
body [data-profile-avatar-node][data-avatar-load="loading"] > .kh-sprite-flip { visibility: hidden !important; }
body [data-avatar-renderer="modular"] > .kc-avatar-sheet {
  position: absolute; left: 0; bottom: 0; width: 100%; height: auto; aspect-ratio: 1;
  display: block; pointer-events: none; background-repeat: no-repeat; background-position: 0 0;
  image-rendering: auto; animation: none !important; transform: none; z-index: 1;
}
/* Match the visible character size of the existing NPC sheets. Scale the
   complete world frame together; portraits and individual rig parts keep
   their native proportions, and the host's floor anchor stays unchanged. */
body .kh-guest[data-avatar-renderer="modular"] { width: 7.84cqw; }
body .kh-guest[data-avatar-renderer="modular"]:not(.is-sitting) { width: calc(7.84cqw * var(--guest-scale, 1)); }
body .kh-guest[data-avatar-renderer="modular"].is-sitting {
  width: calc(7.84cqw * var(--guest-scale, 1));
  transform: translate(-50%, calc(-100% + var(--seat-pose-y, 0cqw)));
  will-change: auto;
}
body .kh-guest[data-avatar-renderer="modular"].is-sitting[data-seat-kind="ground"] { transform: translate(-50%, -100%); }
body .kh-guest[data-avatar-renderer="modular"] > .kc-avatar-sheet {
  bottom: calc(0% - var(--kc-avatar-foot-padding, 8.854167%));
  transform: none;
}
body .kh-guest[data-avatar-renderer="modular"].is-sitting > .kh-sprite-flip { aspect-ratio: 1 !important; }
.kc-wardrobe { margin: 0 0 22px; padding: 17px; border: 1px solid #bed887; border-radius: 18px; background: #f7fbe9; color: #164b47; }
.kc-wardrobe h3 { margin: 0; font-size: 20px; }
.kc-wardrobe p { margin: 7px 0 13px; font-size: 12px; line-height: 1.5; }
.kc-wardrobe-toolbar, .kc-wardrobe-colors, .kc-wardrobe-slots { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; margin: 11px 0; }
.kc-wardrobe button { font: inherit; cursor: pointer; }
.kc-wardrobe-toolbar button, .kc-wardrobe-slots button, .kc-wardrobe-colors button { padding: 7px 11px; background: #fffef5; color: #245c50; border: 1px solid #b3cd8f; border-radius: 10px; font-size: 12px; }
.kc-wardrobe button[aria-pressed="true"] { background: #d8efb1; border-color: #318c33; box-shadow: inset 0 0 0 1px #318c33; }
.kc-wardrobe-colors button { display: inline-flex; align-items: center; gap: 6px; }
.kc-wardrobe-colors i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid #667458; display: inline-block; background: var(--kc-base-swatch); }
.kc-wardrobe-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; max-height: 430px; overflow: auto; padding: 2px; }
.kc-wardrobe-item { display: flex; flex-direction: column; border: 1px solid #cadaae; border-radius: 13px; background: #fffef7; overflow: hidden; min-width: 0; }
.kc-wardrobe-item.is-selected { border-color: #388c36; box-shadow: 0 0 0 1px #388c36; }
.kc-wardrobe-item > button:first-child { display: flex; flex: 1; flex-direction: column; align-items: center; padding: 6px 7px 9px; border: 0; color: #174e47; background: transparent; }
.kc-wardrobe-item img, .kc-wardrobe-item canvas { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; display: block; }
.kc-wardrobe-item strong { font-size: 12px; text-align: center; }
.kc-wardrobe-item small { color: #64784d; margin-top: 4px; font-size: 10px; }
.kc-wardrobe-buy { margin: 0 7px 8px; padding: 6px; border: 1px solid #9dbd60; border-radius: 8px; background: #e6f5bd; color: #315615; font-size: 11px !important; }
.kc-wardrobe-save { width: 100%; padding: 11px 16px; margin-top: 13px; border-radius: 11px; border: 1px solid #23772a; background: linear-gradient(#52b735,#31922b); color: #fff; font-weight: 800 !important; }
.kc-wardrobe button:disabled { opacity: .58; cursor: default; }
.kc-wardrobe-status { display: block; min-height: 18px; margin-top: 9px; font-size: 12px; line-height: 1.4; }
.kc-wardrobe-status.is-error { color: #a73825; }
.kc-wardrobe-empty { grid-column: 1 / -1; padding: 18px; text-align: center; }
[data-self-avatar-mode="modular"] .kh-avatar-options { display: none; }
@media (max-width: 650px) { .kc-wardrobe { padding: 12px; } .kc-wardrobe-items { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 360px; } }

/* Keep the dressing window and its preview still. The complete clothing
   choices, including older skins, share one scroll area above a fixed action. */
body .kh-dialog.kh-dressing-dialog[open] {
  --kh-window-scale: 1 !important;
  --kh-titlebar-inset-top: 18px;
  --kh-titlebar-inset-inline-start: 18px;
  --kh-titlebar-inset-inline-end: 18px;
  position: fixed;
  display: flex;
  flex-direction: column;
  left: 50%;
  right: auto;
  top: calc(var(--kh-shell-head, 58px) + (100dvh - var(--kh-shell-head, 58px) - var(--kh-game-dock-height, 82px)) / 2);
  bottom: auto;
  width: min(960px, calc(100vw - 24px)) !important;
  max-width: none !important;
  height: min(760px, calc(100dvh - var(--kh-shell-head, 58px) - var(--kh-game-dock-height, 82px) - 20px)) !important;
  min-height: 0 !important;
  max-height: calc(100dvh - 20px) !important;
  margin: 0;
  padding: 18px;
  overflow: hidden;
  transform: translate(-50%, -50%) !important;
}
body .kh-dressing-dialog > :not(.kh-dressing-layout) { flex: 0 0 auto; }
body .kh-dressing-dialog > .kh-dressing-intro { margin-bottom: 10px !important; }
body .kh-dressing-dialog > .kh-dressing-layout {
  flex: 1 1 0;
  min-height: 0;
  grid-template-columns: minmax(225px, .72fr) minmax(0, 1.65fr);
  align-items: stretch;
  gap: 12px;
}
body .kh-dressing-dialog .kh-dressing-customization,
body .kh-dressing-dialog .kh-dressing-collection {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
body .kh-dressing-dialog .kh-dressing-collection { padding: 0; border: 0; background: transparent; box-shadow: none; }
body .kh-dressing-collection:has(> .kc-wardrobe) > .kh-clothing-heading { display: none; }
body .kh-dressing-dialog .kh-clothing-preview {
  position: relative;
  flex: 1 1 205px;
  height: auto;
  min-height: 80px;
  max-height: 205px;
  margin-bottom: 8px;
  container-type: size;
}
body .kh-dressing-dialog .kh-clothing-preview .kh-profile-kwaker {
  width: min(175px, 78%, 100cqh);
  margin-bottom: 0;
}
body .kh-dressing-dialog .kh-clothing-preview:has([data-avatar-load="loading"]:not([data-avatar-committed="true"]))::after {
  content: 'Voorbeeld laden…';
  position: absolute;
  right: 4px;
  bottom: 4px;
  left: 4px;
  padding: 5px;
  border: 1px solid #b5cc8d;
  border-radius: 7px;
  color: #365c3c;
  background: #fffdf0;
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  pointer-events: none;
}
body .kh-dressing-dialog .kh-clothing-preview:has([data-avatar-load="loading"][data-avatar-error="unavailable"]:not([data-avatar-committed="true"]))::after { content: 'Voorbeeld even niet beschikbaar.'; }
body .kh-dressing-dialog .kh-motto-editor {
  flex: 0 0 auto;
  gap: 6px;
  margin-top: 8px;
  padding: 9px;
}
body .kh-dressing-dialog .kh-motto-editor label { grid-column: 1; grid-row: 1; }
body .kh-dressing-dialog .kh-motto-editor > span { grid-column: 2; grid-row: 1; text-align: right; }
body .kh-dressing-dialog .kh-motto-editor input { grid-column: 1; grid-row: 2; min-width: 0; width: 100%; }
body .kh-dressing-dialog .kh-motto-editor button { grid-column: 2; grid-row: 2; align-self: center; }
body .kh-dressing-dialog .kh-motto-editor small { grid-row: 3; }
.kc-wardrobe { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
body .kh-dressing-dialog .kc-wardrobe { flex: 1 1 0; margin: 0; padding: 12px; }
.kc-wardrobe > h3, .kc-wardrobe > p, .kc-wardrobe-footer { flex: 0 0 auto; }
.kc-wardrobe > p { margin-bottom: 8px; }
.kh-dressing-choice-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 2px 4px 7px 2px;
}
.kh-dressing-choice-scroll:focus-visible { outline: 2px solid #8fba69; outline-offset: -2px; }
.kh-dressing-choice-scroll > .kh-avatar-options { margin: 0 0 10px; padding-bottom: 10px; border-bottom: 1px solid #cddfac; }
.kh-dressing-choice-scroll .kc-wardrobe-items {
  max-height: none;
  overflow: visible;
  align-items: start;
}
body .kh-dressing-choice-scroll .kh-skin-grid {
  max-height: none;
  overflow: visible;
  margin-top: 7px;
}
.kc-wardrobe-legacy-heading { margin: 17px 0 5px; font-size: 14px; }
.kc-wardrobe-footer { padding-top: 9px; border-top: 1px solid #cddfac; }
.kc-wardrobe-footer .kc-wardrobe-save { margin-top: 0; }
.kc-wardrobe-footer .kc-wardrobe-status { display: block; margin-top: 6px; line-height: 1.35; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  body .kh-dialog.kh-dressing-dialog[open] {
    --kh-titlebar-inset-top: 10px;
    --kh-titlebar-inset-inline-start: 10px;
    --kh-titlebar-inset-inline-end: 10px;
    width: calc(100vw - 12px) !important;
    height: calc(100dvh - var(--kh-shell-head, 54px) - var(--kh-game-dock-height, 78px) - 12px) !important;
    padding: 10px;
  }
  body .kh-dressing-dialog > .kh-dressing-intro { display: none; }
  body .kh-dressing-dialog > .kh-dressing-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
  body .kh-dressing-dialog .kh-dressing-customization {
    display: grid;
    grid-template-columns: minmax(84px, .6fr) minmax(0, 1fr);
    align-items: center;
    column-gap: 9px;
    padding: 8px;
  }
  body .kh-dressing-dialog .kh-clothing-preview { grid-column: 1; grid-row: 1 / span 2; height: 112px; min-height: 0; margin: 0; }
  body .kh-dressing-dialog .kh-avatar-options { grid-column: 2; gap: 3px; }
  body .kh-dressing-dialog .kh-motto-editor { grid-column: 2; margin: 0; padding: 6px; gap: 4px; }
  body .kh-dressing-dialog .kh-motto-editor input { height: 34px; }
  body .kh-dressing-dialog .kh-motto-editor button { height: 32px; padding: 5px 7px; font-size: 10px; }
  body .kh-dressing-dialog .kh-motto-editor small:empty { display: none; }
  body .kh-dressing-dialog .kc-wardrobe { padding: 9px; }
  body .kh-dressing-dialog .kc-wardrobe > h3 { font-size: 17px; }
  body .kh-dressing-dialog .kc-wardrobe > p { margin: 5px 0; font-size: 11px; }
  .kc-wardrobe-footer .kc-wardrobe-save { padding: 10px; }
  .kc-wardrobe-footer .kc-wardrobe-status { font-size: 11px; }
}
@media (max-width: 650px) and (max-height: 720px) and (orientation: portrait) {
  body .kh-dressing-dialog .kc-wardrobe { padding: 7px; }
  body .kh-dressing-dialog .kc-wardrobe > h3 { margin: 0 0 4px; font-size: 16px; line-height: 1.2; }
  body .kh-dressing-dialog .kc-wardrobe > p { display: none; }
}
@media (max-height: 540px) {
  body .kh-dialog.kh-dressing-dialog[open] {
    --kh-titlebar-inset-top: 10px;
    --kh-titlebar-inset-inline-start: 10px;
    --kh-titlebar-inset-inline-end: 10px;
    top: 50%;
    height: calc(100dvh - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    padding: 10px;
  }
  body .kh-dialog.kh-dressing-dialog[open] > .kh-modal-titlebar { min-height: 48px; }
  body .kh-dressing-dialog > .kh-dressing-intro { display: none; }
  body .kh-dressing-dialog > .kh-dressing-layout { grid-template-columns: minmax(180px, .72fr) minmax(0, 1.65fr); grid-template-rows: minmax(0, 1fr); gap: 8px; }
  body .kh-dressing-dialog .kh-dressing-customization { display: flex; padding: 8px; }
  body .kh-dressing-dialog .kh-clothing-preview { flex: 1 1 90px; height: auto; min-height: 50px; margin-bottom: 5px; }
  body .kh-dressing-dialog .kh-avatar-options { gap: 3px; }
  body .kh-dressing-dialog .kh-avatar-options > :is(strong, small) { display: none; }
  body .kh-dressing-dialog .kh-kind-options button { padding: 4px 7px; font-size: 10px; }
  body .kh-dressing-dialog .kh-color-options button { width: 27px; height: 27px; }
  body .kh-dressing-dialog .kh-motto-editor { margin-top: 5px; padding: 6px; }
  body .kh-dressing-dialog .kc-wardrobe > p { display: none; }
  body .kh-dressing-dialog .kc-wardrobe { padding: 8px; }
  body .kh-dressing-dialog .kc-wardrobe > h3 { font-size: 16px; margin-bottom: 5px; }
  .kc-wardrobe-footer { padding-top: 6px; }
  .kc-wardrobe-footer .kc-wardrobe-save { padding: 8px; }
  .kc-wardrobe-footer .kc-wardrobe-status { font-size: 10px; }
}
