:root {
  --paper: #f7f0e6;
  --card: #fffaf3;
  --ink: #2b211d;
  --muted: #74655d;
  --line: #decfc0;
  --cocoa: #743d2a;
  --cocoa-dark: #51291e;
  --cocoa-soft: #a7654d;
  --switch-off: #d7c9bd;
  --canvas: #2c241f;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.app { width: min(1500px, 100%); margin: 0 auto; padding: 0 clamp(18px, 3vw, 48px) 44px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 106px;
  border-bottom: 1px solid var(--line);
}

.app-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  box-shadow: 0 3px 8px rgba(27, 61, 67, .16);
}

h1 {
  margin: 0;
  padding-right: 16px;
  border-right: 1px solid #bfae9f;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(25px, 2.2vw, 33px);
  font-weight: 600;
  letter-spacing: .05em;
}

.topbar > span { color: var(--muted); font-size: 14px; letter-spacing: .08em; }
.mobile-upload { display: none; }

.workbench {
  display: grid;
  grid-template-columns: 356px minmax(0, 1fr);
  gap: clamp(22px, 3vw, 42px);
  align-items: start;
  padding-top: 28px;
}

.controls { display: grid; gap: 22px; }

.drop-zone {
  min-height: 148px;
  display: grid;
  place-content: center;
  width: 100%;
  border: 1px dashed #bf9985;
  border-radius: 11px;
  color: var(--ink);
  background: rgba(255, 250, 243, .42);
  text-align: center;
}

.drop-zone.dragging { border-color: var(--cocoa); background: rgba(116, 61, 42, .08); }
.upload-mark { width: 40px; height: 40px; display: grid; place-items: center; margin: 0 auto 9px; border: 1.5px solid var(--ink); border-radius: 50%; font-size: 25px; line-height: 1; }
.drop-zone strong { display: block; font-family: Georgia, "Songti SC", serif; font-size: 19px; }
.drop-zone small { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }

h2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 14px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 20px;
  font-weight: 600;
}

h2 span { color: var(--muted); font-family: "Noto Sans SC", sans-serif; font-size: 12px; font-weight: 400; text-align: right; }

.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.template-card {
  position: relative;
  overflow: hidden;
  padding: 4px;
  border: 0;
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 4px 10px rgba(72, 44, 32, .12);
}

.template-card img { display: block; width: 100%; aspect-ratio: 1.35; object-fit: cover; border-radius: 5px; }
.template-card.selected::before {
  content: "✓";
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 7px 0 7px 0;
  color: #fff;
  background: var(--cocoa);
  font-size: 18px;
  font-weight: 700;
}

.settings { display: grid; gap: 1px; padding-top: 2px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.setting-row { display: flex; align-items: center; gap: 11px; min-height: 48px; border-bottom: 1px solid rgba(222, 207, 192, .72); font-family: Georgia, "Songti SC", serif; font-size: 17px; }
.setting-row:last-child { border-bottom: 0; }

.line-icon { width: 21px; height: 21px; display: grid; place-items: center; flex: 0 0 auto; border: 1.4px solid var(--ink); border-radius: 4px; font-family: sans-serif; font-size: 12px; font-weight: 700; }
.line-icon.icon-camera, .line-icon.icon-palette { border: 0; border-radius: 0; }
.line-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.line-icon.icon-palette svg { stroke-width: 1.3; }

.switch { position: relative; width: 39px; height: 23px; margin-left: auto; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--switch-off); transition: background .15s ease; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fffaf3; box-shadow: 0 1px 2px rgba(43, 33, 29, .2); transition: transform .15s ease; }
.switch input:checked + span { background: var(--cocoa-soft); }
.switch input:checked + span::after { transform: translateX(16px); }

.download {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(90deg, var(--cocoa-dark), var(--cocoa));
  box-shadow: 0 8px 18px rgba(91, 46, 30, .18);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .05em;
}

.download::before { content: "↓"; margin-right: 9px; font-size: 20px; vertical-align: -1px; }
.status { min-height: 30px; margin: -9px 0 0; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.status.error { color: #a5372a; }

.preview-column { min-width: 0; }
.preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 648px;
  padding: clamp(28px, 4vw, 58px);
  overflow: hidden;
  border-radius: 12px;
  background: radial-gradient(circle at 48% 45%, rgba(115, 82, 58, .2), transparent 28rem), var(--canvas);
  box-shadow: 0 16px 32px rgba(69, 44, 31, .12);
}

#previewCanvas { display: none; max-width: 100%; max-height: 530px; background: #fff; box-shadow: 0 20px 16px rgba(0, 0, 0, .28); }
.preview.ready #previewCanvas { display: block; }
.empty-state { display: grid; justify-items: center; gap: 8px; color: #d7d0c6; text-align: center; }
.empty-state span { font-size: 43px; color: #a88c78; }
.empty-state strong { font-family: Georgia, "Songti SC", serif; font-size: 23px; font-weight: 500; }
.empty-state small { color: #a89b90; font-size: 13px; }
.preview.ready .empty-state { display: none; }

.preview-actions { position: absolute; top: 17px; right: 17px; display: flex; gap: 8px; }
.preview-action { padding: 7px 10px; border: 1px solid rgba(255, 255, 255, .42); border-radius: 6px; color: #fff; background: rgba(34, 28, 24, .6); font-size: 12px; }
.privacy-note { margin: 12px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 1060px) {
  .workbench { grid-template-columns: 310px minmax(0, 1fr); gap: 24px; }
  .template-grid { gap: 9px; }
  .preview { min-height: 550px; padding: 32px; }
}

@media (max-width: 760px) {
  .app { padding: 0 16px 36px; }
  .topbar { min-height: 73px; gap: 10px; }
  .app-icon { width: 29px; height: 29px; border-radius: 8px; }
  h1 { padding-right: 0; border-right: 0; font-size: 23px; }
  .topbar > span { display: none; }
  .mobile-upload { display: block; width: 100%; min-height: 48px; margin-top: 18px; border: 0; border-radius: 8px; color: #fff; background: linear-gradient(90deg, var(--cocoa-dark), var(--cocoa)); font-weight: 650; }
  .mobile-upload::before { content: "＋"; margin-right: 7px; font-size: 19px; }
  .workbench { display: flex; flex-direction: column; gap: 22px; padding-top: 16px; }
  .preview-column { order: 1; width: 100%; }
  .controls { order: 2; width: 100%; gap: 20px; }
  .drop-zone { display: none; }
  .preview { min-height: 0; padding: 16px; border-radius: 10px; }
  #previewCanvas { max-height: none; width: 100%; height: auto; }
  .preview-actions { top: 25px; right: 25px; gap: 6px; }
  .preview-action { padding: 6px 8px; font-size: 11px; }
  .template-grid { gap: 11px; }
  h2 { font-size: 19px; }
  .setting-row { min-height: 45px; }
}
