/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #F7F8FB;
  --surface: #FFFFFF;
  --surface-2: #F1F3F9;
  --text: #12172B;
  --text-muted: #5B6479;
  --border: #E3E6EF;

  --accent: #1652F0;
  --accent-ink: #0B3ECC;
  --accent-soft: #E8EEFF;
  --accent-contrast: #FFFFFF;

  --positive: #0E9F5A;
  --positive-soft: #E7F7ED;
  --danger: #DC3545;

  --shadow-sm: 0 1px 2px rgba(18, 23, 43, 0.06);
  --shadow-md: 0 8px 24px rgba(18, 23, 43, 0.08);
  --shadow-lg: 0 20px 48px rgba(18, 23, 43, 0.14);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Sora", var(--sans);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --ease-soft: cubic-bezier(0.25, 0.46, 0.45, 0.94);

  --container: 1080px;
  --gutter: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0F1E;
    --surface: #131829;
    --surface-2: #1A2036;
    --text: #EDEFF7;
    --text-muted: #97A0BC;
    --border: #262D47;

    --accent: #6C93FF;
    --accent-ink: #8FACFF;
    --accent-soft: #1B2745;
    --accent-contrast: #0B0F1E;

    --positive: #3FD991;
    --positive-soft: #103322;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #0B0F1E;
  --surface: #131829;
  --surface-2: #1A2036;
  --text: #EDEFF7;
  --text-muted: #97A0BC;
  --border: #262D47;

  --accent: #6C93FF;
  --accent-ink: #8FACFF;
  --accent-soft: #1B2745;
  --accent-contrast: #0B0F1E;

  --positive: #3FD991;
  --positive-soft: #103322;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html {
  -webkit-text-size-adjust: 100%;
  tab-size: 2;
  color-scheme: light dark;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
  transition: background-color .25s var(--ease-out), color .25s var(--ease-out);
}
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
input, select { font: inherit; color: inherit; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.1; letter-spacing: -0.01em; font-family: var(--display); }
::selection { background: var(--accent-soft); color: var(--accent-ink); }

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

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* =============================================================
   3. Utilities
   ============================================================= */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--text); color: var(--bg);
  z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   4. Typography
   ============================================================= */
h1 { font-size: clamp(1.7rem, 3.4vw, 2.2rem); font-weight: 700; }
h2 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; }
code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: var(--surface-2);
  padding: .1em .4em;
  border-radius: 4px;
  font-size: .92em;
}

/* =============================================================
   5. Components
   ============================================================= */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .5rem;
  padding: .85rem 1.4rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .96rem;
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out), background-color .18s var(--ease-out);
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-ink); box-shadow: var(--shadow-md); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding-inline: .8rem;
}
.btn-ghost:hover { color: var(--text); }

/* Theme toggle */
.theme-toggle {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background-color .18s var(--ease-out), color .18s var(--ease-out);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Fields */
.field { display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: .84rem; font-weight: 600; color: var(--text-muted); }
.field-input {
  display: flex; align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding-inline: .9rem;
  transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
}
.field-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-input input, .field-input select {
  flex: 1;
  border: 0; background: transparent; outline: 0;
  padding-block: .72rem;
  font-size: 1rem;
  color: var(--text);
  min-width: 0;
}
.field-input select { cursor: pointer; }
.field-suffix { color: var(--text-muted); font-size: .88rem; font-weight: 500; white-space: nowrap; }

/* =============================================================
   6. Sections
   ============================================================= */

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(1px)) {
  .site-header { background: var(--bg); }
}
.site-header__inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: .85rem;
}
.logo {
  display: inline-flex; align-items: center; gap: .5rem;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.logo svg { color: var(--accent); }

/* Hero */
.hero {
  padding-block: 1.4rem .9rem;
  text-align: center;
}
.hero h1 { font-size: clamp(1.5rem, 5.5vw, 2.7rem); }
.hero-sub {
  margin-top: .5rem;
  color: var(--text-muted);
  font-size: .96rem;
  max-width: 46ch;
  margin-inline: auto;
}

/* Tool section */
.tool-section { padding-block: .25rem 1.5rem; }

.tool-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow-md);
}

.calc-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: .9rem;
}
.calc-form__submit { margin-top: .2rem; width: 100%; grid-column: 1 / -1; }

.tool-card__error {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  font-size: .92rem;
  font-weight: 600;
}

/* Result */
.result {
  margin-top: 1.6rem;
  padding-top: 1.6rem;
  border-top: 1px dashed var(--border);
}

.result-headline {
  display: flex; flex-direction: column; gap: .3rem;
  text-align: center;
  padding: 1.2rem 1rem 1.5rem;
}
.result-headline__label { color: var(--text-muted); font-size: .92rem; font-weight: 600; }
.result-headline__value {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.1rem, 6vw, 3rem);
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
  margin-bottom: 1.6rem;
}
.result-stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
}
.result-stat--accent { background: var(--positive-soft); }
.result-stat__label { color: var(--text-muted); font-size: .88rem; font-weight: 500; }
.result-stat__value { font-weight: 700; font-size: 1.05rem; }
.result-stat--accent .result-stat__value { color: var(--positive); }

/* Chart */
.chart-wrap { margin-bottom: 1.5rem; }
.chart-wrap canvas {
  width: 100%; height: auto;
  aspect-ratio: 900 / 360;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.chart-legend {
  display: flex; justify-content: center; gap: 1.4rem;
  margin-top: .7rem;
  font-size: .86rem;
  color: var(--text-muted);
}
.chart-legend__item { display: inline-flex; align-items: center; gap: .4rem; }
.chart-legend__dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chart-legend__dot--capital { background: var(--accent); }
.chart-legend__dot--interes { background: var(--positive); }

/* Result actions */
.result-actions {
  display: flex; flex-wrap: wrap; gap: .7rem;
  justify-content: center;
  margin-bottom: .3rem;
}

/* Table */
.table-wrap { margin-top: 1.3rem; overflow-x: auto; }
.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  min-width: 480px;
}
.calc-table th, .calc-table td {
  padding: .6rem .8rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.calc-table th:first-child, .calc-table td:first-child { text-align: left; }
.calc-table thead th {
  color: var(--text-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-weight: 700;
}
.calc-table tbody tr:hover { background: var(--surface-2); }

/* Privacy badge */
.privacy-badge {
  margin-top: 1.4rem;
  text-align: center;
  font-size: .84rem;
  color: var(--text-muted);
}

/* Ad slots */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: .8rem;
  letter-spacing: .08em;
  font-weight: 700;
}
.ad-slot__label { opacity: .55; }
.ad-slot--leaderboard { min-height: 90px; margin-block: 1.6rem; }
.ad-slot--incontent { min-height: 250px; margin-block: 2.2rem; }
.ad-slot--popup { min-height: 200px; margin-top: .3rem; }
.ad-slot--side { width: 160px; min-height: 280px; }

/* A slot with a real AdSense unit: drop the placeholder framing, let the
   <ins> size itself — flex-centering a fixed width can starve its layout. */
.ad-slot--live {
  display: block;
  border: none;
  background: none;
  padding: 0;
}

/* Content */
.content { padding-block: 1rem 3rem; }

.how-it-works { margin-bottom: 2.6rem; }
.steps {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.1rem;
  margin-top: 1.2rem;
}
.step {
  display: flex; gap: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem;
}
.step__num {
  flex-shrink: 0;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: .9rem;
}
.step h3 { margin-bottom: .25rem; }
.step p { color: var(--text-muted); font-size: .92rem; }

.seo-text { max-width: 72ch; margin-inline: auto; }
.seo-text h2 { margin-bottom: 1rem; }
.seo-text p { margin-bottom: 1.1rem; color: var(--text-muted); }
.seo-text p:last-child { margin-bottom: 0; }
.seo-text strong { color: var(--text); }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 1.6rem;
  color: var(--text-muted);
  font-size: .86rem;
}
.site-footer__inner {
  display: flex; flex-direction: column; gap: .8rem;
  align-items: center; text-align: center;
}
.footer-links { display: flex; gap: 1.2rem; }
.footer-links a:hover { color: var(--text); }

/* Ad dialog (download popup) */
.ad-dialog {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.4rem;
  max-width: min(92vw, 420px);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.ad-dialog::backdrop { background: rgba(10, 13, 26, 0.55); }
.ad-dialog__close {
  position: absolute; top: .7rem; right: .7rem;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text-muted);
}
.ad-dialog__close:hover { background: var(--surface-2); color: var(--text); }
.ad-dialog__cta { width: 100%; margin-top: 1rem; justify-content: center; }

/* Side ads — hug the calculator card itself (desktop only, §8 gates it) */
.side-ads {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 1.25rem;
  z-index: 5;
  flex-direction: column;
  gap: 1rem;
}

/* =============================================================
   7. Effects
   ============================================================= */

/* =============================================================
   8. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .calc-form { grid-template-columns: 1fr 1fr; gap: 1rem; }
  .calc-form__submit { width: auto; justify-self: center; padding-inline: 3rem; }
  .result-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 720px) {
  .tool-card { padding: 2.2rem; }
  .steps { grid-template-columns: repeat(3, 1fr); }
  .step { flex-direction: column; }
}

@media (min-width: 960px) {
  .hero { padding-block: 3.5rem 2rem; }
}

@media (min-width: 1600px) {
  .side-ads { display: flex; }
}

/* =============================================================
   9. Reduced motion (only intrusive effects)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* =============================================================
   10. Print
   ============================================================= */
@media print {
  .site-header, .site-footer, .ad-slot, .hero-sub, .privacy-badge,
  .result-actions, .how-it-works, .seo-text, .faq, .side-ads,
  .calc-form, .chart-wrap { display: none !important; }
  .table-wrap { display: block !important; }
}
