:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #202421;
  --muted: #6b706b;
  --line: #dfe3dc;
  --green: #176f4c;
  --green-dark: #0e4f36;
  --amber: #b66d10;
  --amber-soft: #fff1d8;
  --mint: #e7f4ec;
  --shadow: 0 18px 45px rgba(30, 40, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

html,
body {
  min-width: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar,
.workspace,
.result-toolbar,
.button-row,
.top-actions,
.tabs {
  display: flex;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  font-weight: 780;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
  font-weight: 750;
}

.topbar p,
.panel-heading p,
.result-toolbar p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.workspace {
  align-items: stretch;
  gap: 18px;
}

.input-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  width: 360px;
  flex: 0 0 360px;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.result-panel {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

label {
  display: grid;
  gap: 7px;
  color: #343a35;
  font-size: 14px;
  font-weight: 650;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
}

select:focus,
input[type="text"]:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 111, 76, 0.14);
}

textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
  resize: vertical;
  overflow: auto;
  line-height: 1.65;
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 111, 76, 0.14);
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 8px;
  color: #343a35;
  font-size: 14px;
  font-weight: 650;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: grid;
  min-height: 40px;
  place-items: center;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 680;
}

.segmented label:last-child {
  border-right: 0;
}

.segmented input:checked + label {
  background: var(--mint);
  color: var(--green-dark);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 600;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.primary-button,
.ghost-button,
.icon-button,
.tab {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 720;
}

.primary-button {
  background: var(--green);
  color: white;
}

.primary-button:hover {
  background: var(--green-dark);
}

.ghost-button {
  background: #fbfcfa;
  border-color: var(--line);
  color: #303832;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #fbfcfa;
  border-color: var(--line);
  color: #303832;
  text-decoration: none;
  font-size: 18px;
}

.home-button {
  width: auto;
  min-width: 108px;
  padding: 0 12px;
  gap: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.ghost-button:hover {
  border-color: #bfc8bf;
  background: #f2f6f1;
}

.icon-button:hover {
  border-color: #bfc8bf;
  background: #f2f6f1;
}

.full {
  width: 100%;
}

.top-actions,
.button-row {
  gap: 10px;
  align-items: center;
}

.tabs {
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
  overflow-x: auto;
}

.tab {
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.tab.active {
  background: var(--ink);
  color: white;
}

.tab-page {
  display: none;
  padding: 20px;
}

.tab-page.active {
  display: block;
}

.result-toolbar {
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.output {
  width: 100%;
  min-height: 540px;
  max-height: 65vh;
  overflow: auto;
  margin: 0;
  padding: 18px 18px 30px;
  border: 1px solid #d7ded6;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(231, 244, 236, 0.55), transparent 180px),
    #fcfdfb;
  color: #1f2721;
  font-family:
    "SFMono-Regular", Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  font-size: 15px;
  line-height: 1.78;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.rule-list {
  margin: 14px 0 0;
  padding-left: 22px;
  color: #303832;
  line-height: 1.85;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.topic-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: #28302a;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.35;
}

.topic-button:hover {
  border-color: var(--green);
  background: var(--mint);
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.library-editor {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.import-box textarea {
  min-height: 220px;
}

.mini-output {
  max-height: 180px;
  overflow: auto;
  margin: 10px 0 0;
  color: #303832;
  font-family:
    "SFMono-Regular", Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 0;
  overflow: hidden;
}

.history-open {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 12px;
  cursor: pointer;
}

.history-open strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.history-open p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.score-badge {
  display: inline-block;
  margin-left: 6px;
  color: var(--green-dark);
  font-weight: 750;
}

.score-reason {
  margin-top: 6px;
}

.tag-row,
.feedback-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-row {
  margin-top: 8px;
}

.tag-row span {
  border-radius: 999px;
  background: var(--mint);
  color: var(--green-dark);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 680;
}

.feedback-row {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
}

.feedback-row button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: #303832;
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.feedback-row button.active {
  border-color: var(--green);
  background: var(--mint);
  color: var(--green-dark);
}

.feedback-row button.danger {
  border-color: #e8c0b8;
  background: #fff0ed;
  color: #9a3726;
}

.empty {
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 1100px) {
  .topbar,
  .workspace,
  .result-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .app-shell {
    width: min(100vw - 24px, 1280px);
    padding: 18px 0;
  }

  .input-panel {
    width: 100%;
    flex-basis: auto;
    padding: 18px;
  }

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

  .output {
    min-height: 420px;
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .topbar {
    gap: 12px;
    margin: 0;
    padding: 14px 12px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  h1 {
    font-size: 22px;
  }

  .topbar p,
  .panel-heading p,
  .result-toolbar p {
    font-size: 12px;
    line-height: 1.45;
  }

  .top-actions,
  .button-row {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 8px;
  }

  .workspace {
    gap: 10px;
  }

  .input-panel,
  .result-panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .input-panel {
    padding: 14px 12px;
    gap: 12px;
  }

  .panel-heading h2 {
    font-size: 16px;
  }

  label,
  legend {
    font-size: 13px;
  }

  select,
  input[type="text"],
  textarea {
    min-height: 44px;
    padding: 0 11px;
    font-size: 15px;
  }

  textarea {
    min-height: 180px;
    padding: 12px;
  }

  .primary-button,
  .ghost-button,
  .icon-button,
  .tab {
    min-height: 42px;
    padding: 0 10px;
    font-size: 14px;
  }

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

  .segmented label {
    min-height: 42px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    font-size: 12px;
    text-align: center;
  }

  .segmented label:last-child {
    border-right: 0;
  }

  .tabs {
    padding: 8px 10px;
    gap: 4px;
  }

  .tab-page {
    padding: 12px;
  }

  .result-toolbar {
    gap: 10px;
    margin-bottom: 10px;
  }

  .result-toolbar h2 {
    font-size: 17px;
  }

  .output {
    min-height: 360px;
    padding: 14px 12px 22px;
    font-size: 14px;
    line-height: 1.68;
  }

  .topic-button {
    min-height: 44px;
    font-size: 13px;
  }

  .history-item {
    border-radius: 8px;
  }

  .history-open {
    padding: 10px;
  }

  .feedback-row {
    padding: 8px 10px 10px;
  }

  .feedback-row button {
    flex: 1 1 72px;
  }
}
