[hidden] { display: none !important; }

:root {
  --bg: #e4eef2;
  --ink: #14202b;
  --muted: #3e5160;
  --line: #d3dee6;
  --card: #ffffff;
  --green: #0c6b4e;
  --green-ink: #084936;
  --copper: #b85a28;
  --blue: #1f5f8b;
  --slate: #7d92a3;
  --header: #12202b;
  --save: #e5f5ee;
  color-scheme: light;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, "Apple SD Gothic Neo", "Malgun Gothic", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: var(--green-ink); }

.topbar {
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--header);
  color: #fff;
}

.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: 0 0 auto;
}

.topbar nav {
  display: flex;
  gap: 14px;
  flex: 1 1 auto;
  min-width: 0;
}

.topbar nav a {
  color: #d5e4ea;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.topbar nav a:hover { color: #fff; }

.lang-menu { position: relative; flex: 0 0 auto; }

.lang-menu > summary {
  list-style: none;
  cursor: pointer;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: 13px;
}

.lang-menu > summary::-webkit-details-marker { display: none; }

.lang-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  color: var(--ink);
  min-width: 148px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(18, 32, 43, 0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
}

.lang-pop a {
  text-decoration: none;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: 6px;
}

.lang-pop a:hover { background: #eef5f3; }

.first-screen {
  display: grid;
  align-content: start;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 8px 16px 10px;
  min-width: 0;
}

.first-screen > * { min-width: 0; }

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

.banner,
.notice,
.title-row > .banner {
  grid-column: 1 / -1;
}

.banner {
  margin: 0;
  padding: 6px 8px;
  background: #fff6e8;
  border: 1px solid #efd3a8;
  border-radius: 6px;
  color: #6a3d10;
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  white-space: nowrap;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs { display: flex; gap: 6px; }

.tabs button,
.actions button,
.text-btn {
  border: 1px solid #c5d2dc;
  background: #fff;
  border-radius: 999px;
  height: 32px;
  padding: 0 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.text-btn { height: 30px; }

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

.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 10px;
  min-width: 0;
  min-height: 0;
}

.pane,
.results {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  min-width: 0;
}

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

.pane h2 {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.2;
}

.pane h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 2px;
  background: var(--green);
  vertical-align: 0;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }

.grid-3 { display: grid; grid-template-columns: 1.15fr 1fr 0.72fr; gap: 8px 10px; }

.field { min-width: 0; }

.field label,
.lbl {
  display: block;
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 3px;
}

input[type="text"],
input:not([type="checkbox"]) {
  width: 100%;
  height: 30px;
  border: 1px solid #c5d2dc;
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
}

input:focus,
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

.term-row,
.with-seg {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.with-seg input,
.years-custom { flex: 1 1 auto; min-width: 0; }

.years-custom { position: relative; }

.years-custom .suffix {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.years-custom input { padding-right: 42px; }

.seg {
  display: inline-flex;
  border: 1px solid #c5d2dc;
  border-radius: 6px;
  overflow: hidden;
  flex: 0 0 auto;
}

.seg button {
  border: 0;
  background: #fff;
  height: 30px;
  padding: 0 10px;
  border-radius: 0;
}

.seg button + button { border-left: 1px solid #c5d2dc; }

.seg button[aria-pressed="true"] {
  background: var(--green);
  color: #fff;
}

.loan-line {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.loan-line strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.hint, .aside, .rent-note, .status-line {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.switch {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
}

.switch input { width: 16px; height: 16px; margin-top: 2px; flex: 0 0 auto; }

.switch strong { display: block; font-weight: 650; }

.aside { margin-top: auto; padding-top: 6px; }

.kicker {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
}

.hero {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.hero strong {
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--green-ink);
}

.hero span { color: var(--muted); font-size: 14px; }

.bar {
  display: flex;
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: #e6eeea;
  margin: 6px 0;
}

.bar span { display: block; height: 100%; }

.swatch.pi, #seg-pi { background: var(--green); }
.swatch.tax, #seg-tax { background: #c9842a; }
.swatch.ins, #seg-ins { background: var(--blue); }
.swatch.hoa, #seg-hoa { background: #6b5b95; }
.swatch.pmi, #seg-pmi { background: var(--copper); }

.break {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
}

.break li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
}

.break span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.break b { font-variant-numeric: tabular-nums; font-weight: 650; }

.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 4px;
}

.save {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  background: var(--save);
  border-radius: 8px;
  padding: 6px 8px;
  margin-top: 8px;
}

.save .wide { grid-column: 1 / -1; }

.save span { display: block; font-size: 11px; color: var(--green-ink); }

.save strong {
  display: block;
  font-size: 15px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.results {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#out-loan,
#out-rent {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  flex: 1;
}

.chart-wrap {
  flex: 1 1 auto;
  min-height: 168px;
  position: relative;
  border: 1px solid #e1ebe6;
  border-radius: 8px;
  overflow: hidden;
  background: #f7fbf9;
  margin-top: 6px;
}

canvas.chart { width: 100%; height: 100%; display: block; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--muted);
}

.legend i {
  display: inline-block;
  width: 16px;
  height: 0;
  border-top: 3px solid var(--green);
  margin-right: 4px;
  vertical-align: middle;
}

.legend i.base { border-top: 2px dashed var(--slate); }
.legend i.principal { border-top-color: var(--blue); }
.legend i.interest { border-top-color: var(--copper); }
.legend i.rent { border-top-color: var(--blue); }

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.actions button[id="btn-csv"] {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.compare-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.compare-stats article {
  background: var(--sand);
  border-radius: 8px;
  padding: 6px 8px;
}

.compare-stats strong {
  display: block;
  font-size: 20px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.break-even {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 650;
}

.block {
  width: min(1120px, calc(100% - 32px));
  margin: 16px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 16px;
}

.block h2 { margin: 0 0 8px; font-size: 18px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.table-wrap {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid #e7eef2; white-space: nowrap; }

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

thead th { position: sticky; top: 0; background: #f4f8f7; font-size: 12px; }

.method p, .qa p, .partners p { margin: 0 0 8px; }

.qa { border-top: 1px solid var(--line); padding: 8px 0; }

.qa summary { cursor: pointer; font-weight: 700; }

.qa p { margin: 8px 0 0; color: var(--ink); }

.partners { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.partner-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fbfa;
}

.partner-card strong { display: block; margin-bottom: 4px; }

.disclosure {
  background: #fff8ee;
  border: 1px solid #efd3a8;
  border-radius: 8px;
  padding: 8px 10px;
  color: #5c4018;
}

.site-footer {
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.missing { min-height: 240px; }

@media (min-width: 1100px) {
  .first-screen {
    height: calc(100vh - 48px);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .studio { height: 100%; }
  .pane, .results { height: 100%; }
}

@media (max-width: 1099px) {
  .topbar nav { display: none; }
  .studio, .partners, .break, .save, .compare-stats { grid-template-columns: 1fr; }
  .first-screen { height: auto; }
  .chart-wrap { height: 240px; flex: none; }
  h1 { font-size: 20px; }
  .site-footer { white-space: normal; height: auto; padding: 8px 16px; }
}
