/* ============================================================
   老法师墨宝复刻 · 法水长流风格样式
   设计 token（来源：.team/research/调研报告.md §3.3）
   主底：暖白宣纸 #faf7f2 / #f5efe3
   正文：深灰褐 #4a4038
   强调：朱红 #c81623
   标题：衬线宋体系
   ============================================================ */

/* ---------- 字体 ---------- */
@font-face {
  font-family: "MaShanZheng";
  src: url("../fonts/MaShanZheng-Regular.ttf") format("truetype");
  font-display: swap;
  font-weight: 400;
  font-style: normal;
}

:root {
  --paper: #faf7f2;
  --paper-deep: #f5efe3;
  --paper-card: #fdfaf4;
  --ink: #4a4038;
  --ink-soft: #6b5f54;
  --ink-faint: #9a8f83;
  --cinnabar: #c81623;
  --cinnabar-deep: #a8121c;
  --line: #e3dbcc;
  --line-soft: #ece5d7;
  --white: #ffffff;
  --shadow: 0 2px 10px rgba(74, 64, 56, 0.06);
  --serif: "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun",
    "Songti SC", "华文宋体", serif;
  --calligraphy: "MaShanZheng", "STKaiti", "KaiTi", "楷体", serif;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--paper);
  /* 宣纸质感：极淡的暖色渐变 + 细微纹理 */
  background-image:
    radial-gradient(circle at 20% 10%, rgba(200, 22, 35, 0.025), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(74, 64, 56, 0.03), transparent 45%),
    linear-gradient(180deg, #faf7f2 0%, #f6f1e8 100%);
  background-attachment: fixed;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 40px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 页眉 ---------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 8px 4px 28px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}

.seal-mark {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  background: var(--cinnabar);
  color: #fdf6ec;
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0;
  text-align: center;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18),
    0 2px 8px rgba(200, 22, 35, 0.28);
  writing-mode: vertical-rl;
  padding: 4px;
  box-sizing: border-box;
  overflow: visible;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-title {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--ink);
}

.site-subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--ink-soft);
  letter-spacing: 3px;
}

.site-note { margin: 6px 0 0; font-size: 12px; letter-spacing: 2px; color: var(--ink-faint); }

.site-nav {
  display: flex;
  gap: 8px;
  margin: -12px 0 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  letter-spacing: 3px;
  font-size: 14px;
  padding: 6px 14px;
  border-radius: 8px;
}
.site-nav a:hover,
.site-nav a.is-current {
  color: var(--cinnabar);
  background: rgba(200, 22, 35, 0.06);
}

.how-to { margin-bottom: 24px; }
.how-list { color: var(--ink); line-height: 1.9; padding-left: 22px; }
.how-extra { color: var(--ink-soft); font-size: 14px; line-height: 1.8; }
.how-actions { margin: 8px 0 12px; }
.how-actions .btn { width: auto; min-width: 240px; letter-spacing: 3px; }

.annotate-layout {
  display: grid;
  grid-template-columns: minmax(220px, 3fr) minmax(0, 7fr);
  gap: 24px;
  align-items: start;
}
.source-list { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow: auto; }
.source-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink);
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.source-item:hover, .source-item.is-on { border-color: var(--cinnabar); }
.source-item.is-done .source-meta { color: #4e6b3a; }
.source-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-meta { flex: none; color: var(--ink-faint); letter-spacing: 1px; }
.work-name { letter-spacing: 2px; color: var(--ink-soft); }
.work-preview {
  max-width: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
  margin: 0 auto 16px;
  background: #f7f0e2;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}
.glyph-row {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin: 18px 0 28px;
  padding: 18px;
  background: #fbf7ef;
  border-radius: 16px;
  border: 1px solid #e8e0d2;
}
.glyph-cell {
  width: 124px;
  text-align: center;
}
.glyph-frame {
  position: relative;
  width: 124px;
  height: 124px;
  background: #fffdf6;
  border: 2px solid #9e8d7c;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 2px #f5efe3,
              0 4px 10px rgba(74, 64, 56, 0.10);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.glyph-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(140, 123, 107, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(140, 123, 107, 0.08) 1px, transparent 1px);
  background-size: 50% 50%;
  pointer-events: none;
}
.glyph-cell:hover .glyph-frame {
  border-color: var(--cinnabar);
  box-shadow: 0 0 0 4px rgba(200, 22, 35, 0.14),
              0 6px 16px rgba(74, 64, 56, 0.14);
  transform: translateY(-2px);
}
.glyph-cell img {
  width: 112px;
  height: 112px;
  object-fit: contain;
  background: transparent;
  filter: contrast(1.08) brightness(0.98);
}
.glyph-index {
  position: absolute;
  top: 7px;
  left: 7px;
  min-width: 30px;
  height: 30px;
  line-height: 30px;
  padding: 0 8px;
  background: var(--cinnabar);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  border-radius: 15px;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.35);
  z-index: 2;
  text-align: center;
  letter-spacing: 0;
}
.glyph-char {
  display: inline-block;
  margin-top: 10px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 19px;
  font-weight: 700;
  min-width: 42px;
  letter-spacing: 1px;
  box-shadow: 0 1px 3px rgba(74, 64, 56, 0.08);
}
.glyph-char.is-filled {
  background: #fff;
  border: 1px solid #c4b8a8;
  color: #2c241b;
}
.glyph-char.is-empty {
  background: #fff0f0;
  border: 1px dashed var(--cinnabar);
  color: var(--cinnabar);
}

@media (max-width: 900px) {
  .glyph-cell,
  .glyph-frame {
    width: 96px;
    height: 96px;
  }
  .glyph-cell img {
    width: 86px;
    height: 86px;
  }
  .glyph-index {
    min-width: 24px;
    height: 24px;
    line-height: 24px;
    font-size: 13px;
  }
  .glyph-char {
    font-size: 16px;
    min-width: 34px;
  }
}

@media (max-width: 900px) {
  .annotate-layout { grid-template-columns: 1fr; }
}

/* ---------- 主体布局 ---------- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 28px;
  align-items: start;
  flex: 1;
}

.panel {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
}

.panel-title {
  margin: 0 0 20px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 6px;
  text-align: center;
  color: var(--ink);
}

.title-ornament {
  color: var(--cinnabar);
  font-weight: 400;
  padding: 0 6px;
}

/* ---------- 字段 ---------- */
.field {
  display: block;
  margin-bottom: 22px;
}

.field-label {
  display: block;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.textarea,
.input,
.select {
  width: 100%;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.8;
  letter-spacing: 2px;
}

.textarea:focus,
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--cinnabar);
  box-shadow: 0 0 0 3px rgba(200, 22, 35, 0.08);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234a4038' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-faint);
  text-align: right;
}

.field-options {
  border: none;
  margin: 0 0 22px;
  padding: 0;
}

.field-options legend.field-label {
  padding: 0;
}

.option-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.option-name {
  flex: none;
  width: 44px;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--ink-soft);
}

/* 分段选择：竖排 / 横排 */
.segmented {
  display: inline-flex;
  background: #f3ede1;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}

.seg {
  cursor: pointer;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: inline-block;
  padding: 5px 18px;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--ink-soft);
  border-radius: 6px;
  transition: all 0.16s ease;
}

.seg input:checked + span {
  background: var(--cinnabar);
  color: #fdf6ec;
}

.seg input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(200, 22, 35, 0.2);
}

/* 钤印开关 */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle-track {
  position: relative;
  width: 42px;
  height: 22px;
  background: #d8d0c2;
  border-radius: 999px;
  transition: background 0.2s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input:checked + .toggle-track {
  background: var(--cinnabar);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--ink-soft);
}

/* ---------- 按钮 ---------- */
.btn {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 6px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 13px 20px;
  transition: all 0.18s ease;
}

.btn-primary {
  width: 100%;
  background: var(--cinnabar);
  color: #fdf6ec;
  box-shadow: 0 2px 10px rgba(200, 22, 35, 0.25);
}

.btn-primary:hover {
  background: var(--cinnabar-deep);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(200, 22, 35, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: #c9bfae;
  color: #f6f1e8;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn-secondary {
  background: #fffdf9;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.btn-secondary:hover {
  border-color: var(--cinnabar);
  color: var(--cinnabar);
}

/* 加载态：按钮内旋转小点 */
.btn.is-loading .btn-label::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 10px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- 预览区 ---------- */
.preview-stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-card {
  position: relative;
  min-height: 420px;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background-color: #fdfaf4;
  /* 宣纸纹理 */
  background-image:
    linear-gradient(180deg, #fdfaf4 0%, #f7f0e2 100%),
    repeating-linear-gradient(90deg, rgba(74, 64, 56, 0.012) 0 1px, transparent 1px 7px);
  border: 1px solid var(--line-soft);
  transition: min-height 0.3s ease;
}

.preview-card.is-empty {
  min-height: 300px;
}

.preview-empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 24px;
}

.preview-empty-glyph {
  font-family: var(--calligraphy);
  font-size: 72px;
  color: var(--ink-soft);
  opacity: 0.55;
  line-height: 1;
  margin-bottom: 14px;
}

.preview-empty p {
  margin: 4px 0;
  font-size: 14px;
  letter-spacing: 2px;
}

.preview-empty-sub {
  font-size: 12px !important;
  color: var(--ink-faint);
  opacity: 0.8;
}

.preview-image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

/* 本地书法字体兜底预览（竖排） */
.preview-fallback {
  font-family: var(--calligraphy);
  writing-mode: vertical-rl;
  letter-spacing: 8px;
  color: var(--ink);
  font-size: 44px;
  line-height: 1.25;
  padding: 36px 20px;
  text-align: center;
  max-height: 60vh;
  overflow: auto;
}

.preview-fallback.is-horizontal {
  writing-mode: horizontal-tb;
  letter-spacing: 6px;
  font-size: 34px;
}

/* 状态条 */
.status-bar {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  letter-spacing: 1px;
  line-height: 1.5;
}

.status-bar.is-info {
  background: #f3ede1;
  color: var(--ink-soft);
  border: 1px solid var(--line-soft);
}

.status-bar.is-error {
  background: #faeceb;
  color: var(--cinnabar-deep);
  border: 1px solid #ecc8c4;
}

.status-bar.is-success {
  background: #eef3e9;
  color: #4e6b3a;
  border: 1px solid #d5e0c8;
}

.status-bar .tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(200, 22, 35, 0.1);
  color: var(--cinnabar);
}

.preview-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}

.preview-actions .btn {
  min-width: 200px;
}

/* ---------- 页脚 ---------- */
.site-footer {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.footer-line {
  margin: 4px 0;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--ink-soft);
}

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

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }

  .page {
    padding: 20px 16px 32px;
  }

  .site-title {
    font-size: 24px;
    letter-spacing: 3px;
  }

  .preview-card {
    min-height: 320px;
  }
}

@media (max-width: 480px) {
  .seal-mark {
    width: 54px;
    height: 54px;
    font-size: 10px;
  }

  .site-title {
    font-size: 20px;
  }

  .panel {
    padding: 20px 16px;
  }

  .option-group {
    flex-wrap: wrap;
  }
}

/* ---------- 单字 / 整幅 PSD 下载 ---------- */
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.psd-chars {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed rgba(120, 95, 60, 0.28);
}

.psd-chars-title {
  font-size: 14px;
  font-weight: 600;
  color: #6b5638;
  margin: 0 0 14px;
  letter-spacing: 1px;
}

.psd-chars-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.psd-char-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 92px;
  padding: 10px 8px;
  background: #fbf6ea;
  border: 1px solid rgba(120, 95, 60, 0.18);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(120, 95, 60, 0.08);
}

.psd-char-tile.is-fallback {
  background: #f3efe6;
  opacity: 0.85;
}

.psd-char-glyph {
  font-family: "Ma Shan Zheng", "STKaiti", "KaiTi", serif;
  font-size: 40px;
  line-height: 1.1;
  color: #1b1816;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.psd-char-meta {
  font-size: 12px;
  color: #8a7350;
}

.psd-char-tile.is-fallback .psd-char-meta {
  color: #b08a3a;
}

.btn-mini {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
  background: #6b5638;
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-mini:hover:not(:disabled) {
  background: #533f25;
}

.btn-mini:disabled {
  background: #b9ad97;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .psd-char-tile {
    width: 80px;
  }
  .psd-char-glyph {
    font-size: 34px;
  }
}
