@font-face { font-family: "YinggouCute"; src: url("./fonts/ZCOOLKuaiLe-Regular.ttf") format("truetype"); font-display: block; }
@font-face { font-family: "YinggouHand"; src: url("./fonts/MaShanZheng-Regular.ttf") format("truetype"); font-display: block; }

:root {
  color-scheme: light;
  --paper: #f7f2e8;
  --paper-deep: #ece4d5;
  --paper-light: #fffdf8;
  --ink: #28251f;
  --muted: #756d61;
  --line: #d9cdbb;
  --accent: #ef4b35;
  --accent-dark: #c93a29;
  --shadow: 0 18px 50px rgba(74, 58, 38, .12);
  font-family: "Noto Sans SC", "Microsoft YaHei UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

#generation-hint[data-kind="warning"] { color: #8a351e; font-weight: 600; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--paper); }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 0%, rgba(255,255,255,.85), transparent 32rem),
    linear-gradient(135deg, rgba(239, 75, 53, .04), transparent 32%),
    var(--paper);
}

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

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 24px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 14px 6px 14px 6px;
  color: #fff;
  background: var(--ink);
  box-shadow: 6px 6px 0 var(--accent);
  font-size: 27px;
  font-weight: 800;
}

.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; letter-spacing: .16em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 4vw, 34px); letter-spacing: .08em; }
h2 { margin-bottom: 0; font-size: clamp(21px, 3vw, 28px); }

.install-button { margin-left: auto; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); gap: 22px; align-items: start; }
.card { border: 1px solid rgba(207, 193, 171, .9); border-radius: 26px; background: rgba(255, 253, 248, .82); box-shadow: var(--shadow); }
.editor-card { padding: 25px; }
.result-card { position: sticky; top: 18px; padding: 25px; background: var(--paper-deep); }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.version-badge, .status-pill { border-radius: 999px; padding: 7px 11px; color: var(--muted); background: rgba(255,255,255,.56); font-size: 12px; white-space: nowrap; }
.status-pill { color: var(--accent-dark); background: #fff4ee; }

fieldset { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
legend { width: 100%; margin-bottom: 11px; font-size: 16px; font-weight: 800; }
.field-label { display: block; margin: 11px 0 6px; color: var(--muted); font-size: 13px; }
.field-hint, .api-note, .privacy-note { color: var(--muted); font-size: 12px; line-height: 1.6; }
.field-hint { margin: 8px 0 0; }
.warning-hint { display: none; color: #aa432f; }

select, input[type="text"], input[type="email"], input[type="url"], input[type="password"], input[type="number"], input:not([type]), textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  color: var(--ink);
  outline: none;
  background: rgba(255,255,255,.72);
  transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(239,75,53,.13); }
textarea { resize: vertical; min-height: 104px; line-height: 1.6; }

.upload-zone { display: grid; place-items: center; min-height: 138px; padding: 21px; border: 1px dashed #cdbca6; border-radius: 16px; text-align: center; background: rgba(250,246,238,.8); transition: border-color .2s, background .2s; }
.upload-zone.dragover { border-color: var(--accent); background: #fff4ee; }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-title { font-weight: 700; }
.upload-subtitle { margin-top: 8px; color: var(--muted); font-size: 12px; }
.source-preview { overflow: hidden; margin-top: 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.source-preview img, .source-preview canvas { display: block; width: 100%; max-height: 230px; object-fit: contain; background: #f0ebe2; }
.source-preview [hidden] { display: none; }
.source-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 11px; color: var(--muted); font-size: 12px; }
.source-edit-button { margin: 0 6px 8px; }
.text-button { border: 0; padding: 5px; color: var(--accent-dark); background: transparent; }
.two-column-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; margin-top: 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.check-row input { width: 16px; height: 16px; margin-top: 1px; accent-color: var(--accent); }
.template-summary { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.template-details, .prompt-details { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.template-details summary, .prompt-details summary { cursor: pointer; color: var(--accent-dark); }
.template-details p { margin: 9px 0 0; padding: 10px; border-radius: 10px; color: #625a50; background: rgba(240,234,222,.7); white-space: pre-wrap; }
.api-fieldset { padding: 15px; border: 1px solid #e2d7c8; border-radius: 17px; background: rgba(239,232,220,.58); }
.api-note { margin-bottom: 10px; }
.privacy-note { margin: 12px 0 0; text-align: center; }

.account-panel { margin-bottom: 21px; padding: 16px; border: 1px solid #e2d7c8; border-radius: 17px; background: rgba(239,232,220,.58); }
.account-heading, .account-row, .history-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.account-heading { margin-bottom: 11px; }
.account-heading h3, .history-heading h3 { margin-bottom: 0; font-size: 16px; }
.beta-badge { border-radius: 999px; padding: 5px 9px; color: #8d392b; background: #fff4ee; font-size: 11px; white-space: nowrap; }
.inline-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.account-row p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.credit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 13px 0; }
.credit-grid div { display: flex; flex-direction: column; gap: 4px; padding: 11px; border-radius: 12px; background: rgba(255,255,255,.7); }
.credit-grid span { color: var(--muted); font-size: 11px; }
.credit-grid strong { font-size: 21px; }
.full-width { width: 100%; }
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 13px; }
.plan-card { padding: 12px; border: 1px solid #dfd2c1; border-radius: 13px; background: rgba(255,255,255,.72); }
.plan-card h4 { margin: 0 0 4px; font-size: 14px; }
.plan-price { margin: 0; color: var(--accent-dark); font-size: 22px; font-weight: 800; }
.plan-meta { min-height: 38px; margin: 5px 0 9px; color: var(--muted); font-size: 11px; line-height: 1.6; }

.primary-button, .secondary-button, .ghost-button { border: 0; border-radius: 12px; padding: 12px 16px; }
.primary-button { width: 100%; color: #fff; background: var(--accent); font-weight: 800; box-shadow: 0 8px 18px rgba(239,75,53,.22); }
.primary-button:hover { background: var(--accent-dark); }
.secondary-button { color: var(--ink); background: rgba(255,255,255,.72); }
.ghost-button { color: var(--accent-dark); background: #fff4ee; }

@media (max-width: 520px) { .plan-grid { grid-template-columns: 1fr; } }

.result-stage { position: relative; display: grid; place-items: center; min-height: min(70vh, 680px); overflow: hidden; border: 1px solid #d7cbb9; border-radius: 18px; background: var(--paper-light); }
.empty-state { padding: 50px 20px; color: var(--muted); text-align: center; }
.empty-state p { margin-bottom: 6px; font-weight: 700; }
.empty-state small { font-size: 12px; }
.empty-glyph { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto 15px; border: 1px solid var(--line); border-radius: 50%; color: var(--accent); font-size: 30px; font-weight: 800; }
#result-image { display: block; width: 100%; height: 100%; max-height: 70vh; object-fit: contain; }
.result-loader { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; color: var(--muted); text-align: center; background: rgba(255,253,248,.86); }
.result-loader[hidden] { display: none; }
.loader-ring { width: 38px; height: 38px; margin: 0 auto; border: 3px solid #eadcc9; border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.result-rationale { margin-top: 13px; padding: 13px; border-radius: 13px; color: #635a4e; background: rgba(255,253,248,.62); font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.result-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.animation-panel { margin-top: 14px; padding: 14px; border-radius: 15px; background: rgba(255,253,248,.66); }
.animation-title { margin-bottom: 9px; font-weight: 800; }
.animation-frame { overflow: hidden; border-radius: 11px; background: #f0e9dd; }
.animation-frame img, .animation-frame video { display: block; width: 100%; max-height: 330px; object-fit: contain; }
.animation-frame img { animation: breathe 2.8s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { transform: scale(1) translate(0,0) rotate(0deg); } 50% { transform: scale(1.035) translate(0.5%, -0.4%) rotate(.18deg); } }
.prompt-details pre { max-height: 240px; overflow: auto; margin: 9px 0 0; padding: 10px; border-radius: 10px; color: #625a50; background: rgba(240,234,222,.7); white-space: pre-wrap; font: inherit; }
.history-panel { margin-top: 18px; padding-top: 16px; border-top: 1px solid rgba(201,188,169,.9); }
.history-heading { align-items: center; margin-bottom: 10px; }
.history-list { display: grid; gap: 8px; }
.history-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; color: var(--ink); background: rgba(255,255,255,.65); text-align: left; }
.history-item span { color: var(--muted); font-size: 11px; }
.app-footer { margin: 20px 4px 0; color: var(--muted); font-size: 12px; text-align: center; }
.app-footer a, .notice-page a { color: var(--accent-dark); }
.notice-page { max-width: 900px; margin: 24px auto; padding: 24px; line-height: 1.65; }
.notice-page pre { overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 12px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: min(90vw, 560px); padding: 11px 15px; border-radius: 999px; color: #fff; background: rgba(40,37,31,.92); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; font-size: 13px; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.lettering-dialog { width: min(720px, calc(100vw - 24px)); max-width: none; max-height: min(92vh, 950px); overflow: auto; border: 1px solid var(--line); border-radius: 20px; padding: 20px; color: var(--ink); background: var(--paper-light); box-shadow: var(--shadow); }
.lettering-dialog::backdrop { background: rgba(30, 26, 22, .7); }
.lettering-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lettering-heading h2 { font-size: 22px; }
.lettering-dialog .inline-action { grid-template-columns: minmax(0, 1fr) auto auto; }
.lettering-dialog .inline-action button { padding: 10px; }
.lettering-canvas { display: block; max-width: 100%; max-height: 45vh; width: auto; height: auto; margin: 12px auto; background: #e9e3d8; touch-action: none; cursor: move; }
.lettering-dialog textarea { min-height: 64px; }
.lettering-dialog input[type="color"] { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: white; }
.lettering-dialog input[type="range"] { width: 100%; accent-color: var(--accent); }
.lettering-dialog .two-column-fields > div { min-width: 0; }
.lettering-dialog .primary-button { margin-top: 16px; }

@media (max-width: 900px) {
  .app-shell { padding: 16px; }
  .workspace { grid-template-columns: 1fr; }
  .result-card { position: static; }
  .result-stage { min-height: 52vh; }
}

@media (max-width: 520px) {
  .app-shell { padding: 10px; }
  .topbar { min-height: 57px; margin-bottom: 12px; }
  .brand-mark { width: 43px; height: 43px; font-size: 23px; box-shadow: 4px 4px 0 var(--accent); }
  .editor-card, .result-card { padding: 17px; border-radius: 20px; }
  .section-heading { margin-bottom: 17px; }
  .version-badge { display: none; }
  .result-stage { min-height: 46vh; }
  .result-actions > button { flex: 1 1 calc(50% - 9px); }
  .install-button { padding: 9px 10px; font-size: 12px; }
}
