.kh-room-grid-host {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  /* Let large rooms extend beyond their own layout box. The stage viewport
     clips the final camera view; clipping here cuts away tiles during a pan. */
  overflow: visible;
  transform: translate(calc(0% - var(--kh-room-grid-shift-x, 0%)), calc(0% - var(--kh-room-grid-raise, 0%)));
}
.kh-room-grid-host[hidden] { display: none !important; }
.kh-room-grid { display: block; width: 100%; height: 100%; overflow: visible; }
.kh-room-grid-shadow { fill: rgba(63, 54, 40, .16); filter: blur(1.4px); }
.kh-room-floor-tile {
  fill: var(--room-floor-base, #b98249);
  stroke: rgba(73, 62, 43, .24);
  stroke-width: .34;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 .16px .12px rgba(60, 42, 20, .14));
}
.kh-room-wall {
  stroke: rgba(83, 61, 42, .32);
  stroke-width: .22;
  vector-effect: non-scaling-stroke;
}
.kh-room-wall.is-north { filter: brightness(1.08); }
.kh-room-wall.is-west { filter: brightness(.88); }
.kh-room-grid.is-editable .kh-room-wall[data-room-door-wall] { cursor: pointer; }
.kh-room-grid.is-editable .kh-room-wall-hit:hover { fill: rgba(255, 248, 206, .16) !important; }
.kh-room-door-frame { stroke: #173d32; stroke-width: .58; vector-effect: non-scaling-stroke; }
.kh-room-door-panel { stroke: #104a39; stroke-width: .38; vector-effect: non-scaling-stroke; }
.kh-room-door-arch-trim { stroke: #9b712f; stroke-width: .3; vector-effect: non-scaling-stroke; }
.kh-room-door-window { stroke: #397e79; stroke-width: .3; vector-effect: non-scaling-stroke; }
.kh-room-door-mullion { fill: none; stroke: #f6e6b2; stroke-width: .42; vector-effect: non-scaling-stroke; }
.kh-room-door-kickplate { stroke: #805b2a; stroke-width: .25; vector-effect: non-scaling-stroke; }
.kh-room-grid-door-button {
  position: absolute;
  z-index: 3;
  width: clamp(28px, 5.4cqw, 60px);
  height: clamp(42px, 10cqh, 100px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  transform: translate(-50%, -52%);
  cursor: pointer;
  pointer-events: auto;
}
.kh-room-grid-door-button:hover { background: rgba(245, 211, 92, .14); box-shadow: 0 0 0 2px rgba(255, 224, 101, .55); }
.kh-room-grid-door-button:focus-visible { outline: 3px solid #ffe16a; outline-offset: 1px; }
body .kh-public-exit[hidden] { display: none !important; }
.kh-room-grid-target {
  fill: rgba(255, 222, 78, .27);
  stroke: #fff9c7;
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 2px rgba(255, 221, 58, .95));
  pointer-events: none;
  transition: fill .1s ease, stroke .1s ease;
}
.kh-room-grid-target.is-pinned {
  fill: rgba(255, 222, 78, .4);
  stroke: #fff4a3;
  stroke-width: 1.6;
  filter: drop-shadow(0 0 4px rgba(255, 213, 42, .98));
}
.kh-room-grid-target[data-mode="placing"] { fill: rgba(123, 230, 94, .28); stroke: #d8ff9b; }
.kh-room-grid-target[data-mode="placing"].is-invalid { fill: rgba(239, 92, 65, .27); stroke: #ffb098; }
.kh-client[data-room-grid-active="true"] .kh-walk-target { display: none !important; }
.kh-client[data-room-grid-active="true"] .kh-placement-grid { display: none !important; }
.kh-client[data-room-grid-active="true"] .kh-guest,
.kh-client[data-room-grid-active="true"] .kh-world-npc {
  left: calc(var(--guest-x, 50%) - var(--kh-room-grid-shift-x, 0%));
  top: calc(var(--guest-y, 75%) - var(--kh-room-grid-raise) + var(--kh-room-grid-tile-half-y, 0%));
}
.kh-client[data-room-grid-active="true"] .kh-remote-guest {
  left: calc(var(--guest-x, 50%) - var(--kh-room-grid-shift-x, 0%));
  top: calc(var(--guest-y, 75%) - var(--kh-room-grid-raise) + var(--kh-room-grid-tile-half-y, 0%));
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture {
  left: calc(var(--item-x, 50%) - var(--kh-room-grid-shift-x, 0%));
  top: calc(var(--item-y, 50%) - var(--kh-room-grid-raise) + var(--item-room-grid-anchor-y, var(--kh-room-grid-tile-half-y, 0%)));
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted {
  transform: translate(-50%, -50%) skewY(var(--kh-wall-item-skew, var(--kh-wall-plane-skew-north, 20deg))) scaleX(var(--item-mirror, 1));
  transform-origin: center center;
  filter: drop-shadow(0 1px 1px rgba(34, 30, 23, .2));
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted.is-wall-direction-variant {
  transform: translate(-50%, -50%);
  filter: none;
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted.is-image-furniture {
  background-position: center center;
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted.is-native-wall-art {
  transform: translate(-50%, -50%) scaleX(var(--item-mirror, 1));
  filter: none;
}
/* Uploaded floor images already contain their drawn perspective. Keep their
   source/crop pixels and ratio, independently of the walkable tile footprint. */
.kh-client .kh-placed-furniture.is-native-floor-art {
  min-width: 0;
  min-height: 0;
  height: auto;
  padding: 0;
  image-rendering: pixelated;
  transform: translate(-50%, calc(var(--item-anchor-y, -94%) - var(--item-stack-z, 0px))) scaleX(var(--item-mirror, 1));
}
/* Farm furniture is already drawn in the floor's perspective. Its world
   width follows the reserved tiles; the registered ground point stays on
   their projected center. Never skew the supplied illustration. */
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-farm-tile-art {
  left: var(--item-x);
  top: var(--item-y);
  min-width: 0;
  min-height: 0;
  height: auto;
  padding: 0;
  transform-origin: 50% var(--item-art-origin-y, 85%);
  transform: translate(var(--item-art-anchor-x, -50%), calc(var(--item-anchor-y, -85%) - var(--item-stack-z, 0px))) scale(var(--item-mirror, 1), var(--item-floor-scale-y, 1));
  filter: none;
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted[data-wall-side="north"] {
  --kh-wall-item-skew: var(--kh-wall-plane-skew-north, 20deg);
}
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-wall-mounted[data-wall-side="west"] {
  --kh-wall-item-skew: var(--kh-wall-plane-skew-west, -20deg);
}
.kh-client[data-room-grid-active="true"] .kh-wall-photo-frame.is-wall-mounted {
  transform: translate(-50%, -50%) skewY(var(--kh-wall-item-skew, var(--kh-wall-plane-skew-north, 20deg)));
  transform-origin: center center;
  box-shadow: 0 1px 2px rgba(34, 30, 23, .24);
}
.kh-client[data-room-grid-active="true"] .kh-wall-photo-frame.is-wall-mounted[data-wall-side="north"] {
  --kh-wall-item-skew: var(--kh-wall-plane-skew-north, 20deg);
}
.kh-client[data-room-grid-active="true"] .kh-wall-photo-frame.is-wall-mounted[data-wall-side="west"] {
  --kh-wall-item-skew: var(--kh-wall-plane-skew-west, -20deg);
}
.kh-client[data-room-grid-active="true"] .kh-wall-photo-frame {
  left: calc(var(--photo-x, 50%) - var(--kh-room-grid-shift-x, 0%));
  top: calc(var(--photo-y, 50%) - var(--kh-room-grid-raise));
}
.kh-client[data-room-grid-active="true"] .kh-walk-target {
  left: calc(var(--target-x, 50%) - var(--kh-room-grid-shift-x, 0%));
  top: calc(var(--target-y, 75%) - var(--kh-room-grid-raise));
}
.kh-client[data-room-grid-active="true"] .kh-placement-preview::after { display: none !important; }
.kh-client[data-room-grid-active="true"] .kh-placed-furniture:hover,
.kh-client[data-room-grid-active="true"] .kh-placed-furniture.is-selected {
  outline: none !important;
}
.kh-client[data-room-grid-active="true"] .kh-stage {
  background: #080c0a;
}
.kh-client[data-room-grid-active="true"] .kh-stage-shade { background: transparent; }
.kh-client[data-room-grid-active="true"] .kh-help-bubble { z-index: 40; }
.kh-room-preview .kh-room-grid { position: absolute; inset: 0; }
.kh-room-preview { position: relative; overflow: hidden; }

.kh-room-builder {
  width: min(980px, calc(100vw - 30px));
  max-width: 980px;
  max-height: min(92dvh, 900px);
  padding: 0;
  overflow: hidden;
}
.kh-room-builder[open] { display: flex; flex-direction: column; }
.kh-room-builder .kh-modal-titlebar { flex: 0 0 auto; }
.kh-room-builder-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .94fr);
  gap: 18px;
  min-height: 0;
  padding: 18px;
  overflow: auto;
}
.kh-room-builder-controls,
.kh-room-builder-preview-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid #c9dfa8;
  border-radius: 16px;
  background: #f7fae9;
}
.kh-room-builder-controls { display: grid; gap: 12px; align-content: start; }
.kh-room-builder-controls label { display: grid; gap: 6px; color: #244f3c; font-size: 13px; font-weight: 700; }
.kh-room-builder-controls :is(input, select) {
  width: 100%; min-height: 42px; padding: 8px 11px; border: 1px solid #a4ca76; border-radius: 10px;
  background: #fffef6; color: #174636; font: inherit;
}
.kh-room-builder-hint { margin: 0; color: #55725c; font-size: 13px; line-height: 1.45; }
.kh-room-builder-templates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kh-room-builder-template-section { display: grid; gap: 8px; }
.kh-room-builder-template-section > strong { color: #244f3c; font-size: 13px; }
.kh-room-builder-templates button,
.kh-room-builder-actions button,
.kh-room-builder-size button {
  min-height: 38px; border: 1px solid #9cc66b; border-radius: 10px; padding: 8px 10px;
  background: #fffef5; color: #20583d; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer;
}
.kh-room-builder-templates button[aria-pressed="true"] { color: #fff; border-color: #2d842f; background: linear-gradient(#58bd43, #328f34); }
.kh-room-builder-size { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kh-room-builder-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 3px; }
.kh-room-builder-actions [data-room-builder-save] { color: #fff; border-color: #267b31; background: linear-gradient(#4bb83d, #278634); }
.kh-room-builder-actions button:disabled { opacity: .55; cursor: wait; }
.kh-room-builder-status { min-height: 18px; margin: 0; color: #52705b; font-size: 12px; }
.kh-room-builder-status.is-error { color: #a33721; }
.kh-room-builder-preview-card { display: flex; flex-direction: column; gap: 12px; }
.kh-room-builder-preview-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.kh-room-builder-preview-head strong { color: #174636; }
.kh-room-builder-preview-head span { color: #67816a; font-size: 12px; }
.kh-room-builder-canvas {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 340px;
  padding: 12px;
  overflow: auto;
  border: 1px solid #d4e3bd;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 45%, #fffdf0, #e9f1d4);
}
.kh-room-builder-canvas .kh-room-grid { width: min(100%, 520px); height: auto; aspect-ratio: 84 / 53; overflow: visible; }
.kh-room-grid.is-preview .kh-room-floor-tile { pointer-events: auto; cursor: pointer; transition: fill .12s ease, opacity .12s ease; }
.kh-room-grid.is-preview .kh-room-floor-tile:hover { filter: brightness(1.16); }
.kh-room-grid.is-preview .kh-room-floor-tile.is-empty { fill: rgba(116, 161, 78, .09); stroke: rgba(81, 142, 50, .45); stroke-dasharray: 1.4 1.2; }
.kh-room-grid.is-preview .kh-room-floor-tile.is-empty:hover { fill: rgba(93, 182, 63, .36); }
.kh-room-builder-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; color: #55725c; font-size: 11px; }
.kh-room-builder-legend span { display: inline-flex; gap: 6px; align-items: center; }
.kh-room-builder-legend i { width: 12px; height: 12px; border: 1px solid #8bb757; border-radius: 3px; background: #b98249; }
.kh-room-builder-legend .is-empty { background: #edf4df; border-style: dashed; }
.kh-room-builder-legend .is-door { border-color: #174b3c; background: #38a477; }
.kh-room-grid-host.is-editable { pointer-events: auto; }
.kh-room-builder [data-room-builder-mode="existing"][hidden],
.kh-room-builder [data-room-builder-mode="new"][hidden] { display: none !important; }

/* The shared game-modal rule deliberately keeps most dialogs compact. The
   room builder needs its own workspace so the controls and room preview can
   be used side by side without wrapping into a thin column. */
body.kwakencity-client .kh-room-builder[open] {
  --kh-window-scale: 1 !important;
  left: 50%;
  right: auto;
  width: min(1120px, calc(100vw - 36px)) !important;
  max-width: none !important;
  max-height: min(850px, calc(100dvh - var(--kh-shell-head, 0px) - 36px)) !important;
  padding: 0 !important;
  overflow: hidden;
}
.kh-room-builder-body {
  grid-template-columns: minmax(330px, .82fr) minmax(0, 1.18fr);
  gap: 16px;
  padding: 18px;
  overflow: auto;
}
.kh-room-builder-controls,
.kh-room-builder-preview-card { box-sizing: border-box; }
.kh-room-builder-controls { gap: 13px; }
.kh-room-builder-controls > [data-room-builder-mode],
.kh-room-builder-template-section { min-width: 0; }
.kh-room-builder-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 5px;
  border: 1px solid #d3e5b4;
  border-radius: 13px;
  background: #edf5dd;
}
.kh-room-builder-mode button {
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #a7ca7c;
  border-radius: 9px;
  color: #28583a;
  background: #fffef5;
  font: inherit;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.2;
  cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease, transform .15s ease;
}
.kh-room-builder-mode button:hover { border-color: #4a9b3a; transform: translateY(-1px); }
.kh-room-builder-mode button[aria-pressed="true"] {
  border-color: #2d842f;
  color: #fff;
  background: linear-gradient(145deg, #56b942, #328f34);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.32), 0 2px 0 #276e2c;
}
.kh-room-builder-controls label { min-width: 0; }
.kh-room-builder-controls :is(input, select) { box-sizing: border-box; min-width: 0; }
.kh-room-builder-templates button,
.kh-room-builder-size button,
.kh-room-builder-actions button { min-width: 0; line-height: 1.25; }
.kh-room-builder-actions [data-room-builder-save] { min-height: 44px; flex: 1 1 190px; }
.kh-room-builder-actions [data-room-builder-close] { flex: 0 1 120px; }
.kh-room-builder-preview-card { min-height: 0; padding: 18px; }
.kh-room-builder-preview-head { align-items: flex-start; }
.kh-room-builder-preview-head strong { font-size: 16px; }
.kh-room-builder-preview-head span { flex: 0 1 auto; text-align: right; }
.kh-room-builder-canvas {
  min-height: clamp(360px, 54vh, 520px);
  overflow: hidden;
  padding: 18px;
}
.kh-room-builder-canvas .kh-room-grid { width: min(100%, 700px); }

@media (max-width: 920px) {
  body.kwakencity-client .kh-room-builder[open] {
    width: min(820px, calc(100vw - 28px)) !important;
    max-height: calc(100dvh - var(--kh-shell-head, 0px) - var(--kh-game-dock-height, 0px) - 24px) !important;
  }
  .kh-room-builder-body { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .kh-room-builder-canvas { min-height: clamp(280px, 42vh, 420px); }
}

@media (max-width: 700px) {
  body.kwakencity-client .kh-room-builder[open] {
    left: 6px;
    right: 6px;
    top: calc(var(--kh-shell-head) + 6px);
    bottom: calc(var(--kh-game-dock-height) + 6px);
    width: auto !important;
    max-height: none !important;
    padding: 0 !important;
    overflow: hidden;
    transform: none !important;
  }
  .kh-room-builder-body { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px; }
  .kh-room-builder-controls, .kh-room-builder-preview-card { padding: 12px; border-radius: 13px; }
  .kh-room-builder-canvas { min-height: 240px; }
  .kh-room-builder-canvas .kh-room-grid { width: min(100%, 420px); }
  .kh-room-builder-mode button { min-height: 40px; padding-inline: 7px; }
  .kh-room-builder-actions [data-room-builder-save] { flex-basis: 160px; }
}
