:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #f9f7f3;
  --text: #1d1b18;
  --muted: #6d675e;
  --border: #e5e0d6;
  --accent: #5a4fcf;
  --accent-soft: #ecebfb;
  --a: #5a4fcf;
  --b: #0e7c86;
  --capital: #6b9a78;
  --interest: #d9894a;
  --fee: #b85468;
  --good: #3c7a50;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #1f1e1c;
    --surface-2: #272623;
    --text: #ece9e3;
    --muted: #a39d93;
    --border: #35332f;
    --accent: #a99ff7;
    --accent-soft: #2c2948;
    --a: #a99ff7;
    --b: #5cc6cf;
    --capital: #82b590;
    --interest: #e8a46a;
    --fee: #d97a8d;
    --good: #8fd0a1;
    --danger: #f2b8b5;
    --danger-soft: #3a2220;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top, main, footer { max-width: 1120px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  padding-top: 28px;
}
h1 { margin: 0; font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.01em; }
.top p { margin: 4px 0 0; color: var(--muted); }

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.tabs button {
  border: 0;
  border-radius: 9px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

main { padding-top: 16px; padding-bottom: 16px; }

.layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .layout { grid-template-columns: 330px minmax(0, 1fr); align-items: start; }
  .inputs { position: sticky; top: 16px; }
}

.card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.results, .compare, .cmp-results { display: grid; gap: 16px; min-width: 0; align-content: start; }
.stale { opacity: 0.45; transition: opacity 0.15s; }

h2 { margin: 0 0 12px; font-size: 1rem; }
.label, label, legend { font-size: 0.875rem; font-weight: 600; }
.label { margin: 0; color: var(--muted); }
.hint { font-weight: 400; color: var(--muted); }
.note { margin: 4px 0 0; color: var(--muted); font-size: 0.875rem; }
.card > .note { margin: -6px 0 12px; }

/* Form fields */
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.input-unit, .text {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: inherit;
  font: inherit;
}
.input-unit { display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.input-unit:focus-within, .text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.input-unit input {
  flex: 1;
  width: 0;
  min-width: 0;
  padding: 9px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
}
.input-unit span { color: var(--muted); }
.input-unit:has(input:invalid) { border-color: var(--danger); }
.text { width: 100%; padding: 9px 12px; }
input[type="range"] { width: 100%; margin: 2px 0 0; accent-color: var(--accent); }

.segmented { margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented legend { margin-bottom: 6px; padding: 0; }
.options, .toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.options label, .toggle label { position: relative; }
.options input, .toggle input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.options span, .toggle span { display: block; border-radius: 7px; padding: 7px; text-align: center; color: var(--muted); }
.options small { display: block; font-size: 0.75rem; font-weight: 400; }
.options input:checked + span, .toggle input:checked + span { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.options input:focus-visible + span, .toggle input:focus-visible + span { outline: 2px solid var(--accent); }
.toggle { padding: 2px; border-radius: 8px; gap: 2px; }
.toggle span { padding: 1px 10px; border-radius: 6px; font-size: 0.75rem; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Results */
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.big {
  margin: 2px 0 0;
  font-size: clamp(2.25rem, 7vw, 3.25rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.rates { text-align: right; }
.tae { margin: 2px 0 0; color: var(--accent); font-size: 1.75rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 16px; }
.stat b { display: block; margin-top: 2px; font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.bar { display: flex; gap: 2px; height: 14px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.bar span { display: block; min-width: 0; flex-basis: 0; }
.capital { background: var(--capital); }
.interest { background: var(--interest); }
.fee { background: var(--fee); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.875rem;
}
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; }
.legend b { margin-left: 6px; color: var(--text); font-variant-numeric: tabular-nums; }

.dot { display: inline-block; flex: none; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; vertical-align: 0; }
.dot.a { background: var(--a); }
.dot.b { background: var(--b); }

/* Tables */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
tbody tr:last-child > * { border-bottom: 0; }
tr.strong > * { font-weight: 700; }
td.better { color: var(--good); font-weight: 700; }
td.better::before { content: "✓ "; }

.minibar { display: flex; gap: 1px; width: 90px; height: 8px; margin-left: auto; overflow: hidden; border-radius: 999px; }
.minibar span { display: block; flex-basis: 0; }

.rows { max-height: 420px; overflow: auto; }
.rows thead th { position: sticky; top: 0; background: var(--surface); }
details summary { font-weight: 600; cursor: pointer; }
details[open] summary { margin-bottom: 12px; }


.error {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}

/* Compare */
.cmp-amount { max-width: 320px; }
.offers { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .offers { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.offer { min-width: 0; margin: 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; }
.offer legend { padding: 0 6px; font-size: 1rem; font-weight: 700; }
.verdict-title { margin: 4px 0 6px; font-size: clamp(1.25rem, 4vw, 1.625rem); font-weight: 700; line-height: 1.3; }
.versus th:not(:first-child) { white-space: nowrap; }
.versus tbody th { color: var(--muted); font-weight: 600; text-align: left; }
.bar-row + .bar-row { margin-top: 14px; }
.bar-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.bar-head span { display: flex; align-items: center; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 600px) {
  .card { padding: 16px; }
  .offer { padding: 12px; }
  .rates { text-align: left; }
  .versus { font-size: 0.8125rem; }
  .versus tbody th { white-space: normal; }
  .versus .diff { display: none; }
}

footer { padding-bottom: 40px; color: var(--muted); font-size: 0.8125rem; }
footer p { margin: 0; max-width: 75ch; }
