/* ==========================================================================
   Z·绘 / ZCanvas — 设计系统（Anthropic 风格温暖极简）
   单一视觉事实来源。亮色为默认；[data-theme="dark"] 覆盖。
   ========================================================================== */

/* ---------- 设计 Token：亮色（默认） ---------- */
:root {
  /* 配色（暖米纸 + 粘土珊瑚，禁纯黑纯白） */
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-2: #f4f2ea;
  --surface-3: #ece9df;
  --border: #e6e3d9;
  --border-strong: #d6d2c5;
  --text: #1a1915;
  --text-2: #4a4942;
  --text-3: #807d72;
  --accent: #d97757;
  --accent-hover: #c5674a;
  --accent-press: #ab5639;
  --accent-soft: rgba(217, 119, 87, 0.1);
  --accent-soft-2: rgba(217, 119, 87, 0.18);
  --ok: #5e8c61;
  --error: #b5524a;

  /* 阴影（暖调） */
  --shadow-sm: 0 1px 2px rgba(26, 25, 21, 0.04), 0 1px 3px rgba(26, 25, 21, 0.05);
  --shadow-md: 0 6px 20px rgba(26, 25, 21, 0.07), 0 2px 6px rgba(26, 25, 21, 0.04);
  --shadow-lg: 0 24px 60px -18px rgba(26, 25, 21, 0.22), 0 8px 24px -12px rgba(26, 25, 21, 0.12);

  /* 圆角 */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-pill: 999px;

  /* 字体 */
  --font-serif: "Newsreader", "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-sans: "Inter", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* 节奏 */
  --maxw: 1240px;
  --nav-h: 66px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  color-scheme: light;
}

/* ---------- Token：暗色 ---------- */
[data-theme="dark"] {
  --bg: #1f1e1c;
  --surface: #2a2926;
  --surface-2: #323130;
  --surface-3: #3a3935;
  --border: #3a3935;
  --border-strong: #4a4843;
  --text: #f2f0e9;
  --text-2: #c9c6bc;
  --text-3: #94917f;
  --accent: #e8917a;
  --accent-hover: #eea291;
  --accent-press: #d67e63;
  --accent-soft: rgba(232, 145, 122, 0.14);
  --accent-soft-2: rgba(232, 145, 122, 0.24);
  --ok: #7caa7f;
  --error: #d97670;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.34);
  --shadow-lg: 0 24px 60px -18px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}
img {
  max-width: 100%;
  display: block;
}
button,
input,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: none;
  background: none;
}
a {
  color: var(--accent);
  text-decoration: none;
}
::selection {
  background: var(--accent-soft-2);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 排版 ---------- */
.serif {
  font-family: var(--font-serif);
}
h1,
h2,
h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.01em;
}
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   布局
   ========================================================================== */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 24px;
}

/* ---------- 顶栏 ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav__inner {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font-serif);
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand__mark {
  width: 30px;
  height: 30px;
  flex: none;
}
.nav__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 图标按钮（语言/主题/关于） */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  color: var(--text-2);
  border: 1px solid transparent;
  font-size: 0.86rem;
  font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}
.lang-btn {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border-strong);
}

/* ---------- Hero ---------- */
.hero {
  padding: 56px 0 28px;
  text-align: center;
  max-width: 760px;
  margin-inline: auto;
}
.hero__kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}
.hero__kicker::before,
.hero__kicker::after {
  content: "";
  width: 22px;
  height: 1px;
  background: var(--accent-soft-2);
}
.hero__title {
  font-size: clamp(2.1rem, 5.2vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}
.hero__title em {
  font-style: italic;
  color: var(--accent);
}
.hero__sub {
  font-size: clamp(1rem, 1.6vw, 1.12rem);
  color: var(--text-2);
  max-width: 560px;
  margin-inline: auto;
}

/* ---------- 工作区（两栏） ---------- */
.workspace {
  display: grid;
  grid-template-columns: 416px 1fr;
  gap: 28px;
  align-items: start;
  padding: 12px 0 64px;
}

/* 控制面板（左） */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: calc(var(--nav-h) + 20px);
}
.field {
  margin-bottom: 20px;
}
.field:last-child {
  margin-bottom: 0;
}
.field__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 9px;
  letter-spacing: 0.01em;
}
.field__label .hint {
  font-weight: 500;
  color: var(--text-3);
  font-size: 0.76rem;
}

/* 文本域 */
.textarea {
  width: 100%;
  min-height: 128px;
  resize: vertical;
  padding: 14px 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--text);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}
.textarea::placeholder {
  color: var(--text-3);
}
.input {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 灵感芯片行 */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-2);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.chip:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft-2);
}

/* 分段控件（比例） */
.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px;
}
.segmented__btn {
  padding: 8px 4px;
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-2);
  transition: background 0.18s var(--ease), color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.segmented__btn:hover {
  color: var(--text);
}
.segmented__btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* 滑块 */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--border-strong);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  cursor: pointer;
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-val {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--text-2);
  min-width: 42px;
  text-align: right;
}

/* 种子行 */
.seed-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.seed-row .input {
  flex: 1;
  font-family: var(--font-mono);
}

/* 折叠（高级） */
.disclosure {
  border-top: 1px dashed var(--border);
  padding-top: 16px;
  margin-top: 4px;
}
.disclosure__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-2);
  padding: 4px 0;
}
.disclosure__summary .chev {
  transition: transform 0.25s var(--ease);
}
.disclosure[open] .disclosure__summary .chev {
  transform: rotate(180deg);
}
.disclosure__body {
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 生成按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px 20px;
  border-radius: var(--r);
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background 0.2s var(--ease), transform 0.12s var(--ease), box-shadow 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.btn:active {
  transform: translateY(1px);
}
.btn--primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}
.btn--primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
}
.btn--primary:active {
  background: var(--accent-press);
}
.btn--primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.btn--ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
}
.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}
.btn--soft {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn--soft:hover {
  background: var(--accent-soft-2);
}
.btn--sm {
  padding: 9px 14px;
  font-size: 0.85rem;
  border-radius: var(--r-sm);
}
.btn svg {
  width: 17px;
  height: 17px;
  flex: none;
}
.btn--sm svg {
  width: 15px;
  height: 15px;
}

/* ==========================================================================
   画布（右）
   ========================================================================== */
.canvas {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.canvas__stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  position: relative;
}

/* 空态 */
.empty {
  text-align: center;
  color: var(--text-3);
  max-width: 320px;
}
.empty__mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  opacity: 0.5;
}
.empty__title {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--text-2);
  margin-bottom: 6px;
}

/* 等待态（签名） */
.loading {
  text-align: center;
}
.loading__visual {
  position: relative;
  width: 104px;
  height: 104px;
  margin: 0 auto 26px;
}
.loading__spark {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 56px;
  height: 56px;
  animation: breathe 2.4s var(--ease) infinite;
}
.loading__visual::before,
.loading__visual::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: ripple 2.4s var(--ease) infinite;
}
.loading__visual::after {
  animation-delay: 1.2s;
}
.loading__phase {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 12px;
  min-height: 1.5em;
}
.loading__timer {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--accent);
  margin-bottom: 6px;
}
.loading__usual {
  font-size: 0.86rem;
  color: var(--text-3);
}

/* 结果 */
.result {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.result__img-wrap {
  position: relative;
  max-width: 100%;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--surface-2);
}
.result__img {
  display: block;
  max-width: 100%;
  max-height: min(68vh, 720px);
  width: auto;
  height: auto;
  border-radius: var(--r-lg);
}
.result__img.reveal {
  animation: reveal 0.6s var(--ease) both;
}
.result__meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  font-size: 0.86rem;
  color: var(--text-2);
}
.result__meta span b {
  color: var(--text);
  font-weight: 600;
}
.result__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ==========================================================================
   历史
   ========================================================================== */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 8px 0 18px;
}
.section-head h2 {
  font-size: 1.4rem;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  padding-bottom: 64px;
}
.history-item {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.history-item:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}
.history-item__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent 60%);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
}
.history-item:hover .history-item__overlay {
  opacity: 1;
}
.history-item__btn {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.92);
  color: #1a1915;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.history-item__btn:hover {
  background: #fff;
}
.history-item__btn svg {
  width: 15px;
  height: 15px;
}
.history-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-3);
  padding: 40px 0;
  font-size: 0.95rem;
}

/* ==========================================================================
   页脚
   ========================================================================== */
.footer {
  border-top: 1px solid var(--border);
  padding: 34px 0 48px;
  color: var(--text-3);
  font-size: 0.86rem;
}
.footer__top {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}
.footer__disclaimer {
  max-width: 560px;
  line-height: 1.65;
}

/* ==========================================================================
   模态（密码门 / 关于）
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 60%, rgba(0, 0, 0, 0.28));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade 0.3s var(--ease);
}
.overlay[hidden] {
  display: none;
}
.modal {
  width: 100%;
  max-width: 408px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  text-align: center;
  animation: pop 0.32s var(--ease);
}
.modal__mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
}
.modal__title {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  margin-bottom: 8px;
}
.modal__sub {
  color: var(--text-2);
  font-size: 0.94rem;
  margin-bottom: 24px;
}
.modal .input {
  text-align: center;
  padding: 13px 15px;
  font-size: 1rem;
  margin-bottom: 10px;
}
.modal__error {
  color: var(--error);
  font-size: 0.84rem;
  min-height: 1.2em;
  margin-bottom: 8px;
}
.modal__hint {
  color: var(--text-3);
  font-size: 0.8rem;
  margin-top: 18px;
  line-height: 1.6;
}
.modal__body {
  text-align: left;
  color: var(--text-2);
  font-size: 0.96rem;
  line-height: 1.7;
  margin-bottom: 24px;
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(92vw, 460px);
  padding: 13px 18px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  color: var(--text);
  pointer-events: auto;
  animation: toastIn 0.3s var(--ease);
}
.toast--error {
  border-color: color-mix(in srgb, var(--error) 45%, var(--border));
}
.toast--error .toast__dot {
  background: var(--error);
}
.toast--ok .toast__dot {
  background: var(--ok);
}
.toast__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

/* ==========================================================================
   动效
   ========================================================================== */
@keyframes breathe {
  0%, 100% { transform: scale(0.86); opacity: 0.65; }
  50% { transform: scale(1.08); opacity: 1; }
}
@keyframes ripple {
  0% { transform: scale(0.7); opacity: 0.55; }
  100% { transform: scale(1.9); opacity: 0; }
}
@keyframes reveal {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in {
  animation: fade 0.5s var(--ease) both;
}

/* ==========================================================================
   响应式
   ========================================================================== */
@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .panel {
    position: static;
  }
  .canvas {
    min-height: 440px;
    order: -1; /* 移动端：画布在上 */
  }
}
@media (max-width: 640px) {
  .container {
    padding-inline: 16px;
  }
  .hero {
    padding: 36px 0 20px;
  }
  .panel,
  .modal {
    padding: 20px;
    border-radius: var(--r-lg);
  }
  .canvas {
    border-radius: var(--r-lg);
    min-height: 360px;
  }
  .result__img {
    max-height: 56vh;
  }
  .history-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }
  .nav__actions .icon-btn[data-hide-sm] {
    display: none;
  }
}

/* 尊重减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .loading__spark {
    animation: none;
    opacity: 0.85;
  }
  .loading__visual::before,
  .loading__visual::after {
    display: none;
  }
}

/* 工具类 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
[hidden] {
  display: none !important;
}
