/* ---------- 颜色：浅色为默认，深色跟随系统 ---------- */
:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --field: #faf9f6;
  --text: #1d1f23;
  --muted: #6b6f78;
  --line: #e4e1db;
  --accent: #9b2c1f;          /* 链接、强调文字 */
  --accent-strong: #9b2c1f;   /* 主按钮底色 */
  --on-accent: #ffffff;       /* 主按钮文字 */
  --accent-soft: #f7ebe8;
  --ok: #1d7347;
  --ok-soft: #e4f3ea;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #b3261e;
  --bad-soft: #fbe8e6;
  --quote: #fbf8f1;
  --quote-line: #c9a46a;
  --shadow: 0 1px 2px rgba(30, 25, 20, 0.04), 0 4px 16px rgba(30, 25, 20, 0.05);
  --bone: #ece9e3;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b;
    --panel: #212226;
    --field: #1a1b1e;
    --text: #e9e7e2;
    --muted: #9a9ca3;
    --line: #34363b;
    --accent: #ec9a8a;
    --accent-strong: #d9705e;
    --on-accent: #1a0d0a;
    --accent-soft: #3a2521;
    --ok: #74d39c;
    --ok-soft: #1d3327;
    --warn: #f0c462;
    --warn-soft: #3a3020;
    --bad: #ff8f85;
    --bad-soft: #3d2221;
    --quote: #1b1c1f;
    --quote-line: #8c7447;
    --shadow: none;
    --bone: #2c2e33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
}

button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* ---------- 整体布局（电脑：左输入右结果） ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  min-height: 100vh;
  align-content: start;
}

.composer {
  position: sticky;
  top: 24px;
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
.tagline { margin: 4px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.dev-chip {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- 题目输入 ---------- */
.question-wrap { position: relative; }
textarea {
  display: block;
  width: 100%;
  min-height: 140px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  line-height: 1.65;
}
textarea::placeholder { color: var(--muted); opacity: 0.8; }
textarea:focus, select:focus, .dropzone:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.clear-text {
  position: absolute;
  right: 8px;
  bottom: 8px;
  border: 0;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  background: var(--line);
  color: var(--muted);
}

/* ---------- 图片区 ---------- */
.dropzone {
  margin-top: 12px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-image { cursor: default; border-style: solid; padding: 10px; }
.dropzone.has-image:hover { background: transparent; border-color: var(--line); }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.camera-icon { width: 26px; height: 26px; color: var(--accent); }
.drop-empty strong { font-size: 14px; }
.drop-hint { color: var(--muted); font-size: 12px; }
.drop-preview img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  margin: 0 auto;
  border-radius: 8px;
}
.preview-actions { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.chip-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  padding: 4px 14px;
  font-size: 13px;
}
.image-status { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.image-status.is-error { color: var(--bad); }

/* ---------- 开发者面板 ---------- */
.dev-panel {
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed var(--warn);
  border-radius: 12px;
  background: var(--warn-soft);
}
.field-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--warn); }
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; cursor: pointer; }

/* ---------- 按钮 ---------- */
.actions { display: flex; gap: 10px; margin-top: 18px; }
.primary-button {
  flex: 1;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.primary-button:active { transform: scale(0.98); }
.primary-button:disabled { cursor: progress; }
.primary-button.is-loading { opacity: 0.7; font-variant-numeric: tabular-nums; }
.ghost-button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.link-button { border: 0; background: none; color: var(--accent); padding: 0; font-size: 13px; }
.shortcut { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- 结果区 ---------- */
.results { display: grid; gap: 18px; align-content: start; }
.results.is-compare { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

.placeholder {
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 36px 24px;
  text-align: center;
}
.steps { list-style: none; margin: 0 auto 12px; padding: 0; display: inline-grid; gap: 10px; text-align: left; }
.steps li { display: flex; align-items: center; gap: 10px; }
.steps b {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}
.muted { color: var(--muted); font-size: 13px; margin: 0; }

.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  scroll-margin-top: 12px;
}
.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.result-title { font-weight: 600; flex: 1; }
.result-meta { flex-basis: 100%; color: var(--muted); font-size: 12px; line-height: 1.4; }
.result-meta:empty { display: none; }
.result-body { padding: 4px 18px 18px; }

.section { padding-top: 16px; }
.section + .section { border-top: 1px solid var(--line); margin-top: 16px; }
.section h3 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.section .text { white-space: pre-wrap; }

.locate { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.locate dt { color: var(--muted); font-size: 13px; padding-top: 1px; }
.locate dd { margin: 0; font-weight: 500; white-space: pre-wrap; }

.quote {
  white-space: pre-wrap;
  background: var(--quote);
  border-left: 3px solid var(--quote-line);
  border-radius: 0 10px 10px 0;
  padding: 12px 14px;
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: 15.5px;
  line-height: 1.8;
}
.badge { font-size: 12px; padding: 1px 8px; border-radius: 999px; font-weight: 500; letter-spacing: 0; }
.badge.verified { background: var(--ok-soft); color: var(--ok); }
.badge.partial, .badge.not_found { background: var(--warn-soft); color: var(--warn); }
.missing-list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--bad); }

/* 加载骨架 */
.caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 1px;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.skeleton { padding: 18px 0 6px; }
.bone {
  height: 14px;
  border-radius: 7px;
  margin-bottom: 12px;
  background: linear-gradient(90deg, var(--bone) 0%, var(--panel) 50%, var(--bone) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.bone.w30 { width: 30%; height: 26px; }
.bone.w90 { width: 90%; }
.bone.w75 { width: 75%; }
.bone.w60 { width: 60%; }
.skeleton-tip { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.state { padding: 24px 12px; text-align: center; }
.state.error { color: var(--bad); }
.state p { margin: 0 0 4px; }
.state-detail { font-size: 12px; color: var(--muted); }
.retry-button {
  margin-top: 10px;
  min-height: 40px;
  padding: 6px 22px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: var(--bad);
}

/* 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--panel);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.is-shown { opacity: 0.92; transform: translate(-50%, 0); }

.is-hidden { display: none !important; }
.only-touch { display: none; }

@media (hover: none) {
  .only-desktop { display: none; }
  .only-touch { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .composer { position: static; }
  .results.is-compare { grid-template-columns: 1fr; }
}

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .layout {
    padding: 0 0 calc(84px + env(safe-area-inset-bottom));
    gap: 12px;
  }
  .composer {
    border-radius: 0 0 20px 20px;
    border-width: 0 0 1px;
    padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
  }
  .brand h1 { font-size: 18px; }
  .tagline { margin-bottom: 12px; }
  /* iOS 输入框字号小于 16px 会自动放大页面 */
  textarea, select { font-size: 16px; }
  textarea { min-height: 120px; resize: none; }
  .dropzone { padding: 18px 12px; }
  .drop-empty strong { font-size: 15px; }
  .camera-icon { width: 30px; height: 30px; }
  .chip-button { padding: 6px 16px; font-size: 14px; }

  /* 底部操作栏固定，拇指能够到 */
  .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    margin: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .primary-button, .ghost-button { min-height: 50px; font-size: 16px; border-radius: 14px; }

  .results { padding: 0 12px; }
  .placeholder { padding: 24px 16px; border-radius: 14px; }
  .result { border-radius: 14px; }
  .result-head { padding: 10px 16px; }
  .result-head .copy-button { display: none; } /* 手机上用底部的“复制结果” */
  .result-body { padding: 2px 16px 18px; }
  .locate { grid-template-columns: 1fr; gap: 0; }
  .locate dt { margin-top: 8px; }
  .locate dt:first-child { margin-top: 0; }
  .quote { font-size: 16.5px; padding: 12px; }
}
