:root {
  --ink: #16191d;
  --ink-2: #5b6169;
  --ink-3: #8b9199;
  --paper: #f7f6f2;
  --panel: #ffffff;
  --panel-head: #fbfaf7;
  --line: #e4e2db;
  --line-strong: #d2cfc5;
  --bar: #191d21;
  --bar-line: #2f353b;
  --accent: #2e6b5e;
  --accent-dark: #255a4f;
  --mark: #ffe8a6;
  --warn: #b4472f;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --sans: "PingFang SC", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
  height: 100vh;
  padding: 24px 16px 18px;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 5px;
  background: var(--bar);
  color: #fff;
  font: 600 11.5px/1 var(--mono);
  letter-spacing: 0.02em;
}

.brand__name {
  display: block;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand__sub {
  display: block;
  margin-top: 3px;
  color: var(--ink-3);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 22px;
  min-height: 0;
  overflow-y: auto;
}

.nav__group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav__title {
  padding: 0 10px 6px;
  color: var(--ink-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.nav__item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-left: 2px solid transparent;
  border-radius: 5px;
  color: var(--ink-2);
  font-size: 13.5px;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav__item:hover {
  background: rgba(22, 25, 29, 0.04);
  color: var(--ink);
}

.nav__item.is-active {
  border-left-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(20, 25, 30, 0.06);
  color: var(--ink);
  font-weight: 600;
}

.nav__item.is-muted {
  color: var(--ink-3);
  cursor: default;
}

.nav__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
}

.sidebar__foot {
  padding: 0 8px;
  color: var(--ink-3);
  font-size: 11.5px;
  line-height: 1.65;
}

/* ---------- main ---------- */

.main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  height: 100vh;
  padding: 24px 28px 16px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.lede {
  max-width: 64ch;
  margin: 7px 0 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.65;
}

/* ---------- signature: regex literal bar ---------- */

.rulebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 7px;
  background: var(--bar);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 8px 20px -16px rgba(15, 20, 24, 0.85);
  transition: box-shadow 0.15s ease;
}

.rulebar:focus-within {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 0 0 1.5px rgba(46, 107, 94, 0.9);
}

.rulebar.is-invalid,
.rulebar.is-invalid:focus-within {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 0 0 1.5px var(--warn);
}

.rulebar__sigil {
  flex: none;
  color: #6f7a83;
  font: 500 14px/1 var(--mono);
  user-select: none;
}

.rulebar__input {
  flex: 1;
  min-width: 0;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: #f1efe8;
  font: 500 13.5px/1.6 var(--mono);
}

.rulebar__input:focus {
  outline: none;
}

.rulebar__input::placeholder {
  color: #6b757e;
}

.flags {
  display: flex;
  gap: 2px;
  padding-left: 8px;
  border-left: 1px solid var(--bar-line);
}

.flag {
  width: 25px;
  height: 25px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #8e99a2;
  font: 600 12px/1 var(--mono);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.flag:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #dfe4e8;
}

.flag[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

/* ---------- replace bar ---------- */

.replacebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.replacebar__label {
  flex: none;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.replacebar__input {
  flex: 1;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 13px/1.5 var(--mono);
}

.replacebar__input:focus {
  outline: none;
}

.replacebar__input::placeholder {
  color: #b3b7bb;
  font-family: var(--sans);
}

.replacebar__actions {
  display: flex;
  flex: none;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: 600 12.5px/1 var(--sans);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: #bfbcb2;
  background: #f4f3ef;
}

.btn:active {
  transform: translateY(0.5px);
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.btn--ghost {
  padding: 4px 8px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 600;
}

.btn--ghost:hover {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink);
}

.btn[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn[disabled]:hover {
  border-color: var(--line-strong);
  background: #fff;
}

.btn--primary[disabled]:hover {
  border-color: var(--accent);
  background: var(--accent);
}

/* ---------- panes ---------- */

.panes {
  display: grid;
  flex: 1;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.pane__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-head);
}

.pane__title {
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.pane__tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane__count {
  color: var(--ink-3);
  font: 500 11px/1 var(--mono);
  font-variant-numeric: tabular-nums;
}

.editor {
  position: relative;
  flex: 1;
  min-height: 0;
}

.editor:focus-within {
  box-shadow: inset 0 0 0 1.5px rgba(46, 107, 94, 0.35);
}

.editor__mirror,
.editor__area,
.editor__out {
  margin: 0;
  padding: 14px 16px;
  font: 400 13px/1.75 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.editor__mirror,
.editor__area {
  position: absolute;
  inset: 0;
}

.editor__mirror {
  overflow: hidden;
  color: transparent;
  pointer-events: none;
}

.editor__mirror mark {
  border-radius: 2px;
  background: var(--mark);
  color: transparent;
}

.editor__area {
  border: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--accent);
  resize: none;
}

.editor__area:focus {
  outline: none;
}

.editor__area::placeholder {
  color: #b3b7bb;
  font-family: var(--sans);
}

.editor__out {
  flex: 1;
  min-height: 0;
  overflow: auto;
  color: var(--ink);
}

.editor__out:empty::before {
  color: #b3b7bb;
  content: "替换结果会显示在这里";
  font-family: var(--sans);
}

/* ---------- status ---------- */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 2px;
  color: var(--ink-3);
  font: 500 11.5px/1.6 var(--mono);
  font-variant-numeric: tabular-nums;
}

.statusbar__msg {
  color: var(--ink-2);
}

.statusbar.is-error .statusbar__msg {
  color: var(--warn);
}

.statusbar__nums {
  display: flex;
  flex: none;
  gap: 14px;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  body {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    position: static;
    gap: 14px;
    height: auto;
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
  }

  .nav__group {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .nav__title,
  .sidebar__foot {
    display: none;
  }

  .nav__item {
    padding: 7px 10px;
    border-left: 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
  }

  .nav__item.is-active {
    border-bottom-color: var(--accent);
  }

  .main {
    height: auto;
    padding: 18px 16px 22px;
    overflow: visible;
  }

  .panes {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .pane {
    min-height: 260px;
  }

  .statusbar {
    flex-wrap: wrap;
    gap: 6px 14px;
  }
}

@media (max-width: 560px) {
  .replacebar {
    flex-wrap: wrap;
  }

  .replacebar__input {
    flex-basis: 100%;
    order: 3;
  }

  .replacebar__actions {
    margin-left: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
