:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --shadow-xl: 0 20px 25px rgba(0,0,0,.1), 0 10px 10px rgba(0,0,0,.04);
    --transition: all .2s ease;
}
*, *::before, *::after { box-sizing: border-box }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    margin: 0;
}

/* ===== HEADER ===== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1040;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0,0,0,.06);
    transition: var(--transition);
}
.site-header.scrolled {
    background: rgba(255,255,255,.95);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.site-header .navbar {
    padding: .5rem 0;
    min-height: 60px;
}
.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    text-decoration: none;
    flex-shrink: 0;
}
.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: .95rem;
}
.brand-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -.02em;
}

/* ===== NAVBAR DROPDOWNS ===== */
.site-header .navbar-nav {
    gap: .1rem;
}
.site-header .nav-link {
    font-size: .88rem;
    font-weight: 500;
    color: var(--gray-600);
    padding: .5rem .85rem;
    border-radius: 8px;
    transition: var(--transition);
    white-space: nowrap;
}
.site-header .nav-link:hover,
.site-header .nav-link:focus {
    color: var(--primary);
    background: #f0f0ff;
}
.site-header .nav-link.dropdown-toggle::after {
    margin-left: .35rem;
    font-size: .65rem;
}
.site-header .dropdown-menu {
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: .5rem;
    min-width: 220px;
    margin-top: .25rem;
    animation: fadeInDown .15s ease;
}
.site-header .dropdown-item {
    font-size: .85rem;
    padding: .45rem .75rem;
    border-radius: 6px;
    color: var(--gray-700);
    transition: var(--transition);
}
.site-header .dropdown-item:hover {
    background: #f0f0ff;
    color: var(--primary);
}
.site-header .dropdown-item i {
    width: 18px;
    text-align: center;
    font-size: .82rem;
    color: var(--gray-400);
}
.site-header .dropdown-item:hover i {
    color: var(--primary);
}
.site-header .dropdown-divider {
    margin: .35rem .5rem;
    border-color: var(--gray-100);
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== NAV RIGHT ===== */
.nav-link-pill {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .85rem;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-600);
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid transparent;
}
.nav-link-pill:hover {
    color: var(--primary);
    background: #f0f0ff;
}
.navbar-toggler {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    margin-left: .25rem;
}
.navbar-toggler span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--gray-700);
    border-radius: 2px;
    transition: var(--transition);
}

/* ===== OFFCANVAS MOBILE ===== */
.offcanvas {
    max-width: 320px;
    background: #fff;
}
.offcanvas-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.offcanvas-body {
    padding: 1rem 1.25rem;
    overflow-y: auto;
}
.mobile-nav-section {
    margin-bottom: 1rem;
}
.mobile-nav-heading {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gray-400);
    padding: .5rem 0 .25rem;
}
.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: .88rem;
    transition: var(--transition);
}
.mobile-nav-link:hover {
    background: #f0f0ff;
    color: var(--primary);
}
.mobile-nav-link i {
    width: 18px;
    text-align: center;
    font-size: .85rem;
    color: var(--gray-400);
}
.mobile-nav-link:hover i {
    color: var(--primary);
}
.offcanvas .brand {
    margin-bottom: 0;
}

/* ===== GENERAL ===== */
.hero-section {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    color: #fff;
    padding: 80px 0;
}
.hero-section h1 {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.2;
}
.hero-section .lead {
    font-size: 1.15rem;
    color: rgba(255,255,255,.7);
    max-width: 600px;
}
.tool-card {
    transition: var(--transition);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    background: #fff;
}
.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}
.tool-item-card {
    transition: var(--transition);
    border-radius: 10px;
    border: 1px solid var(--gray-100);
    background: #fff;
    text-decoration: none;
    display: block;
}
.tool-item-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    background: #f8f7ff;
}
.tool-item-card:hover * {
    color: var(--primary) !important;
}
.card {
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}
pre code {
    font-size: .875rem;
    line-height: 1.5;
}
#md-input, #md-output, #text-left, #text-right, #html-input, #html-output, #md-preview, #mermaid-input {
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: .9rem;
    line-height: 1.6;
}
.form-control:focus {
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
    border-color: var(--primary);
}
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
footer a:hover {
    color: var(--primary) !important;
}
.friend-link-card {
    transition: var(--transition);
    border-radius: 10px;
    border: 1px solid var(--gray-200);
}
.friend-link-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.tool-card, .tool-item-card {
    animation: fadeInUp .4s ease-out both;
}

/* ===== THEME TOGGLE ===== */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    background: #fff;
    color: var(--gray-500);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    transition: var(--transition);
    flex-shrink: 0;
}
.theme-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f0f0ff;
}

/* ===== DARK MODE ===== */
html.dark {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;
}
html.dark body {
    background: #0f172a;
    color: #e2e8f0;
}
html.dark .site-header {
    background: rgba(15,23,42,.85);
    border-bottom-color: rgba(255,255,255,.06);
}
html.dark .site-header.scrolled {
    background: rgba(15,23,42,.95);
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
html.dark .brand-text { color: #f1f5f9; }
html.dark .site-header .nav-link { color: #94a3b8; }
html.dark .site-header .nav-link:hover,
html.dark .site-header .nav-link:focus { color: #818cf8; background: rgba(129,140,248,.1); }
html.dark .site-header .dropdown-menu {
    background: #1e293b;
    border-color: #334155;
}
html.dark .site-header .dropdown-item { color: #cbd5e1; }
html.dark .site-header .dropdown-item:hover { background: rgba(129,140,248,.1); color: #818cf8; }
html.dark .site-header .dropdown-item i { color: #64748b; }
html.dark .site-header .dropdown-item:hover i { color: #818cf8; }
html.dark .site-header .dropdown-divider { border-color: #334155; }
html.dark .navbar-toggler span { background: #94a3b8; }
html.dark .nav-link-pill { color: #94a3b8; }
html.dark .nav-link-pill:hover { color: #818cf8; background: rgba(129,140,248,.1); }
html.dark .theme-toggle { border-color: #334155; background: #1e293b; color: #94a3b8; }
html.dark .theme-toggle:hover { border-color: #818cf8; color: #818cf8; background: rgba(129,140,248,.1); }
html.dark .offcanvas { background: #1e293b; }
html.dark .offcanvas-header { border-bottom-color: #334155; }
html.dark .btn-close { filter: invert(1); }
html.dark .mobile-nav-heading { color: #64748b; }
html.dark .mobile-nav-link { color: #cbd5e1; }
html.dark .mobile-nav-link:hover { background: rgba(129,140,248,.1); color: #818cf8; }
html.dark .mobile-nav-link i { color: #64748b; }
html.dark .mobile-nav-link:hover i { color: #818cf8; }

/* Dark cards */
html.dark .card { background: #1e293b; border-color: #334155; }
html.dark .card-header { background: #334155; border-color: #475569; color: #e2e8f0; }
html.dark .card-body { color: #cbd5e1; }
html.dark .tool-card { background: #1e293b; border-color: #334155; }
html.dark .tool-card:hover { border-color: #818cf8; background: #1e293b; }
html.dark .tool-item-card { background: #1e293b; border-color: #334155; }
html.dark .tool-item-card:hover { background: rgba(129,140,248,.05); border-color: #818cf8; }

/* Dark forms */
html.dark .form-control,
html.dark .form-select {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}
html.dark .form-control:focus,
html.dark .form-select:focus {
    background: #0f172a;
    border-color: #818cf8;
    color: #f1f5f9;
}
html.dark .form-control::placeholder { color: #64748b; }
html.dark .form-label { color: #94a3b8; }

/* Dark buttons */
html.dark .btn-outline-secondary { color: #94a3b8; border-color: #475569; }
html.dark .btn-outline-secondary:hover { background: #334155; color: #e2e8f0; border-color: #64748b; }
html.dark .btn-light { background: #334155; color: #e2e8f0; border-color: #475569; }
html.dark .btn-light:hover { background: #475569; color: #f1f5f9; }

/* Dark text helpers */
html.dark .text-muted { color: #94a3b8 !important; }
html.dark .text-secondary { color: #94a3b8 !important; }
html.dark h1, html.dark h2, html.dark h3, html.dark h4, html.dark h5, html.dark h6 { color: #f1f5f9; }
html.dark a { color: #818cf8; }
html.dark a:hover { color: #a5b4fc; }

/* Dark specific sections */
html.dark .bg-light { background: #1e293b !important; }
html.dark .bg-white { background: #1e293b !important; }
html.dark .border-bottom { border-color: #334155 !important; }
html.dark .border-top { border-color: #334155 !important; }
html.dark .accordion { background: transparent; }
html.dark .accordion-item { background: #1e293b; border-color: #334155; }
html.dark .accordion-button { background: #1e293b; color: #e2e8f0; }
html.dark .accordion-button:not(.collapsed) { background: rgba(129,140,248,.05); color: #818cf8; }
html.dark .accordion-button::after { filter: invert(1); }
html.dark .accordion-body { color: #cbd5e1; }
html.dark .breadcrumb { background: transparent; }
html.dark .breadcrumb-item a { color: #818cf8; }
html.dark .breadcrumb-item.active { color: #94a3b8; }
html.dark .breadcrumb-item + .breadcrumb-item::before { color: #64748b; }

/* Dark hero (already dark, keep it) */
html.dark .hero-section { background: linear-gradient(135deg, #020617 0%, #0f172a 50%, #1e293b 100%); }

/* Dark table */
html.dark .table { color: #e2e8f0; --bs-table-bg: #1e293b; --bs-table-border-color: #334155; }
html.dark .table-striped > tbody > tr:nth-of-type(odd) > * { background-color: rgba(30,41,59,.5); }
html.dark .table-hover > tbody > tr:hover > * { background-color: rgba(129,140,248,.05); }

/* Dark code blocks */
html.dark pre { background: #0f172a; border: 1px solid #334155; }
html.dark code { color: #e2e8f0; }
html.dark :not(pre) > code { background: #334155; color: #e2e8f0; }

/* Dark friend links */
html.dark .friend-link-card { background: #1e293b; border-color: #334155; }

/* Dark footer */
html.dark footer { background: #020617 !important; }

/* Dark alert */
html.dark .alert { background: #1e293b; border-color: #334155; color: #e2e8f0; }

/* Dark list group */
html.dark .list-group-item { background: #1e293b; border-color: #334155; color: #e2e8f0; }

/* Dark popover/tooltip */
html.dark .popover { background: #1e293b; border-color: #334155; }
html.dark .tooltip-inner { background: #334155; }

/* Dark dropdown */
html.dark .dropdown-menu { background: #1e293b; border-color: #334155; }
html.dark .dropdown-item { color: #cbd5e1; }
html.dark .dropdown-item:hover { background: rgba(129,140,248,.1); color: #818cf8; }

/* ===== RESPONSIVE ===== */
@media (max-width: 991.98px) {
    .navbar-toggler {
        display: flex;
    }
    .navbar-collapse {
        display: none !important;
    }
    .nav-link-pill span {
        display: none;
    }
}
