:root {
  --ink: #13251d;
  --ink-soft: #526158;
  --forest: #315d45;
  --forest-dark: #183e2d;
  --lime: #cde96f;
  --paper: #f7f5ed;
  --cream: #eee9db;
  --line: rgba(28, 61, 44, 0.14);
  --white: #fffef9;
  --shadow: 0 22px 60px rgba(24, 51, 37, 0.11);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 8%, rgba(205, 233, 111, .2), transparent 24rem),
    linear-gradient(115deg, #f3f0e5 0 36%, #f9f8f3 36% 100%);
}

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

.noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .32;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.045'/%3E%3C/svg%3E");
}

.topbar {
  height: 76px;
  padding: 0 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 237, .78);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 800; letter-spacing: -.02em; }
.brand em { font-size: 9px; letter-spacing: .15em; font-style: normal; color: var(--forest); border: 1px solid var(--line); padding: 3px 5px; border-radius: 20px; }
.brand-mark { width: 30px; height: 30px; display: flex; align-items: flex-end; gap: 3px; padding: 5px; background: var(--forest-dark); border-radius: 50% 50% 46% 54%; transform: rotate(-4deg); }
.brand-mark i { display: block; width: 5px; background: var(--lime); border-radius: 5px; }
.brand-mark i:nth-child(1) { height: 9px; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 12px; }

.topbar-note { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); }
.status-dot { width: 7px; height: 7px; background: #df9b2e; border-radius: 50%; box-shadow: 0 0 0 5px rgba(223,155,46,.1); }
.status-dot.online { background: #5f9f4d; box-shadow: 0 0 0 5px rgba(95,159,77,.1); }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 9px; }
.history-button { height: 38px; padding: 0 14px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.48); color: var(--forest-dark); font-size: 11px; font-weight: 750; cursor: pointer; }
.history-button:hover { background: #fff; transform: translateY(-1px); }
.history-button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { justify-self: end; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: rgba(255,255,255,.48); cursor: pointer; }
.icon-button:hover { background: #fff; transform: translateY(-1px); }
.icon-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.app-shell { min-height: calc(100vh - 76px); display: grid; grid-template-columns: minmax(390px, 0.83fr) minmax(610px, 1.5fr); }
.editor-panel { padding: 48px clamp(28px, 4vw, 64px); border-right: 1px solid var(--line); position: relative; }
.result-panel { padding: 48px clamp(28px, 4vw, 70px) 80px; background: rgba(255,255,255,.38); }
.panel-heading, .result-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.kicker { margin: 0 0 12px; color: var(--forest); letter-spacing: .18em; font-size: 10px; font-weight: 800; }
h1 { font-family: "Songti SC", "STSong", Georgia, serif; font-size: clamp(36px, 3.3vw, 50px); line-height: 1.08; letter-spacing: -.06em; margin: 0 0 40px; font-weight: 700; }
h1 span { color: var(--forest); }
.step-pill { white-space: nowrap; font-size: 11px; color: var(--forest); border: 1px solid var(--line); padding: 7px 10px; border-radius: 20px; background: rgba(255,255,255,.45); }

.field-label { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 750; margin-bottom: 10px; }
.field-label button { border: 0; background: transparent; color: var(--forest); font-size: 11px; cursor: pointer; padding: 0; border-bottom: 1px solid rgba(49,93,69,.3); }
.textarea-wrap { background: rgba(255,255,255,.67); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 8px 30px rgba(37,69,52,.05); transition: border-color .2s, box-shadow .2s; }
.textarea-wrap:focus-within { border-color: rgba(49,93,69,.5); box-shadow: 0 10px 35px rgba(37,69,52,.09); }
textarea { width: 100%; height: 220px; resize: vertical; display: block; border: 0; outline: 0; background: transparent; padding: 18px; color: var(--ink); line-height: 1.72; font-size: 13px; }
textarea::placeholder { color: #93a097; }
.text-meta { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding: 10px 18px; color: #7a887f; font-size: 10px; }

.copy-list { display: grid; gap: 14px; }
.copy-card { animation: rise .3s ease both; }
.copy-card-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 3px 7px; }
.copy-number { color: var(--forest); font-size: 10px; letter-spacing: .08em; }
.remove-copy { border: 0; background: transparent; color: #a06053; font-size: 10px; cursor: pointer; padding: 2px 0; }
.remove-copy:disabled { visibility: hidden; }
.copy-card textarea { height: 160px; min-height: 120px; }
.add-copy-button { width: 100%; min-height: 54px; margin-top: 12px; border: 1px dashed rgba(49,93,69,.36); border-radius: 14px; background: rgba(255,255,255,.4); color: var(--forest); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; cursor: pointer; transition: .2s; }
.add-copy-button span { font-size: 12px; font-weight: 800; }
.add-copy-button small { color: #7b897f; font-size: 9px; }
.add-copy-button:hover { background: rgba(237,245,208,.72); border-color: var(--forest); }
.add-copy-button:disabled { opacity: .45; cursor: not-allowed; }
.copy-limit { margin: 7px 3px 0; color: #859188; font-size: 9px; text-align: right; }

.control-section { margin-top: 28px; }
.field-label strong { color: var(--forest); font-size: 13px; }
.count-control { display: grid; grid-template-columns: 34px 1fr 34px; gap: 12px; align-items: center; }
.count-control button { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.62); cursor: pointer; font-size: 18px; }
.count-control button:hover { background: var(--forest); color: white; }
input[type="range"] { accent-color: var(--forest); cursor: pointer; width: 100%; }
.tick-row { display: flex; justify-content: space-between; color: #8b968f; font-size: 9px; margin: 4px 47px 0; }
.ratio-control { margin-top: 22px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-size: 12px; font-weight: 750; margin-bottom: 10px; }
.segmented { display: flex; background: rgba(255,255,255,.58); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.segmented button { flex: 1; min-width: 0; border: 0; background: transparent; border-radius: 8px; padding: 9px 5px; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px; color: #718078; }
.segmented button.active { background: var(--forest-dark); color: #fff; box-shadow: 0 4px 10px rgba(24,62,45,.18); }
.ratio-icon { display: inline-block; border: 1px solid currentColor; border-radius: 1px; }
.ratio-icon.portrait { width: 7px; height: 9px; }
.ratio-icon.square { width: 8px; height: 8px; }
.ratio-icon.landscape { width: 10px; height: 7px; }
.ratio-icon.story { width: 6px; height: 11px; }
.ratio-icon.cinema { width: 12px; height: 6px; }
select { width: 100%; height: 42px; border: 1px solid var(--line); background: rgba(255,255,255,.62); color: var(--ink); border-radius: 12px; padding: 0 12px; outline: 0; font-size: 11px; }

.ai-toggle { margin-top: 24px; display: flex; justify-content: space-between; align-items: center; gap: 14px; border: 1px solid var(--line); background: linear-gradient(110deg, rgba(255,255,255,.65), rgba(205,233,111,.09)); border-radius: 14px; padding: 13px 14px; cursor: pointer; }
.toggle-copy { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toggle-copy > span:last-child { display: grid; gap: 2px; }
.toggle-copy strong { font-size: 11px; }
.toggle-copy small { font-size: 9px; color: #7b877f; line-height: 1.4; }
.sparkle { width: 30px; height: 30px; display: grid; place-items: center; background: #edf5d0; color: var(--forest); border-radius: 9px; }
.ai-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.ai-toggle > i { width: 38px; height: 22px; flex: 0 0 auto; background: #cdd4cf; border-radius: 20px; position: relative; transition: .2s; }
.ai-toggle > i::after { content: ""; width: 16px; height: 16px; background: white; border-radius: 50%; position: absolute; left: 3px; top: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: .2s; }
.ai-toggle input:checked + i { background: var(--forest); }
.ai-toggle input:checked + i::after { transform: translateX(16px); }

.generate-button { width: 100%; margin-top: 24px; border: 0; background: var(--forest-dark); color: white; height: 56px; border-radius: 14px; display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; font-weight: 750; box-shadow: 0 12px 30px rgba(24,62,45,.2); transition: .2s; }
.generate-button:hover { background: #24513b; transform: translateY(-2px); box-shadow: 0 16px 34px rgba(24,62,45,.24); }
.generate-button:disabled { opacity: .55; cursor: wait; transform: none; }
.secondary-button:disabled, .download-all:disabled { opacity: .42; cursor: not-allowed; }
.generate-button svg, .secondary-button svg, .download-all svg, .privacy-note svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.generate-button svg { width: 18px; }
.privacy-note { display: flex; align-items: center; justify-content: center; gap: 6px; color: #839087; font-size: 9px; margin: 12px 0 0; }
.privacy-note svg { width: 12px; }

.result-heading { align-items: flex-end; }
.result-heading h2 { font-family: "Songti SC", "STSong", Georgia, serif; font-size: 30px; margin: 0 0 7px; letter-spacing: -.045em; }
.result-heading > div > p:last-child { color: var(--ink-soft); font-size: 12px; margin: 0; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.secondary-button, .download-all { height: 40px; border-radius: 11px; padding: 0 14px; display: flex; gap: 7px; align-items: center; justify-content: center; cursor: pointer; font-size: 11px; font-weight: 700; white-space: nowrap; }
.secondary-button { border: 1px solid var(--line); background: rgba(255,255,255,.72); }
.download-all { border: 1px solid var(--forest-dark); background: var(--forest-dark); color: white; }
.secondary-button svg, .download-all svg { width: 14px; }

.progress-banner { margin-top: 24px; height: 58px; border: 1px solid rgba(49,93,69,.17); background: rgba(234,243,205,.48); border-radius: 14px; padding: 0 16px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.progress-banner strong, .progress-banner small { display: block; }
.progress-banner strong { font-size: 11px; }
.progress-banner small { font-size: 9px; color: #738077; margin-top: 2px; }
.progress-banner > span:last-child { font-family: ui-monospace, monospace; font-size: 10px; color: var(--forest); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(49,93,69,.15); border-top-color: var(--forest); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 28px; }
.card-item { min-width: 0; animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(15px); } }
.canvas-frame { position: relative; background: #e1e5dd; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid rgba(22,53,37,.12); transition: transform .25s, box-shadow .25s; }
.canvas-frame:hover { transform: translateY(-5px); box-shadow: 0 28px 66px rgba(24,51,37,.17); }
.canvas-frame canvas { display: block; width: 100%; height: auto; }
.card-index { position: absolute; top: 10px; left: 10px; min-width: 27px; height: 27px; display: grid; place-items: center; color: white; background: rgba(20,49,34,.82); border: 1px solid rgba(255,255,255,.34); border-radius: 50%; font-size: 9px; font-weight: 800; backdrop-filter: blur(10px); }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 2px 0; }
.card-footer div { min-width: 0; }
.card-footer strong { display: block; font-size: 11px; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
.card-footer small { color: #839087; font-size: 9px; }
.download-one { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.7); cursor: pointer; display: grid; place-items: center; }
.download-one:hover { background: var(--forest); color: white; }
.download-one svg { width: 13px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.empty-state { min-height: 520px; display: grid; place-content: center; text-align: center; color: #7d8a81; }
.empty-state img { display: block; width: min(320px, 72%); height: auto; margin: 0 auto 8px; }
.empty-state h3 { color: var(--ink); margin: 12px 0 5px; }
.empty-state p { margin: 0; font-size: 12px; }
.hidden { display: none !important; }

dialog { width: min(460px, calc(100vw - 34px)); border: 1px solid rgba(30,65,45,.15); border-radius: 22px; padding: 32px; background: #faf8f0; color: var(--ink); box-shadow: 0 40px 100px rgba(19,37,29,.25); }
dialog::backdrop { background: rgba(16,34,25,.45); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; right: 16px; top: 12px; font-size: 24px; border: 0; background: transparent; cursor: pointer; color: #718078; }
dialog h2 { font-family: "Songti SC", serif; font-size: 27px; margin: 0 0 24px; }
dialog ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; counter-reset: help; }
dialog li { counter-increment: help; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: white; }
dialog li::before { content: counter(help, decimal-leading-zero); grid-row: span 2; color: var(--forest); font-size: 11px; font-weight: 800; padding-top: 2px; }
dialog li b { font-size: 12px; }
dialog li span { grid-column: 2; font-size: 10px; color: #758178; margin-top: 3px; }
.dialog-tip { font-size: 10px; background: #ecf1db; color: #53654f; padding: 10px 12px; border-radius: 9px; margin: 18px 0 0; }
.history-dialog { width: min(1120px, calc(100vw - 34px)); max-height: min(86vh, 920px); padding: 30px; overflow: auto; }
.history-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding-right: 28px; }
.history-heading h2 { margin-bottom: 5px; }
.history-heading p:last-child { margin: 0; color: var(--ink-soft); font-size: 11px; }
.history-state { min-height: 280px; display: grid; place-items: center; color: #758178; font-size: 12px; text-align: center; }
.history-grid { margin-top: 24px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.history-item { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #fff; box-shadow: 0 10px 28px rgba(24,51,37,.07); }
.history-image { display: block; aspect-ratio: 4 / 3; overflow: hidden; background: #e8ece4; }
.history-image img { display: block; width: 100%; height: 100%; object-fit: contain; }
.history-placeholder { aspect-ratio: 4 / 3; display: grid; place-content: center; justify-items: center; gap: 10px; background: linear-gradient(135deg, #eef2e3, #f7f5ed); color: var(--forest); }
.history-placeholder .spinner { width: 24px; height: 24px; }
.history-placeholder b { font-size: 11px; }
.history-failed .history-placeholder { color: #a04e40; background: #f8ece8; }
.history-copy { padding: 13px 14px 15px; }
.history-copy > div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-status { color: var(--forest); font-size: 9px; font-weight: 800; }
.history-copy time { color: #87928b; font-size: 9px; }
.history-copy p { margin: 10px 0 0; min-height: 4.5em; font-size: 11px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.history-copy small { display: block; margin-top: 8px; color: #a04e40; font-size: 9px; line-height: 1.4; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 50; background: #17392a; color: white; padding: 11px 18px; border-radius: 30px; font-size: 11px; opacity: 0; pointer-events: none; transition: .25s; box-shadow: 0 10px 35px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 390px 1fr; }
  .editor-panel, .result-panel { padding-left: 28px; padding-right: 28px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 18px; }
  .topbar-note { display: none; }
  .app-shell { display: block; }
  .editor-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .result-panel { min-height: 600px; }
  h1 { font-size: 46px; }
}

@media (max-width: 540px) {
  .topbar { height: 64px; }
  .brand em { display: none; }
  .editor-panel, .result-panel { padding: 32px 18px 54px; }
  .segmented { display: grid; grid-template-columns: repeat(5, 1fr); }
  .result-heading { display: block; }
  .result-actions { margin-top: 18px; }
  .card-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .card-footer strong { font-size: 10px; }
  .secondary-button, .download-all { flex: 1; }
  .history-button { padding: 0 10px; }
  .history-dialog { padding: 24px 18px; }
  .history-heading { align-items: flex-start; padding-right: 22px; }
  .history-grid { grid-template-columns: 1fr; }
}
