:root {
  --bar-h: 58px;
  --ctrl-h: 46px;
  --col-w: 380px;
  --src-w: 300px;
  --text-size: 16.5px;
  --gap: 10px;

  --bg: #f6f6f3;
  --panel: #ffffff;
  --panel-2: #fbfbf9;
  --ink: #1b2027;
  --ink-2: #4c5561;
  --ink-3: #8a919c;
  --line: #e2e2dd;
  --line-2: #ededea;
  --accent: #2f6feb;
  --accent-soft: #eaf1ff;
  --del-bg: #ffe3e3;
  --del-ink: #b42318;
  --del-mark: #ffd7d7;
  --add-bg: #dcf5e3;
  --add-ink: #14713d;
  --add-mark: #c6efcf;
  --warn: #b54708;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

html[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1b1e24;
  --panel-2: #171a1f;
  --ink: #e7eaef;
  --ink-2: #b3bbc6;
  --ink-3: #7b848f;
  --line: #2b3038;
  --line-2: #232830;
  --accent: #6aa5ff;
  --accent-soft: #1c2739;
  --del-bg: #3a1d1f;
  --del-ink: #ff9d94;
  --del-mark: #4d2426;
  --add-bg: #16321f;
  --add-ink: #7ee2a0;
  --add-mark: #1d3f28;
  --warn: #d99b52;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.65 -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; overflow: hidden;
}

.serif, .cell-text, .src-text {
  font-family: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: var(--text-size);
  line-height: 1.85;
}

/* ---------- top bar ---------- */
.scroll-progress {
  position: fixed; inset: 0 auto auto 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--accent), #7ad0a5); z-index: 60;
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  overflow: visible;
  height: var(--bar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #55b48a);
  color: #fff; font-weight: 700; font-size: 15px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14.5px; letter-spacing: .2px; white-space: nowrap; }
.brand-text em { font-style: normal; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }

.case-tabs { display: flex; gap: 6px; margin-left: 6px; overflow-x: auto; scrollbar-width: none; }
.case-tabs::-webkit-scrollbar { display: none; }
.case-tabs button {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2);
  padding: 6px 13px; border-radius: 999px; cursor: pointer; font-size: 13px;
  transition: .16s ease; white-space: nowrap; flex: 0 0 auto;
}
.case-tabs button:hover { border-color: var(--accent); color: var(--ink); }
.case-tabs button.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
}
.case-tabs button small { opacity: .75; margin-left: 5px; font-size: 11px; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search-box { display: flex; align-items: center; gap: 8px; }
.search-box input {
  font: inherit; font-size: 13px; width: 210px;
  padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink);
}
.search-box input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.search-count { font-size: 12px; color: var(--ink-3); min-width: 46px; }

.btn {
  font: inherit; font-size: 13px; color: var(--ink-2);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; transition: .14s ease;
}
.btn:hover { color: var(--ink); border-color: var(--accent); }
.btn.icon { padding: 6px 10px; }
.btn.mini { padding: 3px 8px; font-size: 11.5px; border-radius: 7px; }

/* ---------- controls ---------- */
.controls {
  position: sticky; top: var(--bar-h); z-index: 40;
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 9px 18px; min-height: var(--ctrl-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.control-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.control-group.grow { margin-left: auto; }
.control-label { font-size: 12px; color: var(--ink-3); letter-spacing: .3px; white-space: nowrap; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--panel-2);
  color: var(--ink-2); padding: 5px 11px 5px 9px; border-radius: 999px;
  cursor: pointer; font-size: 12.5px; user-select: none; transition: .14s ease;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--c, var(--ink-3)); }
.chip.on { color: var(--ink); border-color: color-mix(in srgb, var(--c, var(--accent)) 55%, var(--line)); background: color-mix(in srgb, var(--c, var(--accent)) 9%, var(--panel)); }
.chip:not(.on) { opacity: .58; }
.chip .cnt { font-size: 11px; color: var(--ink-3); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.segmented button {
  font: inherit; font-size: 12.5px; border: 0; background: var(--panel-2); color: var(--ink-2);
  padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); white-space: nowrap;
}
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--accent); color: #fff; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.switch input { accent-color: var(--accent); }

input[type=range] { width: 92px; accent-color: var(--accent); }
.stat { font-size: 12px; color: var(--ink-3); margin-left: 8px; }

/* ---------- board ---------- */
.workspace { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.notice { margin: 14px 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink-2); font-size: 13px; }

.board-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
/* 表区内独立双向滚动：纵向同步行高，横向可滑向右边的列，序号列与原文列吸附在左侧 */
.board-scroll {
  flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.board-scroll::-webkit-scrollbar { width: 11px; height: 13px; }
.board-scroll::-webkit-scrollbar-track { background: var(--panel-2); }
.board-scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ink-3) 45%, transparent); border-radius: 8px; border: 3px solid var(--panel-2); }
.board-scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
.board-scroll::-webkit-scrollbar-corner { background: var(--panel-2); }

.edge-hint {
  position: absolute; right: 18px; bottom: 14px; z-index: 30;
  font-size: 11.5px; color: #fff; background: color-mix(in srgb, var(--ink) 78%, transparent);
  padding: 5px 11px; border-radius: 999px; pointer-events: none;
  animation: hint-in .3s ease;
}
@keyframes hint-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 底部横向滑轨 ---------- */
.rail {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 7px 16px; background: var(--panel); border-top: 1px solid var(--line);
}
.rail-track { position: relative; flex: 1; height: 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.rail-thumb {
  position: absolute; top: 0; bottom: 0; left: 0; min-width: 34px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 62%, var(--ink-3)); cursor: grab;
  transition: background .14s ease;
}
.rail-thumb:hover, .rail-thumb.dragging { background: var(--accent); cursor: grabbing; }
.rail[data-scrollable="0"] .rail-track { opacity: .4; }
.rail-hint { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }

/* 序号列 + 原文列吸附在左侧，各列天然同步行高 */
.board {
  display: grid;
  grid-template-columns: var(--gutter-w) repeat(auto-fill, minmax(var(--col-w), 1fr));
  min-width: 100%;
}

/* header row cells */
.hcell {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line-2);
  padding: 9px 12px;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 52px;
}
.hcell .hname { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 7px; }
.hcell .hname .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--ink-3)); }
.hcell .hmeta { font-size: 11.5px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; }
.hcell { touch-action: none; cursor: grab; }
.hcell.gutter, .hcell.src { cursor: default; }
.hcell.dragging { opacity: .3; }
.hcell .wpx { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.hcell .move { margin-left: auto; display: inline-flex; gap: 2px; opacity: 0; transition: .12s ease; }
.hcell:hover .move { opacity: 1; }
.hcell .move button {
  font: inherit; font-size: 13px; line-height: 1; width: 20px; padding: 2px 0;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--ink-2); cursor: pointer;
}
.hcell .move button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
body.dragging-col, body.resizing { user-select: none; }
body.dragging-col { cursor: grabbing; }
body.resizing { cursor: col-resize; }
.drag-ghost {
  position: fixed; z-index: 90; pointer-events: none; padding: 8px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--accent); box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 650; color: var(--ink); transform: rotate(-.4deg);
}
.drag-ghost .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; background: var(--c, var(--accent)); }
.board-scroll.panning { cursor: grabbing; user-select: none; }
.hcell.dragging { opacity: .45; }
.hcell.drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.hcell.drop-after { box-shadow: inset -3px 0 0 var(--accent); }
.hcell .resizer {
  position: absolute; top: 0; right: -4px; width: 9px; height: 100%;
  cursor: col-resize; z-index: 28; display: grid; place-items: center;
}
.hcell .resizer::after { content: ""; width: 2px; height: 55%; border-radius: 2px; background: transparent; transition: .12s ease; }
.hcell .resizer:hover::after, .hcell .resizer.active::after { background: var(--accent); height: 100%; }
.hcell .grip { color: var(--ink-3); font-size: 11px; letter-spacing: -1px; }
.hcell .hstage { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--line-2); color: var(--ink-2); }
.hcell .hstage.bad { background: color-mix(in srgb, var(--warn) 16%, var(--panel)); color: var(--warn); }
.hcell.gutter, .cell.gutter { position: sticky; left: 0; z-index: 22; width: var(--gutter-w, 46px); background: var(--panel); }
.hcell.gutter { z-index: 26; align-items: center; }
.hcell.src { left: var(--gutter-w, 46px); z-index: 24; box-shadow: 10px 0 14px -12px rgba(16,24,40,.35); }
.cell.src { position: sticky; left: var(--gutter-w, 46px); z-index: 12; background: var(--panel-2); box-shadow: 1px 0 0 var(--line-2), 10px 0 14px -12px rgba(16,24,40,.35); }
.cell.gutter { z-index: 14; display: grid; place-items: center; background: var(--panel); }

/* body cells */
.cell {
  padding: 12px 14px 14px;
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
  background: var(--panel);
  vertical-align: top;
}
.cell.gutter .pnum { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.cell.gutter .marks { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.cell.gutter .tick { width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--add-ink)); }

.cell.src .src-text { color: var(--ink-2); }
.cell.blank { background: var(--panel-2); }
.cell.is-changed { background: color-mix(in srgb, var(--add-bg) 32%, var(--panel)); }
.cell.is-open { background: color-mix(in srgb, var(--add-bg) 20%, var(--panel)); }
.cell.is-hit { background: var(--accent-soft); }
.cell.flash { animation: flash 1.1s ease; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--accent) 26%, var(--panel)); } 100% { background: var(--panel); } }

.cell-text { word-break: break-word; overflow-wrap: anywhere; white-space: pre-wrap; color: var(--ink); }
.cell-text .empty-tag, .muted { color: var(--ink-3); font-size: 12px; font-family: inherit; }

/* inline diff marks */
ins.add { background: var(--add-mark); color: var(--add-ink); text-decoration: none; border-radius: 3px; padding: 0 1px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--add-ink) 22%, transparent) inset; }
del.rem { background: var(--del-mark); color: var(--del-ink); text-decoration: line-through; text-decoration-thickness: 1px; border-radius: 3px; padding: 0 1px; opacity: .9; }
mark.hit { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }

/* ---------- 审校标记与浮动胶囊 ---------- */

.badge {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel)); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}
.badge.cat-accuracy { background: #fdecec; color: #b42318; border-color: #f6cccc; }
.badge.cat-fluency { background: #eaf1ff; color: #2f6feb; border-color: #cfe0ff; }
.badge.cat-format { background: #f2ebff; color: #7b4bd6; border-color: #e0d4ff; }
.badge.cat-term { background: #e6f7f2; color: #0f7b62; border-color: #c6ecdf; }
html[data-theme="dark"] .badge.cat-accuracy { background: #3a1d1f; color: #ff9d94; border-color: #55292b; }
html[data-theme="dark"] .badge.cat-fluency { background: #1c2739; color: #8ab6ff; border-color: #2a3b57; }
html[data-theme="dark"] .badge.cat-format { background: #2a2140; color: #c3a6ff; border-color: #3b2f57; }
html[data-theme="dark"] .badge.cat-term { background: #14312a; color: #7fdcc0; border-color: #20473c; }

.cell-text { position: relative; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  font: inherit; font-size: 11.5px; line-height: 1;
  padding: 4px 9px 4px 8px; border-radius: 999px; cursor: pointer;
  background: color-mix(in srgb, var(--add-bg) 60%, var(--panel));
  color: var(--add-ink);
  border: 1px solid color-mix(in srgb, var(--add-ink) 28%, transparent);
  transition: .14s ease;
}
.pill:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.pill.unresolved { background: color-mix(in srgb, var(--del-bg) 55%, var(--panel)); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.pill .cat { font-size: 11px; opacity: .8; }
.pill .caret { font-size: 9px; opacity: .65; }
.pill[aria-expanded="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 初译→终稿 模式下的行内两行对照 */
.pair { display: flex; flex-direction: column; gap: 4px; }
.pair .row-old, .pair .row-new { display: flex; gap: 6px; border-radius: 7px; padding: 3px 7px; }
.pair .row-old { background: var(--del-bg); color: var(--del-ink); }
.pair .row-new { background: var(--add-bg); color: var(--add-ink); }
.pair .tag { flex: 0 0 auto; font-size: 11px; font-family: inherit; opacity: .72; padding-top: 4px; }
.pair .txt { font-family: "Songti SC", serif; font-size: var(--text-size); line-height: 1.8; color: var(--ink); overflow-wrap: anywhere; }

.pop {
  position: fixed; z-index: 70; width: min(520px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 44px rgba(16, 24, 40, .18); overflow: hidden;
  animation: pop-in .14s ease;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(.985); } }
.pop-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: color-mix(in srgb, var(--add-bg) 45%, var(--panel));
  border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--add-ink);
}
.pop.unresolved .pop-head { background: color-mix(in srgb, var(--del-bg) 45%, var(--panel)); color: var(--warn); }
.pop-head .who { font-weight: 700; color: var(--ink); }
.pop-head .from { color: var(--ink-3); font-size: 11.5px; }
.pop-head .spacer { margin-left: auto; }
.pop-body { max-height: min(58vh, 520px); overflow: auto; }
.pop-reason { padding: 11px 13px; font-size: 13px; color: var(--ink-2); border-top: 1px solid var(--line-2); background: var(--panel-2); }
.pop-reason b { color: var(--ink); }
.pop-foot { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line-2); font-size: 11.5px; color: var(--ink-3); align-items: center; }
.pop-foot .btn { margin-left: auto; }

.diff { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; line-height: 1.7; }
.diff .line { display: flex; border-bottom: 1px solid var(--line-2); }
.diff .line:last-child { border-bottom: 0; }
.diff .ln { width: 24px; flex: 0 0 24px; text-align: center; color: var(--ink-3); user-select: none; }
.diff .txt { flex: 1; padding: 5px 12px 5px 4px; white-space: pre-wrap; overflow-wrap: anywhere; font-family: "Songti SC", serif; font-size: var(--text-size); line-height: 1.75; }
.diff .line.del { background: var(--del-bg); }
.diff .line.del .ln { background: color-mix(in srgb, var(--del-ink) 18%, var(--del-bg)); color: var(--del-ink); }
.diff .line.add { background: var(--add-bg); }
.diff .line.add .ln { background: color-mix(in srgb, var(--add-ink) 18%, var(--add-bg)); color: var(--add-ink); }

/* ---------- metrics drawer ---------- */
.drawer {
  position: fixed; top: calc(var(--bar-h) + var(--ctrl-h)); right: 0; bottom: 0; width: min(460px, 92vw);
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0, 0, 0, .08);
  transform: translateX(102%); transition: transform .22s ease; z-index: 45;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 14px; }
.drawer-head .btn { margin-left: auto; }
.drawer-body { overflow: auto; padding: 14px; }
.drawer-body h3 { font-size: 12.5px; color: var(--ink-3); margin: 14px 0 8px; font-weight: 650; letter-spacing: .4px; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.metrics th, table.metrics td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line-2); }
table.metrics th:first-child, table.metrics td:first-child { text-align: left; }
table.metrics thead th { color: var(--ink-3); font-weight: 600; font-size: 11.5px; }
table.metrics td.neg, table.metrics .neg { color: var(--warn); }
.keyhint { font-size: 12px; color: var(--ink-3); }
.keyhint kbd { font-family: ui-monospace, monospace; background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; font-size: 11px; color: var(--ink-2); }

.footnote { padding: 16px 18px 30px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); background: var(--panel); }
.footnote b { color: var(--ink-2); }

@media (max-width: 1180px) {
  .controls { gap: 14px; }
  .search-box input { width: 150px; }
}
