/* ==================== CSS CUSTOM PROPERTIES ==================== */
:root {
  --color-primary: #8b1e3f;
  --color-primary-dark: #6b142f;
  --color-primary-tint: #f5dde2;
  --color-success: #2f7d4f;
  --color-accent: #b5651d;
  --color-accent-tint: #f7e2cc;
  --color-ink: #1b1712;
  --color-text: #1b1712;
  --color-text-muted: #6b5f52;
  --color-bg: #fbf0de;
  --color-surface: #fffdf8;
  --color-border: #decdb2;
  --color-border-focus: #8b1e3f;
  --color-contributions: #3b5b7a;
  --color-interest: #2f7d4f;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  --font-serif: Georgia, 'Times New Roman', Times, serif;

  --radius: 0;
  --border-width: 1px;

  --nav-height: 60px;
  --tab-bar-height: 64px;
  --max-width: 1140px;
  --page-pad: clamp(16px, 4vw, 32px);
}

/* ==================== RESET ==================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--tab-bar-height);
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul,
ol {
  list-style: none;
}

button {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ==================== TYPOGRAPHY ==================== */
h1,
h2,
h3,
h4,
.nav-brand,
.footer-brand {
  font-family: var(--font-serif);
  font-weight: 800;
  color: var(--color-ink);
  letter-spacing: -0.02em;
}

h1,
h2,
h3,
h4 {
  line-height: 1.2;
}

h1 {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
}

h2 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
}

h3 {
  font-size: 1.125rem;
}

p {
  line-height: 1.7;
}

/* ==================== LAYOUT ==================== */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--page-pad);
}

main {
  flex: 1;
}

/* ==================== TOP NAV ==================== */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--color-surface);
  border-bottom: var(--border-width) solid var(--color-border);
}

.nav-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-brand {
  font-size: 1.1875rem;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-brand:hover {
  text-decoration: none;
}

.nav-links {
  display: none;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-link {
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-ink);
  text-decoration: none;
}

.nav-lang {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 3px;
  flex-shrink: 0;
  margin-left: auto;
}

.lang-current,
.lang-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 28px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.lang-current {
  background: var(--color-primary);
  color: #fff;
}

.lang-switch {
  color: var(--color-text-muted);
  text-decoration: none;
}

.lang-switch:hover {
  background: var(--color-surface);
  color: var(--color-primary);
  text-decoration: none;
}

/* ==================== MOBILE BOTTOM TAB BAR ==================== */
.tab-bar {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  height: var(--tab-bar-height);
  background: var(--color-surface);
  border-top: var(--border-width) solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-muted);
  text-decoration: none;
}

.tab-bar-item:hover {
  text-decoration: none;
  color: var(--color-text-muted);
}

.tab-bar-icon {
  width: 22px;
  height: 22px;
}

.tab-bar-label {
  font-size: 0.6875rem;
  font-weight: 600;
}

.page-home .tab-home,
.page-tools-list .tab-tools,
.page-calculator .tab-tools {
  color: var(--color-primary);
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.12s, transform 0.08s;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

/* ==================== SEGMENTED CONTROL ==================== */
.segmented {
  display: flex;
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.segmented-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.segmented-btn:hover {
  color: var(--color-ink);
}

.segmented-btn[aria-pressed='true'] {
  background: var(--color-primary);
  color: #fff;
}

.segmented-btn[aria-pressed='true']:hover {
  color: #fff;
}

/* ==================== HERO ==================== */
.hero {
  background: var(--color-primary-tint);
  padding: clamp(40px, 8vw, 96px) 0;
  text-align: center;
}

.hero-inner {
  max-width: 720px;
}

.hero-heading {
  font-size: clamp(2rem, 6vw, 3.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-ink);
  margin-bottom: 16px;
}

.hero-subtitle {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--color-text-muted);
  max-width: 540px;
  margin-inline: auto;
  margin-bottom: 32px;
}

/* ==================== SECTIONS ==================== */
.section-heading {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--color-ink);
}

.featured-section {
  padding: 48px 0 64px;
}

/* ==================== PAGE HEADER ==================== */
.page-header {
  padding: 32px 0 24px;
  border-bottom: var(--border-width) solid var(--color-border);
  margin-bottom: 32px;
}

.page-header h1 {
  margin-bottom: 8px;
}

.page-header .subtitle,
.subtitle {
  font-size: 1.0625rem;
  color: var(--color-text-muted);
  max-width: 640px;
}

/* ==================== BREADCRUMBS ==================== */
.breadcrumbs {
  padding: 16px 0 0;
}

.breadcrumb-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.breadcrumb-item a {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
}

.breadcrumb-item a:hover {
  color: var(--color-primary);
}

.breadcrumb-sep {
  color: var(--color-border);
  font-size: 0.875rem;
  user-select: none;
}

.breadcrumb-current {
  display: none;
  font-size: 0.875rem;
  color: var(--color-text);
  font-weight: 600;
}

/* ==================== TOOL CARDS ==================== */
.tools-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.tools-grid-full {
  max-width: 640px;
}

.card {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
}

.tool-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-card-large {
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 24px;
}

.tool-card-icon {
  width: 52px;
  height: 52px;
  background: var(--color-primary-tint);
  color: var(--color-primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tool-card-large .tool-card-icon {
  width: 56px;
  height: 56px;
}

.tool-card-body {
  flex: 1;
}

.tool-card-name {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--color-ink);
  margin-bottom: 4px;
}

.tool-card-large .tool-card-name {
  font-size: 1.25rem;
}

.tool-card-desc {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.tool-card-link {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
}

.tool-card-link:hover {
  text-decoration: underline;
}

.tool-card-cta {
  flex-shrink: 0;
  align-self: stretch;
  justify-content: center;
}

/* ==================== CALCULATOR LAYOUT ==================== */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 40px;
}

/* ==================== FORM ==================== */
.calculator-form {
  padding: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-ink);
}

.form-input {
  height: 50px;
  padding: 0 14px;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.12s;
  -moz-appearance: textfield;
  appearance: textfield;
}

.form-input::-webkit-outer-spin-button,
.form-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-border-focus);
}

.form-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

/* ==================== RESULTS CARD ==================== */
.calculator-results {
  padding: 20px;
}

.calculator-results h2 {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.result-main {
  background: var(--color-primary);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  color: #fff;
}

.result-label {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 6px;
}

.result-value {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.result-sub {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-top: 8px;
  line-height: 1.5;
}

.result-breakdown {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--color-bg);
  border-radius: var(--radius);
}

.result-item-label {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.result-item-value {
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-item-value.contributions {
  color: var(--color-contributions);
}

.result-item-value.interest {
  color: var(--color-interest);
}

/* ==================== CONTRIBUTION BAR ==================== */
.contribution-bar-wrapper {
  margin-top: 4px;
}

.contribution-bar {
  height: 10px;
  background: var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  margin-bottom: 10px;
}

.bar-contributions {
  background: var(--color-contributions);
  height: 100%;
  transition: width 0.3s ease;
}

.bar-interest {
  background: var(--color-interest);
  height: 100%;
  transition: width 0.3s ease;
}

.bar-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.legend-dot.contributions {
  background: var(--color-contributions);
}

.legend-dot.interest {
  background: var(--color-interest);
}

.legend-dot.balance {
  background: var(--color-primary);
}

.legend-dot.required {
  background: var(--color-accent);
}

/* ==================== CHART ==================== */
.chart-section {
  margin-bottom: 40px;
}

.chart-section h2 {
  margin-bottom: 16px;
}

.chart-wrapper {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  padding: 16px 8px 4px;
}

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-legend {
  margin-top: 14px;
}

.chart-grid-line {
  stroke: var(--color-border);
  stroke-width: 1;
}

.chart-axis-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  fill: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.chart-area-contributions {
  fill: var(--color-contributions);
}

.chart-area-growth {
  fill: var(--color-interest);
}

.chart-line-total {
  stroke: var(--color-ink);
  stroke-width: 1.5;
  stroke-linejoin: miter;
  stroke-linecap: butt;
}

.chart-line-balance {
  stroke: var(--color-primary);
  stroke-width: 2;
  stroke-linejoin: miter;
  stroke-linecap: butt;
}

.chart-line-required {
  stroke: var(--color-accent);
  stroke-width: 2;
  stroke-linejoin: miter;
  stroke-linecap: butt;
  stroke-dasharray: 8 5;
}

.chart-marker-guide {
  stroke: var(--color-ink);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-marker {
  fill: var(--color-ink);
  stroke: var(--color-surface);
  stroke-width: 1.5;
}

/* ==================== BREAKDOWN TABLE ==================== */
.breakdown-section {
  margin-bottom: 48px;
}

.breakdown-section h2 {
  margin-bottom: 16px;
}

.table-wrapper {
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius);
  overflow: auto;
}

.breakdown-table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  font-size: 0.8125rem;
  background: var(--color-surface);
}

.breakdown-table th {
  background: var(--color-bg);
  border-bottom: var(--border-width) solid var(--color-border);
  padding: 10px 8px;
  text-align: right;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.breakdown-table th:first-child {
  text-align: center;
}

.breakdown-table td {
  padding: 9px 8px;
  text-align: right;
  border-bottom: var(--border-width) solid var(--color-border);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.breakdown-table td:first-child {
  text-align: center;
  font-weight: 700;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border-right: var(--border-width) solid var(--color-border);
}

.breakdown-table tbody tr:last-child td {
  border-bottom: none;
}

.breakdown-table tbody tr:hover td {
  background: var(--color-primary-tint);
}

.breakdown-table .end-balance {
  font-weight: 700;
  color: var(--color-primary);
}

/* ==================== FOOTER ==================== */
.footer {
  background: var(--color-surface);
  border-top: var(--border-width) solid var(--color-border);
  padding: 24px 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.footer-rights {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* ==================== RESPONSIVE (MOBILE-FIRST) ==================== */
@media (min-width: 481px) {
  .breadcrumb-current {
    display: inline;
  }
}

@media (min-width: 640px) {
  .nav-links {
    display: flex;
  }

  .nav-lang {
    margin-left: 0;
  }

  .tab-bar {
    display: none;
  }

  body {
    padding-bottom: 0;
  }

  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
  }

  .tool-card-large {
    flex-direction: row;
    align-items: center;
    gap: 24px;
    padding: 32px;
  }

  .tool-card-cta {
    align-self: auto;
  }

  .calculator-form,
  .calculator-results {
    padding: 32px;
  }

  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }

  .breakdown-table {
    min-width: 440px;
    font-size: 0.9375rem;
  }

  .breakdown-table th {
    padding: 12px 16px;
    font-size: 0.75rem;
  }

  .breakdown-table td {
    padding: 11px 16px;
  }
}

@media (min-width: 1024px) {
  .calculator-layout {
    grid-template-columns: 1fr 1.1fr;
    gap: 32px;
  }

  .calculator-layout--coast {
    grid-template-rows: auto auto;
    grid-template-areas:
      'form chart'
      'form results';
  }

  .calculator-layout--coast .calculator-form {
    grid-area: form;
  }

  .calculator-layout--coast .chart-section {
    grid-area: chart;
    margin-bottom: 0;
  }

  .calculator-layout--coast .calculator-results {
    grid-area: results;
  }
}

/* ==================== UTILITIES ==================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
