body {
    font-family: 'Padauk', sans-serif;
    background-color: #f8fafc;
    color: #334155;
    font-size: 17px;
}

/* ─── Dark Mode ─── */
html {
    scroll-behavior: smooth;
    transition: background-color 0.3s, color 0.3s;
}
html.dark {
    color-scheme: dark;
}

/* Backgrounds */
html.dark body { background-color: #0f172a; color: #f1f5f9; }
html.dark .bg-white { background-color: #1e293b; }
html.dark .bg-slate-50 { background-color: #0f172a; }
html.dark .bg-slate-100 { background-color: #1e293b; }
html.dark .from-white { --tw-gradient-from: #1e293b; }
html.dark .to-slate-50\/50 { --tw-gradient-to: rgba(15, 23, 42, 0.5); }
html.dark .bg-indigo-50 { background-color: rgba(99, 102, 241, 0.1); }
html.dark .bg-indigo-50\/60 { background-color: rgba(99, 102, 241, 0.12); }
html.dark .bg-indigo-50\/50 { background-color: rgba(99, 102, 241, 0.05); }
html.dark .bg-indigo-100 { background-color: rgba(99, 102, 241, 0.15); }
html.dark .bg-indigo-200\/70 { background-color: rgba(99, 102, 241, 0.3); }
html.dark .bg-emerald-50 { background-color: rgba(16, 185, 129, 0.1); }
html.dark .bg-blue-50 { background-color: rgba(59, 130, 246, 0.1); }
html.dark .bg-orange-50 { background-color: rgba(249, 115, 22, 0.1); }
html.dark .bg-cyan-50 { background-color: rgba(6, 182, 212, 0.1); }
html.dark .bg-purple-50 { background-color: rgba(168, 85, 247, 0.1); }
html.dark .bg-rose-50 { background-color: rgba(244, 63, 94, 0.1); }
html.dark .bg-slate-900 { background-color: #020617; }

/* Text colors */
html.dark .text-slate-900,
html.dark .text-slate-800,
html.dark .text-slate-700 { color: #f1f5f9; }
html.dark .text-slate-600 { color: #cbd5e1; }
html.dark .text-slate-500 { color: #94a3b8; }
html.dark .text-slate-400 { color: #64748b; }
html.dark .text-indigo-900,
html.dark .text-indigo-800 { color: #a5b4fc; }
html.dark .text-indigo-700 { color: #c7d2fe; }
html.dark .text-indigo-300 { color: #c7d2fe; }
html.dark .text-emerald-900,
html.dark .text-emerald-800 { color: #6ee7b7; }
html.dark .text-emerald-600 { color: #34d399; }
html.dark .text-rose-900,
html.dark .text-rose-800 { color: #fda4af; }
html.dark .text-rose-600 { color: #fb7185; }
html.dark .text-blue-800 { color: #93c5fd; }
html.dark .text-orange-800 { color: #fdba74; }
html.dark .text-cyan-800 { color: #67e8f9; }
html.dark .text-purple-800 { color: #c4b5fd; }

/* Borders */
html.dark .border-slate-200,
html.dark .border-slate-100 { border-color: #334155; }
html.dark .border-slate-300 { border-color: #475569; }
html.dark .border-indigo-100 { border-color: rgba(99, 102, 241, 0.3); }
html.dark .border-indigo-200 { border-color: rgba(99, 102, 241, 0.4); }
html.dark .border-indigo-300 { border-color: rgba(99, 102, 241, 0.5); }
html.dark .border-emerald-100 { border-color: rgba(16, 185, 129, 0.3); }

/* Hover states */
html.dark .hover\:bg-slate-100:hover { background-color: #334155; }
html.dark .hover\:bg-indigo-50:hover { background-color: rgba(99, 102, 241, 0.15); }
html.dark .hover\:text-indigo-600:hover { color: #818cf8; }
html.dark .hover\:text-indigo-700:hover { color: #a5b4fc; }
html.dark .hover\:border-indigo-100:hover { border-color: rgba(99, 102, 241, 0.3); }
html.dark .hover\:border-indigo-200:hover { border-color: rgba(99, 102, 241, 0.4); }

/* CSS Custom Properties (used in comparison modal) */
:root {
    --text-dim: #94a3b8;
    --border: #e2e8f0;
}
html.dark {
    --text-dim: #64748b;
    --border: #334155;
}

/* Selection */
html.dark .selection\:bg-indigo-100 *::selection,
html.dark .selection\:text-indigo-900 *::selection { background-color: rgba(99, 102, 241, 0.3); color: #e0e7ff; }

/* Smooth scroll offset for sticky header */
#core-logic, #database, #comparisons {
    scroll-margin-top: 80px;
}

/* Search inputs */
html.dark #searchInput,
html.dark #mobileSearchInput {
    background-color: #1e293b;
    color: #f1f5f9;
    border-color: #475569;
}
html.dark #searchInput::placeholder,
html.dark #mobileSearchInput::placeholder { color: #64748b; }

/* Footer dark mode */
html.dark footer { background: #020617; }
html.dark footer p { color: #94a3b8; }
html.dark footer a { color: #e2e8f0; }
html.dark footer a:hover { color: #38bdf8; }

/* Bottom sheet (mobile) */
html.dark #bottom-sheet { background: #1e293b; }
html.dark #sheet-header { border-color: #334155; }
html.dark #sheet-header h3 { color: #f1f5f9; }
html.dark #sheet-close-btn { background: #334155; color: #94a3b8; }
html.dark #sheet-close-btn:hover { background: #475569; }
html.dark #sheet-handle { background: #475569; }
html.dark #sheet-backdrop { background: rgba(0, 0, 0, 0.6); }

/* Shadows */
html.dark .shadow-sm { box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.3); }
html.dark .shadow-md { box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4); }
html.dark .shadow-inner { box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.3); }

/* Toggle button */
#themeToggle {
    flex-shrink: 0;
}

.chart-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    height: 300px;
    max-height: 400px;
}

@media (min-width: 768px) {
    .chart-container { height: 350px; }
}

.custom-scrollbar::-webkit-scrollbar { width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

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

.animate-fade-in { animation: fadeIn 0.3s ease-out forwards; }

/* ─── Bottom Sheet (mobile only) ─── */
@media (max-width: 1023px) {

    /* Full-screen list on mobile */
    #mobile-list-view {
        display: flex;
        flex-direction: column;
    }

    /* Prevent mobile zoom on search input (min 16px) */
    #mobileSearchInput {
        font-size: 16px;
    }

    /* Bottom sheet backdrop */
    #sheet-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: 60;
        backdrop-filter: blur(2px);
        animation: fadeIn 0.2s ease-out forwards;
    }
    #sheet-backdrop.open { display: block; }

    /* Bottom sheet panel */
    #bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 88vh;
        background: #ffffff;
        border-radius: 20px 20px 0 0;
        z-index: 70;
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        box-shadow: 0 -4px 40px rgba(0,0,0,0.15);
    }
    #bottom-sheet.open { transform: translateY(0); }

    /* Drag handle */
    #sheet-handle {
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
        margin: 12px auto 8px;
        flex-shrink: 0;
    }

    /* Sheet header bar */
    #sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px 12px;
        border-bottom: 1px solid #e2e8f0;
        flex-shrink: 0;
    }

    #sheet-header h3 {
        font-size: 1rem;
        font-weight: 700;
        color: #1e293b;
    }

    #sheet-close-btn {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: #f1f5f9;
        border: none;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        color: #64748b;
        transition: background 0.15s;
    }
    #sheet-close-btn:hover { background: #e2e8f0; }

    /* Sheet scrollable content */
    #sheet-content {
        flex: 1;
        overflow-y: auto;
        padding: 16px;
        -webkit-overflow-scrolling: touch;
    }
    #sheet-content::-webkit-scrollbar { display: none; }

    /* Hide desktop two-column layout on mobile */
    #desktop-db-layout { display: none; }
}

@media (min-width: 1024px) {
    /* Hide mobile-only elements on desktop */
    #mobile-list-view { display: none; }
    #bottom-sheet { display: none; }
    #sheet-backdrop { display: none; }
    #desktop-db-layout { display: flex; }
}

/* Swipe-down animation */
@keyframes slideDown {
    from { transform: translateY(0); }
    to { transform: translateY(100%); }
}
#bottom-sheet.closing {
    animation: slideDown 0.3s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

/* ─── Semantic Distinctions — Card Grid ─── */
.comparison-stats {
    display: flex;
    gap: 32px;
    margin-bottom: 20px;
    opacity: 0;
    animation: fadeUp 0.7s ease 0.08s forwards;
}
.stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-value {
    font-weight: 800;
    font-size: 28px;
    letter-spacing: -0.03em;
    color: #1e293b;
    font-family: system-ui, sans-serif;
}
html.dark .stat-value { color: #f1f5f9; }
.stat-label {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.progress-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    opacity: 0;
    animation: fadeUp 0.7s ease 0.12s forwards;
}
.progress-track {
    flex: 1;
    height: 4px;
    background: #e2e8f0;
    border-radius: 100px;
    overflow: hidden;
}
html.dark .progress-track { background: #334155; }
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #e8c547, #5fbfce);
    border-radius: 100px;
    transition: width 0.5s ease;
}
.progress-text {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

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

/* Category Groups */
.comparison-category {
    margin-bottom: 32px;
    opacity: 0;
    animation: fadeUp 0.7s ease forwards;
}
.comparison-category:nth-child(1) { animation-delay: 0.15s; }
.comparison-category:nth-child(2) { animation-delay: 0.25s; }
.comparison-category:nth-child(3) { animation-delay: 0.35s; }

.cat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.cat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cat-title {
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: #1e293b;
}
html.dark .cat-title { color: #f1f5f9; }
.cat-count {
    color: #94a3b8;
    font-size: 11px;
    margin-left: auto;
}

/* Cards Grid */
.comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.comparison-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 18px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.comparison-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--cat-accent, #e8c547);
}
.comparison-card:hover {
    background: #f8fafc;
    border-color: transparent;
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.08);
}
html.dark .comparison-card {
    background: #1e293b;
    border-color: #334155;
}
html.dark .comparison-card:hover {
    background: #1a2130;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.card-words {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.card-word {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.02em;
    color: #1e293b;
}
html.dark .card-word { color: #f1f5f9; }
.card-vs {
    font-size: 9px;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 2px 6px;
    background: rgba(0,0,0,0.03);
    border-radius: 4px;
}
html.dark .card-vs { background: rgba(255,255,255,0.05); }

.card-canvas {
    width: 100%;
    height: 56px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 10px;
}
html.dark .card-canvas { background: rgba(0,0,0,0.25); }
.card-canvas svg {
    width: 100%;
    height: 100%;
    display: block;
}

.card-label {
    font-size: 11px;
    color: #64748b;
    line-height: 1.5;
}
html.dark .card-label { color: #94a3b8; }

/* ─── Comparison Modal ─── */
.comparison-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.comparison-modal-overlay.active {
    display: flex;
    animation: fadeIn 0.25s ease;
}

.comparison-modal {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    animation: scaleIn 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
html.dark .comparison-modal {
    background: #1e293b;
    border-color: #334155;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Modal inner — rendered by JS */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px 0;
}
.modal-pair {
    font-weight: 800;
    font-size: 28px;
    letter-spacing: -0.03em;
    color: #1e293b;
}
html.dark .modal-pair { color: #f1f5f9; }

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 20px;
    flex-shrink: 0;
}
html.dark .modal-close {
    background: rgba(255,255,255,0.05);
    border-color: #334155;
}
.modal-close:hover {
    background: rgba(0,0,0,0.1);
    color: #1e293b;
}
html.dark .modal-close:hover {
    background: rgba(255,255,255,0.1);
    color: #f1f5f9;
}

.modal-canvas {
    margin: 20px 28px;
    background: rgba(0,0,0,0.04);
    border-radius: 14px;
    overflow: hidden;
}
html.dark .modal-canvas { background: rgba(0,0,0,0.3); }

.modal-canvas-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.modal-canvas-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 20px 20px;
    gap: 8px;
}

.modal-canvas-label {
    font-weight: 700;
    font-size: 15px;
}
.modal-mm-def {
    font-size: 12px;
    color: #64748b;
    line-height: 1.5;
    text-align: center;
}
html.dark .modal-mm-def { color: #94a3b8; }

.modal-examples {
    padding: 0 28px 24px;
}
.modal-examples-title {
    font-weight: 700;
    font-size: 13px;
    color: #1e293b;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
html.dark .modal-examples-title { color: #f1f5f9; }

.modal-ex-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.02);
    border-radius: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
html.dark .modal-ex-item { background: rgba(255,255,255,0.03); }
.modal-ex-word {
    font-weight: 700;
    font-size: 11px;
    color: #6366f1;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
.modal-ex-sent {
    font-size: 13px;
    color: #334155;
}
html.dark .modal-ex-sent { color: #e2e8f0; }
.modal-ex-word {
    font-weight: 700;
    font-size: 11px;
    color: #6366f1;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
html.dark .modal-ex-word { color: #a5b4fc; }
html.dark .modal-ex-sent { color: #e2e8f0; }
html.dark .modal-ex-sent { color: #e2e8f0; }
.modal-ex-mm {
    font-size: 12px;
    color: #94a3b8;
    width: 100%;
}

@media (max-width: 600px) {
    .comparison-grid { grid-template-columns: 1fr; }
    .modal-canvas-split { grid-template-columns: 1fr; }
    .comparison-stats { gap: 20px; }
    .stat-value { font-size: 22px; }
    .modal-pair { font-size: 22px; }
}

/* ─── Comparison modal SVG side-filtering ─── */
.hide-side-b .side-b-group,
.hide-side-b .side-c-group { display: none !important; }
.hide-side-a .side-a-group,
.hide-side-a .side-c-group { display: none !important; }
/* For 3-way items like In/On/At — both hide classes active */
.hide-side-a.hide-side-b .side-a-group,
.hide-side-a.hide-side-b .side-b-group { display: none !important; }
.hide-side-a.hide-side-b .side-c-group { display: inline !important; }
