:root {
  color-scheme: light;
  --ink: #21182d;
  --muted: #6d5d7c;
  --panel: rgba(255, 255, 255, 0.86);
  --line: rgba(82, 39, 119, 0.16);
  --purple: #6f2dbd;
  --purple-deep: #3b176f;
  --purple-mid: #8d37d6;
  --lavender: #eadcff;
  --rose: #d84f8c;
  --rose-soft: #f3b4db;
  --gold: #d6a84f;
  --paper: #fff8fb;
  --shadow: 0 28px 80px rgba(66, 20, 109, 0.18);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(118deg, rgba(73, 24, 132, 0.18) 0 17%, transparent 17% 100%),
    linear-gradient(302deg, rgba(216, 79, 140, 0.18) 0 18%, transparent 18% 100%),
    linear-gradient(150deg, transparent 0 54%, rgba(111, 45, 189, 0.12) 54% 63%, transparent 63% 100%),
    repeating-linear-gradient(90deg, rgba(111, 45, 189, 0.035) 0 1px, transparent 1px 54px),
    linear-gradient(135deg, #f1e6ff 0%, #fff8fc 42%, #f4eaff 72%, #fce8f5 100%);
  overflow-x: hidden;
}

body.is-locked {
  overflow: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

body::before {
  background:
    linear-gradient(112deg, transparent 0 9%, rgba(92, 28, 154, 0.16) 9% 13%, transparent 13% 100%),
    linear-gradient(293deg, transparent 0 12%, rgba(216, 79, 140, 0.14) 12% 16%, transparent 16% 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), transparent 38%);
}

body::after {
  background:
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(111, 45, 189, 0.035) 18px 19px, transparent 19px 42px),
    repeating-linear-gradient(45deg, transparent 0 26px, rgba(216, 79, 140, 0.03) 26px 27px, transparent 27px 58px);
  opacity: 0.7;
}

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

.shell {
  display: grid;
  grid-template-columns: minmax(22rem, 0.92fr) minmax(24rem, 1.08fr);
  gap: clamp(1rem, 2vw, 1.35rem);
  width: min(96rem, calc(100vw - 2rem));
  margin: 0 auto;
  padding: clamp(2.5rem, 5vw, 4.75rem) 0 clamp(1.5rem, 3vw, 2.5rem);
}

.editor-panel,
.preview-panel {
  position: relative;
  min-width: 0;
  border: 1px solid rgba(134, 72, 190, 0.22);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(255, 248, 253, 0.84) 52%, rgba(245, 235, 255, 0.88)),
    var(--panel);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(22px);
  overflow: hidden;
}

.editor-panel::before,
.preview-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 0.28rem;
  background: linear-gradient(90deg, var(--purple-deep), var(--purple-mid), var(--rose), var(--lavender));
  pointer-events: none;
}

.editor-panel::after,
.preview-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(130deg, rgba(111, 45, 189, 0.06), transparent 28%),
    linear-gradient(315deg, rgba(216, 79, 140, 0.05), transparent 35%);
  pointer-events: none;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1rem, 2.4vw, 1.4rem);
  border-radius: 1.25rem;
}

.preview-panel {
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1rem, 2.4vw, 1.5rem);
  border-radius: 1.25rem;
  margin-top: clamp(1.75rem, 4vw, 3.25rem);
}

.brand-row,
.toolbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-row {
  justify-content: flex-start;
  padding: 0.25rem 0.25rem 0.75rem;
  border-bottom: 1px solid rgba(111, 45, 189, 0.13);
}

.mark {
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.42), transparent 45%),
    linear-gradient(135deg, var(--purple-deep), var(--purple-mid) 48%, var(--rose));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 16px 34px rgba(111, 45, 189, 0.34),
    0 0 0 0.45rem rgba(234, 220, 255, 0.6);
  position: relative;
}

.mark::before,
.mark::after {
  content: "✦";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: auto;
  height: auto;
  color: #fff8fb;
  background: transparent;
  border-radius: 0;
  font-size: 1.5rem;
  transform: none;
}

.mark::before {
  left: 0;
}

.mark::after {
  display: none;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--purple-mid);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  max-width: 16ch;
  font-size: clamp(2rem, 3vw, 3.15rem);
  background: linear-gradient(100deg, #21182d, var(--purple-deep) 54%, #7d2fc5);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 {
  font-size: clamp(1.35rem, 2vw, 1.8rem);
}

.composer {
  display: grid;
  gap: 0.85rem;
}

.form-block {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 0.9rem;
  border: 1px solid rgba(123, 62, 181, 0.14);
  border-radius: 1rem;
  padding: 1rem;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.78), rgba(255, 248, 253, 0.62)),
    rgba(255, 255, 255, 0.62);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    0 12px 34px rgba(78, 29, 129, 0.06);
}

.block-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.block-title > span {
  display: inline-grid;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(111, 45, 189, 0.14), rgba(216, 79, 140, 0.12));
  color: var(--purple-mid);
  font-size: 0.76rem;
  font-weight: 900;
}

.block-title h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

label,
.tone-grid,
.icon-picker,
.swatch-grid,
.output-field {
  display: grid;
  gap: 0.45rem;
}

label > span,
.tone-grid small,
.icon-picker small,
.output-field > span,
legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(111, 45, 189, 0.2);
  border-radius: 0.8rem;
  outline: none;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input {
  min-height: 2.8rem;
  padding: 0 0.9rem;
}

select {
  min-height: 2.8rem;
  padding: 0 2.1rem 0 0.9rem;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 1rem) 1.22rem / 0.42rem
      0.42rem no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 0.72rem) 1.22rem / 0.42rem
      0.42rem no-repeat,
    rgba(255, 255, 255, 0.8);
}

textarea {
  resize: vertical;
  padding: 0.85rem 0.9rem;
  line-height: 1.68;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    linear-gradient(120deg, rgba(59, 23, 111, 0.42), rgba(141, 55, 214, 0.2) 46%, rgba(216, 79, 140, 0.28)),
    linear-gradient(135deg, #f0e4ff, #fff8fc 45%, #f8dff1);
  backdrop-filter: blur(18px);
}

body:not(.is-locked) .access-gate {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

body.is-locked .shell {
  filter: blur(16px);
  pointer-events: none;
  user-select: none;
}

.access-card {
  width: min(27rem, 100%);
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 1.35rem;
  padding: clamp(1.25rem, 4vw, 2rem);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(255, 248, 253, 0.86) 52%, rgba(239, 225, 255, 0.88)),
    rgba(255, 255, 255, 0.82);
  box-shadow:
    0 34px 90px rgba(47, 17, 87, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  display: grid;
  gap: 1rem;
}

.access-mark {
  display: grid;
  width: 3.3rem;
  height: 3.3rem;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, var(--purple-deep), var(--purple-mid), var(--rose));
  box-shadow:
    0 18px 36px rgba(111, 45, 189, 0.32),
    0 0 0 0.55rem rgba(234, 220, 255, 0.7);
  font-size: 1.45rem;
}

.access-card h1 {
  max-width: none;
  font-size: clamp(2rem, 7vw, 3.25rem);
}

.access-card button {
  min-height: 3rem;
}

.access-feedback {
  min-height: 1.25rem;
  margin: -0.25rem 0 0;
  color: #8b2f62;
}

input:focus,
textarea:focus {
  border-color: rgba(111, 45, 189, 0.62);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 0 0 4px rgba(111, 45, 189, 0.12);
}

select:focus {
  border-color: rgba(111, 45, 189, 0.62);
  background-color: rgba(255, 255, 255, 0.94);
  box-shadow: 0 0 0 4px rgba(111, 45, 189, 0.12);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  align-items: end;
}

.segmented,
.tone-grid,
.icon-picker,
.swatch-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented legend,
.tone-grid legend,
.icon-picker legend,
.swatch-grid legend {
  width: 100%;
  margin-bottom: 0.1rem;
}

.segmented label,
.tone-grid label,
.icon-picker label,
.swatch-grid label {
  display: block;
}

.segmented input,
.tone-grid input,
.icon-picker input,
.swatch-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span,
.tone-grid span {
  display: inline-flex;
  min-height: 2.45rem;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(111, 45, 189, 0.18);
  border-radius: 999px;
  padding: 0 0.95rem;
  background: rgba(255, 255, 255, 0.66);
  color: var(--muted);
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.segmented input:checked + span,
.tone-grid input:checked + span,
.icon-picker input:checked + span,
.swatch-grid input:checked + span {
  border-color: transparent;
  background: linear-gradient(135deg, var(--purple-deep), var(--purple-mid) 48%, var(--rose));
  color: white;
  box-shadow:
    0 12px 24px rgba(111, 45, 189, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.segmented span:hover,
.tone-grid span:hover,
.icon-picker span:hover,
.swatch-grid span:hover {
  transform: translateY(-1px);
}

.tone-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.tone-grid label {
  min-width: 0;
}

.tone-grid span {
  min-height: 4.75rem;
  width: 100%;
  align-items: flex-start;
  flex-direction: column;
  gap: 0.28rem;
  border-radius: 0.9rem;
  padding: 0.75rem 0.8rem;
}

.tone-grid strong {
  color: var(--ink);
  font-size: 0.94rem;
}

.tone-grid input:checked + span strong,
.tone-grid input:checked + span small {
  color: white;
}

.tone-grid small {
  line-height: 1.4;
  font-weight: 600;
}

.icon-picker {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.icon-picker span {
  display: grid;
  min-height: 4.3rem;
  place-items: center;
  gap: 0.15rem;
  border: 1px solid rgba(111, 45, 189, 0.18);
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.66);
  color: var(--purple);
  cursor: pointer;
  font-size: 1.45rem;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.icon-picker small {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
}

.icon-picker input:checked + span small {
  color: white;
}

.swatch-grid span {
  display: inline-flex;
  min-height: 2.45rem;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  border: 1px solid rgba(111, 45, 189, 0.18);
  border-radius: 999px;
  padding: 0 0.82rem;
  background: rgba(255, 255, 255, 0.66);
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.swatch-grid span::before {
  content: "";
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.helper-text {
  grid-column: 1 / -1;
  min-height: 1.2rem;
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.tone-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  border-top: 1px solid rgba(111, 45, 189, 0.12);
  padding-top: 0.9rem;
}

.tone-editor label:nth-child(2),
.tone-editor label:nth-child(3),
.tone-editor label:nth-child(4) {
  grid-column: 1 / -1;
}

.tone-editor textarea {
  min-height: 4.4rem;
}

.cta-hint {
  margin-top: -0.35rem;
}

.cta-hint.is-warning {
  color: #8b5d20;
}

.wide-field {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

button {
  min-height: 2.5rem;
  border: 0;
  border-radius: 999px;
  padding: 0 1rem;
  background: linear-gradient(135deg, var(--purple-deep), var(--purple-mid) 48%, var(--rose));
  color: white;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(111, 45, 189, 0.22);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

button:nth-child(2) {
  background: linear-gradient(135deg, #35106e, var(--purple), #8b35d1);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(111, 45, 189, 0.28);
  filter: saturate(1.05);
}

button:active {
  transform: translateY(0);
}

.preview-wrap {
  overflow: hidden;
  height: clamp(31rem, calc(100vh - 19rem), 38rem);
  min-height: 0;
  border: 1px solid rgba(111, 45, 189, 0.22);
  border-radius: 1rem;
  background:
    linear-gradient(135deg, rgba(111, 45, 189, 0.1), rgba(216, 79, 140, 0.08)),
    #f4edf9;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 18px 46px rgba(69, 25, 123, 0.1);
  position: relative;
  z-index: 1;
}

iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

.code-panel {
  position: relative;
  z-index: 1;
  border: 1px solid rgba(111, 45, 189, 0.18);
  border-radius: 1rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(250, 241, 255, 0.74));
  overflow: hidden;
}

.code-panel summary {
  display: flex;
  min-height: 3rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  cursor: pointer;
  color: var(--ink);
  font-weight: 850;
}

.code-panel summary::-webkit-details-marker {
  display: none;
}

.code-panel summary::after {
  content: "+";
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  place-items: center;
  border-radius: 50%;
  background: rgba(111, 45, 189, 0.1);
  color: var(--purple);
  font-weight: 900;
}

.code-panel[open] summary::after {
  content: "−";
}

.code-panel small {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.output-field {
  padding: 0 1rem 1rem;
}

.output-field textarea {
  min-height: 8rem;
  max-height: 14rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(22rem, calc(100vw - 2rem));
  padding: 0.8rem 1rem;
  border-radius: 0.9rem;
  background: rgba(35, 18, 54, 0.92);
  color: white;
  opacity: 0;
  transform: translateY(0.75rem);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
    max-height: none;
    margin-top: 0;
  }

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

  .icon-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  h1 {
    max-width: 14ch;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 1rem, 92rem);
    padding: 1rem 0;
  }

  .editor-panel,
  .preview-panel {
    border-radius: 1rem;
  }

  .brand-row,
  .toolbar,
  .control-row,
  .field-grid,
  .tone-editor {
    grid-template-columns: 1fr;
  }

  .brand-row,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  button {
    flex: 1;
    min-width: 0;
  }

  .preview-wrap,
  iframe {
    height: 30rem;
  }
}

@media (max-width: 420px) {
  .tone-grid {
    grid-template-columns: 1fr;
  }

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