/* 正则表达式测试（/tools/regex-tester）样式
   复用站点主题变量（--bg-primary / --accent / --text-* / --border-color），适配深 / 浅色。 */
:root {
  color-scheme: dark;
  --rt-card: var(--bg-primary, #fff);
  --rt-card-2: var(--bg-secondary, #16181c);
  --rt-fg: var(--text-primary, #e7e9ea);
  --rt-fg-2: color-mix(in srgb, var(--text-secondary, #71767b) 92%, var(--text-primary, #e7e9ea));
  --rt-line: color-mix(in srgb, var(--text-primary, #e7e9ea) 16%, transparent);
  --rt-accent: var(--accent, #136ce9);
  --rt-ac-08: color-mix(in srgb, var(--rt-accent) 8%, transparent);
  --rt-ac-14: color-mix(in srgb, var(--rt-accent) 14%, transparent);
  --rt-ac-40: color-mix(in srgb, var(--rt-accent) 40%, transparent);
  --rt-ac-22: color-mix(in srgb, var(--rt-accent) 22%, transparent);
  --rt-ac-deep: color-mix(in srgb, var(--rt-accent) 88%, #000);
  --rt-ok: #167a4a;
  --rt-err: #c0392b;
  --rt-hit-bg: color-mix(in srgb, var(--rt-accent) 28%, transparent);
  --rt-radius: 16px;
}
[data-theme="light"] {
  color-scheme: light;
  --rt-line: rgba(15, 20, 25, .14);
  --rt-hit-bg: rgba(19, 108, 233, .18);
}
body.page-regex-tester-full .app { max-width: 100%; }
body.page-regex-tester-full .main-content { max-width: 100%; width: 100%; border-right: 0; }

.rt-wrap { max-width: 100%; margin: 0 auto; padding: 24px 20px 64px; box-sizing: border-box; -webkit-text-size-adjust: 100%; }
.rt-wrap *, .rt-wrap *::before, .rt-wrap *::after { box-sizing: border-box; }

/* ================= 头部 ================= */
.rt-hero { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.rt-hero-ico {
  width: 48px; height: 48px; flex: 0 0 auto; display: grid; place-items: center;
  font-size: 24px; border-radius: 14px;
  background: linear-gradient(135deg, var(--rt-accent), var(--rt-ac-deep));
}
.rt-hero-t { flex: 1 1 300px; min-width: 0; }
.rt-title { margin: 0 0 4px; font-size: 24px; font-weight: 800; line-height: 1.25; color: var(--rt-fg); }
.rt-sub { margin: 0; font-size: 13.5px; line-height: 1.65; color: var(--rt-fg-2); max-width: 62em; }

/* ================= 卡片 ================= */
.rt-card {
  background: var(--rt-card); border: 1px solid var(--rt-line);
  border-radius: var(--rt-radius); padding: 16px 18px 18px; margin-bottom: 16px;
}
.rt-card-title { margin: 0 0 12px; font-size: 14.5px; font-weight: 800; color: var(--rt-fg); }
.rt-row { margin-bottom: 14px; }
.rt-row:last-child { margin-bottom: 0; }
.rt-label { display: block; font-size: 12.5px; font-weight: 700; color: var(--rt-fg-2); margin-bottom: 6px; }

/* ================= 示例选择 ================= */
.rt-samples { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rt-select {
  height: 38px; padding: 0 10px; font-family: inherit; font-size: 13px;
  color: var(--rt-fg); background: var(--rt-card-2);
  border: 1px solid var(--rt-line); border-radius: 10px; cursor: pointer;
}
.rt-select:focus { outline: none; border-color: var(--rt-accent); box-shadow: 0 0 0 3px var(--rt-ac-22); }
.rt-samples-hint { font-size: 12px; color: var(--rt-fg-2); }

/* ================= 正则输入 ================= */
.rt-pattern {
  display: flex; align-items: stretch; gap: 0;
  border: 1px solid var(--rt-line); border-radius: 10px;
  background: var(--rt-card-2); overflow: hidden;
}
.rt-pattern:focus-within { border-color: var(--rt-accent); box-shadow: 0 0 0 3px var(--rt-ac-22); }
.rt-slash {
  display: grid; place-items: center; padding: 0 8px; flex: 0 0 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px; color: var(--rt-fg-2); background: var(--rt-ac-08); user-select: none;
}
.rt-input {
  flex: 1 1 auto; min-width: 0; height: 44px; padding: 0 12px; border: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14.5px; color: var(--rt-fg); background: transparent;
}
.rt-input:focus { outline: none; }
.rt-input::placeholder { color: var(--rt-fg-2); opacity: .7; }
.rt-pattern.is-bad { border-color: var(--rt-err); }

/* ================= 标志开关 ================= */
.rt-flags { display: flex; gap: 8px; flex-wrap: wrap; }
.rt-flag {
  appearance: none; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
  background: var(--rt-card-2); color: var(--rt-fg-2); border: 1px solid var(--rt-line);
  transition: color .15s, border-color .15s, background .15s;
}
.rt-flag:hover { color: var(--rt-accent); border-color: var(--rt-ac-40); }
.rt-flag.is-on { background: var(--rt-ac-14); border-color: var(--rt-ac-40); color: var(--rt-accent); }
.rt-flag:focus-visible { outline: 2px solid var(--rt-accent); outline-offset: 2px; }
.rt-flag code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; font-weight: 800; opacity: .9;
}
.rt-flag-desc { font-weight: 400; opacity: .8; }

/* ================= 状态条 ================= */
.rt-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.rt-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--rt-line); background: var(--rt-card-2); color: var(--rt-fg-2);
}
.rt-badge--ok { background: color-mix(in srgb, var(--rt-ok) 14%, transparent); color: var(--rt-ok); border-color: color-mix(in srgb, var(--rt-ok) 40%, transparent); }
.rt-badge--err { background: color-mix(in srgb, var(--rt-err) 14%, transparent); color: var(--rt-err); border-color: color-mix(in srgb, var(--rt-err) 40%, transparent); }
.rt-err { font-size: 12.5px; color: var(--rt-err); font-weight: 600; }
.rt-err[hidden] { display: none !important; }
.rt-trunc { font-size: 12px; color: var(--rt-fg-2); }
.rt-trunc[hidden] { display: none !important; }

/* ================= 文本框 ================= */
.rt-textarea {
  width: 100%; min-height: 150px; padding: 12px 14px; box-sizing: border-box;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; line-height: 1.7; color: var(--rt-fg);
  background: var(--rt-card-2);
  border: 1px solid var(--rt-line); border-radius: 10px; resize: vertical;
}
.rt-textarea:focus { outline: none; border-color: var(--rt-accent); box-shadow: 0 0 0 3px var(--rt-ac-22); }
.rt-textarea::placeholder { color: var(--rt-fg-2); opacity: .7; }
.rt-textarea--out { color: var(--rt-fg); }
.rt-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.rt-cols .rt-card { margin-bottom: 0; }

/* ================= 高亮预览 ================= */
.rt-highlight {
  min-height: 120px; max-height: 340px; overflow: auto;
  padding: 12px 14px; border-radius: 10px;
  background: var(--rt-card-2); border: 1px solid var(--rt-line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; line-height: 1.8; color: var(--rt-fg);
  white-space: pre-wrap; word-break: break-word;
}
.rt-hit {
  background: var(--rt-hit-bg); color: var(--rt-fg);
  border-radius: 3px; padding: 1px 0;
  box-shadow: inset 0 -2px 0 var(--rt-accent);
  font-weight: 700;
}
.rt-empty { color: var(--rt-fg-2); font-family: inherit; font-size: 13px; }

/* ================= 匹配列表 ================= */
.rt-mcount { font-size: 12.5px; color: var(--rt-fg-2); }
.rt-mcount b { color: var(--rt-accent); font-size: 15px; font-variant-numeric: tabular-nums; }
.rt-mlist { display: flex; flex-direction: column; gap: 10px; }
.rt-mlist[hidden] { display: none !important; }
.rt-mcard {
  border: 1px solid var(--rt-line); border-radius: 12px;
  background: var(--rt-card-2); padding: 10px 12px;
  /* 布局与样式各自隔离：一条内容变化不牵连整表重算 */
  contain: layout style;
  /* 屏外条目跳过排版；匹配很多时这一条就是主要收益 */
  content-visibility: auto;
  contain-intrinsic-size: auto 64px;
}
.rt-mhead { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.rt-mno {
  flex: 0 0 auto; font-size: 11.5px; font-weight: 800; color: var(--rt-fg-2);
  font-variant-numeric: tabular-nums;
}
.rt-mtext {
  flex: 1 1 auto; min-width: 0; font-size: 13.5px; font-weight: 700; color: var(--rt-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}
.rt-mmeta { display: flex; gap: 6px; flex-wrap: wrap; flex: 0 0 auto; }
.rt-tag {
  font-size: 11px; padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  background: var(--rt-ac-08); color: var(--rt-fg-2); border: 1px solid var(--rt-line);
  font-variant-numeric: tabular-nums;
}
.rt-groups { display: flex; flex-direction: column; gap: 3px; }
.rt-grow { display: flex; align-items: baseline; gap: 8px; }
.rt-gidx {
  flex: 0 0 auto; min-width: 52px; font-size: 11.5px; font-weight: 700; color: var(--rt-accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.rt-gval {
  font-size: 12.5px; color: var(--rt-fg); word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.rt-grow--named .rt-gidx { color: var(--rt-ok); }
.rt-nogroups { font-size: 12px; color: var(--rt-fg-2); }
.rt-empty-matches {
  padding: 18px; text-align: center; font-size: 13px; color: var(--rt-fg-2);
  border: 1px dashed var(--rt-line); border-radius: 10px;
}
.rt-empty-matches[hidden] { display: none !important; }

/* ================= 替换预览 ================= */
.rt-replace-row[hidden], .rt-replace-out[hidden] { display: none !important; }
.rt-check {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none;
  font-size: 13px; font-weight: 600; color: var(--rt-fg);
}
.rt-check input { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--rt-accent); }
.rt-hint { font-size: 11.5px; color: var(--rt-fg-2); margin-top: 5px; line-height: 1.6; }

/* ================= 操作按钮 ================= */
.rt-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rt-btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; cursor: pointer; font-family: inherit;
  font-size: 13.5px; font-weight: 700; white-space: nowrap;
  color: var(--rt-fg); background: var(--rt-card-2);
  border: 1px solid var(--rt-line); border-radius: 10px;
  transition: color .15s, border-color .15s, background .15s, transform .06s;
}
.rt-btn:hover { border-color: var(--rt-ac-40); color: var(--rt-accent); }
.rt-btn:active { transform: translateY(1px); }
.rt-btn:focus-visible { outline: 2px solid var(--rt-accent); outline-offset: 2px; }
.rt-btn--primary { background: var(--rt-accent); border-color: var(--rt-accent); color: #fff; }
.rt-btn--primary:hover { background: var(--rt-ac-deep); border-color: var(--rt-ac-deep); color: #fff; }
.rt-btn[hidden] { display: none !important; }

/* ================= 语法速查 ================= */
.rt-cheat { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.rt-cheat-block { border: 1px solid var(--rt-line); border-radius: 12px; overflow: hidden; }
.rt-cheat-h {
  padding: 9px 12px; font-size: 12.5px; font-weight: 800; color: var(--rt-fg);
  background: var(--rt-ac-08); border-bottom: 1px solid var(--rt-line);
}
.rt-cheat-tbl { width: 100%; border-collapse: collapse; }
.rt-cheat-tbl td {
  padding: 7px 12px; font-size: 12px; color: var(--rt-fg-2);
  border-bottom: 1px solid var(--rt-line); vertical-align: top;
}
.rt-cheat-tbl tr:last-child td { border-bottom: 0; }
.rt-cheat-tbl td:first-child {
  width: 96px; white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700; color: var(--rt-fg);
}

/* ================= 使用说明 ================= */
.rt-about {
  background: var(--rt-card); border: 1px solid var(--rt-line);
  border-radius: var(--rt-radius); overflow: hidden;
}
.rt-about > summary {
  cursor: pointer; list-style: none; padding: 13px 18px;
  font-size: 14px; font-weight: 700; color: var(--rt-fg);
  -webkit-tap-highlight-color: transparent;
}
.rt-about > summary::-webkit-details-marker { display: none; }
.rt-about > summary:hover { background: var(--rt-ac-08); }
.rt-about > summary:focus-visible { outline: 2px solid var(--rt-accent); outline-offset: -3px; }
.rt-about[open] > summary { border-bottom: 1px solid var(--rt-line); }
.rt-about-body { padding: 16px 18px 18px; font-size: 12.5px; line-height: 1.75; color: var(--rt-fg-2); }
.rt-about-body p { margin: 0 0 10px; }
.rt-about-body h3 { margin: 14px 0 6px; font-size: 13px; font-weight: 800; color: var(--rt-fg); }
.rt-about-body ul { margin: 0 0 8px; padding-left: 18px; }
.rt-about-body li { margin: 3px 0; }
.rt-about-body strong { color: var(--rt-fg); }
.rt-about-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; padding: 1px 5px; border-radius: 4px;
  background: var(--rt-ac-08); color: var(--rt-fg);
}

/* ================= Toast ================= */
.rt-toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(12px);
  max-width: min(90vw, 460px); padding: 11px 18px; border-radius: 12px;
  background: #1f2430; color: #fff; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
  opacity: 0; pointer-events: none; z-index: 100000;
  transition: opacity .2s, transform .2s;
}
.rt-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); will-change: opacity, transform; }
.rt-toast.is-ok { background: var(--rt-ok); }
.rt-toast.is-err { background: var(--rt-err); }
.rt-toast[hidden] { display: none !important; }

/* ================= 响应式 ================= */
@media (max-width: 1000px) {
  .rt-wrap { padding: 20px 16px 56px; }
  .rt-cols { gap: 12px; }
}
@media (max-width: 700px) {
  .rt-wrap { padding: 14px 12px calc(56px + env(safe-area-inset-bottom)); }
  .rt-hero { gap: 12px; }
  .rt-hero-ico { width: 42px; height: 42px; font-size: 20px; }
  .rt-title { font-size: 20px; }
  .rt-sub { font-size: 12.5px; }
  .rt-card { padding: 14px 14px 16px; }
  .rt-cols { grid-template-columns: 1fr; }
  .rt-cheat { grid-template-columns: 1fr; }
  .rt-select { width: 100%; height: 44px; font-size: 16px; }
  .rt-samples { flex-direction: column; align-items: stretch; }
  .rt-samples-hint { display: none; }
  .rt-input { font-size: 16px; }
  .rt-textarea { font-size: 16px; }
  .rt-btn { flex: 1 1 auto; height: 44px; }
  .rt-highlight { max-height: 240px; }
  .rt-cheat-tbl td:first-child { width: 84px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .rt-hero { margin-bottom: 12px; }
  .rt-highlight { max-height: 200px; }
}
@media (hover: none) {
  .rt-btn:active, .rt-flag:active { transform: scale(.98); }
  .rt-btn, .rt-flag, .rt-check { touch-action: manipulation; }
}
@media (prefers-reduced-motion: reduce) {
  .rt-wrap *, .rt-toast { transition: none !important; animation: none !important; }
}
@media print {
  .rt-samples, .rt-actions, .rt-about, .rt-toast, .rt-cheat { display: none !important; }
  .rt-wrap { max-width: none; padding: 0; }
  .rt-hit { background: none; box-shadow: inset 0 -2px 0 #000; font-weight: 700; }
  .rt-mcard { break-inside: avoid; }
}
