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

:root {
    --bg: #ffffff;
    --surface: #f5f5f7;
    --surface-hover: #e8e8ed;
    --border: #d2d2d7;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --success: #30d158;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--surface);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 40px 24px 32px;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.tagline {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

.controls {
    padding: 24px;
    flex: 1;
}

.control-group {
    margin-bottom: 28px;
}

.label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

/* Segmented Control */
.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
    border-radius: 10px;
    padding: 2px;
    gap: 2px;
    position: relative;
}

.segmented-control.category-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
}

.segmented-control.category-grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segment {
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
}

.segmented-control input[type="radio"]:checked + .segment {
    background: var(--bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Search Box */
.search-box {
    position: relative;
}

.input {
    width: 100%;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    transition: all 0.2s;
    font-family: inherit;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
}

.input::placeholder {
    color: var(--text-secondary);
}

.dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 100;
}

.dropdown.show {
    display: block;
}

.dropdown-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--surface);
    transition: background 0.15s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--surface);
}

.dropdown-item-name {
    display: block;
    font-weight: 500;
    margin-bottom: 2px;
}

.dropdown-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--text-primary);
}

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

.toggle-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Stats Box */
.stats-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    line-height: 1;
}

/* Legend */
.legend-box {
    padding: 24px;
    border-top: 1px solid var(--border);
}

.legend-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}

.gradient-bar {
    height: 24px;
    border-radius: 8px;
    /* Reverse Spectral colormap: blue/purple -> green -> yellow -> orange -> red */
    background: linear-gradient(90deg,
        rgb(102, 194, 165) 0%,   /* Cyan-green (low values) */
        rgb(171, 221, 164) 15%,  /* Green */
        rgb(230, 245, 152) 29%,  /* Yellow-green */
        rgb(254, 224, 139) 43%,  /* Yellow */
        rgb(253, 174, 97) 58%,   /* Orange */
        rgb(244, 109, 67) 72%,   /* Orange-red */
        rgb(213, 62, 79) 86%,    /* Red */
        rgb(158, 1, 66) 100%     /* Dark red/purple (high values) */
    );
    margin-bottom: 8px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    gap: 4px;
}

.legend-labels span {
    flex: 1;
    text-align: center;
}

.legend-labels span:first-child {
    text-align: left;
}

.legend-labels span:last-child {
    text-align: right;
}

/* Data Source */
.hover-hint {
    padding: 16px 24px;
    margin-bottom: 24px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    line-height: 1.5;
}

.hover-hint svg {
    flex-shrink: 0;
    color: rgba(59, 130, 246, 0.7);
}

.data-source {
    padding: 20px 24px 24px;
    border-top: 1px solid var(--border);
}

.data-source-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 8px;
}

.data-source-link {
    display: block;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
    line-height: 1.5;
    transition: color 0.2s;
}

.data-source-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Map Area */
.map-area {
    flex: 1;
    position: relative;
    background: var(--surface);
}

.map-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.map-title-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.map-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

#indiaMap {
    width: 100%;
    height: 100%;
    display: block;
}

.district {
    stroke: #000000;
    stroke-width: 0.5;
    cursor: pointer;
    transition: stroke 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.district:hover {
    stroke: var(--accent);
    stroke-width: 1.5;
}

/* State Boundaries */
.state-boundary {
    fill: none;
    stroke: #000000;
    stroke-width: 2.5;
    stroke-linejoin: round;
    pointer-events: none;
}

/* Loading */
.loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hide {
    display: none;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--surface);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* Block Loading Indicators */
.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid var(--surface);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.block-loading-status {
    margin-top: 12px;
    padding: 12px;
    background: var(--surface);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.loading-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

.segment-loading {
    position: relative;
}

.segment-loading.loaded .loading-indicator {
    display: none;
}

input[type="radio"]:disabled + label {
    opacity: 0.5;
    cursor: not-allowed;
}

input[type="radio"]:disabled + label:hover {
    background: transparent;
    color: var(--text-primary);
}

/* Map Controls */
.map-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-btn {
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.control-btn:hover {
    background: var(--surface);
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn svg {
    color: var(--text-primary);
}

/* Tooltip */
.tooltip {
    position: fixed;
    top: 80px;
    left: 360px;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    font-size: 13px;
    min-width: 280px;
    max-width: 400px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.tooltip.show {
    opacity: 1;
}

.tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 14px;
}

.tooltip-subtitle {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 10px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 12px;
}

.tooltip-label {
    opacity: 0.7;
}

.tooltip-value {
    font-weight: 600;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar,
.dropdown::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.dropdown::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Browse View */
.browse-container {
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.browse-header {
    padding: 32px 40px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.browse-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

.browse-search {
    width: 320px;
    padding: 10px 14px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    transition: all 0.2s;
    font-family: inherit;
}

.browse-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
    background: var(--bg);
}

.browse-stats {
    padding: 16px 40px;
    background: var(--surface);
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.browse-table-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 40px 40px;
}

.browse-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.browse-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 16px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    z-index: 10;
}

.browse-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.browse-table thead th.sortable:hover {
    color: var(--text-primary);
}

.browse-table thead th.sortable .sort-icon {
    margin-left: 6px;
    font-size: 10px;
    opacity: 0.3;
}

.browse-table thead th.sortable.active .sort-icon {
    opacity: 1;
    color: var(--accent);
}

.browse-table thead th.sortable.active {
    color: var(--accent);
}

.browse-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.browse-table tbody tr:hover {
    background: var(--surface);
}

.browse-table tbody td {
    padding: 16px 12px;
    color: var(--text-primary);
}

.browse-table tbody td:first-child {
    font-weight: 500;
}

.browse-table tbody td:nth-child(2),
.browse-table tbody td:nth-child(3) {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.browse-table tbody td:nth-child(4) {
    font-size: 13px;
    color: var(--text-secondary);
}

.view-btn {
    padding: 6px 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.view-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.3);
}

.view-btn:active {
    transform: translateY(0);
}

/* Footer */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    flex-wrap: wrap;
    gap: 12px;
}

.footer-section {
    display: flex;
    align-items: center;
}

.footer-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Adjust container for footer */
.container {
    padding-bottom: 50px;
}

/* Responsive */
/* Mobile Optimizations */
@media (max-width: 768px) {
    /* Container Layout */
    .container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
        position: relative;
    }

    /* Sidebar - Fixed at bottom */
    .sidebar {
        width: 100%;
        max-height: 45vh;
        height: auto;
        border-right: none;
        border-top: 1px solid var(--border);
        overflow-y: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--bg);
        transition: max-height 0.3s ease-in-out, border-top 0.3s ease-in-out;
        display: flex;
        flex-direction: column;
    }

    /* Order sidebar children - View mode first, then other controls */
    .sidebar .controls {
        order: 1;
    }

    .sidebar .sidebar-header {
        order: 2;
    }

    .sidebar .hover-hint {
        order: 3;
    }

    .sidebar .legend-box {
        order: 4;
    }

    .sidebar .data-source {
        order: 5;
    }

    /* Sidebar Header */
    .sidebar-header {
        padding: 16px 16px 12px;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
    }

    .logo {
        font-size: 24px;
    }

    .tagline {
        font-size: 11px;
    }

    /* Hover Hint */
    .hover-hint {
        padding: 12px 16px;
        margin-bottom: 16px;
        font-size: 12px;
    }

    .hover-hint svg {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    /* View Mode Tabs - First in controls */
    .control-group:has(input[name="viewMode"]) {
        order: 1;
        padding: 12px 16px;
        margin: 0 -16px;
        border-bottom: 1px solid var(--border);
        background: var(--bg);
    }

    .segmented-control {
        grid-template-columns: 1fr 1.2fr 1.2fr 1.2fr !important;
        gap: 2px !important;
        font-size: 11px;
    }

    .segmented-control .segment {
        padding: 10px 4px !important;
        font-size: 10px !important;
        min-height: 40px;
    }

    /* Controls Section */
    .controls {
        padding: 0 16px 16px;
        gap: 16px;
        max-height: calc(45vh - 60px);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .control-group {
        gap: 8px;
    }

    /* Move colormap to bottom within controls */
    #colormapControl {
        order: 101;
    }

    /* Data source at bottom - styling */
    .data-source {
        padding: 12px 16px;
        font-size: 11px;
    }

    .data-source-label {
        font-size: 10px;
        margin-bottom: 4px;
    }

    .data-source-link {
        font-size: 11px;
    }

    .control-label {
        font-size: 11px;
        font-weight: 600;
    }

    /* Category/Tribe Controls */
    .segmented-control input[type="radio"] + label {
        padding: 10px 12px;
        font-size: 12px;
    }

    /* Tribe Search */
    .tribe-input-wrapper input {
        font-size: 14px;
        padding: 10px 12px;
    }

    .tribe-dropdown {
        font-size: 12px;
        max-height: 200px;
    }

    /* Colormap Dropdown */
    select {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Main Content Area - fills space above bottom sidebar */
    .map-area {
        flex: 1;
        height: calc(100vh - 45vh);
        overflow: hidden;
        padding-bottom: 0;
        position: relative;
        margin-bottom: 45vh;
    }

    /* Map View */
    .map-container {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #map {
        min-height: 400px;
        height: 50vh;
    }

    /* Map Title */
    .map-title-container {
        top: 50px; /* Lower position to avoid conflict with toggle button */
        left: 50%;
        transform: translateX(-50%);
        max-width: 90%;
        max-width: calc(100% - 68px);
        padding: 6px 12px;
        pointer-events: none;
    }

    .map-title {
        font-size: 12px;
        pointer-events: auto;
        line-height: 1.3;
    }

    /* Hide map titles in language views on mobile for cleaner UI */
    #languageViewL1 .map-title-container,
    #languageViewL2 .map-title-container {
        display: none;
    }

    /* Tooltip - Mobile Positioning */
    .tooltip {
        position: fixed;
        top: auto !important;
        left: 50% !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        max-width: 90vw;
        font-size: 12px;
        padding: 10px 12px;
    }

    .language-tooltip {
        position: fixed;
        top: auto !important;
        left: 50% !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        max-width: 90vw;
        min-width: auto;
        font-size: 12px;
        padding: 10px 12px;
    }

    /* Map Controls */
    .map-controls {
        bottom: 20px;
        right: 10px;
        gap: 8px;
    }

    .control-btn {
        width: 44px;
        height: 44px;
        border-radius: 22px;
    }

    /* Legend */
    .legend {
        bottom: auto;
        top: 60px;
        left: 10px;
        padding: 12px;
        font-size: 11px;
    }

    .legend-title {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .legend-gradient {
        height: 12px;
        margin: 6px 0;
    }

    .legend-label {
        font-size: 9px;
    }

    /* Tables - All Views */
    .browse-container,
    .language-container {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Language containers should not block the toggle button */
    .language-container {
        position: relative;
    }

    .browse-header,
    .tribes-table-header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 12px;
    }

    .browse-title,
    .tribes-table-title {
        font-size: 18px;
    }

    .browse-search {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
    }

    .browse-stats {
        padding: 0 16px 8px;
        font-size: 12px;
    }

    /* Table Container - Horizontal Scroll */
    .browse-table-container {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .browse-table {
        font-size: 12px;
        min-width: 600px; /* Force horizontal scroll */
    }

    .browse-table thead th {
        padding: 10px 8px;
        font-size: 11px;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }

    .browse-table tbody td {
        padding: 10px 8px;
    }

    /* View Button */
    .view-btn {
        padding: 6px 12px;
        font-size: 11px;
        white-space: nowrap;
    }

    /* Language View Specific */
    #languageMapL1,
    #languageMapL2 {
        min-height: 350px;
        height: 50vh;
        max-height: 50vh;
        position: relative;
        z-index: 1;
    }

    /* Ensure language containers don't block the menu toggle */
    .language-container {
        position: relative;
        z-index: 1;
    }

    /* Reserve top-right corner for toggle button - prevent SVG overflow */
    #languageViewL1,
    #languageViewL2 {
        padding-top: 10px;
        padding-right: 10px;
    }

    #languageViewL1 #languageMapL1,
    #languageViewL2 #languageMapL2 {
        overflow: visible;
    }

    .language-explanation {
        display: none; /* Hide language explanation on mobile to save space */
    }

    .language-explanation h3 {
        font-size: 18px;
        margin-bottom: 16px;
    }

    .explanation-section {
        margin-bottom: 20px;
    }

    .explanation-section h4 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .explanation-section p,
    .explanation-section li {
        font-size: 13px;
        line-height: 1.6;
    }

    /* Footer */
    .footer {
        padding: 12px 16px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .footer-text {
        font-size: 11px;
    }

    .footer-links {
        gap: 12px;
    }

    .footer-link {
        font-size: 11px;
    }

    /* Loading Spinner */
    .loading {
        padding: 40px 16px;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    /* Mobile Menu Toggle Button */
    .mobile-menu-toggle {
        position: fixed;
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 10001;
        cursor: pointer;
        box-shadow: var(--shadow);
        transition: all 0.3s;
        pointer-events: auto;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.95);
        background: var(--surface);
    }

    .mobile-menu-toggle svg {
        width: 24px;
        height: 24px;
        color: var(--text-primary);
    }

    /* Sidebar collapsed state */
    .sidebar.collapsed {
        max-height: 0 !important;
        overflow: hidden !important;
        border-bottom: none !important;
    }

    /* Legend styling within sidebar */
    .legend-box {
        padding: 12px 16px;
    }

    .legend-title {
        font-size: 11px;
        margin-bottom: 8px;
    }

    .gradient-bar {
        height: 16px;
        margin-bottom: 6px;
    }

    .legend-labels {
        font-size: 9px;
    }
}

/* Extra Small Mobile (< 480px) */
@media (max-width: 480px) {
    .sidebar {
        max-height: 50vh;
    }

    .logo {
        font-size: 20px;
    }

    .segmented-control {
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr 1fr;
        gap: 4px !important;
    }

    .segmented-control .segment {
        font-size: 11px !important;
        padding: 10px 8px !important;
    }

    .map-title {
        font-size: 12px;
    }

    .browse-table {
        min-width: 500px;
        font-size: 11px;
    }

    .browse-table thead th,
    .browse-table tbody td {
        padding: 8px 6px;
    }

    .control-btn {
        width: 40px;
        height: 40px;
    }

    .legend {
        padding: 10px;
        font-size: 10px;
    }

    .tooltip,
    .language-tooltip {
        font-size: 11px;
        padding: 8px 10px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        max-height: 35vh;
    }

    .map-area {
        height: calc(100vh - 35vh);
    }

    #map,
    #languageMapL1,
    #languageMapL2 {
        height: 60vh;
    }
}

/* Language View Styles */
.language-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: white;
}

.language-container .browse-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.language-container .browse-subtitle {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#languageMap,
#languageMapL1,
#languageMapL2 {
    flex: 1;
    width: 100%;
    height: 100%;
}

.language-tooltip {
    position: fixed;
    top: 80px;
    left: 360px;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10000;
    min-width: 320px;
    max-width: 400px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.language-tooltip.show {
    opacity: 1;
}

.language-tooltip h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 6px;
}

.language-tooltip .diversity-stat {
    margin: 6px 0;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}

.language-tooltip .diversity-stat strong {
    color: #fbbf24;
}

.language-tooltip .lang-section {
    margin-top: 12px;
}

.language-tooltip .lang-section h5 {
    margin: 0 0 4px 0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
}

.language-tooltip .lang-list {
    margin: 0;
    padding-left: 16px;
    font-size: 11px;
    line-height: 1.6;
}

.language-tooltip .lang-list li {
    margin: 2px 0;
}

.language-tooltip .lang-name {
    font-weight: 500;
}

.language-tooltip .lang-pop {
    color: #9ca3af;
    font-size: 10px;
    margin-left: 4px;
}

/* Language Explanation Section */
.language-explanation {
    padding: 2rem;
    background: #f9fafb;
    border-top: 1px solid var(--border-color);
    overflow-y: auto;
    max-height: 400px;
}

.language-explanation h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.language-explanation .explanation-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.language-explanation .explanation-section:last-child {
    margin-bottom: 0;
}

.language-explanation h4 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.language-explanation p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.language-explanation ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.language-explanation li {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.language-explanation strong {
    color: var(--text-primary);
    font-weight: 600;
}

.language-explanation sub,
.language-explanation sup {
    font-size: 0.75em;
}

/* Make language container scrollable */
.language-container {
    overflow-y: auto;
}
