:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-soft: #F5EFE6;
  --ink: #1F1D1A;
  --ink-muted: #6E675F;
  --ink-faint: #9B938A;
  --border: #EAE2D6;
  --accent: #D95D39;
  --accent-pressed: #C04A28;
  --accent-soft: #FDF0EB;
  --success: #257A57;
  --success-soft: #EAF6F0;
  --star: #D98A1C;
  --star-soft: #FFF6E5;
  --danger: #C53A2E;
  --shadow-sm: 0 2px 10px rgba(46, 34, 20, 0.05);
  --shadow-md: 0 8px 24px rgba(46, 34, 20, 0.09);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font-family: inherit;
}

.app-shell {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px));
}

/* 顶部栏 */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(250, 247, 242, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(234, 226, 214, 0.7);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

.shop-entry-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.shop-entry-btn:active {
  transform: scale(0.97);
  background: var(--surface-soft);
}

.shop-entry-btn.has-profile {
  border-color: rgba(37, 122, 87, 0.35);
  background: var(--success-soft);
  color: var(--success);
}

.shop-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

/* 主体 */
.main-content {
  padding: 14px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.form-card {
  padding: 18px 16px;
}

.field-group {
  margin-bottom: 16px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.required-mark {
  color: var(--accent);
}

.optional-tag {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface-soft);
  padding: 2px 7px;
  border-radius: 999px;
}

.text-input {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #FCFBF9;
  color: var(--ink);
  font-size: 16px; /* 防止 iOS 微信聚焦自动放大 */
  line-height: 1.4;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input::placeholder {
  color: var(--ink-faint);
}

.text-input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(217, 93, 57, 0.12);
}

.text-input.invalid {
  border-color: var(--danger);
}

.field-error {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--danger);
  font-weight: 500;
}

.shop-sync-hint {
  margin-top: 8px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  color: var(--success);
  font-size: 13px;
  line-height: 1.45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.shop-sync-hint.unlinked {
  background: var(--surface-soft);
  color: var(--ink-muted);
}

.hint-action-btn {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  padding: 2px 4px;
  cursor: pointer;
  flex-shrink: 0;
}

/* 语气风格单选 */
.tone-fieldset {
  border: none;
  margin: 0 0 16px;
  padding: 0;
}

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

.tone-option {
  position: relative;
  display: block;
  cursor: pointer;
}

.tone-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.tone-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 62px;
  padding: 10px 6px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #FCFBF9;
  transition: all 0.15s ease;
}

.tone-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.tone-desc {
  margin-top: 3px;
  font-size: 11px;
  color: var(--ink-muted);
}

.tone-option input[type="radio"]:checked + .tone-card {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.tone-option input[type="radio"]:checked + .tone-card .tone-name {
  color: var(--accent-pressed);
}

.tone-option input[type="radio"]:focus-visible + .tone-card {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 大按钮 */
.primary-cta {
  width: 100%;
  min-height: 54px;
  padding: 14px 20px;
  border: none;
  border-radius: 15px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(217, 93, 57, 0.28);
  transition: transform 0.1s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.primary-cta:active:not(:disabled) {
  transform: scale(0.985);
  background: var(--accent-pressed);
}

.primary-cta:disabled {
  opacity: 0.78;
  cursor: wait;
}

.secondary-cta {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.secondary-cta:active {
  background: var(--surface-soft);
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 结果区 & 加载骨架 */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px;
}

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.summary-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-soft);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 55%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-list,
.skeleton-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.angle-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-pressed);
}

.angle-badge.angle-promo {
  background: #FFF2DC;
  color: #A65E00;
}

.angle-badge.angle-scene {
  background: #EDF5F1;
  color: var(--success);
}

.char-count {
  font-size: 12px;
  color: var(--ink-faint);
}

.copy-body {
  margin: 0;
  font-size: 16px;
  line-height: 1.72;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}

.result-actions {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 10px;
  padding-top: 4px;
}

.action-btn {
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.action-btn:active {
  transform: scale(0.97);
}

.copy-btn {
  border: none;
  background: var(--ink);
  color: #FFFFFF;
}

.copy-btn.copied {
  background: var(--success);
}

.fav-btn {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
}

.fav-btn.is-fav {
  border-color: rgba(217, 138, 28, 0.45);
  background: var(--star-soft);
  color: var(--star);
}

/* 骨架屏 */
.skeleton-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line {
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(90deg, #F2ECE3 25%, #FAF6F0 50%, #F2ECE3 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

.skeleton-line.short {
  width: 34%;
  height: 22px;
}

.skeleton-line.medium {
  width: 68%;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* 错误态 */
.error-card {
  padding: 22px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.error-icon {
  font-size: 28px;
}

.error-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

.error-subtitle {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--ink-muted);
}

.retry-cta {
  width: 100%;
  max-width: 240px;
  min-height: 48px;
  border: none;
  border-radius: 13px;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

/* 历史记录 */
.history-section {
  margin-top: 6px;
  padding-top: 8px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-tabs {
  display: inline-flex;
  background: var(--surface-soft);
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
}

.history-tab {
  min-height: 36px;
  padding: 6px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.history-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.text-link-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: 13px;
  padding: 6px 8px;
  cursor: pointer;
}

.history-tip {
  margin: 8px 2px 12px;
  font-size: 13px;
  color: var(--ink-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 14px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.history-item {
  padding: 14px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.history-item:active {
  transform: scale(0.99);
}

.history-item.copied-flash {
  border-color: var(--success);
  background: #F7FCF9;
}

.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.history-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-muted);
}

.mini-pill {
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.history-content {
  margin: 0 0 10px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-time {
  font-size: 12px;
  color: var(--ink-faint);
}

.history-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-btn {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.mini-copy-btn {
  border: none;
  background: var(--ink);
  color: #FFFFFF;
}

.mini-copy-btn.copied {
  background: var(--success);
}

.mini-fav-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
}

.mini-fav-btn.is-fav {
  border-color: rgba(217, 138, 28, 0.45);
  background: var(--star-soft);
  color: var(--star);
}

/* 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(25, 20, 16, 0.48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal-sheet {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-md);
}

@media (min-width: 540px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }

  .modal-sheet {
    border-radius: 22px;
    padding: 22px;
  }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
}

.icon-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface-soft);
  color: var(--ink-muted);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.manual-copy-area {
  width: 100%;
  padding: 12px;
  margin-bottom: 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #FCFBF9;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  resize: none;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(31, 29, 26, 0.92);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

[hidden] {
  display: none !important;
}
