:root {
  --navy: #0b2340;
  --blue: #155a9a;
  --blue-2: #2e7cc2;
  --sky: #eaf4fb;
  --ice: #f5f9fc;
  --ink: #142235;
  --muted: #5e6f80;
  --line: #d5e0e9;
  --paper: #ffffff;
  --gold: #b57a22;
  --gold-soft: #fff7e8;
  --danger: #a63c3c;
  --danger-soft: #fff1f0;
  --shadow: 0 16px 42px rgba(12, 38, 65, 0.1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: #eef4f8;
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.55;
}

button, input, select { font: inherit; }

a { color: inherit; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 10px clamp(18px, 4vw, 64px);
  color: #fff;
  background: rgba(8, 31, 55, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--navy);
  background: #fff;
  border-radius: 6px;
  font-weight: 900;
}

.brand small, .brand strong { display: block; }
.brand small { color: #bcd3e8; font-size: 0.73rem; letter-spacing: 0.08em; }
.brand strong { font-size: 1.03rem; }

.top-actions { display: flex; align-items: center; gap: 10px; }

.version-pill, .back-link, .status-pill {
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 5px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.back-link { color: #fff; text-decoration: none; }
.back-link:hover { background: rgba(255, 255, 255, 0.1); }

main { width: min(1500px, 100%); margin: 0 auto; padding: 0 clamp(16px, 3vw, 42px) 54px; }

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: clamp(30px, 6vw, 90px);
  align-items: end;
  min-height: 430px;
  padding: 62px clamp(8px, 2vw, 28px) 48px;
  overflow: hidden;
}

.hero::after {
  position: absolute;
  top: 34px;
  right: 1%;
  width: 360px;
  height: 360px;
  content: "";
  border: 1px solid rgba(21, 90, 154, 0.12);
  border-radius: 50%;
  box-shadow: inset 0 0 0 66px rgba(21, 90, 154, 0.035), inset 0 0 0 132px rgba(21, 90, 154, 0.025);
  pointer-events: none;
}

.hero-copy, .hero-highlights { position: relative; z-index: 1; }

.eyebrow, .panel-heading span, .section-heading span, .sources-section > div > span {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 820px;
  margin: 0;
  color: var(--navy);
  font-size: clamp(3rem, 7vw, 6.3rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.hero h1 span {
  display: inline-block;
  margin-top: 16px;
  font-size: clamp(1.2rem, 2.3vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
}

.hero-lead { max-width: 760px; margin: 26px 0 0; color: var(--muted); font-size: 1.06rem; }

.source-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }

.source-links a, .source-list a {
  padding: 8px 11px;
  color: var(--blue);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 750;
}

.source-links a:hover, .source-list a:hover { border-color: var(--blue-2); background: var(--sky); }

.hero-highlights {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-highlights article { padding: 22px 24px; background: rgba(255, 255, 255, 0.96); }
.hero-highlights span, .hero-highlights small { display: block; }
.hero-highlights span { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.hero-highlights strong { display: block; margin: 3px 0 2px; color: var(--navy); font-size: 1.48rem; }
.hero-highlights small { color: #718191; }

.notice {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 24px;
  margin: 0 0 18px;
  padding: 16px 20px;
  color: #5a451d;
  background: var(--gold-soft);
  border: 1px solid #edd6a8;
  border-left: 4px solid var(--gold);
}

.notice strong { color: #7d5617; }
.notice p { margin: 0; }

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.controls-panel { padding: 24px; background: #f7fafc; border-right: 1px solid var(--line); }
.results-panel { min-width: 0; padding: 24px; }

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

.panel-heading span, .section-heading span { display: block; margin-bottom: 2px; }
.panel-heading h2, .section-heading h2 { margin: 0; color: var(--navy); font-size: 1.25rem; }
.section-heading p { max-width: 620px; margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; text-align: right; }

.text-button {
  padding: 0;
  color: var(--blue);
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 750;
}

.text-button:hover { text-decoration: underline; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.field-grid label > span:first-child, .amount-control .label-row > span { display: block; margin-bottom: 5px; color: #42576b; font-size: 0.78rem; font-weight: 750; }

input, select {
  width: 100%;
  height: 42px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bccbd7;
  border-radius: 4px;
  outline: none;
}

input:focus, select:focus { border-color: var(--blue-2); box-shadow: 0 0 0 3px rgba(46, 124, 194, 0.12); }

.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 42px; font-variant-numeric: tabular-nums; }
.input-unit em { position: absolute; right: 10px; top: 50%; color: var(--muted); font-size: 0.76rem; font-style: normal; transform: translateY(-50%); }

.amount-control { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.amount-input input { height: 48px; color: var(--navy); font-size: 1.16rem; font-weight: 800; }
.amount-control p { margin: 7px 0 0; color: var(--muted); font-size: 0.76rem; }

.check-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 18px;
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

.check-row input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue); }
.check-row strong, .check-row small { display: block; }
.check-row strong { font-size: 0.86rem; }
.check-row small { margin-top: 3px; color: var(--muted); }

.formula-note { margin-top: 16px; padding: 14px; color: #365169; background: var(--sky); border-left: 3px solid var(--blue-2); }
.formula-note span { color: var(--blue); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; }
.formula-note p { margin: 3px 0 0; font-size: 0.8rem; }

.form-error, .shortfall-warning { color: var(--danger); background: var(--danger-soft); border: 1px solid #efc3bf; border-radius: 5px; }
.form-error { padding: 10px; font-size: 0.82rem; }

.status-pill { color: #225f49; background: #ebf8f2; border-color: #b9ddcf; }
.status-pill.is-warning { color: var(--danger); background: var(--danger-soft); border-color: #efc3bf; }

.facts-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); }
.facts-strip > span { padding: 13px 15px; border-right: 1px solid var(--line); }
.facts-strip > span:last-child { border-right: 0; }
.facts-strip small, .facts-strip strong { display: block; }
.facts-strip small { color: var(--muted); font-size: 0.72rem; }
.facts-strip strong { margin-top: 2px; color: var(--navy); font-size: 0.92rem; font-variant-numeric: tabular-nums; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.metric-card { min-width: 0; padding: 16px; background: var(--ice); border-top: 3px solid var(--blue-2); }
.metric-card.gold { border-color: var(--gold); background: #fffbf3; }
.metric-card span, .metric-card small { display: block; }
.metric-card span { color: var(--muted); font-size: 0.74rem; }
.metric-card strong { display: block; margin: 5px 0 2px; overflow: hidden; color: var(--navy); font-size: clamp(1.12rem, 2vw, 1.55rem); text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.metric-card small { color: #718191; }

.chart-card { padding: 16px; background: #fff; border: 1px solid var(--line); }
.chart-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.chart-heading span, .chart-heading strong { display: block; }
.chart-heading > div:first-child > span { color: var(--muted); font-size: 0.72rem; }
.chart-heading strong { color: var(--navy); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 0.74rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 18px; height: 3px; }
.account-line { background: var(--blue-2); }
.premium-line { background: #a8b4c0; }

#accountChart { display: block; width: 100%; height: 300px; }

.shortfall-warning { margin-top: 12px; padding: 12px 14px; }
.shortfall-warning p { margin: 3px 0 0; font-size: 0.82rem; }

.detail-section { margin-top: 20px; padding: 24px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.detail-nav { display: flex; gap: 4px; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.detail-tab { padding: 11px 18px; color: var(--muted); background: none; border: 0; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 750; }
.detail-tab:hover { color: var(--blue); }
.detail-tab.is-active { color: var(--blue); border-bottom-color: var(--blue); }

.table-wrap { overflow: auto; border: 1px solid var(--line); }
table { width: 100%; min-width: 1260px; border-collapse: collapse; table-layout: fixed; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid #e5ebf0; }
th { position: sticky; top: 0; z-index: 1; color: #35516b; background: #edf4f8; font-size: 0.7rem; white-space: nowrap; }
th:first-child, th:nth-child(2), td:first-child, td:nth-child(2) { text-align: center; }
tbody tr:hover { background: #f7fbfe; }
tbody tr:last-child td { border-bottom: 0; }
td.is-gold { color: #8f5b0f; font-weight: 800; }
td.is-blue { color: var(--blue); font-weight: 800; }

.formula-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.formula-grid article { padding: 20px; background: var(--ice); border-top: 4px solid var(--blue-2); }
.formula-grid b { display: inline-grid; width: 34px; height: 34px; place-items: center; color: #fff; background: var(--blue); border-radius: 4px; }
.formula-grid h3 { margin: 14px 0 7px; color: var(--navy); font-size: 1rem; }
.formula-grid p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.snapshot-card { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-top: 14px; color: #fff; background: rgba(255, 255, 255, 0.16); border: 1px solid var(--navy); }
.snapshot-card span { padding: 16px; background: var(--navy); }
.snapshot-card small, .snapshot-card strong { display: block; }
.snapshot-card small { color: #b9d0e3; }
.snapshot-card strong { margin-top: 3px; font-size: 1.08rem; font-variant-numeric: tabular-nums; }

.timeline-grid, .bonus-grid { display: grid; gap: 8px; }
.timeline-grid { grid-template-columns: repeat(5, 1fr); }
.bonus-grid { grid-template-columns: repeat(4, 1fr); margin-top: 10px; }
.timeline-grid article, .bonus-grid article { padding: 16px; background: var(--ice); border: 1px solid var(--line); }
.timeline-grid span, .timeline-grid small, .bonus-grid span { display: block; color: var(--muted); font-size: 0.76rem; }
.timeline-grid strong, .bonus-grid strong { display: block; margin: 4px 0; color: var(--blue); font-size: 1.45rem; }
.bonus-grid article { background: var(--gold-soft); border-color: #ead4a8; }
.bonus-grid strong { color: var(--gold); }

.rule-list { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 14px; background: var(--line); border: 1px solid var(--line); }
.rule-list p { margin: 0; padding: 16px; background: #fff; font-size: 0.85rem; }

.sources-section {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(280px, 0.55fr) minmax(360px, 1fr);
  gap: 30px;
  align-items: start;
  margin-top: 20px;
  padding: 28px;
  color: #d8e7f3;
  background: var(--navy);
}

.sources-section h2 { margin: 0; color: #fff; font-size: 1.2rem; }
.sources-section p { margin: 0; font-size: 0.82rem; }
.source-list { display: flex; flex-wrap: wrap; gap: 7px; }
.source-list a { color: #dff1ff; background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.18); }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 24px clamp(18px, 4vw, 64px); color: #8ea5b8; background: #07192c; font-size: 0.82rem; }
footer strong { color: #d9e7f2; }

@media (max-width: 1120px) {
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .hero-highlights { grid-template-columns: repeat(3, 1fr); }
  .calculator-layout { grid-template-columns: 320px minmax(0, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .facts-strip { grid-template-columns: repeat(2, 1fr); }
  .facts-strip > span:nth-child(2) { border-right: 0; }
  .facts-strip > span:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .sources-section { grid-template-columns: 1fr 1fr; }
  .sources-section > p { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
  .version-pill { display: none; }
  main { padding-inline: 12px; }
  .hero { padding-top: 44px; }
  .hero h1 { font-size: clamp(2.8rem, 15vw, 4.7rem); }
  .hero-highlights { grid-template-columns: 1fr; }
  .notice { grid-template-columns: 1fr; gap: 4px; }
  .calculator-layout { grid-template-columns: 1fr; }
  .controls-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .formula-grid, .timeline-grid { grid-template-columns: 1fr; }
  .bonus-grid, .snapshot-card, .rule-list { grid-template-columns: 1fr 1fr; }
  .section-heading { display: block; }
  .section-heading p { margin-top: 6px; text-align: left; }
  .sources-section { grid-template-columns: 1fr; }
  .sources-section > p { grid-column: auto; }
}

@media (max-width: 560px) {
  .topbar { min-height: 62px; padding-inline: 13px; }
  .brand-mark { display: none; }
  .back-link { padding: 6px 8px; }
  .hero { padding-inline: 4px; }
  .hero-lead { font-size: 0.96rem; }
  .field-grid, .metric-grid, .facts-strip, .bonus-grid, .snapshot-card, .rule-list { grid-template-columns: 1fr; }
  .facts-strip > span { border-right: 0; border-bottom: 1px solid var(--line); }
  .facts-strip > span:last-child { border-bottom: 0; }
  .controls-panel, .results-panel, .detail-section { padding: 18px 14px; }
  .chart-heading { display: block; }
  .legend { margin-top: 8px; }
  .detail-nav { overflow-x: auto; }
  .detail-tab { white-space: nowrap; }
  #accountChart { height: 250px; }
  footer { display: block; }
  footer span { display: block; margin-top: 4px; }
}

@media print {
  .topbar, .controls-panel, .detail-nav, footer { display: none !important; }
  body { background: #fff; }
  main { width: 100%; padding: 0; }
  .hero { min-height: auto; padding: 20px 0; }
  .calculator-layout { display: block; box-shadow: none; }
  .detail-section, .results-panel { box-shadow: none; }
}
