:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --panel-soft: #eef4f2;
  --text: #1e2a32;
  --muted: #64737d;
  --line: #d7e0dc;
  --accent: #b93636;
  --accent-strong: #8f2323;
  --teal: #246c73;
  --gold: #a56a12;
  --good: #1d7f53;
  --shadow: 0 8px 20px rgba(30, 42, 50, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Noto Sans SC",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 20px max(18px, calc((100vw - 1280px) / 2 + 18px)) 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: clamp(24px, 2.4vw, 34px);
}

h2 {
  font-size: 16px;
}

.header-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(76px, auto));
  gap: 6px;
  min-width: min(100%, 440px);
}

.stat-pill {
  display: grid;
  gap: 1px;
  min-height: 46px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.stat-pill b {
  font-size: 14px;
}

.stat-pill span {
  color: var(--muted);
  font-size: 11px;
}

.app-shell {
  width: min(1280px, calc(100vw - 24px));
  margin: 12px auto 28px;
  display: grid;
  gap: 12px;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 12px;
}

.section {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title.with-action {
  align-items: center;
}

.form-grid {
  display: grid;
  gap: 9px;
}

.contract-grid {
  grid-template-columns: minmax(240px, 1.5fr) repeat(5, minmax(132px, 1fr));
}

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

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

.field,
.check-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.field.wide {
  grid-column: span 2;
}

.field > span,
.check-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid #cbd6d2;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  background: #f1f4f2;
  color: #89959d;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(36, 108, 115, 0.35);
  outline-offset: 2px;
}

.suffix-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  border: 1px solid #cbd6d2;
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.suffix-input input {
  border: 0;
  border-radius: 0;
}

.suffix-input span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.check-field {
  grid-template-columns: 17px minmax(0, 1fr);
  align-items: center;
  min-height: 34px;
  padding-top: 20px;
}

.compact-check {
  padding-top: 0;
}

.check-field input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--accent);
}

.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.primary-button {
  min-height: 34px;
  padding: 7px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 17px;
  line-height: 17px;
}

.burn-list {
  display: block;
}

.burn-table-wrap {
  border-color: #cddbd6;
}

.burn-table,
.factor-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.burn-table {
  min-width: 1040px;
}

.burn-table th,
.burn-table td,
.factor-table th,
.factor-table td {
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.burn-table th,
.burn-table td {
  padding: 6px 7px;
  text-align: center;
  white-space: nowrap;
}

.burn-table th {
  background: #f1f5f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.burn-table tr:last-child td,
.factor-table tr:last-child td {
  border-bottom: 0;
}

.burn-index-cell {
  color: var(--teal);
  font-weight: 800;
}

.source-control {
  width: 70px;
  min-height: 30px;
  padding: 4px 6px;
}

.small-control {
  width: 78px;
  min-height: 30px;
  padding: 4px 6px;
}

.tiny-control {
  width: 54px;
  min-height: 30px;
  padding: 4px 6px;
  text-align: center;
}

.center-cell input[type="checkbox"] {
  display: block;
  width: 17px;
  min-height: 17px;
  margin: 0 auto;
  accent-color: var(--accent);
}

.icon-button {
  width: 30px;
  height: 30px;
  background: #fff;
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover {
  background: #f8e9e9;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.summary-card {
  min-height: 62px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.summary-card b {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}

.summary-card.good b {
  color: var(--good);
}

.summary-card.warn b {
  color: var(--gold);
}

.summary-card.danger b {
  color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
}

.result-table th,
.result-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.result-table th {
  background: #f1f5f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-table th:first-child,
.result-table td:first-child,
.result-table th:nth-child(2),
.result-table td:nth-child(2),
.result-table th:nth-child(9),
.result-table td:nth-child(9),
.result-table th:last-child,
.result-table td:last-child {
  text-align: left;
}

.result-table tr:last-child td {
  border-bottom: 0;
}

.result-table tr.inactive {
  color: var(--muted);
  background: #fafafa;
}

.damage-split {
  display: grid;
  gap: 2px;
}

.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--teal);
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-button:hover {
  color: var(--accent);
}

.factor-table {
  min-width: 0;
}

.factor-sections {
  display: grid;
  gap: 12px;
}

.factor-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.factor-section .table-wrap {
  border: 0;
  border-radius: 0;
}

.factor-section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px 12px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.factor-section-header h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

.factor-section-header span {
  color: var(--muted);
  font-size: 12px;
}

.factor-section-header b {
  margin-left: auto;
  font-size: 13px;
  white-space: nowrap;
}

.factor-table th,
.factor-table td {
  padding: 8px 9px;
  text-align: left;
}

.factor-table th {
  background: #f1f5f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  width: 132px;
}

.factor-table td {
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 28, 34, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-dialog {
  width: min(780px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(18, 28, 34, 0.28);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.modal-body {
  max-height: calc(100vh - 130px);
  overflow: auto;
  padding: 12px 14px 14px;
}

.factor-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.factor-summary span {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .settings-row {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 820px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-stats,
  .summary-grid,
  .contract-grid,
  .wolf-grid,
  .aglina-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field.wide {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .app-header {
    padding-inline: 12px;
  }

  .app-shell {
    width: min(100vw - 16px, 1280px);
    margin-top: 8px;
  }

  .section {
    padding: 10px;
  }

  .header-stats,
  .contract-grid,
  .wolf-grid,
  .aglina-grid,
  .summary-grid,
  .check-field {
    padding-top: 0;
  }
}
