/* ========== 变量 ========== */
:root {
  --bg-page: #f5f0e1;
  --bg-card: #ffffff;
  --red: #c0392b;
  --yellow: #e6b422;
  --green: #27ae60;
  --indigo: #2c3e50;
  --wood: #8b5e3c;
  --text: #3e2723;
  --text-sub: #8d6e63;
  --border: #d4c5a9;
  --highlight: #fff3cd;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 48px;
  --tabbar-h: 50px;
  --text-min: 16px;
  --page-pad-x: 16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background: var(--bg-page);
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: var(--text-min);
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.6;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--wood); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; }

.ico { width: 22px; height: 22px; display: block; flex-shrink: 0; }

/* ========== 布局 ========== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-page);
}

.main-wrap {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-page);
  justify-content: center;
}

.main-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

/* ========== 顶部标题栏 ========== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: var(--page-pad-x);
  padding-bottom: 0;
  padding-left: var(--page-pad-x);
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  background: #fff;
  border-bottom: 1px solid rgba(212, 197, 169, 0.4);
  flex-shrink: 0;
  z-index: 10;
}

.nav-back, .icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--text);
  border-radius: 8px;
  flex-shrink: 0;
}

.nav-title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

/* ========== 去重面板 ========== */
.dedup-pane {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.dedup-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px var(--page-pad-x) 12px;
  -webkit-overflow-scrolling: touch;
}

body[data-tab="tutorial"] .dedup-pane,
body[data-tab="records"] .dedup-pane {
  flex: 0 0 0;
  overflow: hidden;
}

.tab-pane {
  display: none;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body[data-tab="tutorial"] .tutorial-pane,
body[data-tab="records"] .records-pane {
  display: flex;
}

.pane-inner {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px var(--page-pad-x) 24px;
  -webkit-overflow-scrolling: touch;
}

.pane-title { margin-bottom: 16px; }
.pane-title h2 { font-size: 20px; font-weight: 600; color: var(--text); }
.pane-title p { font-size: var(--text-min); color: var(--text-sub); margin-top: 4px; }

/* ========== 输入卡片 ========== */
.input-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.mode-seg {
  display: flex;
  gap: 4px;
  background: var(--bg-page);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
}

.mode-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
  border-radius: 8px;
  text-align: center;
  transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
  background: var(--bg-card);
  color: var(--wood);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.input-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.input-label {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--text);
}

.line-count {
  font-size: 14px;
  color: var(--text-sub);
}

.text-input {
  width: 100%;
  min-height: 150px;
  padding: 12px;
  font-size: var(--text-min);
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 12px;
  resize: vertical;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s;
}

.text-input:focus {
  outline: none;
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(230, 180, 34, 0.2);
}

.compare-wrap { margin-top: 12px; }
.compare-input { min-height: 100px; }

.settings-panel {
  margin-top: 12px;
  border-top: 1px solid rgba(212, 197, 169, 0.3);
  padding-top: 10px;
}

.settings-panel summary {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-panel summary::before {
  content: "▸";
  font-size: 12px;
  transition: transform 0.2s;
}

.settings-panel[open] summary::before { transform: rotate(90deg); }

.settings-body { padding-top: 10px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-min);
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}

.check-row input { width: 18px; height: 18px; accent-color: var(--wood); }

.slider-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-min);
  color: var(--text);
  margin-bottom: 6px;
}

.slider-val {
  font-family: Consolas, "Courier New", monospace;
  font-weight: 700;
  color: var(--indigo);
}

#thresholdSlider {
  width: 100%;
  accent-color: var(--wood);
  margin-bottom: 6px;
}

.settings-hint {
  font-size: 14px;
  color: var(--text-sub);
}

.btn-process {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  background: var(--wood);
  color: #fff;
  font-size: var(--text-min);
  font-weight: 600;
  border-radius: 10px;
  transition: opacity 0.2s;
}

.btn-process:disabled { opacity: 0.5; cursor: not-allowed; }

.progress-hint {
  margin-top: 8px;
  font-size: 14px;
  color: var(--indigo);
  text-align: center;
}

/* ========== 结果卡片 ========== */
.result-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.stats-block { margin-bottom: 14px; }

.stats-main {
  font-family: Consolas, "Courier New", monospace;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  word-break: break-all;
}

.stats-extra {
  margin-top: 6px;
  font-size: var(--text-min);
  color: var(--indigo);
  font-weight: 500;
}

.section-title {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.result-list {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.result-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(212, 197, 169, 0.25);
  font-size: 14px;
  line-height: 1.5;
}

.result-num {
  flex-shrink: 0;
  width: 28px;
  color: var(--text-sub);
  font-family: Consolas, monospace;
  text-align: right;
}

.result-text {
  flex: 1;
  word-break: break-all;
  color: var(--text);
}

.result-row.more-hint {
  justify-content: center;
  color: var(--text-sub);
  font-size: 14px;
  border: none;
}

/* 语义分组 */
.group-list { display: flex; flex-direction: column; gap: 8px; }

.semantic-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #faf8f5;
}

.group-summary {
  padding: 10px 12px;
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.group-summary::marker { display: none; }

.group-body {
  padding: 0 12px 12px;
  font-size: 14px;
}

.group-line {
  padding: 6px 0;
  border-bottom: 1px dashed rgba(212, 197, 169, 0.4);
  word-break: break-all;
}

.group-line:last-child { border-bottom: none; }

.group-line .sim-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 12px;
  background: var(--highlight);
  color: var(--yellow);
  border-radius: 4px;
  font-weight: 600;
}

.group-line.keep { color: var(--green); }
.group-line.drop { color: var(--red); text-decoration: line-through; opacity: 0.7; }

/* 相似度对比 */
.compare-score {
  text-align: center;
  font-family: Consolas, monospace;
  font-size: 28px;
  font-weight: 700;
  color: var(--indigo);
  margin-bottom: 14px;
}

.compare-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compare-col h4 {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.compare-text {
  padding: 12px;
  background: #faf8f5;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-all;
  min-height: 80px;
}

.compare-text mark {
  background: var(--highlight);
  color: var(--text);
  padding: 0 2px;
  border-radius: 2px;
}

@media (min-width: 600px) {
  body[data-mode="compare"] .compare-panels {
    flex-direction: row;
  }
  body[data-mode="compare"] .compare-col { flex: 1; }
}

/* AI 详情 */
.ai-detail {
  margin-top: 14px;
  border-top: 1px solid rgba(212, 197, 169, 0.3);
  padding-top: 10px;
}

.ai-detail summary {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--indigo);
  cursor: pointer;
}

.ai-pair-list { margin-top: 10px; }

.ai-pair {
  padding: 12px;
  margin-bottom: 10px;
  background: #faf8f5;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.ai-pair-head {
  font-size: var(--text-min);
  font-weight: 600;
  color: var(--indigo);
  margin-bottom: 8px;
}

.ai-text-a, .ai-text-b {
  font-size: 14px;
  padding: 6px 0;
  word-break: break-all;
}

.ai-text-a::before { content: "A: "; font-weight: 600; color: var(--green); }
.ai-text-b::before { content: "B: "; font-weight: 600; color: var(--red); }

.ai-type {
  font-size: 14px;
  color: var(--yellow);
  font-weight: 600;
  margin: 6px 0;
}

.ai-pair-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.ai-keep-a, .ai-keep-b {
  flex: 1;
  padding: 8px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.ai-keep-a.selected, .ai-keep-b.selected {
  background: var(--wood);
  color: #fff;
  border-color: var(--wood);
}

.btn-apply-all {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  background: var(--indigo);
  color: #fff;
  font-size: var(--text-min);
  font-weight: 600;
  border-radius: 10px;
}

/* 操作按钮 */
.result-actions, .bottom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.action-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 120px;
  padding: 10px 12px;
  font-size: var(--text-min);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  transition: background 0.2s;
}

.action-btn.primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
  flex: 1 1 100%;
}

.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 最近处理 */
.recent-section { margin-bottom: 12px; }

.recent-list, .records-list { display: flex; flex-direction: column; gap: 6px; }

.recent-item, .record-item, .history-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid rgba(212, 197, 169, 0.4);
  border-radius: 10px;
  font-size: var(--text-min);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.recent-text, .record-text, .history-text { display: block; }

.empty-hint {
  font-size: var(--text-min);
  color: var(--text-sub);
  text-align: center;
  padding: 16px 0;
}

.btn-clear-records {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  font-size: var(--text-min);
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 10px;
  background: #fff;
}

/* 广告位 */
.ad-slot {
  display: none;
  min-height: 60px;
  max-height: 60px;
  margin: 10px 0;
  color: #999;
  font-size: 14px;
  border-radius: 8px;
  border: 1px dashed #ccc;
  background: #fafafa;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-slot:not(:empty) {
  display: flex;
  flex: 0 0 60px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* SEO & 页脚 */
.seo-area { margin-top: 8px; }

.seo-section {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

.seo-section h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.seo-section h2 { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: var(--wood); }
.seo-section p, .seo-list li { font-size: var(--text-min); color: var(--text-sub); line-height: 1.7; }
.seo-list { padding-left: 20px; }
.seo-list li { margin-bottom: 8px; }

.faq-item { margin-bottom: 12px; }
.faq-item h3 { font-size: var(--text-min); font-weight: 600; color: var(--text); margin-bottom: 4px; }
.faq-item p { font-size: var(--text-min); color: var(--text-sub); }

.site-footer {
  text-align: center;
  padding: 16px 0 8px;
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.7;
}

/* 教程 */
.tutorial-block {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

.tutorial-block h3 { font-size: var(--text-min); font-weight: 600; color: var(--wood); margin-bottom: 6px; }
.tutorial-block p, .tutorial-list li { font-size: var(--text-min); color: var(--text-sub); line-height: 1.7; }
.tutorial-list { padding-left: 20px; margin-top: 6px; }

/* 历史浮层 */
.history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.history-overlay[hidden] { display: none; }

.history-panel {
  width: 100%;
  max-width: 480px;
  max-height: 70vh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 600;
  border-bottom: 1px solid rgba(212, 197, 169, 0.4);
}

.history-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(62, 39, 35, 0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: var(--text-min);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== 底部 TabBar ========== */
.tab-bar {
  display: flex;
  order: 999;
  flex-shrink: 0;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid rgba(212, 197, 169, 0.5);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-sub);
  padding: 4px 0;
}

.tab-btn.active { color: var(--wood); }

.tab-ico { width: 22px; height: 22px; }
.tab-text { font-size: 12px; }

/* PC 居中 */
@media (min-width: 481px) {
  .result-list { max-height: 480px; }
}

.footer-legal-row {
  display: block;
  margin: 0 0 14px;
  line-height: 1.9;
}
.footer-legal-row a,
.footer-legal-row a:visited,
.footer-legal-row a:focus {
  text-decoration: none;
}
.footer-legal-row a:hover {
  text-decoration: none;
}
.footer-legal-row .legal-sep,
.about-site-links .legal-sep {
  padding: 0 10px;
  opacity: 0.65;
  user-select: none;
}
.about-site-links {
  line-height: 1.9;
}
.about-site-links a {
  text-decoration: none;
}
.about-site-links a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
/* footer-stack-spacing */
footer,
.site-footer,
.footer,
#footer,
.app-footer,
.page-footer {
  line-height: 1.8;
}
footer p,
.site-footer p,
.footer p,
#footer p,
.app-footer p,
.page-footer p {
  margin: 0;
}
footer p + p,
.site-footer p + p,
.footer p + p,
#footer p + p,
.app-footer p + p,
.page-footer p + p,
.page-footer .footer-desc {
  margin-top: 10px;
}
