:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f5f8fb;
  --surface-3: #edf2f8;
  --fg: #0f1a24;
  --muted: #5c6b7a;
  --line: #dbe3ec;
  --line-strong: #c2cedb;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e6efff;
  --ok: #0f7b4f;
  --ok-soft: #e2f5eb;
  --warn: #8a5300;
  --warn-soft: #fff3d9;
  --warn-line: #e8c27a;
  --err: #b3261e;
  --err-soft: #fde8e6;
  --err-line: #f0a9a3;
  /* 语法着色 */
  --tok-group: #7c3aed;
  --tok-class: #0b6bcb;
  --tok-escape: #0f7b4f;
  --tok-quant: #b45309;
  --tok-anchor: #c2255c;
  --tok-ref: #0e7490;
  /* 匹配底色，按序循环 */
  --m0: #ffeba3;
  --m1: #cfe6ff;
  --m2: #d2f5d0;
  --m3: #ffd9e8;
  /* 分组下划线 */
  --g1: #e11d48;
  --g2: #7c3aed;
  --g3: #0891b2;
  --g4: #ea580c;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 26, 36, .05), 0 16px 36px -26px rgba(15, 26, 36, .45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1116;
    --surface: #131b22;
    --surface-2: #18222b;
    --surface-3: #1d2833;
    --fg: #e3ebf1;
    --muted: #93a4b1;
    --line: #25323d;
    --line-strong: #35485a;
    --accent: #6ea8ff;
    --accent-ink: #06121f;
    --accent-soft: #16283f;
    --ok: #5fd6a0;
    --ok-soft: #123327;
    --warn: #f2b34b;
    --warn-soft: #33260c;
    --warn-line: #6b4e16;
    --err: #ff9d95;
    --err-soft: #3a1b19;
    --err-line: #7a3530;
    --tok-group: #c4a1ff;
    --tok-class: #82b8ff;
    --tok-escape: #6ddba8;
    --tok-quant: #f6bd63;
    --tok-anchor: #ff92b8;
    --tok-ref: #6fd7ea;
    --m0: rgba(250, 204, 21, .34);
    --m1: rgba(96, 165, 250, .34);
    --m2: rgba(74, 222, 128, .3);
    --m3: rgba(244, 114, 182, .34);
    --g1: #ff8ba7;
    --g2: #c0a2ff;
    --g3: #5ed0e6;
    --g4: #ffab6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -26px rgba(0, 0, 0, .9);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1116;
  --surface: #131b22;
  --surface-2: #18222b;
  --surface-3: #1d2833;
  --fg: #e3ebf1;
  --muted: #93a4b1;
  --line: #25323d;
  --line-strong: #35485a;
  --accent: #6ea8ff;
  --accent-ink: #06121f;
  --accent-soft: #16283f;
  --ok: #5fd6a0;
  --ok-soft: #123327;
  --warn: #f2b34b;
  --warn-soft: #33260c;
  --warn-line: #6b4e16;
  --err: #ff9d95;
  --err-soft: #3a1b19;
  --err-line: #7a3530;
  --tok-group: #c4a1ff;
  --tok-class: #82b8ff;
  --tok-escape: #6ddba8;
  --tok-quant: #f6bd63;
  --tok-anchor: #ff92b8;
  --tok-ref: #6fd7ea;
  --m0: rgba(250, 204, 21, .34);
  --m1: rgba(96, 165, 250, .34);
  --m2: rgba(74, 222, 128, .3);
  --m3: rgba(244, 114, 182, .34);
  --g1: #ff8ba7;
  --g2: #c0a2ff;
  --g3: #5ed0e6;
  --g4: #ffab6b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -26px rgba(0, 0, 0, .9);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 22px 18px 64px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 var(--sans);
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

h1, h2, h3, p { margin: 0; }

code, pre, .mono { font-family: var(--mono); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap {
  max-width: 1360px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- 顶部 ---------- */
.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 2px 2px 4px;
}

.mark {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.6px;
  line-height: 1.1;
}

.mark i { font-style: normal; color: var(--accent); }

.tagline { margin-top: 4px; font-size: 13.5px; color: var(--muted); }

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

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--fg);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s, transform .1s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--accent); border-color: var(--line); }
.btn.file-btn { position: relative; overflow: hidden; }

.grow { flex: 1; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- 面板 ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.panel-head.sub { border-top: 1px solid var(--line); }

.panel-title { font-size: 13.5px; font-weight: 650; letter-spacing: .01em; }

.panel-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- 测试文本分页 ---------- */
.text-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.text-tabs::-webkit-scrollbar { display: none; }

.txt-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 132px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.3px;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.txt-tab:hover { border-color: var(--accent); color: var(--accent); }

.txt-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.txt-tab-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txt-tab-input {
  width: 78px;
  padding: 0 3px;
  border: 0;
  border-bottom: 1px solid var(--accent);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: inherit;
  outline: none;
}

/* ---------- 正则输入条 ---------- */
.pattern-panel {
  position: relative;
  z-index: 20;
  padding: 14px;
  /* 标志下拉要能超出面板，不能被圆角裁掉 */
  overflow: visible;
}

.pattern-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-3);
  transition: border-color .15s, box-shadow .15s;
}

.pattern-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pattern-bar.error {
  border-color: var(--err);
  box-shadow: 0 0 0 3px var(--err-soft);
}

.slash {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}

#pattern {
  flex: 1;
  min-width: 0;
  padding: 5px 0;
  border: 0;
  background: none;
  font-family: var(--mono);
  font-size: 15.5px;
  color: var(--fg);
  outline: none;
}

#flags {
  width: 2.8ch;
  min-width: 2.8ch;
  padding: 5px 0;
  border: 0;
  border-radius: 6px;
  background: none;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  outline: none;
  cursor: pointer;
}

#flags:hover { background: var(--surface); }

.flags-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}

.flags-caret {
  width: 22px;
  height: 22px;
  font-size: 10px;
  color: var(--muted);
}

.flags-caret:hover { background: var(--surface); color: var(--accent); }
.flags-caret.open { color: var(--accent); }

/* 下拉选项面板：每行一个标志，右侧勾选 */
.flag-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 40;
  width: min(330px, calc(100vw - 56px));
  max-height: min(58vh, 420px);
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 44px -14px rgba(15, 26, 36, .38), 0 1px 3px rgba(15, 26, 36, .1);
  scrollbar-width: thin;
}

.flag-menu[hidden] { display: none; }

.flag-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background .12s;
}

.flag-opt + .flag-opt { margin-top: 1px; }
.flag-opt:hover { background: var(--surface-2); }
.flag-opt.on { background: var(--accent-soft); }

.flag-opt b {
  flex-shrink: 0;
  width: 13px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.7;
  color: var(--accent);
}

.flag-opt span {
  flex: 1;
  min-width: 0;
  font-size: 12.8px;
  line-height: 1.7;
  color: var(--muted);
}

.flag-opt.on span { color: var(--fg); }

.flag-opt .tick {
  flex-shrink: 0;
  font-style: normal;
  font-size: 12px;
  line-height: 1.7;
  color: var(--accent);
  visibility: hidden;
}

.flag-opt.on .tick { visibility: visible; }

.bar-btn {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.bar-btn:hover { background: var(--surface); color: var(--err); }

.flag-desc {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 3px 16px;
  margin-top: 9px;
  padding: 8px 11px;
  border: 1px dashed var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 12.2px;
  line-height: 1.7;
  color: var(--muted);
}

.flag-desc .flag-label {
  flex-shrink: 0;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .02em;
  color: var(--fg);
}

.flag-desc .flag-item { max-width: 100%; }

.flag-desc .flag-item b {
  margin-right: 5px;
  font-family: var(--mono);
  color: var(--accent);
}

.flag-desc code {
  padding: 0 3px;
  border-radius: 3px;
  background: var(--surface-3);
  font-size: 11.6px;
}

.status {
  display: none;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 12.8px;
  line-height: 1.6;
  border: 1px solid transparent;
  word-break: break-word;
}

.status.show { display: flex; }
.status.-err { background: var(--err-soft); border-color: var(--err-line); color: var(--err); }
.status.-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.status.-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

.status::before {
  content: "!";
  flex-shrink: 0;
  font-family: var(--mono);
  font-weight: 700;
}

.status.-ok::before { content: "✓"; }

.status-msg { flex: 1; min-width: 0; }
.status-msg b { font-weight: 650; }

.status .status-hint { opacity: .92; }

/* 原始英文报错，弱化显示但仍可对照 */
.status .raw {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 11.2px;
  line-height: 1.6;
  color: var(--muted);
  word-break: break-all;
}

.token-bar {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.token-label {
  flex-shrink: 0;
  padding-top: 5px;
  font-size: 12px;
  color: var(--muted);
}

.token-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.tok-btn {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: .15s;
}

.tok-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- 栅格 ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* ---------- 编辑器（文本 + 高亮层） ---------- */
.editor {
  position: relative;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.hl,
.editor textarea {
  margin: 0;
  padding: 14px 16px;
  border: 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  tab-size: 2;
  letter-spacing: 0;
}

.hl {
  position: absolute;
  inset: 0;
  overflow: auto;
  color: var(--fg);
  pointer-events: none;
  scrollbar-width: none;
}

.hl::-webkit-scrollbar { width: 0; height: 0; }

.hl .m {
  border-radius: 2px;
  background: var(--m0);
  color: inherit;
}

.hl .m.c1 { background: var(--m1); }
.hl .m.c2 { background: var(--m2); }
.hl .m.c3 { background: var(--m3); }

.hl .g1 { text-decoration: underline 2px var(--g1); text-underline-offset: 3px; }
.hl .g2 { text-decoration: underline 2px var(--g2); text-underline-offset: 3px; }
.hl .g3 { text-decoration: underline 2px var(--g3); text-underline-offset: 3px; }
.hl .g4 { text-decoration: underline 2px var(--g4); text-underline-offset: 3px; }

.hl .m.active { outline: 2px solid var(--accent); outline-offset: -1px; }

.editor textarea {
  display: block;
  width: 100%;
  height: 336px;
  resize: vertical;
  background: transparent;
  color: transparent;
  caret-color: var(--accent);
  outline: none;
  border: 0;
  overflow: auto;
  /* 滚动条会挤占宽度导致折行与高亮层错位，两边的滚动条都隐藏 */
  scrollbar-width: none;
}

.editor textarea::-webkit-scrollbar { width: 0; height: 0; }

/* 超长文本时关闭高亮，让文本恢复可见 */
.editor.no-highlight textarea { color: var(--fg); }

.editor textarea::placeholder { color: var(--muted); }
.editor textarea::selection { background: rgba(37, 99, 235, .28); }

/* 输入法合成时恢复可见文本，避免候选与文字看不见 */
.editor.composing .hl { visibility: hidden; }
.editor.composing textarea { color: var(--fg); background: var(--surface); }

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 14px;
  background: var(--surface-2);
}

/* ---------- 替换 ---------- */
.replace-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 14px;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field > span {
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.field input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-3);
  font-family: var(--mono);
  font-size: 13.5px;
  outline: none;
  transition: .15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.repl-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-3);
}

.repl-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 11px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.repl-out {
  margin: 0;
  padding: 11px 13px;
  max-height: 190px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg);
}

.repl-out:empty::after { content: "—"; color: var(--muted); }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 7px 8px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: .15s;
}

.tab:hover { color: var(--fg); background: var(--surface); }

.tab.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--accent);
  font-weight: 600;
}

.badge {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tab-body {
  display: flex;
  flex-direction: column;
  min-height: 120px;
}

.tab-body[hidden] { display: none; }

/* 右侧结果栏撑满整行高度，避免左侧长、右侧短时中间出现空白洞 */
.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.col > .side-panel { flex: 1 1 auto; }

.side-panel .tab-body {
  flex: 1 1 auto;
  min-height: 0;
}

.match-summary {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 12.2px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.match-summary:empty { display: none; }

.match-list,
.explain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 430px;
  overflow: auto;
  scrollbar-width: thin;
}

.match-item {
  display: grid;
  gap: 4px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}

.match-item:last-child { border-bottom: 0; }
.match-item:hover { background: var(--surface-2); }
.match-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }

.match-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11.8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.match-no {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.match-text {
  font-family: var(--mono);
  font-size: 13.2px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--fg);
}

.match-text.empty { color: var(--muted); font-style: italic; }

.group-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.2px;
  line-height: 1.6;
}

.group-key {
  flex-shrink: 0;
  font-family: var(--mono);
  color: var(--g2);
}

.group-val {
  font-family: var(--mono);
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}

.group-line.g1 .group-key { color: var(--g1); }
.group-line.g2 .group-key { color: var(--g2); }
.group-line.g3 .group-key { color: var(--g3); }
.group-line.g4 .group-key { color: var(--g4); }

/* ---------- 解释 ---------- */
.explain-row {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 4px 14px 4px calc(14px + var(--d, 0) * 14px);
  font-size: 12.8px;
  line-height: 1.7;
}

.explain-row code {
  flex-shrink: 0;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--surface-3);
  font-size: 12.8px;
  white-space: pre;
}

.explain-row .desc { color: var(--muted); }
.explain-row .desc b { color: var(--fg); font-weight: 600; }

.t-group { color: var(--tok-group); }
.t-class { color: var(--tok-class); }
.t-escape { color: var(--tok-escape); }
.t-quant { color: var(--tok-quant); }
.t-anchor { color: var(--tok-anchor); }
.t-alt { color: var(--muted); }
.t-ref { color: var(--tok-ref); }
.t-price { color: var(--tok-ref); }
.t-literal { color: var(--fg); }
.t-any { color: var(--tok-anchor); }

/* ---------- 代码 ---------- */
.code-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

select {
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-3);
  font: inherit;
  font-size: 13px;
  outline: none;
}

select:focus { border-color: var(--accent); }

.warn-box {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 9px 13px;
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-line);
  color: var(--warn);
  font-size: 12.5px;
  line-height: 1.65;
}

.warn-box ul { margin: 0; padding-left: 16px; }
.warn-box li { margin: 1px 0; }

.code-out {
  margin: 0;
  padding: 13px 14px;
  flex: 1 1 auto;
  max-height: 430px;
  overflow: auto;
  background: var(--surface-3);
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.72;
  white-space: pre;
  tab-size: 2;
  scrollbar-width: thin;
}

.code-out .k { color: var(--tok-group); font-weight: 600; }
.code-out .s { color: var(--tok-escape); }
.code-out .c { color: var(--muted); font-style: italic; }
.code-out .n { color: var(--tok-quant); }
.code-out .f { color: var(--tok-class); }

/* ---------- 库 / 历史 ---------- */
.lib-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 14px;
  max-height: 330px;
  overflow: auto;
  scrollbar-width: thin;
}

.lib-item {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: .15s;
  min-width: 0;
}

.lib-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.lib-name { font-size: 12.8px; font-weight: 600; }
.lib-pat {
  font-family: var(--mono);
  font-size: 11.2px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 11px 14px 13px;
  min-height: 42px;
}

.history-row .hint { align-self: center; }

.hchip {
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11.8px;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hchip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 速查 ---------- */
.cheat { padding: 2px 14px 12px; }

.cheat details { border-bottom: 1px dashed var(--line); }
.cheat details:last-child { border-bottom: 0; }

.cheat summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.cheat summary::-webkit-details-marker { display: none; }

.cheat summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 11px;
  transition: transform .15s;
}

.cheat details[open] summary::before { transform: rotate(90deg); }

.cheat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px 14px;
  padding-bottom: 10px;
}

.cheat-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  font: inherit;
  font-size: 12.3px;
  cursor: pointer;
  min-width: 0;
}

.cheat-row:hover { background: var(--accent-soft); }

.cheat-row code {
  flex-shrink: 0;
  min-width: 54px;
  color: var(--tok-escape);
  font-size: 12.3px;
}

.cheat-row span { color: var(--muted); }

/* ---------- 弹窗（正则库 / 最近使用） ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
}

.modal[hidden] { display: none; }

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(9, 16, 23, .48);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(900px, 100%);
  max-height: min(84vh, 760px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 26px 64px -22px rgba(9, 16, 23, .5);
  overflow: hidden;
}

.modal-card.narrow { width: min(640px, 100%); }

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.modal-title {
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: .01em;
}

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

.modal-search {
  width: min(260px, 42vw);
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-3);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.modal-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-width: thin;
}

.modal-foot {
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}

.modal .lib-list {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-height: none;
  padding: 14px;
}

.lib-item[hidden] { display: none; }

.lib-empty {
  padding: 34px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- 收藏区 ---------- */
.modal-section + .modal-section { border-top: 1px solid var(--line); }

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px 10px;
}

.section-title { font-size: 13px; font-weight: 650; }
.section-meta { font-size: 12px; color: var(--muted); }
.section-head .btn { margin-left: auto; flex-shrink: 0; }

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover { border-color: var(--accent); color: var(--accent-ink); filter: brightness(1.06); }

.fav-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 12px;
}

.fav-form[hidden] { display: none; }

.fav-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-3);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.fav-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.fav-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 0 14px 14px;
}

.fav-list[hidden] { display: none; }

.fav-item { position: relative; min-width: 0; }
.fav-item .lib-item { width: 100%; padding-right: 26px; }

.fav-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: .15s;
}

.fav-item:hover .fav-del,
.fav-del:focus-visible { opacity: 1; }

.fav-del:hover { background: rgba(210, 75, 75, .14); color: #d24b4b; }

#favSection .lib-empty { padding: 16px 16px 22px; }

@media (hover: none) {
  .fav-del { opacity: 1; }
}

body.modal-open { overflow: hidden; }

/* ---------- 空态 / 页脚 / 提示 ---------- */
.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

/* 只有一条空态时垂直居中，避免拉伸后的面板顶部堆一行字 */
.match-list .empty:only-child,
.explain-list .empty:only-child {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}

.empty code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--fg);
}

.foot {
  display: grid;
  gap: 4px;
  padding: 4px 4px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 99;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (max-width: 1120px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .cheat-grid { grid-template-columns: 1fr 1fr; }
  .modal .lib-list { grid-template-columns: 1fr 1fr; }
  .fav-list { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  body { padding: 14px 10px 48px; }
  .mark { font-size: 22px; }
  .tagline { font-size: 12.5px; }
  .top { align-items: flex-start; }
  .editor textarea { height: 260px; }
  .lib-list,
  .cheat-grid { grid-template-columns: 1fr; }
  .match-list,
  .explain-list { max-height: 340px; }
  .hl,
  .editor textarea { font-size: 13px; padding: 12px; }
  .editor-actions .hint { display: none; }
  /* 窄屏时测试文本分页换到单独一行 */
  .panel-head.has-tabs { flex-wrap: wrap; row-gap: 7px; }
  .panel-head.has-tabs .text-tabs { order: 3; flex-basis: 100%; }
  .field { flex-direction: column; align-items: stretch; gap: 5px; }
  /* 窄屏时把标志面板向右拉，避免超出屏幕左边 */
  .flag-menu {
    right: -42px;
    width: min(326px, calc(100vw - 36px));
  }
  .modal { padding: 12px 10px; }
  .modal-card { max-height: 88vh; }
  .modal-search { width: 100%; }
  .modal-tools { width: 100%; margin-left: 0; }
  .modal .lib-list { grid-template-columns: 1fr; }
  .fav-list { grid-template-columns: 1fr; }
  .fav-form { flex-wrap: wrap; }
  .fav-form input { flex-basis: 100%; }
}

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