:root {
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --primary-light: #ccfbf1;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --nav-height: 56px;
    --nav-bg: rgba(255,255,255,0.92);
}
[data-theme="dark"] {
    --primary: #2dd4bf;
    --primary-dark: #5eead4;
    --primary-light: #134e4a;
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
    --nav-bg: rgba(15,23,42,0.92);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-height) + 16px); }
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
    transition: background 0.25s, color 0.25s;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.nav {
    position: sticky; top: 0; z-index: 100;
    background: var(--nav-bg); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border); height: var(--nav-height);
}
.nav-inner {
    max-width: 1100px; margin: 0 auto; height: 100%;
    display: flex; align-items: center; gap: 3px; padding: 0 10px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.nav-inner::-webkit-scrollbar { display: none; }
.nav a {
    flex-shrink: 0; padding: 7px 11px; border-radius: 999px;
    font-size: 0.8rem; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}
.nav a:hover, .nav a.active {
    background: var(--primary-light); color: var(--primary-dark); text-decoration: none;
}
.nav-logo { font-weight: 700; color: var(--primary-dark) !important; margin-right: 2px; }
.theme-toggle {
    margin-left: auto; flex-shrink: 0; background: none; border: 1px solid var(--border);
    border-radius: 999px; width: 38px; height: 38px; display: flex; align-items: center;
    justify-content: center; cursor: pointer; font-size: 1.1rem; color: var(--text);
}
.theme-toggle:hover { background: var(--primary-light); }

.container { max-width: 720px; margin: 0 auto; padding: 24px 16px 80px; }
section { margin-bottom: 64px; scroll-margin-top: calc(var(--nav-height) + 16px); }
h1 { font-size: clamp(1.7rem, 5vw, 2.2rem); line-height: 1.25; margin-bottom: 12px; }
h2 { font-size: clamp(1.3rem, 4vw, 1.65rem); margin-bottom: 16px; color: var(--primary-dark); }
h3 { font-size: 1.1rem; margin: 20px 0 10px; color: var(--primary-dark); }
p { margin-bottom: 14px; }
.lead { font-size: 1.08rem; color: var(--text-muted); margin-bottom: 28px; }

.card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid var(--border); padding: 20px; margin-top: 20px;
}
.form-grid { display: grid; gap: 16px; }
@media (min-width: 480px) { .form-grid.two-cols { grid-template-columns: 1fr 1fr; } }
label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 6px; }
input, select {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 1rem; background: var(--card); color: var(--text);
}
input:focus, select:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.btn {
    display: inline-flex; align-items: center; justify-content: center; width: 100%;
    padding: 14px 20px; background: var(--primary); color: #fff; border: none;
    border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; margin-top: 8px;
}
.btn:hover { background: var(--primary-dark); }

.method-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.method-tab {
    flex: 1; min-width: 120px; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; background: transparent; color: var(--text-muted);
    font-weight: 600; font-size: 0.9rem; cursor: pointer;
}
.method-tab.active {
    background: var(--primary-light); color: var(--primary-dark); border-color: var(--primary);
}

.result { margin-top: 20px; padding: 16px; border-radius: 8px; background: var(--primary-light); display: none; }
.result.show { display: block; }
.result-value { font-size: 1.7rem; font-weight: 700; color: var(--primary-dark); margin: 4px 0 8px; }
.result-label { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.result-detail { margin-top: 10px; font-size: 0.95rem; }
.result-grid { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 400px) { .result-grid { grid-template-columns: 1fr 1fr; } }
.result-box {
    background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px;
}
.result-box .label { font-size: 0.8rem; color: var(--text-muted); }
.result-box .value { font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); }

.badge {
    display: inline-block; padding: 4px 10px; border-radius: 999px;
    font-size: 0.8rem; font-weight: 600; margin-top: 6px;
}
.badge-essential { background: #e0e7ff; color: #3730a3; }
.badge-athletes { background: #dbeafe; color: #1e40af; }
.badge-fitness { background: #d1fae5; color: #065f46; }
.badge-average { background: #fef3c7; color: #92400e; }
.badge-obese { background: #fee2e2; color: #991b1b; }
.badge-normal { background: #d1fae5; color: #065f46; }
.badge-under { background: #dbeafe; color: #1e40af; }
.badge-over { background: #fef3c7; color: #92400e; }
.badge-risk { background: #fee2e2; color: #991b1b; }
.badge-highrisk { background: #fecaca; color: #7f1d1d; }

[data-theme="dark"] .badge-essential { background: #312e81; color: #c7d2fe; }
[data-theme="dark"] .badge-athletes { background: #1e3a8a; color: #93c5fd; }
[data-theme="dark"] .badge-fitness { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-average { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .badge-obese { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-normal { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-under { background: #1e3a8a; color: #93c5fd; }
[data-theme="dark"] .badge-over { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .badge-risk { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .badge-highrisk { background: #450a0a; color: #fca5a5; }

.hero { text-align: center; padding: 28px 0 12px; }
.hero p { max-width: 540px; margin-left: auto; margin-right: auto; }
footer {
    text-align: center; padding: 32px 16px; color: var(--text-muted);
    font-size: 0.875rem; border-top: 1px solid var(--border);
}
.note { font-size: 0.85rem; color: var(--text-muted); margin-top: 12px; font-style: italic; }
.unit { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }
.hidden { display: none !important; }

.range-table, .compare-table, .data-table {
    width: 100%; border-collapse: collapse; font-size: 0.85rem; margin: 16px 0;
}
.range-table th, .range-table td,
.compare-table th, .compare-table td,
.data-table th, .data-table td {
    padding: 8px 6px; text-align: center; border: 1px solid var(--border);
}
.range-table th, .compare-table th, .data-table th {
    font-weight: 600; color: var(--text-muted); background: var(--primary-light);
}
.data-table td:first-child, .data-table th:first-child {
    font-weight: 600; text-align: left; background: var(--primary-light);
}
.compare-table td:first-child { font-weight: 600; text-align: left; }

/* BMI color coding */
.bmi-under { background: #dbeafe; color: #1e40af; }
.bmi-normal { background: #d1fae5; color: #065f46; }
.bmi-over { background: #fef3c7; color: #92400e; }
.bmi-obese1 { background: #fed7aa; color: #9a3412; }
.bmi-obese2 { background: #fecaca; color: #991b1b; }
.bmi-obese3 { background: #f87171; color: #7f1d1d; }

[data-theme="dark"] .bmi-under { background: #1e3a8a; color: #93c5fd; }
[data-theme="dark"] .bmi-normal { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .bmi-over { background: #78350f; color: #fcd34d; }
[data-theme="dark"] .bmi-obese1 { background: #9a3412; color: #fdba74; }
[data-theme="dark"] .bmi-obese2 { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .bmi-obese3 { background: #450a0a; color: #fca5a5; }

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 16px 0;
}