:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --text: #17211d;
  --muted: #5d6a65;
  --line: #dfe6e2;
  --accent: #0f7b6c;
  --accent-strong: #0a5d52;
  --warn: #945f12;
  --danger: #b42318;
  --shadow: 0 18px 40px rgba(21, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.site-header,
.top-nav,
.collection-hero,
.tool-section,
.scenario-section,
.layout,
.templates,
.seo-content {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  padding: 32px 0 18px;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 0 8px;
}

.top-nav a {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
  text-decoration: none;
}

.top-nav a:hover {
  color: var(--accent-strong);
}

.top-nav .brand {
  margin-right: auto;
  color: var(--text);
  font-size: 1rem;
}

.collection-hero {
  padding: 48px 0 28px;
}

.collection-hero h1 {
  max-width: 900px;
  margin-bottom: 12px;
}

.tool-section,
.scenario-section {
  padding: 12px 0 28px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 100%;
  margin-bottom: 10px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 1.3rem;
}

h3 {
  margin-bottom: 14px;
  font-size: 1rem;
}

.intro {
  max-width: 820px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.tool-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.tool-card h3 {
  margin-bottom: 8px;
  font-size: 1.45rem;
}

.tool-card p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.tool-kicker {
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

.primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

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

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.scenario-grid article {
  min-height: 138px;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.scenario-grid p {
  margin-bottom: 0;
  color: var(--muted);
}

.collection-notes {
  padding-top: 2px;
}

.templates {
  padding: 0 0 18px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.template-card {
  min-height: 126px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.template-card:hover,
.template-card.active {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(15, 123, 108, 0.12);
}

.template-card h3 {
  margin-bottom: 6px;
}

.template-card p {
  margin-bottom: 10px;
  color: var(--muted);
}

.template-card span {
  color: var(--accent-strong);
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: start;
}

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

.results-panel {
  position: sticky;
  top: 16px;
  padding: 20px;
}

.input-panel {
  padding: 20px;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.secondary-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.health {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.health.warn {
  background: #fff7e8;
  color: var(--warn);
}

.health.danger {
  background: #fff1f0;
  color: var(--danger);
}

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

.metric-card {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.primary-metric {
  background: #f4faf8;
  border-color: rgba(15, 123, 108, 0.3);
}

.profit-card {
  grid-column: span 2;
}

.metric-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.metric-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.35rem, 3vw, 1.9rem);
  line-height: 1.1;
}

.profit-card strong {
  color: var(--accent-strong);
  font-size: clamp(1.8rem, 4vw, 2.45rem);
}

.profit-card strong.negative {
  color: var(--danger);
}

.breakdown {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.breakdown summary {
  margin-bottom: 14px;
  font-weight: 800;
  cursor: pointer;
}

.breakdown:not([open]) summary {
  margin-bottom: 0;
}

dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
}

dd {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

fieldset {
  margin: 0 0 18px;
  padding: 0 0 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

fieldset:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

legend {
  margin-bottom: 12px;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

label span {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

small {
  display: inline-grid;
  width: 17px;
  height: 17px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent-strong);
  font-size: 0.7rem;
  cursor: help;
}

.field-control {
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.field-control span {
  display: inline-flex;
  align-items: center;
  align-self: stretch;
  flex: 0 0 auto;
  margin: 0;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.field-control.prefix span {
  border-right: 1px solid var(--line);
}

.field-control.suffix span {
  border-left: 1px solid var(--line);
}

.field-control:focus-within {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 123, 108, 0.14);
}

input,
select {
  width: 100%;
  min-height: 42px;
  min-width: 0;
  padding: 8px 10px;
  border: 0;
  background: #fff;
  color: var(--text);
}

select {
  cursor: pointer;
}

input:focus,
select:focus {
  outline: 0;
}

.seo-content {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  padding: 8px 0 40px;
}

.seo-content article {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.seo-content p {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 6px;
  background: #17211d;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .site-header,
  .top-nav,
  .collection-hero,
  .tool-section,
  .scenario-section,
  .layout,
  .templates,
  .seo-content {
    width: min(100% - 24px, 680px);
  }

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

  .results-panel {
    position: static;
    order: -1;
  }

  .form-grid,
  .template-grid,
  .scenario-grid,
  .seo-content {
    grid-template-columns: 1fr;
  }

  .tool-card {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .multi-tool-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 861px) {
  .site-header h1 {
    white-space: nowrap;
  }
}

@media (max-width: 520px) {
  .site-header {
    padding-top: 24px;
  }

  .collection-hero {
    padding-top: 34px;
  }

  .top-nav {
    gap: 12px;
  }

  .top-nav a {
    font-size: 0.88rem;
  }

  .tool-card {
    padding: 18px;
  }

  .primary-link {
    width: 100%;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .results-panel .panel-heading {
    align-items: center;
    flex-direction: row;
  }

  .secondary-button {
    width: 100%;
  }

  .results-panel .secondary-button {
    width: auto;
    min-width: 86px;
  }

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

  .template-card {
    min-height: 68px;
    padding: 10px;
  }

  .template-card h3 {
    margin-bottom: 0;
    font-size: 0.88rem;
    line-height: 1.25;
  }

  .template-card p,
  .template-card span {
    display: none;
  }

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

  .metric-card {
    min-height: 88px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: 1.28rem;
  }

  .profit-card {
    grid-column: auto;
  }

  .profit-card strong {
    font-size: 1.38rem;
  }

  .secondary-mobile {
    display: none;
  }

}
