:root {
  --msb-gold: #d8b45e;
  --msb-gold-hi: #f3d88f;
  --msb-ink: #100d08;
  --msb-panel: rgba(22, 17, 11, .97);
  --msb-muted: #b9aa8c;
  --msb-safe-top: env(safe-area-inset-top, 0px);
  --msb-safe-right: env(safe-area-inset-right, 0px);
  --msb-safe-bottom: env(safe-area-inset-bottom, 0px);
  --msb-safe-left: env(safe-area-inset-left, 0px);
}

#modular-scene-builder-ui {
  position: fixed;
  inset: 0;
  z-index: 190;
  pointer-events: none;
  font-family: "Crimson Text", Georgia, serif;
}

.msb-workshop {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #11100c;
  color: #f0e4c7;
  pointer-events: auto;
}

.msb-workshop[hidden] {
  display: none;
}

.msb-workshop-head {
  position: relative;
  min-height: calc(66px + var(--msb-safe-top));
  display: grid;
  grid-template-columns: minmax(156px, auto) minmax(0, 1fr) minmax(166px, auto);
  align-items: center;
  gap: 14px;
  padding:
    calc(8px + var(--msb-safe-top))
    max(12px, var(--msb-safe-right))
    8px
    max(12px, var(--msb-safe-left));
  border-bottom: 1px solid rgba(218, 181, 94, .65);
  background:
    linear-gradient(180deg, rgba(45, 34, 19, .97), rgba(17, 13, 8, .98)),
    url("/assets/ui/scene-command-surface.webp");
  background-size: auto, 420px 420px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .66);
}

.msb-workshop-head::after {
  content: "";
  position: absolute;
  top: calc(4px + var(--msb-safe-top));
  right: max(5px, var(--msb-safe-right));
  bottom: 4px;
  left: max(5px, var(--msb-safe-left));
  border: 1px solid rgba(243, 216, 143, .11);
  border-radius: 8px;
  pointer-events: none;
}

.msb-workshop-close,
.msb-workshop-apply {
  position: relative;
  z-index: 1;
  min-height: 46px;
  padding: 7px 13px;
  border: 1px solid rgba(216, 180, 94, .62);
  border-radius: 9px;
  background: linear-gradient(180deg, #44321d, #21180e);
  color: #ead9b2;
  cursor: pointer;
  font: 14px/1.1 "MedievalSharp", Georgia, serif;
  box-shadow: 0 1px 0 rgba(255, 239, 190, .1) inset;
}

.msb-workshop-close:active,
.msb-workshop-apply:active {
  transform: scale(.98);
}

.msb-workshop-apply {
  border-color: #7ca773;
  background: linear-gradient(180deg, #477447, #244524);
  color: #ebf5df;
}

.msb-workshop-apply:disabled {
  cursor: wait;
  filter: grayscale(.6);
  opacity: .56;
}

.msb-workshop-copy {
  position: relative;
  z-index: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.msb-workshop-copy small {
  color: #bda873;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .16em;
}

.msb-workshop-title {
  max-width: 100%;
  overflow: hidden;
  color: var(--msb-gold-hi);
  font: 17px/1.15 "MedievalSharp", Georgia, serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msb-workshop-status {
  max-width: 100%;
  margin-top: 2px;
  overflow: hidden;
  color: var(--msb-muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msb-workshop-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #171712;
}

.msb-inspector {
  position: fixed;
  right: max(18px, var(--msb-safe-right));
  bottom: calc(92px + var(--msb-safe-bottom));
  z-index: 210;
  width: min(390px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid rgba(216, 180, 94, .7);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(35, 27, 16, .97), rgba(13, 10, 7, .98)),
    url("/assets/ui/scene-command-surface.webp");
  background-size: auto, 390px 390px;
  color: #eadfc6;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .68);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.msb-inspector[hidden] {
  display: none;
}

.msb-inspector > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px 10px 14px;
  border-bottom: 1px solid rgba(216, 180, 94, .28);
}

.msb-inspector > header > div {
  min-width: 0;
  flex: 1;
}

.msb-inspector > header small {
  display: block;
  color: #a99775;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .14em;
}

.msb-inspector-name {
  display: block;
  overflow: hidden;
  color: var(--msb-gold-hi);
  font: 18px/1.15 "MedievalSharp", Georgia, serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msb-inspector-close {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(216, 180, 94, .38);
  border-radius: 9px;
  background: rgba(28, 21, 12, .85);
  color: #d5c39f;
  cursor: pointer;
  font-size: 23px;
}

.msb-inspector-summary {
  display: grid;
  grid-template-columns: .75fr 1.35fr;
  gap: 6px;
  padding: 10px 12px 5px;
}

.msb-inspector-summary span {
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 8px;
  border: 1px solid rgba(139, 110, 60, .38);
  border-radius: 8px;
  background: rgba(12, 9, 6, .44);
  color: #aa9b7e;
  font-size: 10px;
}

.msb-inspector-summary span:last-child {
  grid-column: 1 / -1;
}

.msb-inspector-summary b {
  color: #ead8b0;
  font-size: 13px;
  font-weight: 600;
}

.msb-inspector-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 7px 12px 12px;
}

.msb-inspector-actions button {
  min-height: 64px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid rgba(141, 112, 62, .56);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(54, 40, 22, .94), rgba(25, 19, 12, .96));
  color: #e5d5b4;
  text-align: left;
  cursor: pointer;
}

.msb-inspector-actions button > span {
  grid-row: 1 / 3;
  font-size: 21px;
  text-align: center;
}

.msb-inspector-actions button b {
  overflow: hidden;
  font: 13px/1.05 "MedievalSharp", Georgia, serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msb-inspector-actions button small {
  overflow: hidden;
  color: #a99a7d;
  font-size: 9px;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msb-inspector-actions button:hover {
  border-color: var(--msb-gold);
}

.msb-inspector-actions button.danger {
  border-color: rgba(171, 86, 68, .66);
  background: linear-gradient(180deg, rgba(103, 49, 38, .93), rgba(53, 27, 22, .96));
}

.msb-inspector-actions button.danger[data-armed="true"] {
  border-color: #e5826f;
  background: linear-gradient(180deg, #8b3528, #4c1e18);
  animation: msb-armed-pulse 1s ease-in-out infinite alternate;
}

.msb-inspector-actions button:disabled {
  cursor: not-allowed;
  filter: grayscale(.8);
  opacity: .45;
}

.msb-toast {
  position: fixed;
  left: 50%;
  bottom: calc(176px + var(--msb-safe-bottom));
  z-index: 350;
  width: max-content;
  max-width: min(88vw, 560px);
  padding: 9px 14px;
  border: 1px solid rgba(216, 180, 94, .72);
  border-radius: 10px;
  background: rgba(14, 10, 6, .97);
  color: #efdfbd;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .65);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}

.msb-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.msb-toast[data-tone="error"] {
  border-color: rgba(212, 103, 84, .84);
  color: #f0c7bf;
}

.msb-toast[data-tone="ok"] {
  border-color: rgba(108, 164, 96, .84);
  color: #d9efd2;
}

@keyframes msb-armed-pulse {
  from { box-shadow: 0 0 0 rgba(229, 130, 111, 0); }
  to { box-shadow: 0 0 14px rgba(229, 130, 111, .38); }
}

@media (max-width: 720px) {
  .msb-workshop {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .msb-workshop-head {
    min-height: calc(58px + var(--msb-safe-top));
    grid-template-columns: 46px minmax(0, 1fr) minmax(106px, auto);
    gap: 7px;
    padding:
      calc(6px + var(--msb-safe-top))
      max(7px, var(--msb-safe-right))
      6px
      max(7px, var(--msb-safe-left));
  }

  .msb-workshop-close {
    width: 46px;
    min-width: 46px;
    padding: 5px;
    font-size: 21px;
  }

  .msb-workshop-close span {
    display: none;
  }

  .msb-workshop-copy {
    align-items: flex-start;
    text-align: left;
  }

  .msb-workshop-copy small,
  .msb-workshop-status {
    display: none;
  }

  .msb-workshop-title {
    font-size: 14px;
  }

  .msb-workshop-apply {
    min-height: 46px;
    padding: 5px 8px;
    font-size: 11px;
  }

  .msb-inspector {
    right: max(6px, var(--msb-safe-right));
    bottom: calc(80px + var(--msb-safe-bottom));
    left: max(6px, var(--msb-safe-left));
    width: auto;
    max-height: min(64vh, 520px);
    overflow-y: auto;
    border-radius: 14px 14px 11px 11px;
  }

  .msb-inspector > header {
    padding: 9px 8px 8px 12px;
  }

  .msb-inspector-name {
    font-size: 16px;
  }

  .msb-inspector-summary {
    padding: 8px 9px 3px;
  }

  .msb-inspector-actions {
    gap: 6px;
    padding: 6px 9px 9px;
  }

  .msb-inspector-actions button {
    min-height: 59px;
    grid-template-columns: 24px minmax(0, 1fr);
    column-gap: 5px;
    padding: 6px 7px;
  }

  .msb-inspector-actions button > span {
    font-size: 18px;
  }

  .msb-inspector-actions button b {
    font-size: 11px;
  }

  .msb-toast {
    bottom: calc(150px + var(--msb-safe-bottom));
    font-size: 12px;
  }
}

@media (max-width: 390px) {
  .msb-inspector-summary {
    grid-template-columns: 1fr;
  }

  .msb-inspector-summary span:last-child {
    grid-column: auto;
  }

  .msb-inspector-actions button small {
    display: none;
  }

  .msb-inspector-actions button {
    min-height: 52px;
    grid-template-rows: 1fr;
  }

  .msb-inspector-actions button > span {
    grid-row: auto;
  }
}

@media (max-height: 560px) and (min-width: 600px) {
  .msb-workshop-head {
    min-height: calc(52px + var(--msb-safe-top));
    padding-top: calc(4px + var(--msb-safe-top));
    padding-bottom: 4px;
  }

  .msb-workshop-status,
  .msb-workshop-copy small {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msb-toast,
  .msb-inspector-actions button.danger[data-armed="true"] {
    transition: none;
    animation: none;
  }
}
