/* ============================================================
   古文扫描 · 今译  —  样式表（宣纸 / 墨色 / 朱印）
   ============================================================ */

:root {
  --paper:      #f4efe3;
  --paper-2:    #fbf8f0;
  --paper-3:    #ebe3d2;
  --ink:        #23201b;
  --ink-2:      #4a443a;
  --ink-3:      #8b8271;
  --line:       #d9cfba;
  --line-2:     #c6b998;
  --cinnabar:   #9c2b25;
  --cinnabar-2: #c0483a;
  --seal:       #a8332b;
  --jade:       #4a6b58;
  --blue:       #3c5a76;
  --shadow:     0 1px 2px rgba(60,48,28,.06), 0 10px 30px -12px rgba(60,48,28,.22);
  --radius:     10px;
  --font-gu:    "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", "STSong", "Noto Serif CJK SC", serif;
  --font-ui:    "PingFang SC", "Microsoft YaHei", "Noto Sans SC", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* hidden 属性优先：否则带 display 的类（.modal / .mode / .progress…）会把 hidden 顶掉 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.7;
  background:
    radial-gradient(1200px 600px at 12% -10%, #fffdf6 0%, rgba(255,253,246,0) 60%),
    radial-gradient(900px 500px at 100% 0%, #f7f2e6 0%, rgba(247,242,230,0) 55%),
    linear-gradient(180deg, #f6f1e6 0%, #efe8d9 100%);
  min-height: 100%;
}

/* 纸纹 */
.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background-image:
    repeating-linear-gradient(0deg, rgba(120,100,60,.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(120,100,60,.03) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 26px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,253,247,.92), rgba(255,253,247,.55));
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: center; gap: 14px; }

.seal {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 6px;
  background: var(--seal);
  color: #fff6ee;
  font-family: var(--font-gu);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 4px 12px -4px rgba(140,40,30,.6);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-gu);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .12em;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
  letter-spacing: .06em;
}

.topbar-actions { display: flex; gap: 8px; }

/* ---------------- 按钮 ---------------- */
button {
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 8px;
  transition: all .16s ease;
  border: 1px solid transparent;
}
button:disabled { opacity: .5; cursor: not-allowed; }

.primary {
  padding: 10px 22px;
  background: linear-gradient(180deg, var(--cinnabar-2), var(--cinnabar));
  color: #fff8f2;
  border-color: #87231e;
  font-weight: 600;
  letter-spacing: .08em;
  box-shadow: 0 2px 0 #7d201b, 0 8px 18px -10px rgba(140,40,30,.8);
}
.primary:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.primary:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 #7d201b; }

.ghost {
  padding: 8px 14px;
  background: rgba(255,255,255,.6);
  border-color: var(--line);
  color: var(--ink-2);
}
.ghost:hover:not(:disabled) { background: #fff; border-color: var(--line-2); color: var(--ink); }

/* ---------------- 布局 ---------------- */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(340px, 460px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 26px 26px;
  align-items: start;
  max-width: 1560px;
  margin: 0 auto;
}

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

.output-panel {
  min-height: 520px;
  display: flex;
  flex-direction: column;
}

/* ---------------- 标签页 ---------------- */
.tabs, .view-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin: -4px 0 14px;
}
.tab, .vtab {
  padding: 8px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 6px 6px 0 0;
  color: var(--ink-3);
  font-size: 14px;
  letter-spacing: .06em;
}
.tab:hover, .vtab:hover { color: var(--ink); background: rgba(255,255,255,.7); }
.tab.active, .vtab.active {
  color: var(--cinnabar);
  border-bottom-color: var(--cinnabar);
  font-weight: 600;
}

/* ---------------- 拖放区 ---------------- */
.dropzone {
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius);
  background:
    repeating-linear-gradient(45deg, rgba(200,185,150,.10) 0 8px, transparent 8px 16px),
    #fffdf7;
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  transition: all .18s ease;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--cinnabar);
  background-color: #fffaf3;
  outline: none;
  box-shadow: inset 0 0 0 3px rgba(192,72,58,.07);
}
.dz-icon {
  font-family: var(--font-gu);
  font-size: 30px;
  color: var(--line-2);
  line-height: 1;
  margin-bottom: 8px;
}
.dz-title { margin: 0 0 4px; font-size: 13.5px; color: var(--ink-2); }
.dz-hint  { margin: 0; font-size: 11.5px; color: var(--ink-3); }

/* ---------------- 表单 ---------------- */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--ink-2); }
.field > span { letter-spacing: .04em; }
.field.block { margin-top: 14px; }
.field-title { display: flex; justify-content: space-between; align-items: baseline; }
.field-title em { font-style: normal; font-size: 11.5px; color: var(--ink-3); }
.field.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field.checkbox input { accent-color: var(--cinnabar); width: 15px; height: 15px; }

select, input[type="text"], input[type="password"], textarea {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--cinnabar-2);
  box-shadow: 0 0 0 3px rgba(192,72,58,.10);
}

textarea#source {
  min-height: 300px;
  resize: vertical;
  font-family: var(--font-gu);
  font-size: 17px;
  line-height: 2.0;
  letter-spacing: .04em;
  padding: 14px 16px;
  background-image: linear-gradient(180deg, rgba(217,207,186,.55) 1px, transparent 1px);
  background-size: 100% 34px;
  background-position: 0 12px;
}

.ocr-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
  margin-top: 12px;
}
.ocr-bar .field { flex: 1 1 190px; }

/* ---------------- 缩略图 ---------------- */
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.thumb {
  position: relative;
  width: 82px; height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; line-height: 16px;
  border-radius: 50%;
  background: rgba(35,32,27,.72);
  color: #fff; font-size: 12px; text-align: center;
  border: none; padding: 0;
}
.thumb .ok { position: absolute; left: 3px; bottom: 3px; font-size: 11px; color: #fff;
  background: rgba(74,107,88,.9); border-radius: 4px; padding: 0 4px; }
.thumb.pending { opacity: .55; }

/* ---------------- 进度 ---------------- */
.progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12px; color: var(--ink-2); }
.progress .bar { flex: 1; height: 6px; border-radius: 99px; background: var(--paper-3); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--cinnabar-2), var(--cinnabar)); transition: width .25s ease; }

/* ---------------- 示例 ---------------- */
.samples { display: grid; gap: 8px; }
.sample {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  cursor: pointer;
  transition: all .15s ease;
}
.sample:hover { border-color: var(--cinnabar-2); background: #fff8f1; transform: translateX(2px); }
.sample b { display: block; font-family: var(--font-gu); font-size: 15px; letter-spacing: .06em; }
.sample span { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.sample em { font-style: normal; font-size: 12px; color: var(--ink-2); display: block; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 按钮行 ---------------- */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn-row.bottom { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---------------- 统计条 ---------------- */
.stats {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: 12px; color: var(--ink-3);
  padding-bottom: 10px; margin-bottom: 12px;
  border-bottom: 1px dashed var(--line-2);
}
.stats b { color: var(--cinnabar); font-size: 14px; font-family: var(--font-gu); }
.stats .era, .stats .engine { color: var(--ink-2); }
.stats .warnline { color: var(--cinnabar); font-weight: 600; }

/* ---------------- 结果 ---------------- */
.views { flex: 1; min-height: 0; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.result-empty {
  display: grid; place-content: center; gap: 6px;
  text-align: center; color: var(--ink-3);
  padding: 60px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}
.result-empty .big { font-family: var(--font-gu); font-size: 20px; color: var(--ink-2); margin: 0; letter-spacing: .12em; }
.result-empty p { margin: 0; font-size: 13px; }

/* 原文—译文卡片 */
.pair {
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-2);
  border-radius: 8px;
  background: #fffdf8;
  padding: 12px 15px 13px;
  margin-bottom: 11px;
  transition: border-color .15s;
}
.pair:hover { border-left-color: var(--cinnabar); }
.pair .no {
  display: inline-block;
  min-width: 22px;
  font-size: 11px; color: #fff; background: var(--ink-3);
  border-radius: 4px; padding: 0 5px; margin-right: 8px;
  vertical-align: 2px;
}
.pair .gu {
  font-family: var(--font-gu);
  font-size: 17.5px;
  line-height: 1.95;
  letter-spacing: .05em;
  color: var(--ink);
}
.pair .now {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--jade);
}
.pair .now::before {
  content: "译";
  display: inline-block;
  font-family: var(--font-gu);
  font-size: 11px; line-height: 16px;
  color: #fff; background: var(--jade);
  border-radius: 3px; padding: 0 4px; margin-right: 7px;
  vertical-align: 2px;
}
.pair .tags { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11.5px;
  color: var(--blue);
  background: rgba(60,90,118,.08);
  border: 1px solid rgba(60,90,118,.18);
  border-radius: 99px;
  padding: 0 8px;
}
.tag.warn { color: var(--cinnabar); background: rgba(156,43,37,.07); border-color: rgba(156,43,37,.2); }

/* 逐字 */
.w {
  position: relative;
  border-bottom: 1px solid transparent;
  cursor: help;
  padding-bottom: 1px;
}
.w.known { border-bottom-color: rgba(156,43,37,.45); border-bottom-style: dotted; }
.w.ph    { border-bottom-color: rgba(74,107,88,.5); border-bottom-style: dashed; }
.w:hover { background: rgba(255,238,205,.65); border-radius: 3px; }

.gloss-list { display: grid; gap: 8px; }
.gloss-row {
  display: grid;
  grid-template-columns: 74px minmax(0,1fr);
  gap: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 11px 14px;
}
.gloss-row .head {
  font-family: var(--font-gu);
  font-size: 21px;
  color: var(--cinnabar);
  text-align: center;
  border-right: 1px dashed var(--line);
}
.gloss-row .head small { display: block; font-family: var(--font-ui); font-size: 10.5px; color: var(--ink-3); }
.gloss-row .body { font-size: 13.5px; }
.gloss-row .body .mean { font-size: 14.5px; color: var(--ink); }
.gloss-row .body .mean b { color: var(--cinnabar); font-weight: 600; }
.gloss-row .body .pos {
  display: inline-block; font-size: 11px; color: var(--blue);
  border: 1px solid rgba(60,90,118,.25); border-radius: 4px; padding: 0 5px; margin-left: 6px;
  vertical-align: 1px;
}
.gloss-row .body .eg {
  margin-top: 4px; font-family: var(--font-gu); font-size: 13px; color: var(--ink-2);
  background: var(--paper); border-left: 2px solid var(--line-2); padding: 3px 9px; border-radius: 0 6px 6px 0;
}
.gloss-group-title {
  font-family: var(--font-gu);
  font-size: 15px; letter-spacing: .1em;
  color: var(--ink-2);
  margin: 16px 0 8px;
  padding-left: 9px;
  border-left: 3px solid var(--cinnabar);
}
.gloss-group-title:first-child { margin-top: 0; }

/* 悬停释义气泡 */
.tipbox {
  position: fixed;
  z-index: 99;
  max-width: 320px;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(35,32,27,.95);
  color: #f6f1e6;
  font-size: 12.5px;
  line-height: 1.6;
  box-shadow: 0 10px 26px -10px rgba(0,0,0,.6);
  pointer-events: none;
}
.tipbox b { font-family: var(--font-gu); font-size: 15px; color: #ffd9a0; }
.tipbox .t-pos { color: #9ec7a8; }
.tipbox .t-eg { display: block; margin-top: 4px; color: #cfc5ae; font-family: var(--font-gu); }

/* ---------------- 提示文字 ---------------- */
.note { font-size: 12px; color: var(--ink-3); margin: 8px 0 0; line-height: 1.65; }
.note.small { margin-top: 10px; }
.note.err { color: var(--cinnabar); }
.note.ok { color: var(--jade); }

/* ---------------- 弹层 ---------------- */
.modal[hidden] { display: none !important; }   /* 必须显式声明：.modal 的 display 会盖掉 hidden 属性 */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(40,34,24,.42);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.modal-card {
  width: min(460px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--paper-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: 0 30px 60px -20px rgba(50,40,20,.5);
  padding: 20px 22px;
}
.modal-card.wide { width: min(620px, 100%); }
.modal-card h2 {
  margin: 0 0 10px;
  font-family: var(--font-gu);
  font-size: 19px; letter-spacing: .1em;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.help-list { margin: 0; padding-left: 20px; font-size: 13.5px; color: var(--ink-2); }
.help-list li { margin-bottom: 8px; }
.help-list b { color: var(--ink); }

/* ---------------- AI 服务商预设 ---------------- */
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  text-align: left;
  transition: all .15s ease;
}
.preset:hover { border-color: var(--cinnabar-2); background: #fff8f1; transform: translateY(-1px); }
.preset b { font-size: 13px; color: var(--ink); }
.preset .badge-free {
  font-size: 10.5px; color: #fff; background: var(--jade);
  border-radius: 3px; padding: 0 4px;
}
.preset .badge-paid {
  font-size: 10.5px; color: var(--ink-3); background: var(--paper-3);
  border-radius: 3px; padding: 0 4px;
}
.field .hint { font-style: normal; font-size: 11px; color: var(--ink-3); margin-left: 6px; }
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; }
.ghost.tiny { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
#aiModelList { margin-top: 6px; }

/* ---------------- 页脚 ---------------- */
.foot {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 26px 26px;
  font-size: 11.5px; color: var(--ink-3);
  max-width: 1560px; margin: 0 auto;
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 14px 14px 20px; }
  .topbar { padding: 14px 16px 12px; }
  textarea#source { min-height: 220px; }
  .output-panel { min-height: 400px; }
  .brand-text h1 { font-size: 19px; }
}

@media print {
  .topbar-actions, .btn-row, .tabs, .view-tabs, .dropzone, .ocr-bar, .thumbs, .foot { display: none !important; }
  .layout { display: block; }
  body { background: #fff; }
}
