:root {
  --bg: #efe7d5;
  --paper: rgba(255, 252, 246, 0.86);
  --line: rgba(52, 78, 107, 0.16);
  --ink: #163250;
  --ink-soft: #45627f;
  --accent: #af7a2a;
  --shadow: 0 24px 80px rgba(17, 40, 59, 0.14);
  --radius-lg: 28px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  background:
    radial-gradient(circle at top left, rgba(255, 245, 211, 0.86), transparent 34%),
    radial-gradient(circle at right center, rgba(202, 223, 241, 0.6), transparent 28%),
    linear-gradient(135deg, #f3ecda 0%, #e7e1d1 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent 78%);
  pointer-events: none;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(380px, 470px) 1fr;
  gap: 24px;
  padding: 24px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hero-card,
.panel-card,
.preview-stage {
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: var(--paper);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.hero-card {
  position: sticky;
  top: 20px;
  z-index: 3;
  padding: 24px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -44px;
  top: -44px;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(175, 122, 42, 0.28) 0%, transparent 66%);
}

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

.hero-card h1,
.preview-head h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.1;
}

.hero-copy {
  margin: 14px 0 0;
  color: var(--ink-soft);
  line-height: 1.7;
}

.panel-card {
  padding: 20px;
  border-radius: var(--radius-md);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(175, 122, 42, 0.12);
  color: var(--accent);
  font-size: 12px;
}

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

.template-tile,
.upload-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.54);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.template-tile:hover,
.upload-tile:hover,
.template-tile.is-active {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(32, 55, 80, 0.12);
  border-color: rgba(175, 122, 42, 0.35);
}

.template-tile img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(22, 50, 80, 0.08);
}

.template-tile strong,
.upload-tile span {
  font-size: 15px;
}

.template-tile small,
.upload-tile small,
.helper-text {
  color: var(--ink-soft);
  line-height: 1.6;
}

.field-grid,
.mini-grid {
  display: grid;
  gap: 12px;
}

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

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

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-span-2 {
  grid-column: span 2;
}

.field span {
  font-size: 13px;
  color: var(--ink-soft);
}

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

input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(69, 98, 127, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(175, 122, 42, 0.55);
  box-shadow: 0 0 0 4px rgba(175, 122, 42, 0.1);
}

textarea {
  resize: vertical;
}

.compact-field span {
  font-size: 12px;
}

.inline-actions,
.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-actions-stretch .field {
  flex: 1;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.66;
  transform: none;
}

.primary-btn {
  color: #fff8ec;
  background: linear-gradient(135deg, #284768 0%, #15304b 100%);
  box-shadow: 0 16px 28px rgba(21, 48, 75, 0.22);
}

.secondary-btn,
.ghost-btn {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(69, 98, 127, 0.16);
}

.block-card {
  padding: 14px 16px;
  margin-top: 12px;
  border-radius: 16px;
  border: 1px solid rgba(69, 98, 127, 0.12);
  background: rgba(255, 255, 255, 0.56);
}

.block-card summary {
  cursor: pointer;
  font-weight: 600;
}

.block-card[open] summary {
  margin-bottom: 14px;
}

.quality-readout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  border: 1px dashed rgba(69, 98, 127, 0.24);
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink-soft);
}

.preview-stage {
  position: sticky;
  top: 24px;
  align-self: start;
  min-height: calc(100vh - 48px);
  padding: 28px;
  border-radius: 36px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(248, 243, 233, 0.82)),
    rgba(255, 252, 246, 0.92);
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 22px;
}

.preview-meta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(22, 50, 80, 0.06);
  color: var(--ink-soft);
  font-size: 14px;
}

.divider {
  width: 1px;
  height: 16px;
  background: rgba(69, 98, 127, 0.22);
}

.preview-frame {
  position: relative;
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 24px;
  border-radius: 28px;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.94), rgba(240, 234, 220, 0.9));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.88),
    0 28px 80px rgba(17, 40, 59, 0.12);
}

.preview-frame::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 22px;
  border: 1px solid rgba(175, 122, 42, 0.14);
  pointer-events: none;
}

#previewCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 18px;
  background: #f9f5eb;
}

.preview-footer {
  margin-top: 16px;
  color: var(--ink-soft);
  text-align: center;
}

.mobile-export-row {
  display: none;
}

code {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(22, 50, 80, 0.08);
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 12px;
}

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

  .hero-card,
  .preview-stage {
    position: static;
  }

  .preview-stage {
    min-height: auto;
  }
}

@media (max-width: 900px) {
  .app-shell {
    gap: 18px;
  }

  .preview-stage {
    order: -1;
    padding: 22px;
    border-radius: 28px;
  }

  .preview-frame {
    width: 100%;
    padding: 18px;
  }

  .preview-head {
    flex-direction: column;
    align-items: start;
    margin-bottom: 16px;
  }

  .preview-meta {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
    gap: 14px;
  }

  .panel-card,
  .hero-card,
  .preview-stage {
    padding: 16px;
    border-radius: 22px;
  }

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

  .field-span-2 {
    grid-column: span 1;
  }

  .hero-card {
    padding-bottom: 14px;
  }

  .hero-card h1,
  .preview-head h2 {
    font-size: clamp(24px, 7.2vw, 32px);
  }

  .hero-copy,
  .preview-footer,
  .helper-text {
    font-size: 13px;
  }

  .panel-head {
    align-items: start;
    flex-direction: column;
    margin-bottom: 12px;
  }

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

  .template-tile,
  .upload-tile {
    padding: 10px;
    border-radius: 16px;
  }

  .template-tile img {
    aspect-ratio: 5 / 6;
    border-radius: 10px;
  }

  .template-tile strong,
  .upload-tile span {
    font-size: 13px;
  }

  .template-tile small {
    display: none;
  }

  .upload-tile small {
    font-size: 12px;
  }

  input,
  textarea,
  select {
    padding: 11px 12px;
    font-size: 15px;
  }

  .inline-actions,
  .action-row,
  .mobile-export-row {
    width: 100%;
  }

  .inline-actions > *,
  .action-row > *,
  .mobile-export-row > * {
    flex: 1 1 calc(50% - 5px);
  }

  .inline-actions-stretch .field {
    flex-basis: 100%;
  }

  .quality-readout {
    min-height: 44px;
    font-size: 13px;
  }

  .preview-head {
    flex-direction: column;
    align-items: start;
    gap: 12px;
  }

  .preview-stage {
    padding: 16px;
  }

  .preview-meta {
    gap: 8px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .divider {
    display: none;
  }

  .preview-frame {
    padding: 12px;
    border-radius: 22px;
  }

  #previewCanvas {
    border-radius: 14px;
  }

  .mobile-export-row {
    display: flex;
    gap: 10px;
    margin-top: 14px;
  }

  .preview-footer {
    margin-top: 12px;
    text-align: left;
  }
}

@media (max-width: 420px) {
  .template-gallery {
    gap: 8px;
  }

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

  .inline-actions > *,
  .action-row > *,
  .mobile-export-row > * {
    flex-basis: 100%;
  }
}
