/* 藏头诗笺：手机优先，单手可操作；深色模式只改界面，诗笺本身不变 */

:root {
  --bg: #f5f0e6;
  --card: #fffdf8;
  --ink: #2a2420;
  --muted: #74685a;
  --line: #e2d8c6;
  --accent: #b3342b;
  --accent-ink: #ffffff;
  --chip: #f1ebdf;
  --chip-on: #2a2420;
  --chip-on-ink: #fdf8ee;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 6px 20px rgba(60, 40, 20, 0.06);
  --radius: 14px;
  --bar-h: 72px;
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --brush: "Ma Shan Zheng", "STKaiti", "KaiTi", var(--serif);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120e;
    --card: #1f1b16;
    --ink: #ece4d6;
    --muted: #a99d8c;
    --line: #3a332a;
    --accent: #e0645a;
    --accent-ink: #1a0d0b;
    --chip: #2a251e;
    --chip-on: #ece4d6;
    --chip-on-ink: #1f1b16;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #15120e;
  --card: #1f1b16;
  --ink: #ece4d6;
  --muted: #a99d8c;
  --line: #3a332a;
  --accent: #e0645a;
  --accent-ink: #1a0d0b;
  --chip: #2a251e;
  --chip-on: #ece4d6;
  --chip-on-ink: #1f1b16;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  overflow-x: hidden;
}
body.has-bar { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- 头部 ---------- */
.site-head {
  padding: 20px 16px 4px;
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.logo {
  font-family: var(--brush);
  font-size: 34px;
  line-height: 1.1;
  margin: 0;
  letter-spacing: 2px;
  text-decoration: none;
}
.logo .seal {
  display: inline-block;
  vertical-align: 6px;
  margin-left: 6px;
  font: 600 11px/1 var(--serif);
  color: #fff;
  background: var(--accent);
  padding: 3px 3px;
  border-radius: 2px;
  writing-mode: vertical-rl;
  letter-spacing: 0;
}
.head-links { font-size: 14px; color: var(--muted); display: flex; gap: 14px; }
.head-links a { text-decoration: none; }
.tagline { max-width: 1180px; margin: 0 auto; padding: 0 16px 12px; color: var(--muted); font-size: 15px; }

/* ---------- 布局 ---------- */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 32px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.app > * { min-width: 0; }
@media (min-width: 768px) {
  .app { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); align-items: start; gap: 28px; }
  .form-col { position: sticky; top: 16px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
}

/* ---------- 表单 ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.text-input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  font-size: 20px; /* ≥16px，避免 iPhone 自动放大 */
  font-family: var(--serif);
  letter-spacing: 2px;
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.text-input.small { font-size: 17px; min-height: 46px; letter-spacing: 1px; }
.text-input:focus { border-color: var(--ink); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; min-height: 1.2em; }
.hint.warn { color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  cursor: pointer;
  font-size: 15px;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chip:focus-visible, .btn:focus-visible, .thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.btn { text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .sub { font-size: 12px; font-weight: 400; opacity: 0.85; }
.remaining { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
.privacy { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.error { color: var(--accent); font-size: 14px; margin-top: 10px; }

/* ---------- 示例 ---------- */
.examples h2, .section-title { font: 600 15px/1.4 var(--sans); color: var(--muted); margin: 4px 0 10px; }
.example-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.example-grid img { border-radius: 8px; box-shadow: var(--shadow); width: 100%; height: auto; aspect-ratio: 3 / 4; }

/* ---------- 结果 ---------- */
.poem-title { font: 600 24px/1.4 var(--serif); margin: 0 0 4px; letter-spacing: 2px; }
.poem-meta { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.poem-lines { font: 20px/2 var(--serif); letter-spacing: 1px; margin: 0 0 12px; }
.poem-lines .head { color: var(--accent); }
.poem-note { font-size: 15px; margin: 0 0 8px; }
.annotations { margin: 8px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }
.annotations b { color: var(--ink); font-weight: 600; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.result-actions .btn { flex: 1 1 auto; }

.card-wrap { margin-top: 14px; }
.card-img {
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(40, 25, 10, 0.18);
  cursor: zoom-in;
  -webkit-touch-callout: default; /* 允许长按保存 */
  user-select: auto;
}
.card-hint { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.secondary-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.secondary-actions .btn { min-height: 44px; font-size: 14px; padding: 8px 14px; }

/* 样式选择器：手机上左右滑动，电脑上网格 */
.style-picker { margin-top: 16px; }
.group-tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.group-tabs .chip { flex: 0 0 auto; min-height: 44px; font-size: 14px; padding: 6px 14px; }
.thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 2px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.thumb {
  flex: 0 0 auto;
  width: 84px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  scroll-snap-align: start;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.thumb img { width: 84px; height: 112px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; }
.thumb[aria-pressed="true"] img { border-color: var(--accent); }
.thumb[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
.thumb .badge { display: inline-block; font-size: 11px; color: var(--accent); }
@media (min-width: 768px) {
  .thumbs { flex-wrap: wrap; overflow: visible; }
}

/* ---------- 底部固定操作栏（手机） ---------- */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.action-bar .btn { flex: 1 1 0; min-width: 0; padding: 8px 6px; flex-direction: column; gap: 0; line-height: 1.2; }
@media (min-width: 768px) {
  body.has-bar { padding-bottom: 0; }
  .action-bar {
    position: static;
    padding: 0;
    margin-top: 14px;
    background: none;
    border: 0;
    backdrop-filter: none;
    justify-content: center;
  }
  .action-bar .btn { flex: 0 1 180px; flex-direction: row; gap: 6px; }
}

/* ---------- 全屏查看 ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 8, 6, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.viewer img { max-height: 100%; max-width: 100%; object-fit: contain; -webkit-touch-callout: default; }
.viewer .close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 15px;
  padding: 0 14px;
}
.viewer .viewer-hint { position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #ddd; font-size: 13px; }

/* ---------- 等待：墨迹晕开 ---------- */
.loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.ink { position: relative; width: 120px; height: 120px; }
.ink span {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 25, 22, 0.75) 0%, rgba(30, 25, 22, 0.35) 45%, rgba(30, 25, 22, 0) 70%);
  animation: ink 2.4s ease-out infinite;
}
.ink span:nth-child(2) { animation-delay: 0.8s; }
.ink span:nth-child(3) { animation-delay: 1.6s; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ink span {
    background: radial-gradient(circle, rgba(236, 228, 214, 0.7) 0%, rgba(236, 228, 214, 0.3) 45%, rgba(236, 228, 214, 0) 70%);
  }
}
@keyframes ink {
  0% { transform: scale(0.1); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}
.loading-text { font: 18px/1.4 var(--serif); letter-spacing: 3px; }
.loading-sub { font-size: 13px; color: var(--muted); margin-top: -10px; }
@media (prefers-reduced-motion: reduce) {
  .ink span { animation: none; opacity: 0.6; transform: scale(0.8); }
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ---------- 分享页、关于页 ---------- */
.share-page { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
.cta { margin: 16px 0 8px; }
.cta .btn { width: 100%; font-size: 18px; min-height: 54px; }
.prose { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }
.prose h2 { font: 600 18px/1.4 var(--serif); margin: 28px 0 8px; }
.prose p, .prose li { color: var(--ink); }
.prose .muted { color: var(--muted); }
.site-foot { text-align: center; font-size: 13px; color: var(--muted); padding: 20px 16px 28px; }
.site-foot a { margin: 0 6px; }

/* ---------- 验证面板 ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 14, 8, 0.5);
}
.sheet-card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
}
@media (min-width: 768px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 18px; padding-bottom: 22px; }
}
.sheet-title { font: 600 20px/1.4 var(--serif); margin: 0 0 8px; }
.sheet-text { white-space: pre-line; color: var(--muted); font-size: 15px; margin: 0 0 16px; }
.sheet .step { display: flex; flex-direction: column; gap: 10px; }
.code-input { text-align: center; text-transform: uppercase; letter-spacing: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; min-height: 44px; width: 100%; cursor: pointer; text-decoration: underline; }

/* ---------- 后台 ---------- */
.admin { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; display: grid; gap: 16px; }
.admin-title { font: 600 18px/1.4 var(--serif); margin: 0 0 14px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats b { display: block; font-size: 20px; margin-top: 2px; }
.stats .unit { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; }
.row .text-input { flex: 1 1 auto; min-width: 0; }
.row .btn { flex: 0 0 auto; }
.text-input.code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 4px; text-transform: uppercase; }
.textarea { resize: vertical; line-height: 1.6; font-family: var(--sans); letter-spacing: 0; }
.code-input::placeholder { letter-spacing: 1px; font-family: var(--sans); }
