:root {
  --surface: #f8f9fc;
  --surface-panel: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --text: #16181d;
  --text-muted: #657084;
  --text-soft: #9aa3b3;
  --primary: #2563eb;
  --primary-deep: #1d4ed8;
  --outline: rgba(101, 112, 132, 0.18);
  --outline-strong: rgba(37, 99, 235, 0.42);
  --shadow-soft: 0 28px 70px -46px rgba(15, 23, 42, 0.32);
  --shadow-card: 0 24px 60px -42px rgba(15, 23, 42, 0.34);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --toolbar-height: 86px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-width: 320px;
  font-family: "Inter", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(170, 199, 255, 0.28), transparent 28%),
    radial-gradient(circle at right 14%, rgba(232, 239, 252, 0.9), transparent 28%),
    linear-gradient(180deg, #fbfcff 0%, #f2f5fb 100%);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.studio-shell {
  min-height: 100vh;
}

.studio-toolbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--toolbar-height);
  padding: 16px 28px;
  border-bottom: 1px solid var(--outline);
  background: rgba(248, 249, 252, 0.82);
  backdrop-filter: blur(24px);
}

.toolbar-brand,
.toolbar-actions,
.device-toggle {
  display: flex;
  align-items: center;
}

.toolbar-brand {
  gap: 18px;
}

.brand {
  font-size: 1.1rem;
  font-weight: 800;
}

.toolbar-brand h1,
.toolbar-brand p,
.panel-heading h2,
.panel-heading span,
.canvas-header h2,
.canvas-header span {
  margin: 0;
}

.toolbar-brand h1 {
  font-size: 1.34rem;
  font-weight: 800;
}

.toolbar-brand p {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.toolbar-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.soft-button,
.device-toggle button,
.library-button,
.small-button,
.danger-button,
.ghost-button {
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.soft-button {
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

.soft-button:hover,
.device-toggle button:hover,
.library-button:hover,
.small-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.28);
  color: var(--primary);
}

.device-toggle {
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
}

.device-toggle button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
}

.device-toggle button.is-active {
  background: var(--primary);
  color: #fff;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(560px, 1fr) minmax(300px, 380px);
  gap: 20px;
  padding: 20px;
}

.block-library,
.canvas-panel,
.inspector-panel {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: var(--radius-xl);
  background: var(--surface-panel);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(20px);
}

.block-library,
.inspector-panel {
  position: sticky;
  top: calc(var(--toolbar-height) + 18px);
  align-self: start;
  max-height: calc(100vh - var(--toolbar-height) - 36px);
  overflow: auto;
  padding: 18px;
}

.canvas-panel {
  min-height: calc(100vh - var(--toolbar-height) - 36px);
  padding: 18px;
}

.panel-heading,
.canvas-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading {
  display: block;
}

.panel-heading span,
.canvas-header span,
.form-group > span,
.fieldset-title {
  color: var(--text-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.panel-heading h2,
.canvas-header h2 {
  margin-top: 6px;
  font-size: 1.15rem;
}

#statusMessage {
  min-height: 20px;
  margin: 0;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 700;
}

.library-list {
  display: grid;
  gap: 18px;
}

.library-search {
  display: grid;
  gap: 8px;
  margin: -2px 0 18px;
}

.library-search span,
.library-group-heading {
  color: var(--text-soft);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.library-search input {
  width: 100%;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid rgba(101, 112, 132, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--text);
  outline: none;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.library-search input:focus {
  border-color: rgba(37, 99, 235, 0.34);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.library-group {
  display: grid;
  gap: 8px;
}

.library-group-list {
  display: grid;
  gap: 4px;
}

.library-empty {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px dashed rgba(101, 112, 132, 0.28);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.48);
}

.library-empty strong {
  font-size: 0.92rem;
}

.library-empty span {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.library-button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 8px 8px 8px 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  text-align: left;
}

.library-button:hover {
  background: rgba(255, 255, 255, 0.62);
  border-color: rgba(101, 112, 132, 0.14);
}

.library-button:active {
  cursor: grabbing;
}

.library-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: rgba(17, 24, 39, 0.045);
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.library-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.library-button strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-button small {
  display: block;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-add {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  font-size: 1rem;
  font-weight: 800;
  opacity: 0.72;
}

.library-button:hover .library-add {
  opacity: 1;
}

.library-button.is-featured {
  align-items: flex-start;
  min-height: 118px;
  padding: 14px;
  border-color: rgba(37, 99, 235, 0.14);
  border-radius: 22px;
  background:
    radial-gradient(circle at 12% 0, rgba(37, 99, 235, 0.12), transparent 34%),
    rgba(255, 255, 255, 0.64);
}

.library-button.is-featured:hover {
  border-color: rgba(37, 99, 235, 0.26);
  background:
    radial-gradient(circle at 12% 0, rgba(37, 99, 235, 0.16), transparent 36%),
    rgba(255, 255, 255, 0.78);
}

.library-button.is-featured .library-icon {
  width: 38px;
  height: 38px;
  border-radius: 15px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  font-size: 1.15rem;
}

.library-button.is-featured strong {
  font-size: 1rem;
}

.library-button.is-featured small {
  max-width: 180px;
  margin-top: 3px;
  line-height: 1.45;
  white-space: normal;
}

.library-badge {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.canvas-stage {
  display: flex;
  justify-content: center;
  min-height: calc(100vh - var(--toolbar-height) - 104px);
  padding: 18px;
  overflow: auto;
  border-radius: 24px;
  background:
    linear-gradient(90deg, rgba(101, 112, 132, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(101, 112, 132, 0.06) 1px, transparent 1px),
    rgba(255, 255, 255, 0.42);
  background-size: 28px 28px;
}

.preview-device {
  flex: 0 0 auto;
  width: 390px;
  transition: width 180ms ease;
}

.preview-device.is-phone {
  width: 390px;
}

.preview-device.is-tablet {
  width: 768px;
}

.preview-device.is-desktop {
  width: 100%;
}

.canvas-block {
  position: relative;
  outline: 2px solid transparent;
  outline-offset: 4px;
  transition: opacity 160ms ease, outline-color 160ms ease, transform 160ms ease;
}

.canvas-block.is-selected {
  outline-color: var(--outline-strong);
}

.canvas-block.is-hidden-block {
  opacity: 0.52;
}

.canvas-block.is-dragging {
  opacity: 0.42;
}

.canvas-block[draggable="true"] {
  cursor: grab;
}

.drop-marker {
  position: relative;
  height: 0;
  pointer-events: none;
  opacity: 0;
  transform: scaleY(0.72);
  transition: opacity 140ms ease, transform 140ms ease;
}

.drop-marker.is-active {
  height: 18px;
  opacity: 1;
  transform: scaleY(1);
}

.drop-marker span {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.08);
}

.resize-handle {
  position: absolute;
  z-index: 8;
  display: block;
  background: var(--primary);
  box-shadow: 0 10px 18px -12px rgba(15, 23, 42, 0.5);
  opacity: 0.92;
}

.resize-handle::after {
  content: "";
  position: absolute;
  inset: -8px;
}

.resize-n,
.resize-s {
  left: 22px;
  right: 22px;
  height: 6px;
  border-radius: 999px;
  cursor: ns-resize;
}

.resize-n {
  top: -5px;
}

.resize-s {
  bottom: -5px;
}

.resize-e,
.resize-w {
  top: 22px;
  bottom: 22px;
  width: 6px;
  border-radius: 999px;
  cursor: ew-resize;
}

.resize-e {
  right: -5px;
}

.resize-w {
  left: -5px;
}

.resize-ne,
.resize-se,
.resize-sw,
.resize-nw {
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 999px;
}

.resize-ne {
  top: -8px;
  right: -8px;
  cursor: nesw-resize;
}

.resize-se {
  right: -8px;
  bottom: -8px;
  cursor: nwse-resize;
}

.resize-sw {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

.resize-nw {
  top: -8px;
  left: -8px;
  cursor: nwse-resize;
}

.block-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: none;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 16px 32px -24px rgba(15, 23, 42, 0.36);
}

.canvas-block.is-selected .block-actions,
.canvas-block:hover .block-actions {
  display: flex;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
}

.icon-button:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
}

.icon-button.is-danger:hover {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

.form-stack,
.array-editor,
.field-row {
  display: grid;
  gap: 12px;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 16px;
  padding: 5px;
  border: 1px solid rgba(101, 112, 132, 0.16);
  border-radius: 18px;
  background: rgba(245, 247, 251, 0.82);
}

.inspector-tabs button {
  min-height: 34px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.inspector-tabs button:not(:disabled) {
  cursor: pointer;
}

.inspector-tabs button.is-active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 12px 26px -20px rgba(15, 23, 42, 0.38);
}

.inspector-tabs button:disabled {
  opacity: 0.36;
}

.form-section {
  display: grid;
  gap: 14px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--outline);
}

.advanced-section {
  border-bottom: 1px solid var(--outline);
  margin-bottom: 18px;
  padding-bottom: 18px;
}

.advanced-section summary {
  cursor: pointer;
  list-style: none;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.advanced-section summary::-webkit-details-marker {
  display: none;
}

.advanced-section summary::after {
  content: "展开";
  float: right;
  color: var(--text-soft);
  font-size: 0.72rem;
}

.advanced-section[open] summary::after {
  content: "收起";
}

.advanced-section .form-section {
  margin-top: 14px;
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.form-group {
  display: grid;
  gap: 8px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid rgba(101, 112, 132, 0.22);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  outline: none;
}

.form-group input[type="file"] {
  padding: 9px;
  cursor: pointer;
}

.range-field span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.range-field strong {
  color: var(--primary);
}

.range-field input[type="range"] {
  min-height: 28px;
  padding: 0;
  accent-color: var(--primary);
}

.form-group textarea {
  min-height: 92px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: rgba(37, 99, 235, 0.44);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.checkbox-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--text-muted);
  font-weight: 700;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.field-row {
  grid-template-columns: 1fr 1fr;
}

.array-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--outline);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.54);
}

.small-button,
.danger-button,
.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
}

.danger-button {
  border-color: rgba(220, 38, 38, 0.2);
  color: #dc2626;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
}

.preview-modal.is-open {
  display: block;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: blur(10px);
}

.preview-dialog {
  position: relative;
  width: min(92vw, 520px);
  max-height: 88vh;
  margin: 6vh auto;
  overflow: auto;
}

.icon-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font-size: 1.4rem;
}

@media (max-width: 1180px) {
  .studio-layout {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .studio-toolbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .toolbar-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .studio-layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .block-library,
  .inspector-panel {
    position: static;
    max-height: none;
  }

  .canvas-panel {
    min-height: auto;
    padding: 12px;
  }

  .canvas-stage {
    padding: 10px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
