/* =============================================================
   Rent vs Buy — editorial / analytical aesthetic
   Refined, restrained, numbers-first. Not a flashy SaaS form.
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --ink:           #1a1a1a;
  --ink-soft:      #4a4a4a;
  --ink-mute:      #888;
  --paper:         #f6f3ec;
  --paper-card:    #fbfaf6;
  --rule:          #d8d2c4;
  --rule-soft:     #ebe6da;

  --accent:        #b85c38;        /* warm terracotta */
  --rent-color:    #2a6a5e;        /* deep teal */
  --buy-color:     #b85c38;        /* terracotta */
  --good:          #2a6a5e;
  --bad:           #a83838;

  --font-display:  'Fraunces', Georgia, serif;
  --font-body:     'Inter', -apple-system, sans-serif;
  --font-mono:     'JetBrains Mono', ui-monospace, monospace;

  --max-w:         1100px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ----- header ----- */
.site-header {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 4rem 1.5rem 2rem;
  border-bottom: 1px solid var(--rule);
}
.site-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.5rem, 6vw, 4rem);
  letter-spacing: -0.025em;
  line-height: 1;
  margin: 0 0 0.5rem;
  font-variation-settings: 'opsz' 144;
}
.site-header h1::after {
  content: '.';
  color: var(--accent);
}
.site-header .subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

/* ----- main layout ----- */
main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ----- form sections ----- */
.form-section {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.75rem 1.75rem 1.5rem;
  margin-bottom: 1.25rem;
}
.form-section h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.35rem;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule-soft);
  color: var(--ink);
}

.grid {
  display: grid;
  gap: 1rem 1.5rem;
}
.grid.two   { grid-template-columns: repeat(2, 1fr); }
.grid.three { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 640px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
  gap: 0.35rem;
}
label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--ink);
  padding-top: 1.25rem;
}
label.checkbox input { width: auto; }
.lbl-text { display: inline; }
.curr { display: inline; }

input[type="number"], select {
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 0.55rem 0.7rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 1px;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}
input[type="number"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
input[type="number"].error, select.error {
  border-color: var(--bad);
  background: #fdf1f1;
}
select {
  font-family: var(--font-body);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.hint {
  font-size: 0.75rem;
  color: var(--ink-mute);
  font-style: italic;
}

/* ----- actions ----- */
.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}
button {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.75rem 1.75rem;
  border-radius: 1px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, color 0.15s;
  letter-spacing: 0.02em;
}
button.primary {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
}
button.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}
button.primary:active { transform: translateY(1px); }
button.secondary {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
}
button.secondary:hover { color: var(--ink); border-color: var(--ink-soft); }

.errors {
  background: #fdf1f1;
  border: 1px solid #e0b8b8;
  color: var(--bad);
  padding: 0.85rem 1rem;
  border-radius: 1px;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}
.errors ul { margin: 0.25rem 0 0; padding-left: 1.25rem; }

/* =============================================================
   RESULTS
   ============================================================= */
#results {
  margin-top: 3.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--rule);
}

.verdict {
  text-align: center;
  margin-bottom: 3rem;
  padding: 2rem 1rem;
}
.verdict .label {
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 0.75rem;
}
.verdict .headline {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 1rem;
  font-variation-settings: 'opsz' 96;
}
.verdict .headline .winner { color: var(--accent); }
.verdict .headline .amount {
  font-family: var(--font-mono);
  font-weight: 600;
  font-feature-settings: 'tnum';
}
.verdict .sub {
  color: var(--ink-soft);
  font-size: 0.95rem;
}
.verdict .sub .num {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  color: var(--ink);
}

/* ----- side-by-side breakdown ----- */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 3rem;
}
@media (max-width: 720px) {
  .results-grid { grid-template-columns: 1fr; }
}

.breakdown {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.5rem 1.75rem;
  position: relative;
}
.breakdown.rent-card { border-top: 3px solid var(--rent-color); }
.breakdown.buy-card  { border-top: 3px solid var(--buy-color); }

.breakdown h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.4rem;
  margin: 0 0 1.25rem;
  letter-spacing: -0.01em;
}
.rent-card h3 { color: var(--rent-color); }
.buy-card  h3 { color: var(--buy-color); }

.b-section {
  margin-bottom: 1rem;
}
.b-section-label {
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.b-section-label.earned::before { content: '+'; color: var(--good); font-weight: 600; }
.b-section-label.spent::before  { content: '−'; color: var(--bad); font-weight: 600; }

.b-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px dotted var(--rule-soft);
  font-size: 0.92rem;
}
.b-row:last-child { border-bottom: none; }
.b-row .lbl { color: var(--ink-soft); }
.b-row .val {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  font-size: 0.95rem;
  color: var(--ink);
}
.b-row .sign {
  font-weight: 600;
  margin-right: 0.2rem;
  opacity: 0.85;
}
.b-row .sign.earned { color: var(--good); }
.b-row .sign.spent  { color: var(--bad); }
.b-row.subtotal {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
  border-bottom: none;
  font-weight: 500;
}
.b-row.subtotal .lbl { color: var(--ink); }

.b-net {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.b-net .lbl {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
}
.b-net .val {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 600;
  font-feature-settings: 'tnum';
}
.b-net.positive .val { color: var(--good); }
.b-net.negative .val { color: var(--bad); }

/* ----- chart ----- */
.chart-section {
  margin-bottom: 3rem;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  padding: 1.75rem;
  border-radius: 2px;
}
.chart-section h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}
.chart-help {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin: 0 0 1.25rem;
}
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
  margin: 0 0.25rem 0 0.5rem;
}
.legend-dot.rent { background: var(--rent-color); }
.legend-dot.buy  { background: var(--buy-color); }

.chart-more {
  margin: 0 0 1.25rem;
}
.chart-more summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  user-select: none;
}
.chart-more summary::-webkit-details-marker { display: none; }
.chart-more summary::before {
  content: "\25B8";              /* right-pointing triangle */
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}
.chart-more[open] summary::before { transform: rotate(90deg); }
.chart-more summary:hover { text-decoration: underline; }
.chart-more-body {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule-soft);
  color: var(--ink-soft);
  font-size: 0.88rem;
}
.chart-more-body h4 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.02rem;
  color: var(--ink);
  margin: 1.4rem 0 0.45rem;
  letter-spacing: -0.01em;
}
.chart-more-body h4:first-child { margin-top: 0; }
.chart-more-body p { margin: 0 0 0.7rem; line-height: 1.6; }
.chart-more-body ul { margin: 0 0 0.7rem; padding-left: 1.15rem; }
.chart-more-body li { margin-bottom: 0.35rem; line-height: 1.55; }
.chart-more-body strong { color: var(--ink); }
.chart-example {
  background: var(--paper);
  border-left: 3px solid var(--accent);
  border-radius: 2px;
  padding: 0.9rem 1.1rem;
  margin: 0.6rem 0 0.9rem;
}
.chart-example .chart-example-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  display: block;
  margin-bottom: 0.5rem;
}
.chart-example p:last-child { margin-bottom: 0; }
.chart-fineprint {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0.4rem 0 0;
}

#wealth-chart, #waste-chart {
  width: 100%;
  height: auto;
  max-height: 460px;
  display: block;
}

@media (max-width: 640px) {
  #wealth-chart, #waste-chart {
    height: 260px;
  }
}

/* ----- sensitivity table ----- */
.sensitivity-section {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  padding: 1.75rem;
  border-radius: 2px;
}
.sensitivity-section h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}

.sensitivity-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.sensitivity {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 1.05rem;
  margin-top: 0.5rem;
}
table.sensitivity th, table.sensitivity td {
  padding: 0.85rem 0.9rem;
  text-align: right;
  border: 1px solid var(--rule-soft);
}
table.sensitivity th {
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  background: var(--paper);
}
table.sensitivity td {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  color: var(--ink);
  font-size: 1.05rem;
}
table.sensitivity td.row-label {
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  font-feature-settings: normal;
  font-weight: 500;
}

@media (max-width: 640px) {
  .sensitivity-section {
    padding: 1.25rem 1rem;
  }
  table.sensitivity th, table.sensitivity td {
    padding: 0.55rem 0.6rem;
    font-size: 0.82rem;
  }
  table.sensitivity td {
    font-size: 0.82rem;
  }
  table.sensitivity td.row-label {
    font-size: 0.82rem;
  }
}

/* ----- footer ----- */
.site-footer {
  max-width: var(--max-w);
  margin: 2rem auto 0;
  padding: 2rem 1.5rem 3rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-mute);
  font-size: 0.8rem;
  font-style: italic;
}

