:root {
  --app-bg: #f5f7fb;
  --panel: #ffffff;
  --panel-strong: #eef3f8;
  --ink: #121820;
  --muted: #5d6978;
  --line: #d9e1ea;
  --brand-ink: #10233f;
  --brand-coral: #ff6b4a;
  --brand-mint: #4ad6a7;
  --brand-gold: #f9c74f;
  --danger: #ce3b4c;
  --shadow: 0 18px 50px rgba(16, 35, 63, 0.12);
  --radius: 8px;
  --stage-bg: #f8fbff;
  --stage-text: #142033;
  --stage-accent: #ff6b4a;
  --stage-support: #4ad6a7;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto minmax(200px, 1fr);
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(16px);
}

.brand {
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.34), 0 10px 24px rgba(16, 35, 63, 0.18);
  position: relative;
  overflow: hidden;
}

.brand-mark__image {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-copy strong {
  font-size: 18px;
  line-height: 1.1;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.flow-tabs,
.segmented {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.flow-tab,
.segmented button {
  border: 0;
  color: var(--muted);
  background: transparent;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 700;
  white-space: nowrap;
}

.flow-tab.is-active,
.segmented button.is-active {
  color: var(--brand-ink);
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(16, 35, 63, 0.08);
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.primary-button,
.ghost-button,
.wide-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button,
.wide-button {
  color: #ffffff;
  background: var(--brand-ink);
  box-shadow: 0 10px 22px rgba(16, 35, 63, 0.16);
}

.primary-button:hover,
.wide-button:hover,
.ghost-button:hover,
.icon-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.ghost-button,
.icon-button {
  color: var(--brand-ink);
  background: #ffffff;
  border-color: var(--line);
}

.danger-button {
  color: #ffffff;
  background: var(--danger);
}

.wide-button,
.full-width {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: 294px minmax(420px, 1fr) 312px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.tool-panel,
.inspector-panel,
.stage-panel {
  min-height: 0;
}

.tool-panel,
.inspector-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.panel-section,
.stage-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(16, 35, 63, 0.05);
}

.panel-section {
  padding: 14px;
}

.step-section {
  display: none;
}

.step-section.is-active {
  display: block;
}

.section-heading {
  margin-bottom: 12px;
}

.section-heading.compact {
  margin-bottom: 8px;
}

.section-heading h2,
.dialog-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-coral);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hidden-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.field-label,
.control-grid span,
.visibility-box > span {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.text-input,
.number-input,
.select-input,
.text-area,
.export-code {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

.text-input,
.number-input,
.select-input {
  height: 38px;
  padding: 0 10px;
}

.text-input:focus,
.number-input:focus,
.select-input:focus,
.text-area:focus,
.export-code:focus {
  border-color: var(--brand-mint);
  box-shadow: 0 0 0 3px rgba(74, 214, 167, 0.16);
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.template-grid,
.add-grid,
.theme-list,
.layer-list {
  display: grid;
  gap: 8px;
}

.template-grid {
  grid-template-columns: 1fr;
  margin-top: 12px;
}

.template-card,
.add-grid button,
.theme-swatch,
.layer-item {
  min-height: 54px;
  text-align: left;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px;
}

.template-card span,
.theme-swatch,
.layer-item strong {
  display: block;
  font-weight: 850;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.template-card small,
.layer-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.template-card:hover,
.add-grid button:hover,
.theme-swatch:hover,
.layer-item:hover {
  border-color: rgba(255, 107, 74, 0.55);
  box-shadow: 0 8px 18px rgba(16, 35, 63, 0.07);
}

.add-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 12px 0;
}

.switch-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 750;
}

.switch-row input,
.visibility-box input {
  accent-color: var(--brand-coral);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.text-area {
  min-height: 132px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.color-input {
  inline-size: 100%;
  block-size: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.range-input {
  width: 100%;
  accent-color: var(--brand-coral);
}

.finish-card {
  display: grid;
  gap: 3px;
  padding: 12px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
}

.finish-card span {
  color: var(--muted);
  font-size: 12px;
}

.theme-swatch {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
}

.theme-swatch span {
  width: 42px;
  height: 24px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--swatch-a) 0 33%, var(--swatch-b) 33% 66%, var(--swatch-c) 66%);
  border: 1px solid rgba(16, 35, 63, 0.14);
}

.theme-swatch.is-active {
  border-color: var(--brand-coral);
  box-shadow: 0 0 0 3px rgba(255, 107, 74, 0.13);
}

.stage-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.canvas-toolbar {
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.canvas-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.stage-scroll {
  overflow: auto;
  min-height: 0;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(217, 225, 234, 0.45) 1px, transparent 1px),
    linear-gradient(0deg, rgba(217, 225, 234, 0.45) 1px, transparent 1px),
    #edf2f7;
  background-size: 32px 32px;
}

.stage-viewport {
  min-width: min-content;
  width: fit-content;
  margin: 0 auto;
}

.canvas-stage {
  width: 960px;
  height: 620px;
  position: relative;
  overflow: hidden;
  color: var(--stage-text);
  background: var(--stage-bg);
  border: 1px solid rgba(16, 35, 63, 0.16);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.stage-viewport[data-breakpoint="tablet"] .canvas-stage {
  width: 720px;
  height: 780px;
}

.stage-viewport[data-breakpoint="mobile"] .canvas-stage {
  width: 390px;
  height: 760px;
}

.canvas-stage.has-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(16, 35, 63, 0.055) 1px, transparent 1px),
    linear-gradient(0deg, rgba(16, 35, 63, 0.055) 1px, transparent 1px);
  background-size: 24px 24px;
  z-index: 0;
}

.canvas-stage.is-preview::before {
  display: none;
}

.canvas-element {
  position: absolute;
  z-index: 1;
  display: grid;
  align-items: center;
  min-width: 20px;
  min-height: 20px;
  border: 1px solid transparent;
  user-select: none;
  touch-action: none;
  opacity: var(--base-opacity, 1);
  transition: box-shadow 170ms ease, transform 170ms ease, filter 170ms ease, opacity 170ms ease;
}

.canvas-stage:not(.is-preview) .canvas-element {
  cursor: grab;
}

.canvas-stage:not(.is-preview) .canvas-element:hover,
.canvas-element.is-selected {
  border-color: rgba(255, 107, 74, 0.7);
  box-shadow: 0 0 0 3px rgba(255, 107, 74, 0.14);
}

.canvas-element.is-selected {
  z-index: 1000;
}

.canvas-element.is-locked {
  cursor: default;
}

.canvas-element.is-not-visible {
  opacity: 0.32 !important;
  filter: saturate(0.4);
}

.hover-vis-hide:hover .element-content {
  opacity: 0;
}

.hover-vis-show .element-content {
  opacity: 0.2;
}

.canvas-stage:not(.is-preview) .hover-vis-show::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(255, 107, 74, 0.7);
  background:
    linear-gradient(45deg, rgba(255, 107, 74, 0.12) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 107, 74, 0.12) 25%, transparent 25%);
  background-size: 14px 14px;
  border-radius: inherit;
  pointer-events: none;
}

.type-image.hover-vis-show,
.type-image.hover-vis-hide:hover {
  background: transparent !important;
}

.canvas-stage.is-preview .hover-vis-show .element-content {
  opacity: 0;
}

.hover-vis-show:hover .element-content,
.canvas-stage:not(.is-preview) .hover-vis-show.is-selected .element-content {
  opacity: 1;
}

.canvas-element.is-not-visible::after {
  content: "Hidden here";
  position: absolute;
  right: 6px;
  top: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(18, 24, 32, 0.76);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
}

.element-content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  align-items: center;
  padding: 10px;
  line-height: 1.16;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: opacity 170ms ease;
  pointer-events: none;
}

.type-image .element-content {
  padding: 0;
}

.type-image img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: inherit;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.button-link {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: inherit;
  text-decoration: none;
  pointer-events: auto;
}

.type-box .element-content,
.type-card .element-content {
  align-items: start;
}

.type-button .element-content,
.type-badge .element-content {
  justify-items: center;
  text-align: center;
}

.resize-handle {
  position: absolute;
  right: -8px;
  bottom: -8px;
  z-index: 5;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--brand-coral);
  border: 2px solid #ffffff;
  box-shadow: 0 4px 10px rgba(16, 35, 63, 0.18);
  cursor: nwse-resize;
  display: none;
  touch-action: none;
}

.canvas-element.is-selected .resize-handle {
  display: block;
}

.canvas-stage.is-preview .resize-handle,
.canvas-stage.is-preview .canvas-element {
  border-color: transparent;
  box-shadow: none;
  cursor: default;
}

.hover-lift:hover {
  transform: translateY(-8px);
  box-shadow: 0 18px 30px rgba(16, 35, 63, 0.14);
}

.hover-glow:hover {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--stage-accent), transparent 68%), 0 16px 30px rgba(16, 35, 63, 0.12);
}

.hover-tilt:hover {
  transform: rotate(-2deg) translateY(-4px);
}

.hover-grow:hover {
  transform: scale(1.035);
}

.hover-soften:hover {
  filter: saturate(1.1) brightness(1.04);
}

.empty-state {
  color: var(--muted);
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.45;
}

.visibility-box {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.device-layout-box {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.device-layout-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.visibility-box label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  font-weight: 700;
}

.layer-list {
  max-height: 280px;
  overflow: auto;
}

.layer-item {
  width: 100%;
}

.layer-item.is-active {
  border-color: var(--brand-coral);
  background: #fff8f5;
}

.export-dialog {
  width: min(920px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.export-dialog::backdrop {
  background: rgba(16, 35, 63, 0.38);
}

.export-dialog form {
  padding: 18px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.export-code {
  min-height: 360px;
  margin: 14px 0;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 250px minmax(360px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
  }
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    position: static;
  }

  .flow-tabs,
  .top-actions {
    justify-self: stretch;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button,
  .flow-tab {
    flex: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .inspector-panel {
    display: flex;
  }

  .canvas-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }
}
