:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f5f6f7;
  --hover: #f0f1f3;
  --border: #ebecee;
  --border-strong: #d9dce1;
  --text: #2a2e35;
  --muted: #7d838d;
  --accent: #2457d6;
  --accent-hover: #1c47b4;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;

  --del-bg: #ffecec;
  --del-ln: #ffdcdc;
  --del-hl: #ffb3b3;
  --del-fg: #c3262b;
  --ins-bg: #e7f8ec;
  --ins-ln: #cff2d9;
  --ins-hl: #96e2ad;
  --ins-fg: #18853e;
  --none-bg: #f3f4f6;
  --fold-bg: #eef3fd;
  --fold-fg: #3d5ea8;
  --current: #2457d6;

  --mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Consolas, Menlo, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014;
    --surface: #161920;
    --surface-2: #1b1f27;
    --hover: #232833;
    --border: #262b34;
    --border-strong: #3a404c;
    --text: #e4e7ec;
    --muted: #8d95a3;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1d2a47;
    --on-accent: #0b1020;
    --del-bg: rgba(248, 81, 73, 0.13);
    --del-ln: rgba(248, 81, 73, 0.2);
    --del-hl: rgba(248, 81, 73, 0.42);
    --del-fg: #ff7b72;
    --ins-bg: rgba(46, 160, 67, 0.13);
    --ins-ln: rgba(46, 160, 67, 0.22);
    --ins-hl: rgba(46, 160, 67, 0.45);
    --ins-fg: #56d364;
    --none-bg: #1a1d24;
    --fold-bg: #18223a;
    --fold-fg: #8fb0ff;
    --current: #5b8cff;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1b1f27;
  --hover: #232833;
  --border: #262b34;
  --border-strong: #3a404c;
  --text: #e4e7ec;
  --muted: #8d95a3;
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --accent-soft: #1d2a47;
  --on-accent: #0b1020;
  --del-bg: rgba(248, 81, 73, 0.13);
  --del-ln: rgba(248, 81, 73, 0.2);
  --del-hl: rgba(248, 81, 73, 0.42);
  --del-fg: #ff7b72;
  --ins-bg: rgba(46, 160, 67, 0.13);
  --ins-ln: rgba(46, 160, 67, 0.22);
  --ins-hl: rgba(46, 160, 67, 0.45);
  --ins-fg: #56d364;
  --none-bg: #1a1d24;
  --fold-bg: #18223a;
  --fold-fg: #8fb0ff;
  --current: #5b8cff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, select, input, textarea { font: inherit; color: inherit; }

kbd {
  display: inline-block;
  padding: 0 4px;
  margin-left: 3px;
  border-radius: 4px;
  border: 1px solid currentColor;
  font: 11px/16px var(--mono);
  opacity: 0.7;
}

/* ---------- 左侧功能栏（参考 jsont.run 的图标栏） ---------- */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 48px;
  flex-shrink: 0;
  padding: 8px 0 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}
.rail-logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--on-accent);
  font: 700 17px/1 var(--mono);
  text-decoration: none;
}
.modes { display: flex; flex-direction: column; gap: 4px; }
.modes a, .rail-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.modes svg, .rail-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.modes a:hover, .rail-btn:hover { background: var(--hover); color: var(--text); }
.modes a.on { background: var(--accent-soft); color: var(--accent); }
.modes a.on::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
/* 悬停提示 */
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translate(-4px, -50%);
  padding: 4px 9px;
  border-radius: 5px;
  background: #1d2127;
  color: #fff;
  font: 12px/1.5 var(--sans);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
  z-index: 60;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(0, -50%); }

/* ---------- 标签页 ---------- */
.tabs { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tab-switch { position: relative; }
.tab-current {
  gap: 8px;
  max-width: 240px;
  background: var(--surface-2);
  font: 600 12px/1 var(--mono);
  letter-spacing: 0.03em;
}
.tab-current:hover { background: var(--hover); }
.tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 11px/18px var(--sans);
  letter-spacing: 0;
  text-align: center;
}
.caret { color: var(--muted); font-size: 11px; }

.tab-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 260px;
  max-width: 360px;
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.14);
}
.tab-menu[hidden] { display: none; }
.tab-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.tab-item:hover { background: var(--surface-2); }
.tab-item.active { background: var(--accent-soft); }
.tab-item.active .tab-title { color: var(--accent); font-weight: 650; }
.tab-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.tab-title, .tab-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-sub { color: var(--muted); font-size: 12px; }
.tab-rename {
  width: 100%;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  outline: none;
}
.tab-act {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}
.tab-act:hover { background: var(--surface); color: var(--accent); }
.tab-act[data-act="close"]:hover { color: var(--del-fg); }
.tab-act[data-act="close"] { font-size: 17px; }
.tab-new { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.tab-new button {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  text-align: left;
  cursor: pointer;
}
.tab-new button:hover { background: var(--surface-2); }

main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
}

/* ---------- 按钮与控件（扁平、图标 + 文字） ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--hover); }
.btn.primary { padding: 0 11px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { height: 24px; padding: 0 7px; font-size: 12px; }
.btn.primary.small { padding: 0 9px; }
.btn:disabled { opacity: 0.4; cursor: default; background: transparent; }
.btn.primary:disabled { background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 按钮图标：data-i 指定，用 mask 着色以跟随文字颜色 */
.btn[data-i]::before {
  content: "";
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat;
  mask: var(--i) center / contain no-repeat;
}
.btn.small[data-i]::before { width: 13px; height: 13px; }
[data-i="plus"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
[data-i="play"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M7 4.5v15a1 1 0 0 0 1.5.86l12.5-7.5a1 1 0 0 0 0-1.72L8.5 3.64A1 1 0 0 0 7 4.5z'/%3E%3C/svg%3E"); }
[data-i="copy"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E"); }
[data-i="download"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3'/%3E%3C/svg%3E"); }
[data-i="trash"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6'/%3E%3C/svg%3E"); }
[data-i="folder"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9l-.8-1.2A2 2 0 0 0 7.9 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2z'/%3E%3C/svg%3E"); }
[data-i="sample"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 3 9.2 8.2 4 10l5.2 1.8L11 17l1.8-5.2L18 10l-5.2-1.8zM19 15v6M16 18h6'/%3E%3C/svg%3E"); }
[data-i="panel"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Cpath d='M9 3v18'/%3E%3C/svg%3E"); }
[data-i="undo"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 14 4 9l5-5'/%3E%3Cpath d='M4 9h11a5 5 0 0 1 0 10h-3'/%3E%3C/svg%3E"); }
[data-i="code"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m16 18 6-6-6-6M8 6l-6 6 6 6'/%3E%3C/svg%3E"); }
[data-i="print"] { --i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9V2h12v7M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2'/%3E%3Crect x='6' y='14' width='12' height='8'/%3E%3C/svg%3E"); }

select {
  height: 28px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  cursor: pointer;
}
select:hover { border-color: var(--border-strong); }

.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer; user-select: none; white-space: nowrap; }
.check input { accent-color: var(--accent); margin: 0; }

.seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button {
  height: 22px;
  padding: 0 9px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1); }

/* ---------- 输入区 ---------- */
.inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}
body.inputs-collapsed .inputs { display: none; }

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  overflow: hidden;
  transition: box-shadow 0.12s;
}
.pane.dragover { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
.pane-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 8px 4px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.pane-title { font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }

/* 可重命名的标题：平时像普通文字，悬停/聚焦时显示输入框 */
.pane-name {
  width: 4em;
  min-width: 3em;
  max-width: 260px;
  height: 24px;
  margin-left: -5px;
  font-size: 12.5px;
  padding: 0 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-weight: 600;
  text-overflow: ellipsis;
  cursor: text;
}
.pane-name::placeholder { color: var(--text); opacity: 1; }
.pane-name:hover { border-color: var(--border-strong); }
.pane-name:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.pane-name:focus::placeholder { color: var(--muted); }
.rename-btn {
  margin-left: -4px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.pane-head:hover .rename-btn, .rename-btn:focus-visible { opacity: 1; }
.rename-btn:hover { color: var(--accent); }
@media (hover: none) { .rename-btn { opacity: 1; } }

.dt thead th {
  padding: 4px 8px;
  text-align: left;
  font: 600 12.5px/1.6 var(--sans);
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dt thead th + th { border-left: 1px solid var(--border); }
.dt thead .dot { margin-right: 6px; vertical-align: 1px; }
.pane-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.del { background: var(--del-fg); }
.dot.ins { background: var(--ins-fg); }

.pane textarea {
  display: block;
  width: 100%;
  height: 260px;
  min-height: 120px;
  padding: 10px 12px;
  border: 0;
  resize: vertical;
  background: transparent;
  font: 13px/1.6 var(--mono);
  tab-size: 4;
  outline: none;
  white-space: pre;
  overflow: auto;
}

.swap {
  align-self: stretch;
  width: 36px;
  border: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}
.swap:hover { background: var(--hover); color: var(--accent); }

/* ---------- 工具栏 ---------- */
/* 每个功能页顶部的工具栏 */
.toolbar.bar {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  gap: 4px 6px;
  min-height: 42px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.bar > .group + .group, .bar > .tabs + .group, .bar > .bar-title + .group { padding-left: 10px; border-left: 1px solid var(--border); }
.bar > .spacer + .group { border-left: 0; }
.bar-title {
  display: inline-flex;
  align-items: center;
  height: 28px;
  margin-right: 4px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--surface-2);
  font-weight: 650;
  white-space: nowrap;
}
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.label { color: var(--muted); font-size: 12px; }
#optContext[hidden] { display: none; }

/* ---------- 结果区 ---------- */
.diff-scroll { flex: 1; min-height: 0; overflow: auto; background: var(--surface); }
.result { background: var(--surface); }
.result-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  min-height: 38px;
  padding: 5px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.stats { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.stats .count { font-weight: 650; }
.stats .add { color: var(--ins-fg); font-weight: 600; }
.stats .rem { color: var(--del-fg); font-weight: 600; }
.stats .muted { color: var(--muted); font-size: 12.5px; }
.stats .stale { color: #b7791f; font-size: 12.5px; }
.nav, .copy { display: flex; align-items: center; gap: 8px; }
.nav-pos { min-width: 56px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.diff { overflow-x: auto; }

.placeholder {
  padding: 56px 20px;
  text-align: center;
  color: var(--muted);
}
.placeholder.same { color: var(--ins-fg); font-size: 16px; font-weight: 600; }
.placeholder small { display: block; margin-top: 6px; font-weight: 400; font-size: 13px; color: var(--muted); }

table.dt {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font: 13px/1.6 var(--mono);
  tab-size: 4;
}
.dt col.ln { width: calc(var(--ln, 3ch) + 18px); }
.dt col.sign { width: 20px; }
.dt td { padding: 0 8px; vertical-align: top; }
.dt td.ln {
  color: var(--muted);
  text-align: right;
  user-select: none;
  font-size: 12px;
  line-height: 20.8px;
  background: var(--surface-2);
}
.dt td.sign { padding: 0 0 0 4px; user-select: none; text-align: center; }
.dt td.code { white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere; }
.dt.split td.code + td.ln { border-left: 1px solid var(--border); }

.dt td.del { background: var(--del-bg); }
.dt td.ln.del { background: var(--del-ln); color: var(--del-fg); }
.dt td.sign.del { color: var(--del-fg); }
.dt td.ins { background: var(--ins-bg); }
.dt td.ln.ins { background: var(--ins-ln); color: var(--ins-fg); }
.dt td.sign.ins { color: var(--ins-fg); }
.dt td.none {
  background: var(--none-bg);
  background-image: repeating-linear-gradient(135deg, transparent 0 6px, var(--border) 6px 7px);
}
.dt td.del .hl { background: var(--del-hl); border-radius: 2px; }
.dt td.ins .hl { background: var(--ins-hl); border-radius: 2px; }

.dt tr.blk-start td { border-top: 1px solid var(--border); }
.dt tr.blk-end td { border-bottom: 1px solid var(--border); }
.dt tr.current td:first-child { box-shadow: inset 3px 0 0 var(--current); }

.dt td.has-copy { position: relative; }
.blk-copy {
  position: absolute;
  top: 1px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}
.blk-copy button {
  height: 20px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font: 12px/18px var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
.dt tr.chg:hover .blk-copy, .dt tr.current .blk-copy, .blk-copy:focus-within { opacity: 1; }
.blk-copy button:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .blk-copy { opacity: 1; } }

.dt tr.fold td { padding: 0; }
.fold-btn {
  display: block;
  width: 100%;
  padding: 3px 12px;
  border: 0;
  border-top: 1px dashed var(--border-strong);
  border-bottom: 1px dashed var(--border-strong);
  background: var(--fold-bg);
  color: var(--fold-fg);
  font: 12.5px/1.6 var(--sans);
  text-align: left;
  cursor: pointer;
}
.fold-btn:hover { filter: brightness(0.97); text-decoration: underline; }

/* 不换行时：整表随最长行变宽，结果区横向滚动 */
.diff.nowrap table.dt { width: max-content; min-width: 100%; table-layout: auto; }
.diff.nowrap .dt td.code { white-space: pre; word-break: normal; overflow-wrap: normal; }
.diff.nowrap .dt td.ln { min-width: calc(var(--ln, 3ch) + 18px); }

/* ---------- 对话框与提示 ---------- */
dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog p { margin: 0 0 10px; }
dialog textarea {
  width: 100%;
  height: 320px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  font: 12.5px/1.5 var(--mono);
  white-space: pre;
  resize: vertical;
}
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 6px;
  background: #1d2127;
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 窄屏 ---------- */
@media (max-width: 860px) {
  .tab-current { max-width: 160px; }
  .inputs { grid-template-columns: minmax(0, 1fr); }
  .swap { width: auto; height: 30px; border: 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .pane textarea { height: 180px; }
  .result-head { position: static; }
  .diff:not(.nowrap) table.dt.split { font-size: 12px; }
}

/* ---------- 功能切换 ---------- */
body:not([data-mode="diff"]) .diff-only, body:not([data-mode="json"]) .json-only,
body:not([data-mode="md"]) .md-only, body:not([data-mode="eol"]) .eol-only,
body:not([data-mode="oneline"]) .ol-only { display: none !important; }

/* ---------- JSON 格式化 ---------- */
:root {
  --j-key: #0b57b8;
  --j-str: #1a7f37;
  --j-num: #b35400;
  --j-lit: #8250df;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --j-key: #79c0ff; --j-str: #7ee787; --j-num: #ffa657; --j-lit: #d2a8ff; }
}
:root[data-theme="dark"] { --j-key: #79c0ff; --j-str: #7ee787; --j-num: #ffa657; --j-lit: #d2a8ff; }


/* 可拖动的左右分栏（JSON / Markdown / 换行符页共用） */
.split-body {
  display: grid;
  grid-template-columns: minmax(0, var(--split-left, 1fr)) 1px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  background: var(--surface);
}
.split-body > .pane { min-height: 0; }
.split-body.hide-left, .split-body.hide-right { grid-template-columns: minmax(0, 1fr); }
.split-body.hide-left > :first-child, .split-body.hide-right > :last-child,
.split-body.hide-left > .vsplit, .split-body.hide-right > .vsplit { display: none; }
/* 分隔线只有 1px，前后各扩出 4px 方便拖动 */
.vsplit { position: relative; z-index: 5; background: var(--border); cursor: col-resize; touch-action: none; outline: none; }
.vsplit::before { content: ""; position: absolute; inset: 0 -4px; }
.vsplit::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 3px;
  background: var(--accent); opacity: 0; transition: opacity .15s;
}
.vsplit:hover::after, .vsplit:focus-visible::after, .vsplit.active::after { opacity: 1; }
body.split-dragging { cursor: col-resize; user-select: none; }
body.split-dragging .split-body > .pane { pointer-events: none; }
.jt-out-head { flex-wrap: wrap; row-gap: 6px; }

.jt-ctl { display: inline-flex; align-items: center; gap: 4px; }
.jt-ctl[hidden] { display: none; }
.jt-ctl select { height: 24px; }
.jt-filter {
  width: 260px;
  max-width: 100%;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font: 12.5px var(--mono);
}
.jt-filter:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.jt-editor { display: flex; flex: 1; min-height: 0; }
.jt-gutter {
  flex-shrink: 0;
  min-width: 3.5ch;
  padding: 10px 8px 60px;
  overflow: hidden;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  color: var(--muted);
  font: 12px/1.6 var(--mono);
  line-height: 20.8px;
  text-align: right;
  white-space: pre;
  user-select: none;
}
.jt-gutter .err { color: var(--del-fg); background: var(--del-ln); font-weight: 700; }
.jt-editor textarea {
  flex: 1;
  min-width: 0;
  height: auto;
  min-height: 0;
  padding: 10px 12px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font: 13px/1.6 var(--mono);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.jt-view { flex: 1; min-height: 0; overflow: auto; position: relative; }
.jt-view .placeholder { padding: 60px 20px; }

.j-k { color: var(--j-key); }
.j-s { color: var(--j-str); }
.j-n { color: var(--j-num); }
.j-l { color: var(--j-lit); font-weight: 600; }
.j-i { color: var(--muted); }
.j-p { color: var(--muted); }

/* 树形视图 */
.jt-tree { padding: 8px 6px 24px; font: 13px/1.7 var(--mono); }
.jt-line { padding-right: 8px; border-radius: 4px; white-space: pre-wrap; word-break: break-all; cursor: default; }
.jt-line:hover { background: var(--surface-2); }
.jt-line.sel { background: var(--accent-soft); }
.jt-tog, .jt-sp { display: inline-block; width: 16px; text-align: center; color: var(--muted); user-select: none; }
.jt-tog { cursor: pointer; }
.jt-tog::before { content: "▾"; }
.jt-node.collapsed > .jt-line > .jt-tog::before { content: "▸"; }
.jt-tog:hover { color: var(--accent); }
.jt-node.collapsed > .jt-kids, .jt-node.collapsed > .jt-end { display: none; }
.jt-node.branch:not(.collapsed) > .jt-line > .jt-sum,
.jt-node.branch:not(.collapsed) > .jt-line > .jt-inl,
.jt-node.branch:not(.collapsed) > .jt-line > .jt-comma { display: none; }
.jt-sum {
  margin: 0 4px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font: 11.5px/1.5 var(--sans);
  cursor: pointer;
}
.jt-sum:hover { color: var(--accent); border-color: var(--accent); }
.jt-more {
  margin: 2px 0;
  padding: 2px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  background: var(--fold-bg);
  color: var(--fold-fg);
  font: 12px var(--sans);
  cursor: pointer;
}

/* 文本 / 转换视图 */
.jt-text { display: flex; min-width: max-content; min-height: 100%; font: 13px/1.6 var(--mono); }
.jt-text pre { margin: 0; font: inherit; }
.jt-lnums {
  position: sticky;
  left: 0;
  padding: 10px 8px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  color: var(--muted);
  text-align: right;
  user-select: none;
}
.jt-code { flex: 1; padding: 10px 12px; tab-size: 4; }

/* 表格视图：多级嵌套表格 */
.jg { display: inline-block; min-width: 100%; padding: 10px; font: 12.5px/1.5 var(--mono); }
.jg table { width: max-content; border-collapse: collapse; background: var(--surface); }
.jg th, .jg td { padding: 5px 10px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.jg th.jg-k { background: var(--surface-2); color: var(--text); font-weight: 600; white-space: nowrap; }
.jg th.jg-i { background: var(--surface-2); color: var(--muted); font-weight: 400; text-align: right; white-space: nowrap; }
.jg thead th { background: var(--surface-2); color: var(--j-key); font-weight: 600; white-space: nowrap; }
.jg td.jg-v { min-width: 48px; }
.jg td.jg-empty { background: var(--none-bg); }
.jg [data-cell] { cursor: default; }
.jg tr.sel > th, .jg tr.sel > td, .jg td.sel { background: var(--accent-soft); }
.jg-str { display: inline-block; max-width: 640px; white-space: pre-wrap; overflow-wrap: anywhere; }
.jg-head { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; user-select: none; white-space: nowrap; }
.jg-type b { color: var(--j-key); font-weight: 400; }
.jg-tog {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid var(--muted);
  border-radius: 2px;
  color: var(--muted);
  font: 12px/1 var(--mono);
}
.jg-tog::before { content: "−"; }
.jg-node.collapsed > .jg-head .jg-tog::before { content: "+"; }
.jg-head:hover .jg-tog, .jg-head:hover .jg-type { color: var(--accent); border-color: var(--accent); }
.jg-body { margin-top: 6px; }
.jg-node.collapsed > .jg-body { display: none; }
.jg tr.jg-more td { padding: 4px 8px; background: transparent; }

/* 出错面板 */
.jt-error { padding: 20px; }
.jt-error .title { margin: 0 0 10px; color: var(--del-fg); font-weight: 600; }
.jt-error pre {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface-2);
  font: 12.5px/1.6 var(--mono);
  overflow-x: auto;
}
.jt-error .cur { color: var(--text); font-weight: 600; }
.jt-error .caret { color: var(--del-fg); font-weight: 700; }

/* 状态栏 */
/* 底部状态栏 */
.jt-status {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  gap: 2px 12px;
  min-height: 28px;
  padding: 3px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}
.st-note { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.st-note::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ins-fg); }
.jt-state, .jt-path { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-width: 0; }
.jt-path code { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12.5px var(--mono); }
.jt-status .ok { color: var(--ins-fg); font-weight: 600; }
.jt-status .warn { color: #b7791f; }
.jt-status .muted { color: var(--muted); }
.jt-err {
  padding: 0;
  border: 0;
  background: none;
  color: var(--del-fg);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.jt-err:hover { text-decoration: underline; }

@media (max-width: 860px) {
  .split-body { grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(0, 1fr); }
  .split-body.hide-left, .split-body.hide-right { grid-auto-rows: minmax(0, 1fr); }
  .vsplit { display: none; }
  .split-body > .pane + .vsplit + .pane { border-top: 1px solid var(--border); }
  .jt-filter { width: 100%; }
  .st-note { display: none; }
}

/* ---------- Markdown 预览 ---------- */
.md-pane { position: relative; }
.md-pane > textarea {
  flex: 1;
  height: auto;
  min-height: 0;
  resize: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 4;
  font: 13.5px/1.7 var(--mono);
  padding: 12px 16px;
}
.md-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; }
.md-preview { padding: 20px 32px 48px; }
.md-preview .placeholder { padding: 60px 0; }
.md-mirror {
  position: absolute;
  top: 0;
  left: -100000px;
  visibility: hidden;
  box-sizing: border-box;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border: 0;
}
.md-toc-wrap { position: relative; }
.md-toc {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  width: 300px;
  max-height: 60vh;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
}
.md-toc[hidden] { display: none; }
.md-toc a {
  display: block;
  padding: 4px 8px;
  border-radius: 5px;
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.md-toc a:hover { background: var(--surface-2); color: var(--accent); }
.md-toc .lv1 { padding-left: 22px; }
.md-toc .lv2 { padding-left: 36px; color: var(--muted); }
.md-toc .lv3 { padding-left: 50px; color: var(--muted); }

/* ---------- 文本压缩 ---------- */
.ol-pane > textarea { flex: 1; height: auto; min-height: 0; resize: none; }
.ol-pane > textarea.ol-single { white-space: pre-wrap; word-break: break-all; }
.ol-pane > textarea[readonly] { background: var(--surface-2); }

/* ---------- 换行符转换 ---------- */
.eol-pane > textarea { flex: 1; height: auto; min-height: 0; resize: none; }
.eol-out {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  font: 13px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
}
.eol-out .placeholder { display: block; padding: 60px 0; font-family: var(--sans); }
.eol-tag {
  display: inline-block;
  margin: 0 1px;
  padding: 0 4px;
  border-radius: 3px;
  font: 600 10px/15px var(--mono);
  vertical-align: 1px;
  user-select: none;
  background: var(--accent-soft);
  color: var(--accent);
}
.eol-tag.crlf { background: rgba(197, 138, 0, 0.16); color: #a86f00; }
.eol-tag.cr { background: rgba(130, 80, 223, 0.15); color: #8250df; }
.eol-custom {
  width: 120px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: 12.5px var(--mono);
}
.eol-custom[hidden] { display: none; }
.small-check { font-size: 12.5px; color: var(--muted); }

/* ---------- 打印（Markdown 页「打印 / PDF」只输出预览内容） ---------- */
@media print {
  body[data-mode="md"] { background: #fff; }
  body[data-mode="md"] > :not(#mdTool),
  body[data-mode="md"] #mdTool > :not(#mdBody),
  body[data-mode="md"] #mdBody > :not(:last-child),
  body[data-mode="md"] #mdBody > .pane > .pane-head,
  body[data-mode="md"] .md-code-copy { display: none !important; }
  body[data-mode="md"] #mdTool { padding: 0; }
  body[data-mode="md"] #mdBody { display: block; height: auto; }
  body[data-mode="md"] #mdBody > .pane { display: block !important; border: 0; box-shadow: none; overflow: visible; }
  body[data-mode="md"] .md-scroll { overflow: visible; }
  body[data-mode="md"] .md-preview { padding: 0; }
  body[data-mode="md"] .md-preview pre, body[data-mode="md"] .md-preview table { overflow: visible; }
  body[data-mode="md"] .md-preview pre code { white-space: pre-wrap; }
}

/* ---------- 手机：工具栏横向滚动，避免占用过多高度 ---------- */
@media (max-width: 860px) {
  .rail { width: 44px; }
  [data-tip]::after { display: none; }
  .toolbar.bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar.bar::-webkit-scrollbar { display: none; }
  .bar > .group, .bar > .tabs { flex-wrap: nowrap; flex-shrink: 0; }
  .tab-menu { position: fixed; top: 48px; left: 52px; right: 8px; width: auto; min-width: 0; }
}
@media (max-width: 480px) {
  .pane-meta { white-space: nowrap; }
  .pane-head .btn.small[data-i] { gap: 0; padding: 0 6px; font-size: 0; }
}
