:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #f0f4f3;
  --border: #dfe7e5;
  --text: #13201e;
  --muted: #5c6e6b;
  --accent: #0f766e;
  --accent-soft: #d5efec;
  --principal: #0f766e;
  --interest: #f59e0b;
  --track: #e6ecea;
  --shadow: 0 1px 2px rgba(16, 24, 23, .04), 0 8px 24px rgba(16, 24, 23, .06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1312;
    --surface: #131d1c;
    --surface-2: #1a2726;
    --border: #253533;
    --text: #e6efed;
    --muted: #93a6a2;
    --accent: #2dd4bf;
    --accent-soft: #123a36;
    --principal: #2dd4bf;
    --interest: #fbbf24;
    --track: #22302e;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0c1312;
  --surface: #131d1c;
  --surface-2: #1a2726;
  --border: #253533;
  --text: #e6efed;
  --muted: #93a6a2;
  --accent: #2dd4bf;
  --accent-soft: #123a36;
  --principal: #2dd4bf;
  --interest: #fbbf24;
  --track: #22302e;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
}

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

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

.muted { color: var(--muted); font-weight: 400; }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 700;
}
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* Intro */
.intro { padding: 32px 0 20px; }
.intro h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  letter-spacing: -0.02em;
}
.intro p { margin: 0; color: var(--muted); max-width: 640px; }

/* Layout */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  min-width: 0;
}
.grid .card { margin-bottom: 0; }
.grid { margin-bottom: 20px; }
.card-title {
  margin: 0 0 18px;
  font-size: 1.1rem;
  font-weight: 600;
}
@media (max-width: 480px) {
  .card { padding: 18px; }
}

/* Method switch */
.method-switch, .seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.method-btn, .seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.method-btn.active, .seg-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.method-hint {
  color: var(--muted);
  font-size: .9rem;
  margin: 10px 0 22px;
  min-height: 2.7em;
}

/* Fields */
.field { margin-bottom: 26px; }
.field:last-child { margin-bottom: 0; }
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.field-head label { font-weight: 500; }

.input-affix {
  display: flex;
  align-items: stretch;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  overflow: hidden;
}
.input-affix:focus-within { border-color: var(--accent); }
.input-affix input,
.input-affix select {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  padding: 8px 10px;
  outline: none;
}
.input-affix input {
  width: 130px;
  text-align: right;
  -moz-appearance: textfield;
}
#rate { width: 80px; }
#tenure { width: 64px; }
.input-affix input::-webkit-outer-spin-button,
.input-affix input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-affix select { cursor: pointer; padding-right: 4px; }
.input-affix select option { color: var(--text); background: var(--surface); }
.affix {
  display: grid;
  place-items: center;
  padding: 0 12px 0 0;
  color: var(--accent);
  font-weight: 700;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--fill, 50%), var(--track) var(--fill, 50%), var(--track) 100%);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
}
input[type="range"]:focus-visible { box-shadow: 0 0 0 4px var(--accent-soft); }

/* Results */
.emi-big {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.emi-value {
  font-size: clamp(2rem, 6vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.emi-unit { color: var(--muted); }

.chart-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.pie-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  flex: none;
  margin: 0 auto;
}
#pie { width: 100%; height: 100%; transform: rotate(-90deg); }
#pie circle { fill: none; stroke-width: 34; }
.pie-track { stroke: var(--track); }
.pie-principal { stroke: var(--principal); transition: stroke-dasharray .4s ease, stroke-dashoffset .4s ease; }
.pie-interest { stroke: var(--interest); transition: stroke-dasharray .4s ease, stroke-dashoffset .4s ease; }
.pie-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.pie-pct { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pie-label { font-size: .8rem; color: var(--muted); }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 200px;
}
.legend li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.legend li:last-child { border-bottom: 0; }
.legend-total .legend-value { font-size: 1.15rem; }
.legend-label { display: block; font-size: .85rem; color: var(--muted); }
.legend-value { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { width: 12px; height: 12px; border-radius: 4px; margin-top: 5px; flex: none; }
.dot-principal { background: var(--principal); }
.dot-interest { background: var(--interest); }
.dot-none { background: transparent; }

/* Tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: .95rem;
}
th, td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
thead th {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}
tbody tr:last-child td { border-bottom: 0; }
.compare-table td:first-child { color: var(--muted); }
.compare-table .active-col { color: var(--accent); font-weight: 700; }
.diff-bad { color: #dc2626; font-weight: 600; }
:root[data-theme="dark"] .diff-bad { color: #f87171; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .diff-bad { color: #f87171; } }

.note {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: .92rem;
}
.note:empty { display: none; }

.schedule-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.schedule-head .card-title { margin: 0; }
.seg { min-width: 200px; }
.seg-btn { padding: 6px 12px; font-size: .9rem; }
.schedule-table tbody { }
.schedule .table-scroll { max-height: 480px; overflow-y: auto; }
.schedule thead th { position: sticky; top: 0; z-index: 1; }

/* FAQ */
.faq details {
  border-top: 1px solid var(--border);
  padding: 14px 0;
}
.faq details:first-of-type { border-top: 0; padding-top: 0; }
.faq summary { font-weight: 600; cursor: pointer; }
.faq p { margin: 10px 0 0; }
.formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: .9rem;
}

/* Footer */
.site-footer {
  padding: 24px 0 40px;
  font-size: .85rem;
  color: var(--muted);
}
.site-footer p { margin: 4px 0; }
