/* FinMath — shared stylesheet
   Dark navy + mint accent. Mobile-first. Dark mode default.
*/

:root {
  --bg: #0b1726;
  --bg-elev: #13243a;
  --bg-elev-2: #1a2f4d;
  --border: #24395a;
  --text: #e6edf6;
  --text-dim: #9db0c9;
  --text-faint: #6a7e98;
  --accent: #5eead4;
  --accent-strong: #2dd4bf;
  --accent-ink: #042f2e;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 4px 16px rgba(0,0,0,.35);
  --maxw: 1120px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

[data-theme="light"] {
  --bg: #f6f8fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f4fa;
  --border: #dbe4ef;
  --text: #0b1726;
  --text-dim: #3d4e66;
  --text-faint: #7587a0;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-ink: #ffffff;
  --shadow-1: 0 1px 2px rgba(15, 30, 50, .07);
  --shadow-2: 0 4px 16px rgba(15, 30, 50, .1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.75rem, 4vw, 2.4rem); }
h2 { font-size: clamp(1.35rem, 3vw, 1.75rem); }
h3 { font-size: 1.15rem; }

p { margin: 0 0 1em; color: var(--text-dim); }

code, pre, .mono { font-family: var(--mono); }

/* --- Layout --- */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 23, 38, 0.85);
  backdrop-filter: saturate(1.3) blur(8px);
  -webkit-backdrop-filter: saturate(1.3) blur(8px);
  border-bottom: 1px solid var(--border);
}
[data-theme="light"] .site-header { background: rgba(255,255,255,0.85); }

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 0.85rem;
}

.nav-links { display: flex; gap: 18px; align-items: center; }
.nav-links a { color: var(--text-dim); font-size: .95rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* --- Hero & cards --- */
.hero {
  padding: 48px 0 32px;
  text-align: center;
}
.hero h1 { margin-bottom: .3em; }
.hero .tagline {
  color: var(--text-dim);
  font-size: clamp(1rem, 2vw, 1.15rem);
  max-width: 620px;
  margin: 0 auto 24px;
}

.tool-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  margin: 24px 0 48px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: block;
  color: var(--text);
  transition: border-color .15s, transform .15s;
}
.card:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
  transform: translateY(-1px);
}
.card .card-title {
  font-weight: 600;
  margin: 0 0 6px;
  display: flex; align-items: center; gap: 8px;
}
.card .card-desc { color: var(--text-dim); font-size: .92rem; margin: 0; }
.card .tag {
  display: inline-block;
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-faint);
  margin-left: auto;
}
.card .tag.new { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.card .tag.soon { background: var(--bg-elev-2); color: var(--text-faint); }

.section-heading {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 32px 0 12px;
}
.section-heading h2 { margin: 0; }
.section-heading .muted { color: var(--text-faint); font-size: .9rem; }

/* --- Form & calculator --- */
.calc-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin: 24px 0;
}
@media (min-width: 860px) {
  .calc-wrap.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h3 { margin-top: 0; }

.field {
  display: block;
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: .85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}
.field .help {
  font-size: .75rem;
  color: var(--text-faint);
  margin-top: 4px;
}

.input, .select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.input[inputmode="decimal"] { font-family: var(--mono); }

.input-group {
  display: flex;
  align-items: stretch;
}
.input-group .prefix, .input-group .suffix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: .9rem;
}
.input-group .prefix { border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .suffix { border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group .prefix + .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group .input:not(:last-child) { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .row-2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: var(--accent-ink);
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.05); text-decoration: none; }
.btn-ghost { background: transparent; }

/* --- Results --- */
.result-hero {
  text-align: center;
  padding: 8px 0 16px;
}
.result-hero .label {
  font-size: .85rem;
  color: var(--text-dim);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.result-hero .value {
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  letter-spacing: -0.02em;
  margin: 4px 0;
}
.result-hero .unit { font-size: .9rem; color: var(--text-faint); }

.result-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 16px 0;
}
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-width: 0;
  overflow: hidden;
}
.stat .stat-label { font-size: .75rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  margin-top: 2px;
  font-size: clamp(0.82rem, 2.6vw, 1rem);
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* --- Table (amortization) --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
}
table.amort {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: .88rem;
}
.amort th, .amort td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.amort th:first-child, .amort td:first-child { text-align: left; }
.amort thead th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 600;
  position: sticky; top: 0;
}
.amort tr.year-boundary td { border-top: 2px solid var(--border); }

/* --- Ad slot --- */
.ad-slot {
  display: block;
  margin: 24px auto;
  min-height: 90px;
  max-width: 728px;
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  color: var(--text-faint);
  font-size: .8rem;
  padding: 8px;
  overflow: hidden;
}
.ad-slot::before {
  content: "Advertisement";
  display: block;
  opacity: .6;
  margin-bottom: 4px;
}

/* --- Article (SEO content) --- */
.article {
  max-width: 760px;
  margin: 32px auto;
}
.article h2 { margin-top: 2em; }
.article p, .article li { color: var(--text-dim); }
.article ul, .article ol { padding-left: 1.4em; }
.article code {
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .9em;
}

/* --- Footer --- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0 40px;
  color: var(--text-faint);
  font-size: .9rem;
  margin-top: 48px;
}
.site-footer .footer-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .site-footer .footer-grid { grid-template-columns: 2fr 1fr 1fr; }
}
.site-footer a { color: var(--text-dim); }
.site-footer a:hover { color: var(--text); }
.site-footer h4 { color: var(--text); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 8px; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: 4px; }
.site-footer .copyright { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 12px; }

/* --- Utility --- */
.text-muted { color: var(--text-dim); }
.text-faint { color: var(--text-faint); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 12px; }
.mt-4 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.flex-gap { display: flex; gap: 10px; flex-wrap: wrap; }

/* Print */
@media print {
  .site-header, .site-footer, .ad-slot, .no-print { display: none !important; }
  body { background: white; color: black; }
  .panel { border-color: #ccc; background: white; }
}
