:root {
  color-scheme: light;
  --ink: #162235;
  --muted: #667085;
  --line: #d8dee9;
  --paper: #ffffff;
  --wash: #f5f7fb;
  --blue: #174ea6;
  --green: #1d7f63;
  --amber: #b76b00;
  --red: #b42318;
  --shadow: 0 16px 40px rgba(22, 34, 53, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--blue);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 48px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.brand p,
.brand strong {
  display: block;
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
}

.brand strong {
  font-size: 18px;
}

.motto {
  color: var(--blue);
  font-weight: 700;
  white-space: nowrap;
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.intro-copy {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.18;
}

.intro-copy p:last-child {
  margin: 12px 0 0;
  color: var(--muted);
  max-width: 68ch;
}

.source-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.source-strip a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  color: var(--blue);
  background: #eef4ff;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.workspace {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
}

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

.controls,
.results,
.distribution-panel,
.table-panel {
  padding: 18px;
}

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

.section-title span {
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
}

.section-title small {
  min-width: 0;
  color: var(--muted);
  line-height: 1.4;
  text-align: right;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fbfcff;
  border: 1px solid #cfd6e4;
  border-radius: 8px;
  font: inherit;
}

input:focus,
select:focus {
  outline: 2px solid #b9cdfa;
  border-color: var(--blue);
}

input[readonly] {
  color: #0f5132;
  background: #f6fef9;
  border-color: #abefc6;
  font-weight: 700;
}

.fund-lock {
  margin: 16px 0;
  padding: 14px;
  background: #f6fef9;
  border: 1px solid #abefc6;
  border-radius: 8px;
}

.fund-lock span,
.fund-lock strong,
.fund-lock small {
  display: block;
}

.fund-lock span {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.fund-lock strong {
  margin: 4px 0;
}

.fund-lock small {
  color: var(--muted);
}

.fund-lock small span {
  display: block;
}

button.action-link {
  min-height: 44px;
  font: inherit;
  cursor: pointer;
}

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

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 16px;
  color: #fff;
  background: var(--blue);
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.panel-actions button.action-link {
  width: auto;
}

.inline-age-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--muted);
  background: #fbfcff;
  border: 1px solid #d9e2f2;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.inline-age-control span {
  margin: 0;
  white-space: nowrap;
}

.inline-age-control input {
  width: 72px;
  min-height: 30px;
  padding: 4px 8px;
  text-align: center;
}

.action-link-secondary {
  color: var(--blue);
  background: #eef4ff;
  border: 1px solid #c7d7fe;
}

.action-link.action-link-secondary:hover {
  color: var(--blue);
  background: #dbeafe;
}

.action-link.action-link-secondary.is-active,
.action-link.action-link-secondary.is-active:hover {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.action-link:hover {
  background: #0b3b82;
}

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

.metric {
  min-width: 0;
  min-height: 104px;
  padding: 14px;
  background: #fbfcff;
  border: 1px solid #d9e2f2;
  border-radius: 8px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(20px, 2vw, 24px);
  line-height: 1.15;
  white-space: nowrap;
}

.chart-legend {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 18px;
  margin: 14px 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.legend-line {
  width: 28px;
  height: 0;
  border-top: 3px solid var(--blue);
}

.legend-basic {
  border-top-color: #7891b2;
  border-top-width: 2px;
  border-top-style: dashed;
  opacity: 0.7;
}

.chart-wrap {
  margin-top: 0;
  height: 310px;
  border: 1px solid #d9e2f2;
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcff;
}

.chart-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#valueChart {
  width: 100%;
  height: 100%;
  display: block;
}

.axis {
  stroke: #98a2b3;
  stroke-width: 1;
}

.grid {
  stroke: #e4e9f2;
  stroke-width: 1;
}

.line-account {
  fill: none;
  stroke: var(--blue);
  stroke-width: 3;
}

.line-basic {
  stroke: #7891b2;
  stroke-width: 1.5;
  stroke-dasharray: 7 7;
  opacity: 0.58;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.table-panel {
  margin-top: 18px;
}

.distribution-panel {
  margin-top: 18px;
}

.distribution-note {
  margin: 14px 0 16px;
  color: var(--muted);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1160px;
  border-collapse: collapse;
  font-size: 14px;
}

tbody tr:nth-child(odd) {
  background: #fbfdff;
}

tbody tr:nth-child(even) {
  background: #f2f7ff;
}

tbody tr:hover {
  background: #e7f0ff;
}

.distribution-table {
  min-width: 900px;
}

.distribution-table tbody tr:nth-child(odd) {
  background: #f8fbff;
}

.distribution-table tbody tr:nth-child(even) {
  background: #edf5ff;
}

.distribution-table tbody tr:hover {
  background: #dbeafe;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #e5eaf3;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  color: #344054;
  background: #f8fafd;
  font-weight: 800;
}

td.negative {
  color: var(--red);
}

td.bonus {
  color: var(--green);
  font-weight: 800;
}

@media (max-width: 980px) {
  .intro,
  .workspace {
    grid-template-columns: 1fr;
  }

  .source-strip {
    justify-content: flex-start;
  }

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

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .motto {
    white-space: normal;
  }

  .shell {
    width: min(100% - 20px, 1240px);
    margin-top: 16px;
  }

  h1 {
    font-size: 28px;
  }

  .field-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 260px;
  }
}
