:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #5f6b85;
  --line: #dbe2ef;
  --primary: #3468ff;
  --primary-dark: #264fd1;
  --success: #127c56;
  --danger: #d03c3c;
  --warning: #9a6700;
  --shadow: 0 14px 40px rgba(22, 32, 51, 0.08);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #eef4ff 0%, var(--bg) 18%, var(--bg) 100%);
  color: var(--text);
  transition: background 0.25s ease, color 0.25s ease;
}

body.theme-dark {
  --bg: #111827;
  --surface: #192334;
  --surface-soft: #222f44;
  --text: #e9f0ff;
  --muted: #aab9d8;
  --line: #324764;
  --primary: #7ba2ff;
  --primary-dark: #94b4ff;
  --success: #3bd39f;
  --danger: #ff8181;
  --warning: #f9be52;
  --shadow: 0 16px 42px rgba(1, 10, 25, 0.42);
  background: radial-gradient(circle at 15% 0%, #203354 0%, #111827 42%, #111827 100%);
}

button,
input {
  font: inherit;
}

.page {
  width: min(1320px, calc(100% - 32px));
  margin: 32px auto 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-lite {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.hero {
  padding: 28px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.08;
}

h2,
h3 {
  margin: 0 0 12px;
}

.hero-text,
.panel p,
.explanation p,
.explanation li,
.note,
.field small,
.muted,
.compare-summary {
  color: var(--muted);
  line-height: 1.65;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.hero-badges span {
  padding: 10px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  white-space: nowrap;
}

.theme-toggle-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.theme-toggle-btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
  color: var(--primary);
}

body.theme-dark .theme-toggle-btn {
  background: var(--surface-soft);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
  gap: 24px;
}

.panel {
  padding: 24px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.panel-head.compact {
  margin-bottom: 16px;
}

.term-picker {
  margin-bottom: 20px;
}

.quick-guide,
.mode-switch {
  margin-bottom: 18px;
  padding: 18px;
}

.compact-head {
  margin-bottom: 12px;
}

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

.guide-item {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.guide-item ol {
  margin: 8px 0 0 18px;
  padding: 0;
  color: var(--muted);
}

.guide-tag {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-dark);
}

.mode-buttons {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.term-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.term-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.term-btn:hover {
  transform: translateY(-1px);
}

.term-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

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

.equal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
}

.equal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.segment-box,
.fee-box,
.equal-box {
  margin-top: 18px;
  padding: 18px;
}

body.mode-equal #segment-box {
  display: none;
}

body.mode-segment #equal-box {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.field input,
.compare-payment-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.compare-payment-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(52, 104, 255, 0.12);
}

.actions,
.section-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.actions {
  margin-top: 20px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: #e8efff;
  color: var(--primary-dark);
}

.btn-ghost {
  background: #f1f4fa;
  color: var(--muted);
}

.note {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.compare-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

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

.compare-table {
  width: 100%;
  border-collapse: collapse;
}

.compare-table th,
.compare-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.compare-table th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.compare-table tbody tr:last-child td {
  border-bottom: none;
}

.compare-table tbody tr.is-selected {
  background: rgba(52, 104, 255, 0.05);
}

.compare-term {
  font-weight: 800;
}

.compare-status.ok {
  color: var(--success);
  font-weight: 700;
}

.compare-status.error {
  color: var(--danger);
  font-weight: 700;
}

.compare-status.empty {
  color: var(--warning);
  font-weight: 700;
}

.compare-summary {
  margin: 14px 0 0;
}

.result-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 18px;
  align-self: start;
}

.result-box {
  padding: 20px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.result-box.success {
  background: rgba(18, 124, 86, 0.08);
  border-color: rgba(18, 124, 86, 0.28);
}

.result-box.error {
  background: rgba(208, 60, 60, 0.08);
  border-color: rgba(208, 60, 60, 0.25);
}

.result-label {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.result-value {
  margin: 0 0 8px;
  font-size: clamp(28px, 4.8vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.result-meta {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.rate-level {
  margin: -4px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
  background: var(--surface-soft);
}

.rate-level.neutral {
  color: var(--muted);
}

.rate-level.low {
  color: var(--success);
  border-color: rgba(18, 124, 86, 0.4);
  background: rgba(18, 124, 86, 0.08);
}

.rate-level.medium {
  color: #8a6500;
  border-color: rgba(154, 103, 0, 0.35);
  background: rgba(249, 190, 82, 0.14);
}

.rate-level.high,
.rate-level.very-high {
  color: var(--danger);
  border-color: rgba(208, 60, 60, 0.35);
  background: rgba(208, 60, 60, 0.1);
}

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

.metric {
  padding: 16px;
}

.metric-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.metric-value {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.insight {
  padding: 16px;
}

.insight h3 {
  margin: 0 0 8px;
}

.insight p {
  margin: 0;
  line-height: 1.6;
}

.schedule {
  padding: 16px;
}

.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.schedule-row span:first-child {
  color: var(--muted);
}

.schedule-row span:last-child {
  font-weight: 700;
}

.explanation ul {
  margin: 0 0 12px 18px;
  padding: 0;
}

body.theme-dark .btn-secondary {
  background: rgba(123, 162, 255, 0.2);
  color: #d9e5ff;
}

body.theme-dark .btn-ghost {
  background: rgba(136, 159, 202, 0.18);
  color: #c8d8ff;
}

body.theme-dark .rate-level.medium {
  color: #ffd782;
  border-color: rgba(255, 195, 100, 0.45);
  background: rgba(249, 190, 82, 0.18);
}

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

  .hero,
  .panel-head,
  .section-head {
    flex-direction: column;
  }

  .hero-badges {
    justify-content: flex-start;
  }

  .result-panel {
    position: static;
  }
}

@media (max-width: 860px) {
  .form-grid,
  .segment-grid,
  .cost-grid,
  .metric-grid,
  .two-col,
  .equal-grid,
  .guide-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 640px) {
  .page {
    width: min(100% - 20px, 1320px);
    margin: 20px auto 32px;
  }

  .hero,
  .panel {
    padding: 18px;
  }

  .btn {
    width: 100%;
  }

  .actions,
  .section-actions {
    width: 100%;
  }
}
