:root {
    /* Modern Fintech Palette */
    --primary: #2563eb;
    --primary-dark: #1e3a8a;
    --primary-light: #eff6ff;
    --accent: #0f172a;
    --success: #10b981;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

    --radius: 16px;
    --header-height: 64px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--background);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
    /* Critical for mobile */
    width: 100%;
    position: relative;
}

html {
    overflow-x: hidden;
    width: 100%;
}

h1,
h2,
h3,
h4 {
    font-family: 'Outfit', sans-serif;
    margin-top: 0;
    color: var(--accent);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 1rem;
}

a {
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

/* --- Navbar (Mobile First) --- */
nav {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    height: var(--header-height);
    transition: all 0.3s ease;
}

.nav-container {
    padding: 0 1rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.5px;
}

.brand span {
    color: var(--primary);
}

/* Mobile Menu Button */
.menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 102;
}

.menu-btn span {
    width: 100%;
    height: 2px;
    background: var(--text-main);
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Mobile Nav Overlay */
.nav-links {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
    z-index: 101;
    visibility: hidden;
    /* Hide completely when closed to prevent scroll */
}

.nav-links.active {
    transform: translateX(0);
    visibility: visible;
}

.nav-links a {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.nav-links a.active {
    color: var(--primary);
}

/* --- Hero Section (Mobile First) --- */
.hero-section {
    padding: 3rem 1rem;
    text-align: center;
    background: radial-gradient(circle at 50% 50%, rgba(37, 99, 235, 0.05) 0%, transparent 50%);
}

.hero-section h1 {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-section p {
    font-size: 1.1rem;
    padding: 0 1rem;
}

/* --- Cards & Grid (Stacked by Default) --- */
.tool-grid {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 0 1rem;
    padding-bottom: 4rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    /* Ensure no overflow */
}

.calc-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

/* --- Inputs Design --- */
.input-group {
    margin-bottom: 1.5rem;
}

.label-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    align-items: center;
}

.label-row label {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--primary-light);
    padding: 10px 14px;
    border-radius: 12px;
    border: 2px solid transparent;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    background: white;
}

.input-wrapper input {
    border: none;
    background: transparent;
    width: 100%;
    text-align: right;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 1.1rem;
    outline: none;
    font-family: 'Outfit', sans-serif;
}

.symbol {
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
    margin-right: 8px;
}

/* Range Slider - Large Touch Targets */
input[type=range] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    margin: 16px 0;
    background: transparent;
    height: 24px;
    /* Larger hit area */
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #cbd5e1;
    border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: white;
    border: 5px solid var(--primary);
    -webkit-appearance: none;
    margin-top: -9px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* --- Result Box --- */
/* Mobile: Sticky at bottom or top? Let's keep it static at top for immediate feedback, or bottom for reachability? 
   Standard: Top for visibility, or below inputs. Sticking to below inputs for flow.
*/
.result-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    text-align: center;
    /* order: -1; REMOVED to keep Calculator First, Results Second */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* --- Ad Slots --- */
.ad-container {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    margin: 2rem auto;
    max-width: 800px;
    position: relative;
    border: 1px dashed #cbd5e1;
    overflow: hidden;
}

.ad-label {
    display: block;
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

/* Organic Header Ad (Small) */
.ad-header {
    margin: 1rem auto;
    max-width: 728px;
    display: none;
    /* JS toggles this for organic */
}

/* Primary Result Ad (High Value) */
.ad-result {
    margin: 2rem 0;
    /* Space out from results */
    min-height: 250px;
}

/* Sticky Bottom Ad */
.ad-sticky {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    padding: 0.5rem;
    display: none;
    /* JS toggles */
    text-align: center;
}

/* Wait, effectively "Order: -1" puts it at top. On mobile, seeing the result immediately as you scroll is good, but inputs are needed first. 
   Let's keep standard calculation flow: Inputs -> Result.
*/
.result-val {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
}

/* --- Footer --- */
footer {
    background: white;
    border-top: 1px solid var(--border);
    padding: 3rem 1rem 2rem;
    margin-top: auto;
}

.footer-content {
    display: grid;
    gap: 2rem;
}

/* --- DESKTOP / TABLET OVERRIDES (min-width) --- */
@media (min-width: 768px) {

    /* Navbar */
    .menu-btn {
        display: none;
    }

    .nav-links {
        position: static;
        width: auto;
        height: auto;
        background: transparent;
        flex-direction: row;
        transform: none;
        padding: 0;
        gap: 2.5rem;
        visibility: visible;
        /* Always visible on desktop */
    }

    .nav-links a {
        font-size: 0.95rem;
        font-weight: 500;
        color: var(--text-muted);
    }

    .nav-links a.active {
        color: var(--primary);
        font-weight: 600;
    }

    /* Hero */
    .hero-section {
        padding: 4rem 1.5rem;
    }

    .hero-section h1 {
        font-size: 3.5rem;
    }

    /* Grid */
    .tool-grid {
        display: grid;
        grid-template-columns: 1.5fr 1fr;
        padding: 0 1.5rem 4rem;
        align-items: start;
    }

    .calc-card {
        padding: 2.5rem;
    }

    .result-box {
        position: sticky;
        top: 100px;
        padding: 2.5rem;
        order: 2;
        /* Ensure it's on the right/second slot */
    }

    .footer-content {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        max-width: 1200px;
        margin: 0 auto;
    }
}