.adspace-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--pb-adspace-overlay-z);
  display: none;
  pointer-events: none;
}

.adspace-overlay.is-active {
  display: block;
  pointer-events: auto;
}

.adspace-backdrop {
  position: absolute;
  inset: 0;
  background: var(--pb-adspace-backdrop-bg);
  -webkit-backdrop-filter: var(--pb-adspace-backdrop-filter);
  backdrop-filter: var(--pb-adspace-backdrop-filter);
}

.adspace-panel {
  position: absolute;
  inset: 0 0 auto;
  z-index: var(--pb-adspace-panel-z);
  width: 100vw;
  height: min(var(--pb-adspace-active-height, var(--pb-adspace-panel-height)), calc(100vh - var(--pb-adspace-close-size) - var(--pb-space-6)));
  overflow: visible;
  border-bottom: var(--pb-border-width-sm) solid var(--pb-adspace-panel-border);
  background: var(--pb-adspace-panel-bg);
  box-shadow: var(--pb-adspace-panel-shadow);
}

.adspace-panel.is-editor-workspace {
  inset: var(--pb-space-6) var(--pb-space-6) auto;
  width: auto;
  height: calc(100vh - var(--pb-space-12) - var(--pb-adspace-close-size) - var(--pb-space-3));
  border: var(--pb-border-width-sm) solid var(--pb-adspace-panel-border);
  border-radius: var(--pb-radius-xl);
}

.adspace-frame-shell {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--pb-adspace-frame-bg);
}

.adspace-panel.is-editor-workspace .adspace-frame-shell {
  border-radius: inherit;
}

.adspace-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--pb-adspace-frame-bg);
}

.adspace-host-close {
  position: absolute;
  top: calc(100% + var(--pb-space-3));
  left: 50%;
  z-index: var(--pb-adspace-close-z);
  min-width: calc(var(--pb-adspace-close-size) * 2);
  height: var(--pb-adspace-close-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pb-space-2);
  padding-inline: var(--pb-space-3);
  border: var(--pb-border-width-sm) solid var(--pb-adspace-close-border);
  border-radius: var(--pb-radius-md);
  background: var(--pb-adspace-close-bg);
  color: var(--pb-adspace-close-text);
  font: inherit;
  font-size: var(--pb-font-size-sm);
  font-weight: var(--pb-font-weight-semibold);
  transform: translateX(-50%);
  cursor: pointer;
}

.adspace-host-close:hover,
.adspace-host-close:focus-visible {
  background: var(--pb-adspace-close-bg-hover);
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-host-close svg,
.adspace-icon-button svg,
.adspace-action-button svg {
  width: var(--pb-size-icon-md);
  height: var(--pb-size-icon-md);
  flex: 0 0 auto;
  fill: currentColor;
}

.adspace-body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: var(--pb-font-sans);
  color: var(--pb-adspace-page-text);
  background: var(--pb-adspace-page-bg);
}

.adspace-shell {
  position: relative;
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--pb-adspace-page-bg);
}

.adspace-context {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.adspace-editor-header {
  display: none;
}

.adspace-editor-header[hidden],
.adspace-editor-panel[hidden] {
  display: none;
}

.adspace-workspace,
.adspace-stage {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.adspace-stage-header {
  display: none;
}

.adspace-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  isolation: isolate;
  border: 0;
  background: var(--pb-adspace-canvas-bg);
  background-repeat: no-repeat;
}

.adspace-canvas::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  border-bottom: var(--pb-border-width-sm) solid var(--pb-adspace-canvas-border);
}

.adspace-item {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  max-width: min(72vw, 980px);
  transform: translate(-50%, -50%);
}

.adspace-text-item {
  margin: 0;
  padding: var(--pb-space-2) var(--pb-space-4);
  color: var(--pb-adspace-page-text);
  font-size: clamp(var(--pb-font-size-sm), 2.2vw, var(--pb-font-size-2xl));
  font-weight: var(--pb-font-weight-bold);
  line-height: var(--pb-line-height-tight);
  text-wrap: balance;
  text-shadow: var(--pb-adspace-text-shadow);
}

button.adspace-text-item {
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
}

.adspace-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--pb-adspace-link-text);
  text-decoration: none;
}

.adspace-button-visual {
  box-sizing: border-box;
  min-width: calc(var(--pb-size-control-lg) * 2);
  min-height: var(--pb-size-control-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--pb-space-2) var(--pb-space-4);
  border: var(--pb-border-width-sm) solid transparent;
  border-radius: var(--pb-radius-md);
  background: var(--pb-adspace-button-bg, var(--pb-adspace-link-bg));
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: var(--pb-line-height-tight);
  text-decoration: inherit;
  opacity: var(--pb-adspace-button-opacity, 1);
  box-shadow: var(--pb-shadow-sm);
}

.adspace-link-button[data-ai-effect="fade"] .adspace-button-visual {
  animation: adspace-button-fade var(--pb-adspace-button-effect-duration) ease-out both;
}

.adspace-link-button[data-ai-effect="rise"] .adspace-button-visual {
  animation: adspace-button-rise var(--pb-adspace-button-effect-duration) ease-out both;
}

.adspace-link-button[data-ai-effect="pop"] .adspace-button-visual {
  animation: adspace-button-pop var(--pb-adspace-button-effect-duration) ease-out both;
}

.adspace-link-button:hover .adspace-button-visual,
.adspace-link-button:focus-visible .adspace-button-visual {
  background: var(--pb-adspace-link-bg-hover);
}

.adspace-link-button:focus-visible {
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-edit-target {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.adspace-edit-target:active,
.adspace-edit-target[data-ai-state="dragging"] {
  cursor: grabbing;
}

.adspace-edit-target.is-selected {
  outline: var(--pb-border-width-md) solid var(--pb-adspace-item-selected-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-shell[data-mode="edit"],
.adspace-shell[data-mode="preview"] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--pb-space-4);
  padding: var(--pb-space-4);
  background: var(--pb-color-surface-subtle);
}

.adspace-shell[data-mode="edit"] .adspace-editor-header,
.adspace-shell[data-mode="preview"] .adspace-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pb-space-4);
  min-height: var(--pb-size-control-lg);
}

.adspace-shell[data-mode="edit"] .adspace-link-button.is-invisible-region:not(.is-selected) {
  outline: var(--pb-border-width-sm) dashed var(--pb-adspace-item-selected-ring);
  outline-offset: var(--pb-space-1);
}

@keyframes adspace-button-fade {
  from { opacity: 0; }
  to { opacity: var(--pb-adspace-button-opacity, 1); }
}

@keyframes adspace-button-rise {
  from {
    opacity: 0;
    transform: translateY(var(--pb-adspace-button-effect-distance));
  }
  to {
    opacity: var(--pb-adspace-button-opacity, 1);
    transform: translateY(0);
  }
}

@keyframes adspace-button-pop {
  from {
    opacity: 0;
    transform: scale(var(--pb-adspace-button-effect-scale));
  }
  to {
    opacity: var(--pb-adspace-button-opacity, 1);
    transform: scale(1);
  }
}

.adspace-editor-heading {
  display: grid;
  gap: var(--pb-space-1);
  min-width: 0;
}

.adspace-editor-heading strong {
  color: var(--pb-color-text-primary);
  font-size: var(--pb-font-size-xl);
  line-height: var(--pb-line-height-tight);
}

.adspace-editor-heading > span:last-child {
  color: var(--pb-color-text-secondary);
  font-size: var(--pb-font-size-sm);
}

.adspace-editor-eyebrow {
  color: var(--pb-color-brand-700);
  font-size: var(--pb-font-size-2xs);
  font-weight: var(--pb-font-weight-bold);
  text-transform: uppercase;
}

.adspace-preview-toggle {
  min-height: var(--pb-size-control-md);
  padding: 0 var(--pb-space-4);
  border: var(--pb-border-width-sm) solid var(--pb-adspace-control-border);
  border-radius: var(--pb-radius-md);
  background: var(--pb-adspace-control-bg);
  color: var(--pb-adspace-control-text);
  font: inherit;
  font-size: var(--pb-font-size-sm);
  font-weight: var(--pb-font-weight-semibold);
  white-space: nowrap;
  cursor: pointer;
}

.adspace-preview-toggle:hover,
.adspace-preview-toggle:focus-visible,
.adspace-preview-toggle[aria-pressed="true"] {
  border-color: var(--pb-adspace-action-bg);
  color: var(--pb-adspace-action-bg);
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-shell[data-mode="edit"] .adspace-workspace,
.adspace-shell[data-mode="preview"] .adspace-workspace {
  height: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(calc(var(--pb-size-control-lg) * 6), calc(var(--pb-size-control-lg) * 8));
  gap: var(--pb-space-4);
}

.adspace-shell[data-mode="preview"] .adspace-workspace {
  grid-template-columns: minmax(0, 1fr);
}

.adspace-shell[data-mode="edit"] .adspace-stage,
.adspace-shell[data-mode="preview"] .adspace-stage {
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-4);
  padding: var(--pb-space-4);
  overflow: hidden;
  border: var(--pb-border-width-sm) solid var(--pb-color-border-subtle);
  border-radius: var(--pb-radius-xl);
  background: var(--pb-color-surface-base);
  box-shadow: var(--pb-shadow-sm);
}

.adspace-shell[data-mode="edit"] .adspace-stage-header,
.adspace-shell[data-mode="preview"] .adspace-stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--pb-space-4);
  color: var(--pb-color-text-secondary);
  font-size: var(--pb-font-size-xs);
}

.adspace-stage-header > div {
  display: grid;
  gap: var(--pb-space-1);
}

.adspace-stage-header strong {
  color: var(--pb-color-text-primary);
  font-size: var(--pb-font-size-md);
}

.adspace-stage-mode {
  padding: var(--pb-space-1) var(--pb-space-2);
  border-radius: var(--pb-radius-pill);
  background: var(--pb-color-surface-muted);
  color: var(--pb-color-brand-800);
  font-weight: var(--pb-font-weight-semibold);
  white-space: nowrap;
}

.adspace-shell[data-mode="edit"] .adspace-canvas,
.adspace-shell[data-mode="preview"] .adspace-canvas {
  height: max(var(--pb-adspace-panel-height), calc(var(--pb-size-control-lg) * 3));
  min-height: calc(var(--pb-size-control-lg) * 3);
  margin-block: auto;
  flex: 0 0 auto;
  border: var(--pb-border-width-sm) solid var(--pb-adspace-canvas-border);
  border-radius: var(--pb-radius-lg);
  box-shadow: var(--pb-shadow-md);
}

.adspace-shell[data-mode="preview"] .adspace-editor-panel {
  display: none;
}

.adspace-editor-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--pb-space-4);
  padding: var(--pb-space-4);
  overflow-x: hidden;
  overflow-y: auto;
  border: var(--pb-border-width-sm) solid var(--pb-adspace-editor-border);
  border-radius: var(--pb-radius-xl);
  background: var(--pb-color-surface-base);
  box-shadow: var(--pb-adspace-editor-shadow);
}

.adspace-tool-group {
  display: grid;
  gap: var(--pb-space-3);
  padding-bottom: var(--pb-space-4);
  border-bottom: var(--pb-border-width-sm) solid var(--pb-adspace-editor-border);
}

.adspace-tool-group:last-child {
  border-bottom: 0;
}

.adspace-tool-heading {
  display: grid;
  gap: var(--pb-space-1);
}

.adspace-tool-heading strong {
  color: var(--pb-color-text-primary);
  font-size: var(--pb-font-size-sm);
}

.adspace-tool-heading span {
  color: var(--pb-adspace-control-muted);
  font-size: var(--pb-font-size-xs);
}

.adspace-field,
.adspace-range-field {
  color: var(--pb-adspace-control-muted);
  font-size: var(--pb-font-size-xs);
  font-weight: var(--pb-font-weight-semibold);
}

.adspace-field-help {
  margin: 0;
  color: var(--pb-adspace-control-muted);
  font-size: var(--pb-font-size-2xs);
  line-height: var(--pb-line-height-normal);
}

.adspace-range-field > span {
  display: grid;
  gap: var(--pb-space-1);
}

.adspace-range-field output {
  color: var(--pb-adspace-control-text);
  font-size: var(--pb-font-size-2xs);
  font-weight: var(--pb-font-weight-regular);
}

.adspace-field-stack {
  display: grid;
  gap: var(--pb-space-2);
}

.adspace-range-field {
  display: grid;
  grid-template-columns: minmax(calc(var(--pb-size-control-lg) * 2), auto) minmax(0, 1fr);
  align-items: center;
  gap: var(--pb-space-3);
}

.adspace-field input[type="text"],
.adspace-field input[type="url"],
.adspace-field select {
  box-sizing: border-box;
  width: 100%;
  height: var(--pb-size-control-md);
  min-width: 0;
  padding: 0 var(--pb-space-3);
  border: var(--pb-border-width-sm) solid var(--pb-adspace-control-border);
  border-radius: var(--pb-radius-sm);
  background: var(--pb-adspace-control-bg);
  color: var(--pb-adspace-control-text);
  font: inherit;
}

.adspace-color-field {
  display: grid;
  gap: var(--pb-space-2);
  color: var(--pb-adspace-control-muted);
  font-size: var(--pb-font-size-xs);
  font-weight: var(--pb-font-weight-semibold);
}

.adspace-color-controls {
  display: grid;
  grid-template-columns: var(--pb-size-control-lg) minmax(0, 1fr);
  gap: var(--pb-space-2);
}

.adspace-color-controls input[type="color"] {
  box-sizing: border-box;
  width: var(--pb-size-control-lg);
  height: var(--pb-size-control-sm);
  padding: var(--pb-space-1);
  border: var(--pb-border-width-sm) solid var(--pb-adspace-control-border);
  border-radius: var(--pb-radius-md);
  background: var(--pb-adspace-control-bg);
  cursor: pointer;
}

.adspace-color-controls input[type="color"]:focus-visible {
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-compact-button[aria-pressed="true"] {
  border-color: var(--pb-adspace-action-bg);
  background: var(--pb-adspace-action-bg);
  color: var(--pb-adspace-action-text);
}

.adspace-field input:focus-visible,
.adspace-field select:focus-visible,
.adspace-range-field input:focus-visible {
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-range-field input[type="range"] {
  width: 100%;
  accent-color: var(--pb-adspace-action-bg);
}

.adspace-file-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.adspace-button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--pb-space-2);
}

.adspace-alignment-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--pb-space-2);
}

.adspace-icon-button,
.adspace-action-button,
.adspace-compact-button {
  min-height: var(--pb-size-control-sm);
  min-width: var(--pb-size-control-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pb-space-2);
  padding: 0 var(--pb-space-3);
  border: var(--pb-border-width-sm) solid var(--pb-adspace-control-border);
  border-radius: var(--pb-radius-md);
  background: var(--pb-adspace-control-bg);
  color: var(--pb-adspace-control-text);
  font-family: inherit;
  font-size: var(--pb-font-size-xs);
  font-weight: var(--pb-font-weight-semibold);
  cursor: pointer;
}

.adspace-labeled-button {
  width: 100%;
}

.adspace-action-button {
  min-height: var(--pb-size-control-md);
  background: var(--pb-adspace-action-bg);
  color: var(--pb-adspace-action-text);
  border-color: transparent;
  font-size: var(--pb-font-size-sm);
}

.adspace-action-button:hover,
.adspace-action-button:focus-visible {
  background: var(--pb-adspace-action-bg-hover);
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-icon-button:hover,
.adspace-icon-button:focus-visible,
.adspace-compact-button:hover,
.adspace-compact-button:focus-visible {
  border-color: var(--pb-adspace-action-bg);
  outline: var(--pb-border-width-md) solid var(--pb-color-focus-ring);
  outline-offset: var(--pb-space-1);
}

.adspace-icon-button:disabled,
.adspace-action-button:disabled,
.adspace-compact-button:disabled,
.adspace-field input:disabled,
.adspace-field select:disabled,
.adspace-range-field input:disabled {
  cursor: not-allowed;
  opacity: var(--pb-opacity-disabled);
}

.adspace-save-group {
  position: sticky;
  bottom: calc(var(--pb-space-4) * -1);
  z-index: 3;
  margin-top: auto;
  margin-inline: calc(var(--pb-space-4) * -1);
  margin-bottom: calc(var(--pb-space-4) * -1);
  padding: var(--pb-space-4);
  background: var(--pb-color-surface-base);
  box-shadow: var(--pb-shadow-sm);
}

.adspace-status {
  min-height: var(--pb-font-size-sm);
  color: var(--pb-adspace-muted-text);
  font-size: var(--pb-font-size-xs);
}

@media (max-width: 760px) {
  .adspace-panel.is-editor-workspace {
    inset: var(--pb-space-2) var(--pb-space-2) auto;
    height: calc(100vh - var(--pb-space-4) - var(--pb-adspace-close-size) - var(--pb-space-2));
  }

  .adspace-text-item {
    max-width: 66vw;
  }

  .adspace-shell[data-mode="edit"],
  .adspace-shell[data-mode="preview"] {
    gap: var(--pb-space-2);
    padding: var(--pb-space-2);
  }

  .adspace-shell[data-mode="edit"] .adspace-editor-header,
  .adspace-shell[data-mode="preview"] .adspace-editor-header {
    gap: var(--pb-space-2);
  }

  .adspace-editor-heading > span:last-child,
  .adspace-editor-eyebrow {
    display: none;
  }

  .adspace-editor-heading strong {
    font-size: var(--pb-font-size-lg);
  }

  .adspace-preview-toggle {
    min-height: var(--pb-size-control-sm);
    padding-inline: var(--pb-space-2);
    font-size: var(--pb-font-size-xs);
  }

  .adspace-shell[data-mode="edit"] .adspace-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--pb-space-2);
  }

  .adspace-shell[data-mode="preview"] .adspace-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .adspace-shell[data-mode="edit"] .adspace-stage,
  .adspace-shell[data-mode="preview"] .adspace-stage {
    gap: var(--pb-space-2);
    padding: var(--pb-space-2);
  }

  .adspace-stage-header span:not(.adspace-stage-mode) {
    display: none;
  }

  .adspace-shell[data-mode="edit"] .adspace-canvas,
  .adspace-shell[data-mode="preview"] .adspace-canvas {
    height: calc(var(--pb-size-control-lg) * 3);
    min-height: calc(var(--pb-size-control-lg) * 3);
  }

  .adspace-editor-panel {
    gap: var(--pb-space-3);
    padding: var(--pb-space-3);
  }

  .adspace-save-group {
    bottom: calc(var(--pb-space-3) * -1);
    margin-inline: calc(var(--pb-space-3) * -1);
    margin-bottom: calc(var(--pb-space-3) * -1);
    padding: var(--pb-space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .adspace-link-button[data-ai-effect] .adspace-button-visual {
    animation: none;
    opacity: var(--pb-adspace-button-opacity, 1);
  }
}
