:root {
  --accent: #4338ca;
  --accent-dark: #3730a3;
  --accent-soft: #eef2ff;
  --text: #111827;
  --muted: #4b5563;
  --border: #d1d5db;
  --bg: #ffffff;
  --bg-soft: #f9fafb;
  --error: #b91c1c;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}

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

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip-link { position: absolute; left: 0.5rem; top: -3rem; background: var(--accent); color: #fff; padding: 0.5rem 0.75rem; border-radius: 6px; z-index: 10; }
.skip-link:focus { top: 0.5rem; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.intro, main, .site-footer { max-width: 1000px; margin: 0 auto; padding: 0 1rem; }
.intro { padding-top: 1.5rem; padding-bottom: 0.5rem; }
.intro h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 0.5rem; }
.intro p { color: var(--muted); margin: 0; max-width: 65ch; }

/* Tool layout: stacked on mobile, side by side on wide screens. */
.tool { display: grid; gap: 1.25rem; margin: 1.25rem 0 2.5rem; }
@media (min-width: 860px) {
  .tool { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
}

.tool-form { display: grid; gap: 1rem; }
.example-note { margin: 0; padding: 0.6rem 0.8rem; background: var(--accent-soft); border-radius: var(--radius); font-size: 0.95rem; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem 1rem; margin: 0; min-width: 0; }
legend { font-weight: 650; padding: 0 0.3rem; }
.radio-group { border: 0; padding: 0; margin-top: 0.75rem; }
.radio-group legend { padding: 0; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.95rem; }
.radio-group label { display: flex; gap: 0.5rem; align-items: center; padding: 0.3rem 0; cursor: pointer; }
.radio-group input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); margin: 0; }
.radio-group label:has(input:disabled) { color: var(--muted); cursor: not-allowed; }

.grid { display: grid; gap: 0.75rem 1rem; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field label { font-weight: 550; font-size: 0.95rem; }
input[type="number"], select {
  font: inherit; color: var(--text); background: #fff; width: 100%;
  border: 1px solid #9ca3af; border-radius: 8px; padding: 0.5rem 0.6rem; min-height: 2.6rem;
}
input[aria-invalid="true"] { border-color: var(--error); border-width: 2px; }
.hint { margin: 0; color: var(--muted); font-size: 0.85rem; }
.error { margin: 0; color: var(--error); font-size: 0.85rem; font-weight: 600; }
.error:empty { display: none; }
.note { margin: 0.4rem 0 0; font-size: 0.85rem; color: var(--muted); background: var(--bg-soft); border-left: 3px solid var(--accent); padding: 0.4rem 0.6rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.button {
  font: inherit; font-weight: 600; border-radius: 8px; padding: 0.55rem 0.9rem; cursor: pointer; min-height: 2.6rem;
  border: 2px solid var(--accent); background: var(--accent); color: #fff;
}
.button.secondary { background: #fff; color: var(--accent); }
.button:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }

/* Results panel */
.results { border: 2px solid var(--accent); border-radius: var(--radius); padding: 1rem; background: #fff; }
.results h2 { margin: 0 0 0.5rem; font-size: 1.3rem; }
.results h3 { font-size: 1rem; margin: 1.25rem 0 0.4rem; }
.summary { margin: 0 0 1rem; font-weight: 550; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.stat { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem; }
.stat.accent { background: var(--accent-soft); border-color: var(--accent); }
.stat-label { margin: 0; font-size: 0.85rem; color: var(--muted); }
.stat-value { margin: 0.1rem 0 0; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.35rem 0.4rem; border-bottom: 1px solid #e5e7eb; vertical-align: middle; }
thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.breakdown td:nth-child(2), .breakdown td:nth-child(3) { text-align: right; white-space: nowrap; }
.breakdown thead th:nth-child(2), .breakdown thead th:nth-child(3) { text-align: right; }
.breakdown tbody th { font-weight: 500; }
.breakdown tfoot th, .breakdown tfoot td { font-weight: 700; border-bottom: 0; }
.breakdown td:last-child { width: 30%; }
.bar { display: block; height: 0.6rem; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
@media (max-width: 380px) { .breakdown td:last-child, .breakdown th:last-child { display: none; } }

.outcome { margin: 0; display: grid; gap: 0.1rem; }
.outcome div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.3rem 0; border-bottom: 1px solid #e5e7eb; }
.outcome dt { margin: 0; }
.outcome dd { margin: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.outcome .fee dt, .outcome .fee dd { color: var(--muted); }
.outcome .strong { font-weight: 700; }
.outcome .negative dd { color: var(--error); }

/* Guide content */
.guide { max-width: 70ch; margin-bottom: 2rem; }
.guide h2 { font-size: 1.35rem; margin: 2rem 0 0.5rem; }
.guide h3 { font-size: 1.05rem; margin: 1.25rem 0 0.3rem; }
.guide p, .guide li, .guide dd { color: #1f2937; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; overflow-x: auto; }
.definitions dt { font-weight: 650; margin-top: 0.75rem; }
.definitions dd { margin: 0.15rem 0 0; }
.example-table { margin: 0.75rem 0; font-size: 0.95rem; }
.example-table caption { text-align: left; font-weight: 650; padding-bottom: 0.3rem; }
.example-table td:last-child { text-align: right; white-space: nowrap; }
.example-table tfoot th, .example-table tfoot td { font-weight: 700; }

.site-footer { border-top: 1px solid var(--border); padding-top: 1rem; padding-bottom: 2rem; color: var(--muted); font-size: 0.9rem; }
.site-footer p { margin: 0.25rem 0; }

.print-only { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .skip-link, .intro, .tool-form, .guide, .site-footer, noscript { display: none !important; }
  .tool { display: block; margin: 0; }
  .results { border: 0; padding: 0; }
  .print-only { display: block; color: #000; }
  .results h2 { font-size: 1.4rem; }
  .bar { border: 1px solid #000; background: #fff; }
  .bar > span { background: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stat, .stat.accent { background: #fff; border-color: #000; }
  a { color: #000; }
}
