/* Main stylesheet — responsive layout, light/dark themes */

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --font-sans: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg: #f4f6fa;
    --bg-elevated: #ffffff;
    --text: #1a1d26;
    --text-muted: #5c6370;
    --border: #e2e6ef;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --success: #059669;
    --header-bg: linear-gradient(135deg, #ffffff 0%, #f0f4ff 100%);
    --input-bg: #ffffff;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.35);
}

[data-theme="dark"] {
    --bg: #0f1219;
    --bg-elevated: #171c28;
    --text: #eef1f7;
    --text-muted: #9aa3b5;
    --border: #2a3142;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: rgba(96, 165, 250, 0.15);
    --success: #34d399;
    --header-bg: linear-gradient(135deg, #171c28 0%, #1e293b 100%);
    --input-bg: #1e2535;
    --focus-ring: 0 0 0 3px rgba(96, 165, 250, 0.35);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 0.75rem 1rem;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    left: 1rem;
    top: 1rem;
}

/* Header */
.site-header {
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.brand:hover {
    color: var(--accent);
}

.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.1rem;
}

.mobile-nav-toggle {
    display: none;
    margin-left: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    cursor: pointer;
    color: var(--text);
}

.hamburger {
    display: block;
    width: 1.35rem;
    height: 2px;
    background: currentColor;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.primary-nav {
    flex: 1;
    display: flex;
    justify-content: flex-start;
}

.nav-root {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

.nav-item {
    position: relative;
}

.nav-trigger {
    background: transparent;
    border: none;
    font: inherit;
    color: var(--text);
    cursor: pointer;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.nav-trigger::after {
    content: "";
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 3px;
    transform: rotate(45deg);
    margin-top: -2px;
    opacity: 0.7;
}

.nav-trigger:hover,
.nav-trigger:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    outline: none;
}

.dropdown {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
    min-width: 220px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    position: absolute;
    top: 100%;
    left: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
    z-index: 50;
}

.dropdown a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.925rem;
}

.dropdown a:hover,
.dropdown a:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    outline: none;
}

@media (min-width: 901px) {
    .nav-item.has-dropdown:hover .dropdown,
    .nav-item.has-dropdown:focus-within .dropdown {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
}

.dropdown.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

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

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

@media (max-width: 900px) {
    .mobile-nav-toggle {
        display: block;
        order: -1;
    }

    .primary-nav {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(84vw, 320px);
        display: block;
        overflow-y: auto;
        background: var(--bg-elevated);
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow-lg);
        padding: 1rem 0.75rem;
        transform: translateX(-100%);
        transition: transform var(--transition);
        z-index: 220;
    }

    .primary-nav.is-open {
        transform: translateX(0);
    }

    .nav-root {
        flex-direction: column;
        align-items: stretch;
    }

    .nav-item.has-dropdown .dropdown {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: none;
        background: var(--bg);
        display: none;
        margin: 0.25rem 0 0.5rem 0.5rem;
        padding-left: 0.5rem;
        border-left: 2px solid var(--accent);
        border-radius: 0;
    }

    .nav-item.has-dropdown .dropdown.is-open {
        display: block;
    }

    .header-inner {
        flex-wrap: wrap;
    }

    .brand {
        flex: 1;
    }

    body.mobile-nav-open {
        overflow: hidden;
    }

}

/* Layout shell */
.layout-shell {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 1.25rem 1rem 2rem;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .layout-shell {
        grid-template-columns: 1fr;
    }
}

.wide-layout {
    max-width: 1600px;
}

.main-column {
    min-width: 0;
}

/* Sidebar */
.sidebar-mobile-toggle {
    display: none;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.sidebar {
    position: sticky;
    top: 5rem;
}

.sidebar-inner {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.sidebar-title {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-section {
    border-bottom: 1px solid var(--border);
    padding: 0.35rem 0;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.sidebar-summary {
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 0;
    list-style: none;
    color: var(--text);
}

.sidebar-summary::-webkit-details-marker {
    display: none;
}

.sidebar-summary::after {
    content: "+";
    float: right;
    color: var(--accent);
    font-weight: 400;
}

details[open] > .sidebar-summary::after {
    content: "−";
}

.sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0 0 0.5rem 0.75rem;
}

.sidebar-list a {
    display: block;
    padding: 0.35rem 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
}

.nav-link,
.sidebar-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link i,
.sidebar-link i {
    width: 1rem;
    text-align: center;
    color: var(--accent);
    flex-shrink: 0;
}

/* Colorful menu icon accents for better visual scanning */
.dropdown li:nth-child(5n + 1) .nav-link i,
.sidebar-list li:nth-child(5n + 1) .sidebar-link i {
    color: #2563eb;
}

.dropdown li:nth-child(5n + 2) .nav-link i,
.sidebar-list li:nth-child(5n + 2) .sidebar-link i {
    color: #16a34a;
}

.dropdown li:nth-child(5n + 3) .nav-link i,
.sidebar-list li:nth-child(5n + 3) .sidebar-link i {
    color: #ea580c;
}

.dropdown li:nth-child(5n + 4) .nav-link i,
.sidebar-list li:nth-child(5n + 4) .sidebar-link i {
    color: #db2777;
}

.dropdown li:nth-child(5n) .nav-link i,
.sidebar-list li:nth-child(5n) .sidebar-link i {
    color: #7c3aed;
}

.sidebar-list a:hover,
.sidebar-list a:focus-visible {
    color: var(--accent);
    outline: none;
}

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

    .sidebar {
        position: static;
    }

    .sidebar:not(.is-collapsed-open) .sidebar-inner {
        display: none;
    }

    .sidebar.is-collapsed-open .sidebar-inner {
        display: block;
    }
}

@media (min-width: 901px) {
    .sidebar .sidebar-inner {
        display: block !important;
    }
}

/* Footer */
.site-footer {
    margin-top: auto;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
    padding: 2rem 1rem;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: space-between;
    align-items: flex-start;
}

.footer-tagline {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-nav a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.footer-nav a:hover {
    text-decoration: underline;
}

.footer-copy {
    max-width: 1200px;
    margin: 1.5rem auto 0;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Calculator cards & forms */
.page-hero {
    margin-bottom: 1.5rem;
}

.page-hero h1 {
    margin: 0 0 0.5rem;
    font-size: clamp(1.5rem, 4vw, 2rem);
    letter-spacing: -0.02em;
}

.page-hero p {
    margin: 0;
    color: var(--text-muted);
    font-size: 1rem;
}

.calc-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.calc-card h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: var(--text);
}

.form-grid {
    display: grid;
    gap: 1rem;
}

@media (min-width: 560px) {
    .form-grid.cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--accent);
}

.field-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

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

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    opacity: 0.9;
}

.result-box {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    border: 1px solid var(--border);
}

.result-box strong {
    color: var(--accent);
}

.result-table-wrap {
    overflow-x: auto;
    margin-top: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.result-table th,
.result-table td {
    padding: 0.5rem 0.65rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.result-table th:first-child,
.result-table td:first-child {
    text-align: left;
}

.result-table thead {
    background: var(--bg);
}

.muted {
    color: var(--text-muted);
}

.link-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.home-card {
    display: block;
    padding: 1.25rem;
    border-radius: var(--radius);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: border-color var(--transition), transform var(--transition);
}

.home-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.home-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    color: var(--accent);
}

.home-card p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.card-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 1.25rem;
    transition: transform var(--transition), background var(--transition);
}

.home-card:hover .card-icon {
    transform: scale(1.08);
    filter: brightness(1.06);
}

.link-grid .home-card:nth-child(6n + 1) .card-icon {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: #1d4ed8;
}

.link-grid .home-card:nth-child(6n + 2) .card-icon {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #15803d;
}

.link-grid .home-card:nth-child(6n + 3) .card-icon {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #b45309;
}

.link-grid .home-card:nth-child(6n + 4) .card-icon {
    background: linear-gradient(135deg, #fce7f3, #fbcfe8);
    color: #be185d;
}

.link-grid .home-card:nth-child(6n + 5) .card-icon {
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
    color: #4338ca;
}

.link-grid .home-card:nth-child(6n) .card-icon {
    background: linear-gradient(135deg, #cffafe, #a5f3fc);
    color: #0e7490;
}

.section-label {
    margin: 2rem 0 1rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.section-label i {
    margin-right: 0.5rem;
    color: var(--accent);
}

/* Scientific keypad */
.sci-calc {
    max-width: 360px;
}

.sci-display {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 1.35rem;
    font-family: var(--font-mono);
    text-align: right;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    margin-bottom: 0.75rem;
}

.sci-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
}

.sci-keys button {
    padding: 0.65rem 0.25rem;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    font-family: var(--font-mono);
}

.sci-keys button:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.sci-keys .btn-wide {
    grid-column: span 2;
}

/* Static pages */
.prose {
    max-width: 65ch;
}

.calc-card.prose {
    max-width: none;
}

.prose h1 {
    margin-top: 0;
}

.prose p {
    color: var(--text-muted);
}

/* AdSense / display slots (calculator pages) */
.ad-slot {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
}

.ad-slot__inner {
    width: 100%;
    max-width: min(728px, 100%);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-slot--header {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
}

.ad-slot--footer {
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.ad-slot--sidebar .ad-slot__inner {
    max-width: 100%;
    min-height: 250px;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .ad-slot--sidebar .ad-slot__inner {
        min-height: 100px;
    }
}
