:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #121829;
    --bg-glass: rgba(255, 255, 255, 0.04);
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.45);
    --accent-2: #8b5cf6;
    --underweight: #3b82f6;
    --normal: #10b981;
    --overweight: #f59e0b;
    --obese: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 18px;
    --shadow: 0 20px 60px -15px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: rgba(0, 0, 0, 0.08);
    --shadow: 0 20px 60px -15px rgba(99, 102, 241, 0.2);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    font-family: 'Space Grotesk', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
    position: relative;
}

#bgCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.5;
    pointer-events: none;
}

.bmi-app {
    width: 100%;
    max-width: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 8px);
    padding: 2rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    position: relative;
    z-index: 1;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px var(--accent-glow);
}

.logo svg {
    width: 24px;
    height: 24px;
    color: white;
}

.title-block h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.theme-toggle {
    width: 52px;
    height: 28px;
    border-radius: 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px;
    position: relative;
    transition: background 0.3s ease;
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle svg {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
}

.toggle-thumb {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    top: 50%;
    left: 4px;
    transform: translateY(-50%);
    transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 12px var(--accent-glow);
}

[data-theme="light"] .toggle-thumb {
    left: 28px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    letter-spacing: -0.01em;
}

.unit-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.unit-btn {
    background: var(--bg-glass);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.unit-btn .unit-icon {
    font-size: 1.3rem;
}

.unit-btn .unit-sub {
    font-size: 0.65rem;
    opacity: 0.7;
}

.unit-btn.active {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}

.unit-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.input-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.input-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-field.half {
    flex: 1;
}

.input-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.label-icon {
    font-size: 0.95rem;
}

.label-unit {
    color: var(--accent);
    font-weight: 500;
}

.input-wrapper {
    position: relative;
}

.input-main {
    width: 100%;
    background: var(--bg-glass);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    font-weight: 600;
    padding: 0.9rem 1rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -moz-appearance: textfield;
}

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

.input-main:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select.input-main {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 3rem;
}

.input-slider-wrapper {
    margin-top: 0.25rem;
}

.input-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.input-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.input-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.input-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    box-shadow: 0 0 12px var(--accent-glow);
    cursor: pointer;
}

.imperial-fields {
    margin-bottom: 1.25rem;
}

.imperial-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.extra-inputs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.btn {
    border: none;
    border-radius: var(--radius);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    color: white;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 8px 24px -8px var(--accent-glow);
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.05rem;
    width: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px -8px var(--accent-glow);
}

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

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.result-section {
    margin-top: 0.5rem;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.bmi-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.bmi-visual {
    position: relative;
    width: 200px;
    height: 200px;
    margin-bottom: 1rem;
}

.bmi-arc {
    width: 100%;
    height: 100%;
}

.arc-fill {
    transition: stroke-dasharray 1s cubic-bezier(0.16, 1, 0.3, 1);
}

.bmi-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.bmi-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: transform 0.3s ease;
}

.bmi-value.bump {
    transform: scale(1.1);
}

.bmi-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.bmi-needle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 3px;
    height: 85px;
    background: var(--text-primary);
    transform-origin: bottom center;
    transform: translate(-50%, -100%) rotate(0deg);
    transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1);
    border-radius: 3px;
}

.bmi-category {
    text-align: center;
}

.category-badge {
    display: inline-block;
    padding: 0.4rem 1.25rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.category-badge.underweight { background: rgba(59, 130, 246, 0.15); border-color: var(--underweight); color: #60a5fa; }
.category-badge.normal { background: rgba(16, 185, 129, 0.15); border-color: var(--normal); color: #34d399; }
.category-badge.overweight { background: rgba(245, 158, 11, 0.15); border-color: var(--overweight); color: #fbbf24; }
.category-badge.obese { background: rgba(239, 68, 68, 0.15); border-color: var(--obese); color: #f87171; }

.category-desc {
    margin-top: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 300px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.metric-icon {
    font-size: 1.5rem;
}

.metric-info {
    display: flex;
    flex-direction: column;
}

.metric-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
}

.metric-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

.health-insights {
    margin-bottom: 1.5rem;
}

.insights-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.insights-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.insight-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 0.75rem;
    background: var(--bg-glass);
    border-radius: 12px;
    border-left: 3px solid var(--accent);
    animation: fadeIn 0.4s ease backwards;
}

.insight-item .insight-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.bmi-scale {
    margin-top: 1.5rem;
}

.scale-labels,
.scale-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.6rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.scale-values {
    margin-top: 0.35rem;
    font-size: 0.65rem;
    font-family: 'JetBrains Mono', monospace;
}

.scale-bar {
    position: relative;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    margin: 0.35rem 0;
}

.scale-segment {
    height: 100%;
}

.scale-segment.underweight { background: var(--underweight); }
.scale-segment.normal { background: var(--normal); }
.scale-segment.overweight { background: var(--overweight); }
.scale-segment.obese { background: var(--obese); }

.scale-marker {
    position: absolute;
    top: -4px;
    width: 4px;
    height: 20px;
    background: white;
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    transition: left 1s cubic-bezier(0.16, 1, 0.3, 1);
    left: 0%;
}

.app-footer {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.7rem;
    line-height: 1.5;
}

@media (max-width: 480px) {
    .bmi-app { padding: 1.5rem; }
    .metrics-grid { grid-template-columns: 1fr; }
    .extra-inputs { flex-direction: column; gap: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
