:root {
  color-scheme: light;
  --ink: #1c1c1a;
  --muted: #68635a;
  --paper: #fbf7ef;
  --panel: #fffdf8;
  --line: #ded5c5;
  --accent: #a43120;
  --accent-dark: #762417;
  --mint: #dfeee7;
  --steel: #24323a;
  --shadow: 0 24px 70px rgba(36, 50, 58, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(164, 49, 32, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(61, 116, 101, 0.14), transparent 38%),
    var(--paper);
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 28px;
  width: min(1440px, calc(100vw - 40px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0;
}

.editor-panel,
.preview-panel {
  min-width: 0;
}

.editor-panel {
  align-self: start;
  padding: 26px;
  border: 1px solid rgba(222, 213, 197, 0.84);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.title-block {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0;
}

.summary {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 20px;
  padding: 4px;
  border: 1px solid rgba(222, 213, 197, 0.86);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.72);
}

.mode-tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0;
  transition:
    background 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.mode-tab.is-active {
  background: #fffdf8;
  color: var(--accent-dark);
  box-shadow: 0 8px 18px rgba(36, 50, 58, 0.1);
}

.mode-panel {
  margin-top: 18px;
  min-height: var(--mode-panel-min-height, auto);
}

.card-form {
  display: grid;
  gap: 16px;
}

.field,
.guide-toggle {
  display: grid;
  gap: 8px;
}

.field span,
.guide-toggle span {
  color: var(--steel);
  font-size: 13px;
  font-weight: 700;
}

.field .label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.label-row em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
}

.textarea-wrap {
  position: relative;
  display: block;
}

.char-count {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 250, 240, 0.88);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.char-count.is-under {
  color: #9b5b18;
}

.char-count.is-ideal {
  color: var(--accent-dark);
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fffaf0;
  color: var(--ink);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.field input {
  height: 44px;
  padding: 0 13px;
}

.field textarea {
  min-height: 396px;
  resize: vertical;
  padding: 12px 13px 34px;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(164, 49, 32, 0.72);
  background: #fffdf8;
  box-shadow: 0 0 0 3px rgba(164, 49, 32, 0.12);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.actions,
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.actions {
  padding-top: 8px;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.guide-toggle {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.guide-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.primary-action,
.ghost-action {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.primary-action {
  padding: 0 20px;
  background: var(--accent);
  color: #fffaf0;
  box-shadow: 0 12px 24px rgba(164, 49, 32, 0.22);
}

.ghost-action {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.82);
  color: var(--steel);
}

.template-link,
.batch-download-link {
  display: inline-grid;
  min-height: 34px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  color: var(--steel);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.primary-action:hover,
.ghost-action:hover {
  transform: translateY(-1px);
}

.primary-action:hover {
  background: var(--accent-dark);
  box-shadow: 0 15px 28px rgba(164, 49, 32, 0.26);
}

.batch-panel {
  display: grid;
  gap: 14px;
}

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

.batch-head h2 {
  margin: 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 28px;
  line-height: 1.2;
}

.batch-head .eyebrow {
  margin-bottom: 5px;
}

.batch-upload {
  display: grid;
  gap: 10px;
  justify-items: start;
  padding: 16px;
  border: 1px dashed rgba(164, 49, 32, 0.42);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(164, 49, 32, 0.08), transparent 46%),
    rgba(255, 250, 240, 0.78);
  cursor: pointer;
}

.batch-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.batch-upload-button {
  display: inline-grid;
  min-height: 42px;
  align-items: center;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--accent);
  color: #fffaf0;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(164, 49, 32, 0.2);
  transition:
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.batch-upload:hover .batch-upload-button {
  background: var(--accent-dark);
  box-shadow: 0 15px 28px rgba(164, 49, 32, 0.25);
  transform: translateY(-1px);
}

.batch-upload strong {
  overflow: hidden;
  color: var(--steel);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-schema {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.batch-schema span {
  font-weight: 800;
}

.batch-schema code {
  padding: 3px 7px;
  border: 1px solid rgba(0, 88, 184, 0.18);
  border-radius: 6px;
  background: rgba(238, 247, 251, 0.86);
  color: #0058b8;
  font-family: inherit;
  font-weight: 800;
}

.batch-summary,
.batch-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.batch-summary {
  padding: 10px 12px;
  border: 1px solid rgba(222, 213, 197, 0.84);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.74);
}

.batch-summary.is-ready {
  border-color: rgba(0, 88, 184, 0.24);
  color: var(--steel);
}

.batch-summary.is-error {
  border-color: rgba(164, 49, 32, 0.5);
  color: var(--accent-dark);
}

.batch-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid rgba(222, 213, 197, 0.84);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.74);
}

.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.batch-table th,
.batch-table td {
  padding: 8px 9px;
  border-bottom: 1px solid rgba(222, 213, 197, 0.72);
  text-align: left;
  vertical-align: top;
}

.batch-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff6e7;
  color: var(--steel);
  font-weight: 900;
}

.batch-table td:nth-child(1),
.batch-table td:nth-child(4) {
  width: 44px;
  color: var(--muted);
}

.batch-table td:nth-child(5) {
  width: 70px;
  font-weight: 800;
}

.batch-table .is-error td:nth-child(5) {
  color: var(--accent-dark);
}

.batch-table .is-warning td:nth-child(5) {
  color: #9b5b18;
}

.batch-download-link {
  justify-self: start;
  border-color: rgba(0, 88, 184, 0.22);
  color: #0058b8;
}

.batch-actions .primary-action:disabled,
.batch-actions .ghost-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-self: start;
  gap: 14px;
  height: var(--editor-panel-height, auto);
  min-height: var(--editor-panel-height, auto);
}

.preview-toolbar {
  min-height: 62px;
  padding: 14px 18px;
  border: 1px solid rgba(222, 213, 197, 0.86);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.76);
}

.preview-toolbar strong,
.preview-toolbar span {
  display: block;
}

.preview-toolbar strong {
  font-size: 15px;
}

.preview-toolbar span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(222, 213, 197, 0.86);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(36, 50, 58, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(36, 50, 58, 0.05) 1px, transparent 1px),
    rgba(255, 253, 248, 0.64);
  background-size: 22px 22px;
}

.software-signature {
  position: absolute;
  right: 18px;
  bottom: 14px;
  z-index: 2;
  color: #0058b8;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

canvas {
  display: block;
  width: auto;
  max-width: min(100%, 520px);
  max-height: 100%;
  height: auto;
  border-radius: 3px;
  background: white;
  box-shadow: 0 22px 60px rgba(36, 50, 58, 0.24);
}

.help-dialog {
  width: min(920px, calc(100vw - 36px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
}

.help-dialog::backdrop {
  background: rgba(28, 28, 26, 0.38);
  backdrop-filter: blur(4px);
}

.help-panel {
  padding: 24px;
  border: 1px solid rgba(222, 213, 197, 0.9);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 28px 80px rgba(36, 50, 58, 0.26);
}

.help-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.help-header .eyebrow {
  margin-bottom: 6px;
}

.help-header h2 {
  margin: 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 30px;
  line-height: 1.2;
}

.dialog-close {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.88);
  color: var(--steel);
  cursor: pointer;
  font-weight: 800;
}

.help-content {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) 1.1fr;
  gap: 22px;
  padding-top: 18px;
}

.help-visual {
  margin: 0;
}

.help-visual img {
  display: block;
  width: 100%;
  max-height: 390px;
  object-fit: contain;
  border: 1px solid rgba(0, 88, 184, 0.24);
  border-radius: 8px;
  background: #eef7fb;
}

.help-visual figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.help-steps {
  display: grid;
  align-content: center;
  gap: 18px;
}

.help-group {
  display: grid;
  gap: 12px;
}

.help-group h3 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
}

.help-steps section {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  align-items: start;
}

.help-steps section > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #0058b8;
  color: #fffdf8;
  font-size: 15px;
  font-weight: 900;
}

.help-steps strong {
  display: block;
  color: var(--steel);
  font-size: 16px;
}

.help-steps p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(720px, calc(100vw - 28px));
    padding: 18px 0;
  }

  .editor-panel {
    padding: 20px;
  }

  .canvas-stage {
    max-height: none;
  }

  .help-content {
    grid-template-columns: 1fr;
  }

  .help-visual img {
    max-height: 280px;
  }
}

@media (max-width: 560px) {
  .field-grid,
  .actions,
  .preview-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-buttons {
    display: grid;
    grid-template-columns: 1fr;
  }

  .batch-head,
  .batch-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-action,
  .ghost-action,
  .template-link,
  .batch-download-link {
    width: 100%;
  }

  h1 {
    font-size: 34px;
  }

  .help-panel {
    padding: 18px;
  }

  .help-header {
    display: grid;
  }
}
