:root {
  --paper: #f7f3ea;
  --paper-strong: #fffaf1;
  --ink: #1f2328;
  --muted: #6d665d;
  --line: #d7ccba;
  --rail: #26231f;
  --rail-soft: #343029;
  --red: #bb2a2a;
  --teal: #0f766e;
  --gold: #b7791f;
  --shadow: 0 22px 60px rgba(46, 38, 25, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 35, 40, 0.045) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(0deg, rgba(31, 35, 40, 0.035) 1px, transparent 1px) 0 0 / 36px 36px,
    var(--paper);
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", "PingFang SC", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: min(1440px, calc(100vw - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  overflow: hidden;
  border: 1px solid rgba(31, 35, 40, 0.14);
  border-radius: 10px;
  background: var(--paper-strong);
  box-shadow: var(--shadow);
}

.rule-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 18px;
  color: #f6efe2;
  background:
    linear-gradient(180deg, rgba(187, 42, 42, 0.24), transparent 35%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 9px),
    var(--rail);
}

.brand-block {
  padding: 4px 6px 18px;
  border-bottom: 1px solid rgba(246, 239, 226, 0.18);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 27px;
  line-height: 1.2;
}

h2 {
  margin-top: 2px;
  font-size: 26px;
  line-height: 1.25;
}

h3 {
  font-size: 16px;
}

.rule-list {
  display: grid;
  gap: 10px;
}

.rule-button {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 12px;
  border: 1px solid rgba(246, 239, 226, 0.15);
  border-radius: var(--radius);
  color: #f8f0e2;
  background: rgba(255, 255, 255, 0.055);
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.settings-entry {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 54px;
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(247, 243, 234, 0.32);
  border-radius: var(--radius);
  color: #f8f0e2;
  background: rgba(183, 121, 31, 0.2);
  text-align: left;
  transition:
    transform 160ms ease,
    background 160ms ease;
}

.settings-entry:hover {
  transform: translateX(2px);
  background: rgba(183, 121, 31, 0.34);
}

.rule-button:hover:not(:disabled),
.rule-button.is-active {
  transform: translateX(2px);
  border-color: rgba(247, 243, 234, 0.62);
  background: rgba(187, 42, 42, 0.34);
}

.rule-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.rule-index {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(247, 243, 234, 0.12);
  font-size: 13px;
  font-weight: 700;
}

.rule-title {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 28px;
}

.workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.status-pill {
  flex: 0 0 auto;
  max-width: 260px;
  padding: 8px 12px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 999px;
  color: var(--teal);
  background: rgba(15, 118, 110, 0.08);
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.status-pill.has-error {
  border-color: rgba(187, 42, 42, 0.32);
  color: var(--red);
  background: rgba(187, 42, 42, 0.08);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  padding-top: 20px;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.52);
}

.result-pane {
  background: rgba(31, 35, 40, 0.035);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.pane-head label {
  font-size: 14px;
  font-weight: 800;
}

textarea {
  width: 100%;
  min-height: 0;
  flex: 1;
  resize: none;
  padding: 16px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-family: Consolas, "Microsoft YaHei UI", monospace;
  font-size: 15px;
  line-height: 1.7;
}

textarea::placeholder {
  color: rgba(109, 102, 93, 0.72);
}

.action-bar {
  display: flex;
  gap: 12px;
  padding-top: 18px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 38px;
  border-radius: var(--radius);
  font-weight: 800;
  transition:
    transform 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.primary-button {
  min-width: 128px;
  padding: 0 22px;
  color: #fff7ec;
  background: var(--red);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.secondary-button {
  padding: 0 18px;
  color: var(--ink);
  background: #e6d8c2;
}

.ghost-button {
  padding: 0 12px;
  color: var(--red);
  background: rgba(187, 42, 42, 0.08);
}

.issue-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid rgba(187, 42, 42, 0.28);
  border-radius: var(--radius);
  background: rgba(187, 42, 42, 0.06);
}

.issue-panel h3 {
  color: var(--red);
}

#issueList {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.issue-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(187, 42, 42, 0.18);
  border-radius: 6px;
  background: rgba(255, 250, 241, 0.72);
  font-size: 13px;
}

.issue-source {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 11px 14px;
  border-radius: var(--radius);
  color: #fffaf1;
  background: #1f2328;
  box-shadow: 0 14px 36px rgba(31, 35, 40, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.settings-drawer[hidden] {
  display: none;
}

.settings-drawer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  justify-items: end;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(31, 35, 40, 0.42);
}

.drawer-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(720px, calc(100vw - 22px));
  height: calc(100vh - 22px);
  margin: 11px;
  overflow: hidden;
  border: 1px solid rgba(247, 243, 234, 0.5);
  border-radius: 10px;
  background: var(--paper-strong);
  box-shadow: -18px 0 48px rgba(31, 35, 40, 0.22);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--ink);
  background: #e6d8c2;
  font-size: 26px;
  line-height: 1;
}

.settings-form {
  display: grid;
  gap: 16px;
  min-height: 0;
  overflow: auto;
  padding: 18px 22px;
}

.settings-group {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
}

.field-label {
  font-size: 13px;
  font-weight: 800;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.settings-textarea,
.settings-template {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 250, 241, 0.8);
}

.settings-template {
  min-height: 146px;
}

.drawer-actions {
  display: flex;
  gap: 12px;
  padding: 18px 22px;
  border-top: 1px solid var(--line);
  background: rgba(230, 216, 194, 0.36);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 16px, 760px);
    min-height: auto;
    margin: 8px auto;
  }

  .rule-rail {
    padding: 20px 14px;
  }

  .rule-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-entry {
    margin-top: 0;
  }

  .workspace {
    padding: 20px 14px;
  }

  .workspace-head {
    align-items: stretch;
    flex-direction: column;
  }

  .status-pill {
    max-width: none;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-pane {
    min-height: 330px;
  }
}

@media (max-width: 560px) {
  .rule-list {
    grid-template-columns: 1fr;
  }

  .pane-head,
  .action-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }

  .drawer-actions {
    flex-direction: column;
  }
}
