:root {
  color-scheme: light;
  --bg: #e7e2d6;
  --panel: #f6f1e7;
  --panel-strong: #fffaf0;
  --ink: #24302f;
  --muted: #66706b;
  --line: #bdb4a4;
  --line-dark: #8b8173;
  --teal: #2d746e;
  --teal-dark: #1e5350;
  --gold: #d79a43;
  --red: #b85f56;
  --floor: #98765e;
  --shadow: 0 16px 38px rgba(36, 48, 47, 0.22);
  font-family: "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(53, 82, 80, 0.16), transparent 32%),
    linear-gradient(120deg, rgba(215, 154, 67, 0.16), transparent 38%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid color-mix(in srgb, var(--line), var(--ink) 8%);
  background: var(--panel-strong);
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: var(--teal);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.command-bar {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) auto minmax(320px, 1.2fr) minmax(390px, 1.5fr);
  align-items: center;
  gap: 14px;
  min-height: 78px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(246, 241, 231, 0.92);
  backdrop-filter: blur(14px);
}

.brand-block h1,
.inspector h2 {
  margin: 0;
  line-height: 1;
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: clamp(22px, 2.2vw, 34px);
}

.eyebrow {
  display: block;
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.accent,
.filter-button.active,
.mode-button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff9ed;
}

.mode-switch {
  display: inline-flex;
  gap: 6px;
  justify-self: start;
}

.mode-switch button {
  white-space: nowrap;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: var(--line);
  overflow: hidden;
}

.status-strip div {
  min-width: 0;
  padding: 9px 11px;
  background: rgba(255, 250, 240, 0.9);
}

.status-strip span {
  display: block;
  font-size: clamp(18px, 2vw, 25px);
  font-weight: 850;
  line-height: 1;
}

.status-strip small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(230px, 22vw, 320px);
  gap: 14px;
  padding: 14px;
}

.room-wrap {
  min-width: 0;
  display: grid;
  align-items: center;
}

.room-stage {
  position: relative;
  width: min(100%, calc((100dvh - 270px) * 16 / 9));
  max-width: 100%;
  aspect-ratio: 16 / 9;
  margin: auto;
  overflow: hidden;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  background: #d3cbbf;
  box-shadow: var(--shadow);
  isolation: isolate;
  touch-action: none;
}

.room-anchor-image {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.room-anchor-image:not([hidden]) ~ .room-wall,
.room-anchor-image:not([hidden]) ~ .room-floor,
.room-anchor-image:not([hidden]) ~ .floor-grid {
  opacity: 0;
}

.room-stage.receiving {
  outline: 3px solid rgba(215, 154, 67, 0.72);
  outline-offset: 3px;
}

.room-wall {
  position: absolute;
  inset: 0 0 32%;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.22), transparent 32%),
    linear-gradient(180deg, #d8d5ca, #a7b9b1 68%, #879d94);
}

.wall-panel {
  position: absolute;
  left: 7%;
  right: 7%;
  top: 13%;
  bottom: 18%;
  border: 2px solid rgba(63, 75, 72, 0.24);
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.14) 0 2px, transparent 2px 92px),
    rgba(247, 241, 226, 0.25);
}

.wall-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16%;
  height: 18px;
  background: #62736e;
  border-top: 3px solid #9b8868;
  border-bottom: 2px solid rgba(37, 46, 45, 0.28);
}

.room-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  background:
    linear-gradient(165deg, rgba(255,255,255,0.16), transparent 26%),
    repeating-linear-gradient(0deg, rgba(60, 69, 66, 0.1) 0 2px, transparent 2px 42px),
    linear-gradient(180deg, #b68d66, var(--floor));
  clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%);
}

.floor-grid {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 5%;
  height: 35%;
  background-image:
    linear-gradient(rgba(255,255,255,0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.16) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.55;
  transform: skewX(-11deg);
  pointer-events: none;
}

.instance-layer {
  position: absolute;
  inset: 0;
}

.placement-zone {
  position: absolute;
  z-index: 2;
  border: 2px dashed rgba(215, 154, 67, 0.86);
  background: rgba(215, 154, 67, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.28);
  pointer-events: none;
}

.placement-zone[data-surface="wall"] {
  border-color: rgba(45, 116, 110, 0.82);
  background: rgba(45, 116, 110, 0.12);
}

.placement-zone[data-surface="ceiling"] {
  border-color: rgba(102, 112, 107, 0.82);
  background: rgba(102, 112, 107, 0.12);
}

.placement-feedback {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 120;
  min-height: 28px;
  padding: 6px 10px;
  border: 1px solid rgba(36, 48, 47, 0.22);
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.86);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.selection-tools {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 130;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(36, 48, 47, 0.2);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  box-shadow: 0 12px 24px rgba(36, 48, 47, 0.18);
}

.selection-tools button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 760;
}

.placed-item {
  position: absolute;
  width: var(--w);
  height: var(--h);
  transform: translate(-50%, -100%);
  object-fit: contain;
  cursor: grab;
  user-select: none;
  touch-action: none;
  filter: drop-shadow(0 14px 10px rgba(34, 42, 40, 0.22));
}

.placed-item.active {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.placed-item.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 20px 16px rgba(34, 42, 40, 0.34));
}

.drag-ghost {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  transform: translate(-50%, -100%);
  opacity: 0.82;
  filter: drop-shadow(0 22px 18px rgba(34, 42, 40, 0.34));
}

.drag-ghost img {
  display: block;
  object-fit: contain;
}

.review-watermark {
  position: absolute;
  inset: auto -8% 9% auto;
  transform: rotate(-15deg);
  color: rgba(255, 250, 242, 0.42);
  font-size: clamp(58px, 10vw, 150px);
  font-weight: 900;
  pointer-events: none;
  mix-blend-mode: overlay;
}

.inspector {
  min-width: 0;
  align-self: stretch;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(246, 241, 231, 0.88);
  padding: 14px;
}

.inspector p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.orientation-reference {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.control-pack-image {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  border: 1px solid rgba(139, 129, 115, 0.42);
  background: #00ff00;
}

.inspector-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.detail-list,
.gate-list {
  display: grid;
  gap: 7px;
}

.detail-row,
.gate-item {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.detail-row span,
.gate-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-row strong,
.gate-item strong {
  display: block;
  margin-top: 3px;
  line-height: 1.32;
}

.gate-item.blocked strong {
  color: var(--red);
}

.gate-panel {
  margin-top: 14px;
}

.asset-dock {
  min-width: 0;
  padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(246, 241, 231, 0.94);
  backdrop-filter: blur(14px);
}

.dock-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 260px);
  align-items: end;
  gap: 12px;
  margin-bottom: 8px;
}

.filter-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filter-row button {
  white-space: nowrap;
}

.search-box {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf2;
  color: var(--ink);
  padding: 0 10px;
}

.asset-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(136px, 158px);
  gap: 9px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  padding-bottom: 3px;
}

.asset-card {
  position: relative;
  display: grid;
  grid-template-columns: 62px 1fr;
  grid-template-rows: 62px auto;
  column-gap: 8px;
  min-height: 102px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.82);
  text-align: left;
  scroll-snap-align: start;
  touch-action: none;
}

.asset-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(45, 116, 110, 0.18);
}

.asset-frame {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid rgba(139, 129, 115, 0.35);
  background: rgba(231, 226, 214, 0.58);
}

.asset-thumb {
  width: 58px;
  height: 58px;
  object-fit: contain;
  pointer-events: none;
}

.asset-meta {
  min-width: 0;
}

.asset-card h3 {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.12;
}

.asset-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.asset-count,
.asset-plus {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  font-weight: 850;
}

.asset-count {
  right: 8px;
  bottom: 8px;
  background: #e5d6bd;
  color: var(--teal-dark);
}

.asset-plus {
  right: 8px;
  top: 8px;
  background: var(--teal);
  color: #fff9ed;
  font-size: 18px;
}

@media (orientation: landscape) and (max-height: 720px) {
  .app-shell {
    height: 100dvh;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr) 114px;
  }

  .command-bar {
    min-height: 48px;
    grid-template-columns: 120px auto minmax(260px, 1fr) auto;
    gap: 9px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: 6px;
  }

  .brand-block h1 {
    font-size: 20px;
  }

  .eyebrow {
    margin-bottom: 3px;
  }

  .status-strip div {
    padding: 6px 8px;
  }

  .status-strip span {
    font-size: 18px;
  }

  .status-strip small {
    margin-top: 2px;
    font-size: 10px;
  }

  .toolbar button {
    min-height: 30px;
    padding: 0 8px;
  }

  .toolbar {
    max-width: 340px;
    gap: 5px;
  }

  .mode-switch button {
    min-height: 30px;
    padding: 0 8px;
  }

  .workspace {
    min-height: 0;
    overflow: hidden;
    grid-template-columns: minmax(0, 1fr) 220px;
    padding: 8px;
    gap: 8px;
  }

  .room-stage {
    width: min(100%, calc((100dvh - 210px) * 16 / 9));
  }

  .inspector {
    padding: 10px;
    overflow: auto;
  }

  .control-pack-image {
    max-height: 84px;
  }

  .selection-tools {
    left: 8px;
    right: 8px;
    bottom: 8px;
    justify-content: center;
  }

  .selection-tools button {
    min-width: 0;
    flex: 1;
    padding: 0 6px;
  }

  .detail-row,
  .gate-item {
    padding: 6px 0;
  }

  .asset-dock {
    height: 114px;
    overflow: hidden;
    padding-top: 7px;
    padding-bottom: max(7px, env(safe-area-inset-bottom));
  }

  .dock-head {
    grid-template-columns: minmax(0, 1fr) 190px;
    margin-bottom: 6px;
  }

  .asset-list {
    grid-auto-columns: minmax(118px, 136px);
  }

  .asset-card {
    min-height: 70px;
    grid-template-columns: 46px 1fr;
    grid-template-rows: 46px auto;
    padding: 6px;
  }

  .asset-thumb {
    width: 42px;
    height: 42px;
  }

  .asset-card h3 {
    font-size: 12px;
  }

  .asset-card p {
    font-size: 10px;
  }

  .asset-count,
  .asset-plus {
    min-width: 21px;
    height: 21px;
  }
}

@media (orientation: portrait) {
  .app-shell {
    grid-template-rows: auto auto auto auto;
  }

  .command-bar {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .toolbar {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .toolbar button {
    white-space: nowrap;
    min-height: 38px;
  }

  .status-strip {
    grid-template-columns: repeat(4, minmax(82px, 1fr));
    overflow-x: auto;
  }

  .workspace {
    display: contents;
  }

  .room-wrap {
    grid-row: 2;
    padding: 10px 10px 0;
  }

  .room-stage {
    width: 100%;
  }

  .asset-dock {
    grid-row: 3;
    margin-top: 10px;
  }

  .inspector {
    grid-row: 4;
    margin: 10px;
    max-height: none;
  }

  .dock-head {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .asset-list {
    grid-auto-columns: minmax(124px, 140px);
  }

  .asset-card {
    min-height: 94px;
    grid-template-columns: 54px 1fr;
    grid-template-rows: 54px auto;
  }

  .asset-thumb {
    width: 50px;
    height: 50px;
  }
}
