:root {
  --bg: #efeae1;
  --paper: #fffdf8;
  --ink: #1c1915;
  --muted: #4e4942;
  --faint: #746d64;
  --line: #e4d9ca;
  --green: #1e4638;
  --green-soft: #e7f0eb;
  --sand: #f6f1e7;
  --seal: #9c2f1a;
  --hot: #f6e2d4;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 280px at 0% -40px, #f7f1e6, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "PingFang HK", "PingFang TC", "Noto Sans CJK TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.wrap {
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 calc(36px + env(safe-area-inset-bottom));
}

.top { margin-bottom: 8px; }

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

.seal {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--seal);
  color: #fff8ee;
  font-weight: 700;
  font-size: 22px;
  border-radius: 10px;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--seal);
  font-weight: 600;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 12px;
  background: var(--bg);
}

.tab {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--green);
  border-color: var(--green);
  color: #f4f7f4;
}

.tab:focus-visible,
.ghost:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--seal);
  outline-offset: 2px;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel[hidden] { display: none; }

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

h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.lede {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14.5px;
}

.formula {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--sand);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13.5px;
}

.ghost {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.fields {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

.control {
  display: flex;
  align-items: center;
  min-height: 48px;
  border: 1px solid #d9cfc0;
  border-radius: 10px;
  background: #fff;
}

.control:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(30, 70, 56, 0.16);
}

.control input,
.control select {
  width: 100%;
  min-height: 46px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  padding: 8px 12px;
}

.control input:focus,
.control select:focus { outline: none; }

.affix,
.suffix {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.affix { padding-left: 12px; }
.suffix { padding-right: 12px; }

.mortgages {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

fieldset {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
}

legend {
  padding: 0 6px;
  font-weight: 700;
}

.banner {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8ece6;
  color: #6d2c16;
  font-size: 14.5px;
}

.banner:empty { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.stat {
  background: var(--sand);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat .k {
  font-size: 12.5px;
  color: var(--muted);
}

.stat .v {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat.primary {
  grid-column: 1 / -1;
  background: var(--green);
  color: #f4f7f4;
}

.stat.primary .k { color: #d5e3db; }

.stat.primary .v {
  font-size: clamp(28px, 8vw, 36px);
  line-height: 1.15;
}

.mix-block { margin: 4px 0 14px; }

.mix {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--line);
}

.mix .principal-part { background: var(--green); }
.mix .interest-part { background: var(--seal); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 99px;
  margin-right: 6px;
}

.legend .dot-p { background: var(--green); }
.legend .dot-i { background: var(--seal); }

.callouts {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.callout {
  background: var(--green-soft);
  border-radius: 12px;
  padding: 10px 12px;
}

.callout .k { font-size: 12.5px; color: var(--green); font-weight: 700; }
.callout .v { font-variant-numeric: tabular-nums; font-size: 14.5px; }

.dsr { margin-top: 4px; }

.dsr-track {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.dsr-track .fill {
  display: block;
  height: 100%;
  background: var(--green);
}

.dsr-track .fill.is-high { background: var(--seal); }

.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.table-scroll {
  overflow: auto;
  max-height: 440px;
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

caption {
  caption-side: bottom;
  text-align: left;
  padding: 8px 10px 10px;
  color: var(--faint);
  font-size: 12.5px;
}

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

th:first-child,
td:first-child { text-align: left; }

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f3eee4;
  font-weight: 600;
}

tbody tr.is-selected td { background: var(--hot); }

.chart {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.chart-frame {
  position: relative;
  margin-top: 4px;
}

.chart-frame::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: var(--chart-bar, 0px);
  width: var(--chart-clip, 0px);
  background: var(--paper);
  pointer-events: none;
  z-index: 4;
}

.chart-scroll {
  max-height: min(68vh, 640px);
  margin-top: 0;
  scroll-snap-type: x mandatory;
}

.chart th:first-child,
.chart td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--paper);
  text-align: left;
  box-shadow: 8px 0 8px -8px rgba(28, 25, 21, 0.35);
}

.chart td {
  min-width: 7.25rem;
  scroll-snap-align: start;
}

.chart thead th { z-index: 2; }
.chart thead th:first-child { z-index: 3; background: #f3eee4; }

.chart td.is-hot {
  background: var(--hot);
  box-shadow: inset 0 0 0 1px var(--seal);
}

footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

footer p { margin: 0; }

.brandline {
  margin-top: 6px;
  color: var(--faint);
}

@media (max-width: 640px) {
  .schedule thead { display: none; }
  .schedule,
  .schedule tbody,
  .schedule caption {
    display: block;
    width: 100%;
    max-width: 100%;
    white-space: normal;
  }
  .schedule tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
    padding: 10px 2px;
    border-bottom: 1px solid var(--line);
  }
  .schedule th,
  .schedule td {
    display: block;
    border: 0;
    padding: 2px 0;
    text-align: left;
    white-space: normal;
  }
  .schedule th[scope="row"] {
    grid-column: 1 / -1;
    font-size: 14px;
  }
  .schedule th[scope="row"]::before { content: "第 "; }
  .schedule th[scope="row"]::after { content: " 期"; }
  .schedule td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }
}

@media (min-width: 720px) {
  .fields.cols-2 { grid-template-columns: 1fr 1fr; }
  .fields.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .callouts { grid-template-columns: 1fr 1fr; }
  .panel { padding: 22px; }
}

@media (min-width: 880px) {
  h1 { font-size: 40px; }
  .mortgages { grid-template-columns: 1fr 1fr; }
  .flat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: start;
  }
}

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