:root {
  color-scheme: light;
  --background: #f2f5f4;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --text: #15201d;
  --muted: #65736f;
  --border: #dce4e1;
  --primary: #126d55;
  --primary-dark: #0b5541;
  --primary-soft: #e8f4ef;
  --good: #067647;
  --warning: #9a5b13;
  --danger: #b42318;
  --shadow: 0 22px 65px rgb(26 57 48 / 12%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 3%, rgb(18 109 85 / 10%), transparent 28rem),
    var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 32px 24px;
}

.calculator {
  overflow: hidden;
  border: 1px solid rgb(18 109 85 / 14%);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.page-header {
  padding: 32px 36px 26px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #fbfdfc 0%, #f2f8f5 100%);
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -0.04em;
}

.page-description {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.75;
}

.page-content {
  padding: 28px 36px 36px;
}

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

.field label,
.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 700;
}

.input-wrap {
  position: relative;
}

input,
select,
.field-output {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

input,
select {
  padding: 0 14px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input-wrap input {
  padding-right: 76px;
}

select {
  padding-right: 42px;
}

input:focus,
select:focus,
.table-scroll:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgb(18 109 85 / 14%);
}

.unit {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.field-output {
  display: flex;
  align-items: center;
  padding: 9px 14px;
  background: var(--surface-soft);
  color: #31413c;
  font-size: 14px;
  line-height: 1.45;
}

.field-hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none;
}

.primary-button {
  width: 100%;
  min-height: 52px;
  margin-top: 24px;
  border: 0;
  border-radius: 13px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

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

.primary-button:active {
  transform: translateY(1px);
}

.primary-button:focus-visible {
  outline: 4px solid rgb(18 109 85 / 20%);
  outline-offset: 2px;
}

.error-message {
  margin-top: 18px;
  padding: 13px 15px;
  border: 1px solid rgb(180 35 24 / 18%);
  border-radius: 11px;
  background: rgb(180 35 24 / 8%);
  color: var(--danger);
  line-height: 1.6;
}

.result {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.recommendation-card {
  padding: 24px;
  border: 1px solid rgb(18 109 85 / 28%);
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary-soft), #f7fbf9);
}

.recommendation-label {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.recommendation-title {
  margin-bottom: 6px;
  font-size: clamp(32px, 5vw, 48px);
  letter-spacing: -0.04em;
}

.recommendation-note {
  margin-bottom: 0;
  color: #52615d;
  line-height: 1.75;
}

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

.stat-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.stat-card dt {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.stat-card dd {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.stat-card .rate-value {
  color: var(--primary-dark);
  font-size: 14px;
}

.plan-section {
  margin-top: 28px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.section-heading h3 {
  margin-bottom: 0;
  font-size: 20px;
}

.section-heading > p {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.table-scroll {
  isolation: isolate;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
}

table {
  width: 100%;
  min-width: 1480px;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}

th,
td {
  padding: 13px 11px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background-color: var(--surface);
  box-shadow: 1px 0 0 var(--border);
  text-align: left;
}

thead {
  background: var(--surface-soft);
}

thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

thead th:first-child {
  z-index: 3;
  background-color: var(--surface-soft);
}

tbody:last-child tr:last-child > * {
  border-bottom: 0;
}

.custom-plan {
  background: #fbfcfc;
}

.custom-plan th:first-child,
.custom-plan td:first-child {
  background-color: #fbfcfc;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgb(6 118 71 / 10%);
  color: var(--good);
  font-size: 11px;
  font-weight: 700;
}

.tag.warning {
  background: rgb(154 91 19 / 11%);
  color: var(--warning);
}

.custom-years-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#customYears {
  width: 76px;
  min-height: 34px;
  padding: 0 8px;
  border-radius: 8px;
}

.footnote {
  margin-top: 20px;
  padding: 17px 18px;
  border-radius: 13px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

.footnote p {
  margin-bottom: 8px;
}

.footnote p:last-child {
  margin-bottom: 0;
}

.footnote a {
  color: var(--primary);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 920px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .calculator {
    border-radius: 18px;
  }

  .page-header,
  .page-content {
    padding-left: 18px;
    padding-right: 18px;
  }

  .form-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: block;
  }

  .section-heading > p {
    margin-top: 7px;
  }

  .table-scroll {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  .table-scroll:focus-visible {
    box-shadow: none;
  }

  table,
  tbody {
    display: block;
    width: 100%;
    min-width: 0;
    background: transparent;
  }

  thead {
    display: none;
  }

  #alternativeRows,
  .custom-plan {
    display: grid;
    gap: 12px;
  }

  .custom-plan {
    margin-top: 12px;
  }

  #alternativeRows tr,
  .custom-plan tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
    padding: 0 12px 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
  }

  #alternativeRows tr > th:first-child,
  .custom-plan tr > th:first-child {
    position: static;
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 -12px;
    padding: 14px 12px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
    box-shadow: none;
    font-size: 16px;
    white-space: normal;
  }

  #alternativeRows tr > td,
  .custom-plan tr > td {
    position: static;
    display: flex;
    min-width: 0;
    min-height: 64px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 5px;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    background: transparent;
    box-shadow: none;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  #alternativeRows tr > td:nth-child(even),
  .custom-plan tr > td:nth-child(even) {
    border-right: 1px solid var(--border);
  }

  #alternativeRows tr > td:last-child,
  .custom-plan tr > td:last-child {
    grid-column: 1 / -1;
    border-bottom: 0;
    border-right: 0;
  }

  #alternativeRows td::before,
  .custom-plan td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    line-height: 1.35;
  }

  .tag {
    margin-left: 0;
  }

  #customYears {
    min-height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ===== V2 布局：输入集中、结果分层、选填隐藏、结论优先 ===== */
/* V2：输入集中、结果分层、选填隐藏、结论优先 */
      .page-content { padding-top: 24px; }

      .input-section-title {
        display: flex;
        align-items: end;
        justify-content: space-between;
        gap: 18px;
        margin-bottom: 14px;
      }
      .input-section-title h2 {
        margin: 0;
        font-size: 20px;
        letter-spacing: -0.02em;
      }
      .input-section-title p {
        margin: 0;
        color: var(--muted);
        font-size: 12px;
      }

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

      .more-settings {
        margin-top: 18px;
        border: 1px solid var(--border);
        border-radius: 16px;
        background: var(--surface-soft);
        overflow: clip;
      }
      .more-settings > summary,
      .result-details > summary,
      .result-block > summary,
      .footnote-details > summary {
        list-style: none;
        cursor: pointer;
        user-select: none;
      }
      .more-settings > summary::-webkit-details-marker,
      .result-details > summary::-webkit-details-marker,
      .result-block > summary::-webkit-details-marker,
      .footnote-details > summary::-webkit-details-marker { display: none; }

      .more-settings > summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 15px 17px;
        font-weight: 800;
      }
      .more-settings > summary::after,
      .result-details > summary::after,
      .result-block > summary::after,
      .footnote-details > summary::after {
        content: var(--details-expand-label, "展开");
        color: var(--primary);
        font-size: 12px;
        font-weight: 800;
      }
      .more-settings[open] > summary::after,
      .result-details[open] > summary::after,
      .result-block[open] > summary::after,
      .footnote-details[open] > summary::after { content: var(--details-collapse-label, "收起"); }

      .summary-copy {
        display: flex;
        flex-direction: column;
        gap: 3px;
      }
      .summary-copy small {
        color: var(--muted);
        font-size: 12px;
        font-weight: 500;
      }
      .more-settings-body {
        padding: 0 17px 17px;
        border-top: 1px solid var(--border);
      }
      .optional-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px 18px;
        padding-top: 16px;
      }
      .optional-field {
        padding: 14px;
        border: 1px solid var(--border);
        border-radius: 13px;
        background: var(--surface);
      }
      .optional-field .field-hint { line-height: 1.55; }
      .optional-label {
        display: inline-flex;
        align-items: center;
        gap: 7px;
      }
      .optional-tag {
        padding: 2px 6px;
        border-radius: 999px;
        background: var(--primary-soft);
        color: var(--primary-dark);
        font-size: 10px;
        font-weight: 800;
      }

      .submit-row {
        display: flex;
        align-items: center;
        gap: 14px;
        margin-top: 20px;
      }
      .submit-row .primary-button { margin-top: 0; }
      .submit-hint {
        flex: 0 0 auto;
        color: var(--muted);
        font-size: 12px;
        white-space: nowrap;
      }

      .result { margin-top: 32px; }
      .primary-stats {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 12px;
        margin-top: 14px;
      }
      .primary-stat {
        min-width: 0;
        padding: 17px;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: var(--surface);
      }
      .primary-stat dt {
        margin-bottom: 7px;
        color: var(--muted);
        font-size: 12px;
        line-height: 1.45;
      }
      .primary-stat dd {
        margin: 0;
        font-size: 19px;
        font-weight: 850;
        line-height: 1.35;
        overflow-wrap: anywhere;
      }

      .result-details,
      .result-block,
      .footnote-details {
        margin-top: 14px;
        border: 1px solid var(--border);
        border-radius: 14px;
        background: var(--surface);
        overflow: clip;
      }
      .result-details > summary,
      .result-block > summary,
      .footnote-details > summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 14px 16px;
        font-size: 14px;
        font-weight: 800;
      }
      .details-body { padding: 0 16px 16px; }
      .detail-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
      }
      .detail-stat {
        padding: 13px 14px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface-soft);
      }
      .detail-stat dt {
        margin-bottom: 5px;
        color: var(--muted);
        font-size: 11px;
      }
      .detail-stat dd {
        margin: 0;
        font-size: 15px;
        font-weight: 800;
        overflow-wrap: anywhere;
      }

      .decision-card {
        margin-top: 24px;
        padding: 21px;
        border: 1px solid rgb(18 109 85 / 28%);
        border-radius: 17px;
        background: linear-gradient(135deg, var(--primary-soft), #f8fbfa);
      }
      .decision-card[hidden] { display: none; }
      .decision-kicker {
        margin: 0 0 5px;
        color: var(--primary);
        font-size: 12px;
        font-weight: 850;
        letter-spacing: 0.08em;
      }
      .decision-title {
        display: block;
        margin-bottom: 8px;
        font-size: clamp(24px, 4vw, 34px);
        line-height: 1.2;
        letter-spacing: -0.03em;
      }
      .decision-text {
        margin: 0;
        color: #52615d;
        line-height: 1.75;
      }
      .decision-strip {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
        margin-top: 14px;
      }
      .decision-mini {
        padding: 12px 13px;
        border: 1px solid rgb(18 109 85 / 16%);
        border-radius: 12px;
        background: rgb(255 255 255 / 72%);
      }
      .decision-mini span {
        display: block;
        margin-bottom: 4px;
        color: var(--muted);
        font-size: 11px;
      }
      .decision-mini strong {
        font-size: 15px;
        overflow-wrap: anywhere;
      }
      .good { color: var(--good); }
      .bad { color: var(--warning); }

      .rent-math {
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid rgb(18 109 85 / 14%);
      }

      /* “查看这个结论怎么算的”入口做成按钮外观（保留 summary 语义与原生展开行为）；
         布局与其他 details 入口一致：文字在左，展开/收起在右 */
      .rent-math > summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 12px 14px;
        border: 1px solid rgb(18 109 85 / 24%);
        border-radius: 12px;
        background: rgb(255 255 255 / 78%);
        color: var(--primary-dark);
        font-size: 13px;
        font-weight: 800;
        list-style: none;
        cursor: pointer;
        user-select: none;
        transition: background 160ms ease, border-color 160ms ease;
      }
      .rent-math > summary::-webkit-details-marker { display: none; }
      .rent-math > summary::marker { content: ""; }
      .rent-math > summary::after {
        content: var(--details-expand-label, "展开");
        color: var(--primary);
        font-size: 12px;
        font-weight: 800;
      }
      .rent-math[open] > summary::after { content: var(--details-collapse-label, "收起"); }
      .rent-math > summary:hover {
        border-color: rgb(18 109 85 / 42%);
        background: #ffffff;
      }
      .rent-math > summary:focus-visible {
        outline: 4px solid rgb(18 109 85 / 20%);
        outline-offset: 2px;
      }
      .rent-math-grid {
        margin-top: 10px;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 10px;
      }
      .rent-math-item {
        padding: 11px 12px;
        border-radius: 11px;
        background: rgb(255 255 255 / 76%);
      }
      .rent-math-item span {
        display: block;
        margin-bottom: 4px;
        color: var(--muted);
        font-size: 11px;
      }
      .rent-math-item strong { font-size: 14px; }
      .rent-math-note {
        margin: 10px 0 0;
        color: var(--muted);
        font-size: 12px;
        line-height: 1.7;
      }

      .custom-compare {
        margin-top: 24px;
        padding: 20px;
        border: 1px solid var(--border);
        border-radius: 16px;
        background: var(--surface-soft);
      }
      .custom-compare[hidden] { display: none; }
      .custom-compare-head {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        margin-bottom: 12px;
      }
      .custom-compare-head h3 { margin: 0; font-size: 19px; }
      .custom-compare-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
      .custom-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
      }
      .custom-card {
        padding: 16px;
        border: 1px solid var(--border);
        border-radius: 13px;
        background: var(--surface);
      }
      .custom-card-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        margin-bottom: 11px;
        font-size: 14px;
        font-weight: 850;
      }
      .custom-card dl { margin: 0; }
      .custom-line {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        padding: 7px 0;
        border-top: 1px solid var(--border);
      }
      .custom-line:first-child { border-top: 0; }
      .custom-line dt { color: var(--muted); font-size: 12px; }
      .custom-line dd { margin: 0; font-size: 13px; font-weight: 800; text-align: right; }
      .custom-delta {
        margin: 12px 0 0;
        color: var(--muted);
        font-size: 12px;
        line-height: 1.65;
      }

      .plan-section { margin-top: 0; }
      .plan-section .section-heading { margin: 2px 0 12px; }
      .result-block .table-scroll { border-radius: 12px; }
      .result-block table { min-width: 1320px; }

      .footnote-details .footnote {
        margin: 0;
        border-radius: 0;
      }

      .inline-error {
        margin-top: 8px;
        color: var(--danger);
        font-size: 12px;
        line-height: 1.5;
      }

      @media (max-width: 900px) {
        .core-form-grid,
        .optional-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .primary-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .detail-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
        .rent-math-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
      }

      @media (max-width: 680px) {
        .page-header { padding: 25px 20px 21px; }
        .page-content { padding: 20px; }
        .core-form-grid,
        .optional-grid,
        .primary-stats,
        .detail-stats,
        .decision-strip,
        .custom-grid,
        .rent-math-grid { grid-template-columns: 1fr; }
        .input-section-title,
        .custom-compare-head { align-items: start; flex-direction: column; }
        .input-section-title p { display: none; }
        .submit-row { align-items: stretch; flex-direction: column; }
        .submit-hint { white-space: normal; }
        .more-settings > summary { align-items: flex-start; }
        .result-block .table-scroll {
          overflow: visible;
          border: 0;
          border-radius: 0;
        }
        .result-block table { min-width: 0; }
      }
    
