:root {
    --primary-color: #5b46d1;
    --primary-hover: #4834a3;
    --bg-color: #f7f9fa;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-color: #e5e7eb;
    --card-bg: #ffffff;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --success-color: #10b981;
}

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

html,
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
    width: 100%;
}

/* Header & Navigation */
.navbar {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
    height: 75px;
    display: flex;
    align-items: center;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: #1e293b;
}

.logo .text-primary {
    color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav-links li a {
    font-weight: 600;
    color: #475569;
    transition: 0.3s;
}

.nav-links li a:hover,
.nav-links li a.active {
    color: var(--primary-color);
}

.mobile-menu-toggle {
    display: none;
    background: #f1f5f9;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    font-size: 1.25rem;
    color: var(--primary-color);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

/* Main Layout */
.main-layout {
    display: flex;
    gap: 30px;
    margin: 40px auto;
    align-items: start;
}

.content-area {
    flex: 1;
    min-width: 0;
}

.sidebar {
    width: 320px;
    flex-shrink: 0;
    position: sticky;
    top: 100px;
}

/* Tool Cards & Grid */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.tool-card {
    background: white;
    border-radius: 16px;
    padding: 25px 15px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: 0.3s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.icon-wrap {
    width: 48px;
    height: 48px;
    margin: 0 auto 15px;
    border-radius: 12px;
    background: #eef2ff;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

/* Widgets */
.widget {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.widget-header {
    font-weight: 800;
    font-size: 0.95rem;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #334155;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    transition: 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(91, 70, 209, 0.1);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    width: 100%;
}

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

/* Responsive Overrides */
@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        position: static;
    }
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .nav-links {
        display: none !important;
        position: absolute;
        top: 75px;
        left: 0;
        right: 0;
        background: white;
        flex-direction: column;
        padding: 20px;
        border-bottom: 1.5px solid var(--border-color);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        gap: 10px;
        z-index: 999;
    }

    .nav-links.active {
        display: flex !important;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links li a {
        display: block;
        padding: 12px;
        background: #f8fafc;
        border-radius: 10px;
        text-align: center;
    }

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

@media (max-width: 480px) {
    .tools-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .hero h1 {
        font-size: 1.75rem;
    }

    .container {
        padding: 0 10px;
    }

    .logo span {
        font-size: 1.1rem;
    }
}

/* ═══════════════════════════════════════ THE NUCLEAR OPTION ══════════════════════════════════════ */
/* Forces all containers to stay within viewport on any device < 600px */
@media (max-width: 600px) {
    * {
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }

    .container,
    .main-layout,
    .content-area,
    .sidebar,
    .rt-card,
    [class*="container"] {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Ensure grids stack */
    [style*="display: grid"]:not(.tools-grid),
    .rt-grid,
    .rt-res-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    /* Responsive Chart sizing */
    canvas {
        width: 100% !important;
        height: auto !important;
    }

    /* Fix for cards that have explicit margins in their styles */
    [style*="margin: 0 auto"] {
        margin: 0 !important;
    }
}

/* ═══════════════════════════════════════ LEGENDARY ADVANCED TOOLS ══════════════════════════════════════ */
:root {
    --legend-primary: #6366f1;
    --legend-secondary: #a855f7;
    --legend-accent: #ec4899;
    --legend-glow: 0 0 20px rgba(99, 102, 241, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
}

.adv-card {
    max-width: 950px;
    margin: 50px auto;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 3rem;
    overflow: hidden;
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--glass-border);
    font-family: 'Outfit', 'Inter', sans-serif;
    transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    position: relative;
    border: none;
}

.adv-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.05), transparent);
}

.adv-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 70px 120px -30px rgba(0, 0, 0, 0.3), var(--legend-glow);
}

.adv-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #db2777 100%);
    background-size: 200% 200%;
    animation: legendaryGradient 10s ease infinite;
    padding: 80px 40px;
    text-align: center;
    position: relative;
    overflow: hidden;
    color: #ffffff;
}

@keyframes legendaryGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.adv-header i {
    font-size: 4rem;
    filter: drop-shadow(0 0 15px rgba(255,255,255,0.4));
    margin-bottom: 25px;
    text-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.adv-header h2 {
    font-size: 3rem;
    text-transform: uppercase;
    letter-spacing: -0.05em;
    font-weight: 1000;
    margin-bottom: 10px;
}

.adv-header p {
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 500;
}

.adv-content {
    padding: 60px 40px;
    background: #ffffff;
}

.adv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.adv-input-group label {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 12px;
    letter-spacing: 0.02em;
}

.adv-input {
    width: 100%;
    padding: 18px 22px;
    background: #f8fafc;
    border: 2px solid #eef2ff;
    border-radius: 1.5rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: #1e293b;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.adv-input:focus {
    background: #ffffff;
    border-color: var(--legend-primary);
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.15), 0 4px 12px rgba(99, 102, 241, 0.1);
    outline: none;
    transform: translateY(-2px);
}

.adv-calc-btn {
    width: 100%;
    padding: 22px;
    background: linear-gradient(135deg, var(--legend-primary) 0%, var(--legend-secondary) 100%);
    color: #ffffff;
    border: none;
    border-radius: 1.75rem;
    font-size: 1.3rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 25px 50px -12px rgba(79, 70, 229, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.adv-calc-btn:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 35px 70px -15px rgba(79, 70, 229, 0.6), var(--legend-glow);
    background: linear-gradient(135deg, var(--legend-secondary) 0%, var(--legend-accent) 100%);
}

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

.adv-result-card {
    margin-top: 50px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 2.5rem;
    padding: 50px;
    text-align: center;
    border: 2px solid var(--legend-primary);
    box-shadow: var(--legend-glow);
    display: none;
    animation: advSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.adv-result-value {
    font-size: 5rem;
    font-weight: 1000;
    color: #1e293b;
    line-height: 1.1;
    margin: 15px 0;
    background: linear-gradient(135deg, #6366f1 0%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.05em;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.2));
}

.adv-result-label {
    font-size: 1.1rem;
    font-weight: 800;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.legend-insight {
    margin-top: 40px;
    padding: 35px;
    background: linear-gradient(to right, #f8fafc, #ffffff);
    border-radius: 2rem;
    border-left: 8px solid var(--legend-primary);
    text-align: left;
    position: relative;
    overflow: hidden;
    box-shadow: 0 15px 35px rgba(0,0,0,0.03);
}

.legend-insight::before {
    content: '✨';
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 2.5rem;
    opacity: 0.15;
}

.legend-chart-container {
    margin-top: 50px;
    background: #ffffff;
    border-radius: 3rem;
    padding: 40px;
    box-shadow: 0 30px 60px -15px rgba(0,0,0,0.08);
    border: 1px solid #f1f5f9;
}

@media (max-width: 600px) {
    .adv-card { margin: 15px; border-radius: 2rem; }
    .adv-header { padding: 60px 20px; }
    .adv-header h2 { font-size: 2rem; }
    .adv-header i { font-size: 3rem; }
    .adv-content { padding: 40px 20px; }
    .adv-result-card { padding: 30px 20px; }
    .adv-result-value { font-size: 3rem; }
}

@media (max-width: 600px) {
    .adv-card { margin: 15px; border-radius: 1.5rem; }
    .adv-header { padding: 40px 20px; }
    .adv-header h2 { font-size: 1.8rem; }
    .adv-content { padding: 30px 20px; }
    .adv-result-value { font-size: 2.5rem; }
}