:root {
  --bg: #ffffff;
  --text: #111827;
  --text-muted: #4b5563;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --surface: #f9fafb;
  --surface-border: #e5e7eb;
  --error: #ef4444;
  --success: #22c55e;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --radius: 0.5rem;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --surface: #1e293b;
  --surface-border: #334155;
  --error: #f87171;
  --success: #4ade80;
}

/* Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-sans); background-color: var(--bg); color: var(--text); line-height: 1.6; transition: background-color 0.2s, color 0.2s; }
a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { text-decoration: underline; color: var(--primary-hover); }
p { margin-bottom: 1.25rem; font-size: 1.05rem; }
ul, ol { margin-left: 1.5rem; margin-bottom: 1.25rem; font-size: 1.05rem; }
li { margin-bottom: 0.5rem; }

/* Layout */
header { border-bottom: 1px solid var(--surface-border); background-color: var(--bg); position: sticky; top: 0; z-index: 50; transition: background-color 0.2s; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.nav-inner { display: flex; justify-content: space-between; align-items: center; height: 4rem; }
.logo { font-size: 1.5rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 0.5rem; }
.logo svg { width: 24px; height: 24px; color: var(--primary); }
.logo:hover { text-decoration: none; color: var(--primary); }
.nav-links { display: flex; gap: 1.5rem; align-items: center; }
.nav-links a { color: var(--text-muted); font-weight: 500; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); text-decoration: none; }

.controls { display: flex; align-items: center; gap: 1rem; }
.theme-toggle, .mobile-menu-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 0.375rem; transition: background-color 0.2s, color 0.2s; }
.theme-toggle:hover, .mobile-menu-btn:hover { background-color: var(--surface); color: var(--text); }
.mobile-menu-btn { display: none; }

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

@media (max-width: 768px) {
  .nav-links { display: none; position: absolute; top: 4rem; left: 0; right: 0; background-color: var(--bg); flex-direction: column; padding: 1.5rem; border-bottom: 1px solid var(--surface-border); box-shadow: var(--shadow-lg); gap: 1.5rem; }
  .nav-links.active { display: flex; }
  .mobile-menu-btn { display: flex; }
}

main { padding: 2rem 0 3rem 0; min-height: calc(100vh - 12rem); }

/* Breadcrumbs */
.breadcrumbs { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.breadcrumbs a { color: var(--primary); }
.breadcrumbs span.separator { color: var(--surface-border); }

/* Typography */
h1 { font-size: 2.5rem; line-height: 1.2; margin-bottom: 1rem; font-weight: 800; letter-spacing: -0.025em; }
h2 { font-size: 1.875rem; line-height: 1.3; margin-top: 2.5rem; margin-bottom: 1.25rem; font-weight: 700; letter-spacing: -0.025em; }
h3 { font-size: 1.5rem; margin-top: 2rem; margin-bottom: 1rem; font-weight: 600; }
h4 { font-size: 1.2rem; margin-top: 1.5rem; margin-bottom: 0.75rem; font-weight: 600; }
.lead { font-size: 1.25rem; color: var(--text-muted); margin-bottom: 2.5rem; }

/* Tool Hub */
.calc-grid { display: grid; gap: 2rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 4rem; }
.calc-card { background-color: var(--surface); border: 1px solid var(--surface-border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s; }
.calc-card:hover { box-shadow: var(--shadow-lg); }
.calc-card h2 { font-size: 1.5rem; margin-top: 0; margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.75rem; }
.calc-desc { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.95rem; }

/* Form Controls */
.calc-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; flex-wrap: wrap; font-size: 1.1rem; font-weight: 500; }
.calc-row input { background-color: var(--bg); border: 1px solid var(--surface-border); color: var(--text); padding: 0.75rem; border-radius: 0.375rem; font-size: 1.1rem; width: 140px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; font-family: inherit; }
.calc-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
.calc-row input.invalid { border-color: var(--error); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }
.calc-row input[type="number"] { -moz-appearance: textfield; }
.calc-row input[type="number"]::-webkit-outer-spin-button, .calc-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.calc-actions { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; align-items: center; }

.btn { background-color: var(--primary); color: #ffffff; border: none; padding: 0.75rem 1.5rem; border-radius: 0.375rem; cursor: pointer; font-weight: 600; font-size: 1rem; transition: background-color 0.2s, transform 0.1s; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; font-family: inherit; }
.btn:hover { background-color: var(--primary-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-secondary { background-color: var(--surface-border); color: var(--text); }
.btn-secondary:hover { background-color: var(--text-muted); color: #ffffff; }

/* Precision Control */
.precision-control { display: flex; align-items: center; gap: 0.5rem; margin-top: 1.5rem; font-size: 0.9rem; color: var(--text-muted); }
.precision-control select { background-color: var(--bg); border: 1px solid var(--surface-border); color: var(--text); padding: 0.25rem 0.5rem; border-radius: 0.25rem; font-size: 0.9rem; outline: none; cursor: pointer; }

/* Results */
.result-area { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--surface-border); display: none; animation: fadeIn 0.3s ease; }
.result-area.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.result-val { font-size: 2.25rem; font-weight: 800; margin-bottom: 1.5rem; color: var(--primary); word-break: break-all; }
.steps-box { background-color: var(--bg); padding: 1.5rem; border-radius: 0.375rem; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.95rem; color: var(--text-muted); border: 1px solid var(--surface-border); line-height: 1.8; overflow-x: auto; margin-top: 1.5rem; }
.steps-box b { color: var(--text); }
.steps-box .step-header { font-weight: 700; color: var(--text); margin-bottom: 0.5rem; font-family: var(--font-sans); font-size: 1.05rem; }

/* Visual Bar / SVG */
.visual-container { margin: 1.5rem 0; width: 100%; }
.bar-track { width: 100%; height: 24px; background-color: var(--surface-border); border-radius: 12px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; background-color: var(--primary); transition: width 0.5s ease-out; }
.bar-fill.negative { background-color: var(--error); }
.bar-fill.positive { background-color: var(--success); }
.bar-labels { display: flex; justify-content: space-between; margin-top: 0.5rem; font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.compare-bars { display: flex; flex-direction: column; gap: 1rem; }
.compare-bar-row { display: flex; align-items: center; gap: 1rem; }
.compare-label { width: 60px; font-weight: 600; font-size: 0.9rem; }
.compare-track { flex-grow: 1; height: 24px; background-color: var(--surface-border); border-radius: 12px; overflow: hidden; }

/* Utilities */
.error-msg { color: var(--error); font-size: 0.95rem; margin-top: 0.75rem; display: none; background: rgba(239, 68, 68, 0.1); padding: 0.75rem; border-radius: 0.375rem; border: 1px solid var(--error); }
.copy-msg { color: var(--success); font-size: 0.9rem; margin-left: 0.5rem; display: none; font-weight: 500; }

/* Content Section */
.content-section { max-width: 850px; margin: 0 auto 4rem auto; }
.table-responsive { overflow-x: auto; margin-bottom: 2rem; border-radius: var(--radius); border: 1px solid var(--surface-border); }
table { width: 100%; border-collapse: collapse; text-align: left; background: var(--surface); }
th, td { padding: 1rem; border-bottom: 1px solid var(--surface-border); }
th { background-color: rgba(0,0,0,0.02); font-weight: 600; white-space: nowrap; }
[data-theme="dark"] th { background-color: rgba(255,255,255,0.02); }
tr:last-child td { border-bottom: none; }

.faq-item { border-bottom: 1px solid var(--surface-border); padding: 1.5rem 0; }
.faq-item h3 { margin-top: 0; margin-bottom: 0.75rem; font-size: 1.25rem; color: var(--text); }
.faq-item p:last-child { margin-bottom: 0; }

.example-box { background-color: var(--surface); border-left: 4px solid var(--primary); padding: 1.5rem; margin-bottom: 2rem; border-radius: 0 var(--radius) var(--radius) 0; box-shadow: var(--shadow); }
.example-box h4 { font-size: 1.2rem; margin-bottom: 1rem; color: var(--text); }
.example-box .calc-step { margin-bottom: 0.5rem; display: flex; }
.example-box .calc-step strong { min-width: 80px; display: inline-block; }

.pitfall-box { background-color: rgba(239, 68, 68, 0.05); border-left: 4px solid var(--error); padding: 1.5rem; margin-bottom: 2rem; border-radius: 0 var(--radius) var(--radius) 0; }
.pitfall-box h4 { color: var(--error); margin-top: 0; }

/* Footer */
footer { text-align: center; padding: 3rem 1.5rem; border-top: 1px solid var(--surface-border); background-color: var(--surface); color: var(--text-muted); }
.footer-links { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.footer-links a { color: var(--text-muted); font-size: 0.95rem; font-weight: 500; }
.footer-links a:hover { color: var(--primary); }
.copyright { font-size: 0.9rem; }

/* Header Right Wrapper */
.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
