:root {
  color-scheme: light;
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-muted: #f7f9f9;
  --border: #d7dedc;
  --border-strong: #aebbb7;
  --text: #1c2925;
  --text-muted: #61706b;
  --green: #176b50;
  --green-soft: #e4f3ed;
  --amber: #9a5b09;
  --amber-soft: #fff4dc;
  --red: #a43b3b;
  --red-soft: #fff0f0;
  --shadow: 0 10px 28px rgba(35, 55, 48, 0.08);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

button,
label,
summary {
  -webkit-tap-highlight-color: transparent;
}

.site-header {
  width: min(1280px, calc(100% - 36px));
  min-height: 68px;
  margin: 18px auto 0;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.site-wordmark {
  color: var(--green);
  font-size: 25px;
  font-weight: 850;
  letter-spacing: -1px;
  text-decoration: none;
}

.site-heading {
  display: grid;
  gap: 2px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.site-heading strong {
  font-size: 15px;
}

.site-heading span,
.site-home-link {
  color: var(--text-muted);
  font-size: 12px;
}

.site-home-link {
  text-decoration: none;
}

.site-home-link:hover,
.notification-help a:hover {
  color: var(--green);
}

.section-heading h2,
.preview-heading h2,
.subsection-heading h3,
.section-body h3 {
  margin: 0;
}

.app-shell {
  width: min(1280px, calc(100% - 36px));
  margin: 22px auto 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  align-items: start;
  gap: 20px;
}

.editor,
.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.form-section {
  padding: 22px;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child {
  border-bottom: 0;
}

.section-heading,
.preview-heading,
.subsection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.offline-row {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

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

.section-heading > div,
.preview-heading > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 24px;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

.section-heading h2,
.preview-heading h2 {
  font-size: 17px;
  line-height: 1.4;
}

.section-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.section-description {
  margin: -8px 0 18px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
}

.field-grid,
.rule-grid {
  display: grid;
  gap: 16px;
}

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

.rule-grid {
  grid-template-columns: minmax(180px, 0.85fr) minmax(260px, 1.3fr) minmax(180px, 0.85fr);
  align-items: end;
}

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

.notification-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 0.9fr);
  gap: 20px;
  align-items: start;
}

.notification-help {
  min-height: 92px;
  padding: 13px 15px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.notification-help strong {
  font-size: 13px;
}

.notification-help a {
  width: fit-content;
  color: var(--green);
  font-size: 12px;
  text-decoration: none;
}

.field,
.field-group {
  min-width: 0;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 600;
}

.field small {
  min-height: 18px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 80, 0.12);
}

.field input.invalid-input {
  border-color: var(--red);
  background: var(--red-soft);
}

.field textarea.invalid-input {
  border-color: var(--red);
  background: var(--red-soft);
}

.field-group {
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.compact-group {
  margin-top: 16px;
}

.field-group legend {
  margin-bottom: 8px;
  padding: 0;
  color: var(--text);
  font-weight: 600;
}

.choice-grid {
  display: grid;
  gap: 8px;
}

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

.choice-pill input,
.segmented input,
.check-segmented input,
.card-type-choice input,
.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-pill span,
.segmented span,
.check-segmented span {
  min-height: 40px;
  padding: 9px 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.choice-pill:first-child span,
.segmented label:first-child span,
.check-segmented label:first-child span {
  border-radius: 5px 0 0 5px;
}

.choice-pill:last-child span,
.segmented label:last-child span,
.check-segmented label:last-child span {
  border-radius: 0 5px 5px 0;
}

.choice-pill span {
  border-radius: 5px;
}

.choice-pill input:checked + span,
.segmented input:checked + span,
.check-segmented input:checked + span {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
}

.segmented,
.check-segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
}

.segmented label + label span,
.check-segmented label + label span {
  border-left: 0;
}

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

.card-type-choice {
  min-height: 68px;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
}

.card-type-choice:has(input:checked) {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
}

.card-type-choice img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  flex: 0 0 auto;
}

.section-body h3,
.subsection-heading h3 {
  font-size: 14px;
}

.subsection-heading {
  margin: 22px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.switch-control strong {
  font-size: 13px;
}

.switch-track {
  width: 40px;
  height: 22px;
  padding: 3px;
  display: flex;
  align-items: center;
  border-radius: 11px;
  background: #aab4b1;
  transition: background 120ms ease;
}

.switch-track::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 120ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--green);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(18px);
}

.disabled-section {
  opacity: 0.48;
  pointer-events: none;
}

.preview-panel {
  position: sticky;
  top: 18px;
  overflow: hidden;
}

.preview-heading {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.validation-badge {
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.validation-badge.valid {
  color: var(--green);
  background: var(--green-soft);
}

.validation-badge.invalid {
  color: var(--amber);
  background: var(--amber-soft);
}

.validation-errors {
  display: none;
  margin: 14px 18px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--amber);
  background: var(--amber-soft);
  color: #724407;
  line-height: 1.7;
}

.validation-errors.visible {
  display: block;
}

.summary-preview {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.75;
}

.summary-preview {
  min-height: 260px;
  padding: 16px 18px;
  color: #25332e;
}

.actions {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.actions button {
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  grid-column: 1 / -1;
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
}

.text-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.action-status {
  min-height: 36px;
  margin: 0;
  padding: 0 18px 14px;
  color: var(--green);
  text-align: center;
  font-size: 12px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 360px;
  }

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

  .rule-grid,
  .rotation-grid {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .reward-field {
    max-width: none;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }

  .topbar {
    display: none;
  }

  .site-header {
    width: calc(100% - 24px);
    margin: 12px auto;
    grid-template-columns: auto 1fr;
  }

  .site-home-link {
    display: none;
  }

  .app-shell {
    width: 100%;
    margin: 0;
    display: block;
  }

  .editor,
  .preview-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .form-section {
    padding: 20px 16px;
  }

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

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

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

  .choice-pill span,
  .segmented span,
  .check-segmented span,
  .actions button,
  .field input,
    .field select,
    .field textarea {
    min-height: 46px;
  }

  .star-segmented {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-flow: row;
  }

  .star-segmented label:nth-child(2) span,
  .star-segmented label:nth-child(4) span {
    border-left: 0;
  }

  .star-segmented label:nth-child(3) span,
  .star-segmented label:nth-child(4) span {
    border-top: 0;
  }

  .star-segmented label:nth-child(2) span {
    border-radius: 0 5px 0 0;
  }

  .star-segmented label:nth-child(3) span {
    border-radius: 0 0 0 5px;
  }

  .preview-panel {
    position: static;
    border-top: 10px solid var(--bg);
  }

  .summary-preview {
    min-height: 0;
  }

  .actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(28, 41, 37, 0.1);
  }
}

@media (max-width: 390px) {
  .form-section {
    padding-inline: 13px;
  }

  .card-type-choice {
    min-height: 62px;
  }

  .card-type-choice img {
    width: 40px;
    height: 40px;
  }
}

