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

:root {
    /* Surfaces — tinted toward accent hue (oklch ~250°) */
    --bg:             oklch(99.2% 0.004 250);
    --surface:        oklch(96.8% 0.007 250);
    --surface-hover:  oklch(93.5% 0.010 250);
    --border:         oklch(87.0% 0.012 250);
    --border-strong:  oklch(74.0% 0.018 250);
    --district-stroke: oklch(0% 0 0 / 0.45);
    --dot-high: oklch(40% 0.18 258);
    --dot-low:  oklch(50% 0.20 20);

    /* Text */
    --text-primary:   oklch(18.0% 0.008 250);
    --text-secondary: oklch(52.0% 0.012 250);
    --text-tertiary:  oklch(62.0% 0.008 250);

    /* Accent */
    --accent:         oklch(50.5% 0.200 258);
    --accent-hover:   oklch(46.0% 0.210 258);
    --accent-dim:     oklch(50.5% 0.200 258 / 0.10);

    /* Feedback */
    --accent-warm:    oklch(61.0% 0.16 68);    /* amber-saffron — warm accent for delight elements */
    --overlay:        oklch(0% 0 0 / 0.45);   /* modal/drawer scrim */
    --boundary:       oklch(28.0% 0.008 250); /* map state boundaries — stays dark in both themes */

    /* Dark surface (tooltip / inverted panels) — bg hue inverted for dark contexts */
    --dark-surface:        oklch(18.0% 0.008 250);
    --dark-surface-alpha:  oklch(18.0% 0.008 250 / 0.95);
    --dark-fg:             oklch(99.2% 0.004 250);
    --dark-fg-strong:      oklch(99.2% 0.004 250 / 0.90);
    --dark-fg-mid:         oklch(99.2% 0.004 250 / 0.65);
    --dark-fg-dim:         oklch(99.2% 0.004 250 / 0.55);
    --dark-fg-faint:       oklch(99.2% 0.004 250 / 0.12);
    --dark-fg-bar:         oklch(99.2% 0.004 250 / 0.70);
    --dark-divider:        oklch(99.2% 0.004 250 / 0.20);

    /* Translucent backgrounds (glass surfaces) */
    --glass-bg-light:  oklch(99.2% 0.004 250 / 0.90);
    --glass-bg-solid:  oklch(99.2% 0.004 250 / 0.94);
    --glass-bg-soft:   oklch(99.2% 0.004 250 / 0.92);

    /* Easing tokens */
    --ease-out-expo:  cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --ease-in-out:    cubic-bezier(0.65, 0, 0.35, 1);

    /* Shadows */
    --shadow-sm:  0 1px 3px oklch(0% 0 0 / 0.06), 0 1px 2px oklch(0% 0 0 / 0.04);
    --shadow:     0 2px 8px oklch(0% 0 0 / 0.07), 0 1px 3px oklch(0% 0 0 / 0.05);
    --shadow-lg:  0 8px 24px oklch(0% 0 0 / 0.10), 0 2px 6px oklch(0% 0 0 / 0.06);

    /* Spacing scale (4pt base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;
}

/* Dark theme — applied via [data-theme="dark"] on <html> */
[data-theme="dark"] {
    /* Surfaces */
    --bg:             oklch(16.0% 0.008 250);
    --surface:        oklch(20.5% 0.010 250);
    --surface-hover:  oklch(25.0% 0.012 250);
    --border:         oklch(30.0% 0.012 250);
    --border-strong:  oklch(42.0% 0.016 250);
    --district-stroke: oklch(0% 0 0 / 0.45);
    --dot-high: oklch(62% 0.18 258);
    --dot-low:  oklch(65% 0.20 20);

    /* Text — secondary raised to 68.5% for WCAG AA on --surface (20.5% bg) */
    --text-primary:   oklch(94.0% 0.005 250);
    --text-secondary: oklch(68.5% 0.010 250);
    --text-tertiary:  oklch(60.0% 0.009 250);

    /* Accent — slightly lighter for dark bg contrast */
    --accent:         oklch(62.0% 0.195 258);
    --accent-hover:   oklch(67.0% 0.195 258);
    --accent-dim:     oklch(62.0% 0.195 258 / 0.15);

    /* Feedback */
    --accent-warm:    oklch(80.0% 0.12 80);   /* amber slightly lighter on dark */
    --overlay:        oklch(0% 0 0 / 0.65);   /* darker scrim on dark theme */
    --boundary:       oklch(100% 0 0);

    /* Inverted panel tokens (tooltips become light on dark bg) */
    --dark-surface:        oklch(94.0% 0.004 250);
    --dark-surface-alpha:  oklch(94.0% 0.004 250 / 0.95);
    --dark-fg:             oklch(18.0% 0.008 250);
    --dark-fg-strong:      oklch(18.0% 0.008 250 / 0.90);
    --dark-fg-mid:         oklch(18.0% 0.008 250 / 0.65);
    --dark-fg-dim:         oklch(18.0% 0.008 250 / 0.55);
    --dark-fg-faint:       oklch(18.0% 0.008 250 / 0.12);
    --dark-fg-bar:         oklch(18.0% 0.008 250 / 0.70);
    --dark-divider:        oklch(18.0% 0.008 250 / 0.20);

    /* Glass — dark-tinted */
    --glass-bg-light:  oklch(16.0% 0.008 250 / 0.90);
    --glass-bg-solid:  oklch(16.0% 0.008 250 / 0.94);
    --glass-bg-soft:   oklch(16.0% 0.008 250 / 0.92);

    /* Deeper shadows on dark */
    --shadow-sm:  0 1px 3px oklch(0% 0 0 / 0.20), 0 1px 2px oklch(0% 0 0 / 0.15);
    --shadow:     0 2px 8px oklch(0% 0 0 / 0.28), 0 1px 3px oklch(0% 0 0 / 0.18);
    --shadow-lg:  0 8px 24px oklch(0% 0 0 / 0.40), 0 2px 6px oklch(0% 0 0 / 0.24);
}

/* Visually hidden but accessible to screen readers */
.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;
}

/* Global focus indicator — keyboard users only */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Inputs use a ring instead of outline for better appearance */
.input:focus-visible,
.browse-search:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

body {
    font-family: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--surface);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

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

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

.sidebar-header {
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
}

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

.tagline {
    font-size: 7px;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.1;
}

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

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

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


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

.input {
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    color: var(--text-primary);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

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

.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: 8px 12px;
    min-height: 44px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid var(--surface);
    transition: background 0.15s;
}

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

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

.dropdown-item.active,
.dropdown-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

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

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

/* Segmented buttons — sector + display mode */
.sector-btn,
.toggle-btn,
.india-sector-btn {
    flex: 1;
    padding: 4px 4px;
    min-height: 32px;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    color: var(--text-secondary);
}

.sector-btn:hover,
.toggle-btn:hover,
.india-sector-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.sector-btn.active,
.toggle-btn.active,
.india-sector-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.sector-btn:not(.active):active,
.toggle-btn:not(.active):active {
    background: var(--surface);
}

.sector-btn:focus-visible,
.toggle-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

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

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

.stat-value {
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    color: var(--accent);
}

/* National avg gets slightly warmer accent to distinguish it as a summary value */
#statAvgExp {
    color: var(--accent-warm);
}

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

.legend-title {
    font-size: 7px;
    font-weight: 600;
    margin-bottom: 4px;
}

.gradient-bar {
    height: 12px;
    border-radius: 3px;
    background: var(--surface);
    margin-bottom: 6px;
}

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

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

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

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

.map-legend-overlay {
    position: absolute;
    top: 20%;
    left: 47%;
    z-index: 10;
    background: var(--bg);
    padding: 10px 14px;
    min-width: 230px;
    max-width: 280px;
    pointer-events: none;
}

.map-legend-overlay .legend-title {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 4px;
}

.map-legend-overlay .gradient-bar {
    height: 14px;
    margin-bottom: 6px;
}

.map-legend-overlay .legend-labels {
    font-size: 11px;
}

@media (max-width: 768px) {
    .map-legend-overlay {
        top: 12%;
        left: 45%;
        min-width: 180px;
        max-width: 220px;
        padding: 8px 10px;
    }
    .map-legend-overlay .legend-title { font-size: 11px; }
    .map-legend-overlay .gradient-bar { height: 11px; }
    .map-legend-overlay .legend-labels { font-size: 9px; }
}

/* Data Source */
.hover-hint {
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-5);
    background: var(--accent-dim);
    border: 1px solid color-mix(in oklch, var(--accent) 20%, transparent);
    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: color-mix(in oklch, var(--accent) 70%, transparent);
}

.data-source {
    padding: var(--space-5) var(--space-5) var(--space-5);
    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: hidden;
}

.map-title-container {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: var(--glass-bg-light);
    backdrop-filter: blur(8px);
    padding: 4px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    max-width: 90%;
    width: max-content;
}

.map-title {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    letter-spacing: 0;
}

#indiaMap {
    width: 100%;
    height: 100%;
    display: block;
    max-width: 100%;
    max-height: 100%;
    touch-action: none; /* Let D3 zoom handle all touch gestures */
}

#stateMap {
    touch-action: none;
}

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

/* State Boundaries */
.state-boundary {
    fill: none;
    stroke: var(--boundary);
    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,
.map-control-btn {
    width: 44px;
    height: 44px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow);
    font-family: inherit;
    font-size: 16px;
    color: var(--text-primary);
    line-height: 1;
}

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

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

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

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--text-primary);
    color: var(--bg);
    padding: 8px 12px;
    border-radius: 6px;
    contain: layout style paint;
    pointer-events: none;
    display: none;
    z-index: 1000;
    font-size: 12px;
    line-height: 1.55;
    min-width: 140px;
    max-width: 240px;
    box-shadow: var(--shadow);
}

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

.tooltip-subtitle {
    font-size: 12px;
    color: var(--dark-fg-mid);
    margin-bottom: 10px;
}

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

.tooltip-label {
    color: var(--dark-fg-mid);
}

.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: 8px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.browse-header-left {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.browse-title {
    font-family: 'Sora', sans-serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--text-secondary);
    white-space: nowrap;
}

.browse-count {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.browse-search {
    width: 280px;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
    color: var(--text-primary);
}

.browse-search::placeholder {
    color: var(--text-tertiary);
}

.browse-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
    background: var(--bg);
}

.browse-stats {
    display: none;
    padding: 8px 40px;
    background: var(--surface);
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

/* Count number in browse stats gets accent so it reads as live data */
#browseCount {
    color: var(--accent);
    font-weight: 600;
}

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

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

.browse-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    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: 10px 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;
    min-height: 32px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.15s, box-shadow 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

.view-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px color-mix(in oklch, var(--accent) 30%, transparent);
}

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

.view-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* 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;
}

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

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

.footer-about-btn {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 11px;
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s;
}
.footer-about-btn:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* About Modal */
.about-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay);
    opacity: 0;
    transition: opacity 0.2s var(--ease-in-out);
    padding: 16px;
}
.about-modal-overlay.is-open {
    opacity: 1;
}
.about-modal-overlay[hidden] {
    display: none;
}
.about-modal {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateY(8px);
    transition: transform 0.25s var(--ease-out-quart);
}
.about-modal-overlay.is-open .about-modal {
    transform: translateY(0);
}
.about-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.about-modal-title {
    font-family: 'Sora', sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}
.about-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.about-modal-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.about-modal-close:active {
    background: var(--surface);
}
.about-modal-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.about-modal-close svg {
    width: 14px;
    height: 14px;
}
.about-modal-body {
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.about-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.about-section-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.about-section p {
    font-size: 13px;
    line-height: 1.65;
    color: var(--text-secondary);
}
.about-section p strong {
    color: var(--text-primary);
    font-weight: 600;
}
.about-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0;
}
.about-list li {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary);
    padding-left: 14px;
    position: relative;
}
.about-list li::before {
    content: '·';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 700;
}
.about-list li strong {
    color: var(--text-primary);
    font-weight: 600;
}
.about-section--source {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}
.about-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.15s;
}
.about-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    /* Map Title */
    .map-title-container {
        top: 8px;
        max-width: calc(100% - 20px);
        padding: 4px 12px;
    }

    .map-title {
        font-size: 11px;
        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 (above category strip) */
    .tooltip,
    .language-tooltip {
        position: fixed;
        top: auto !important;
        left: 50% !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        max-width: calc(100vw - 32px);
        min-width: auto;
        font-size: 12px;
        padding: 10px 12px;
        z-index: 500;
    }

    /* 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: row;
        align-items: center;
        padding: 8px 12px;
        gap: 8px;
    }

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

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

    /* 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: var(--bg);
        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: background 0.15s, box-shadow 0.15s, transform 0.15s;
        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: 44px;
        height: 44px;
    }

    .category-cell {
        width: 90px;
    }

    .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: 42vh;
    }

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

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

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

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

.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: 120px;
    left: 20px;
    background: var(--dark-surface-alpha);
    backdrop-filter: blur(20px);
    color: var(--dark-fg);
    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: var(--shadow-lg);
}

@media (min-width: 1024px) {
    .language-tooltip {
        left: auto;
        right: calc(33.333% + 20px);
    }
}

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

.language-tooltip h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid var(--dark-divider);
    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: var(--accent-warm);
}

.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.04em;
    color: var(--dark-fg-mid);
}

.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: var(--dark-fg-mid);
    font-size: 10px;
    margin-left: 4px;
}

/* Language Explanation Section */
.language-explanation {
    padding: 2rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    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: var(--bg);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.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;
}

/* Isolated tribes table row selection */
#isolatedTableBody tr.selected-row {
    background-color: var(--accent-dim) !important;
}

#isolatedTableBody tr.selected-row:hover {
    background-color: color-mix(in oklch, var(--accent) 18%, var(--bg)) !important;
}

/* District Details Table (appears when clicking districts in ST view) */
.district-details-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border-strong);
    box-shadow: 0 -4px 12px oklch(0% 0 0 / 0.08);
    max-height: 50vh;
    overflow-y: auto;
    z-index: 200;
    contain: layout paint;
}

.district-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 1;
}

.close-btn {
    font-size: 1.2rem;
    cursor: pointer;
    background: none;
    border: none;
    padding: var(--space-2);
    margin: calc(-1 * var(--space-2));
    line-height: 1;
    color: var(--text-secondary);
    transition: color 0.15s;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.close-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.close-btn:active {
    transform: scale(0.92);
}

.district-details-table-wrapper {
    overflow-x: auto;
}

.district-details-table {
    width: 100%;
    border-collapse: collapse;
}

.district-details-table thead {
    background: var(--surface);
    position: sticky;
    top: 0;
}

.district-details-table th {
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
}

.district-details-table td {
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.district-details-table tbody tr:hover {
    background-color: var(--surface) !important;
}

/* Sortable headers for district details */
.district-details-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

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

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

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

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

.detail-cell {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-primary);
}
.detail-cell--muted { color: var(--text-secondary); }
.detail-cell--num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Mobile adjustments for district details */
@media (max-width: 768px) {
    .district-details-container {
        max-height: 60vh;
    }

    .district-details-header h3 {
        font-size: 0.875rem;
    }

    .district-details-table th,
    .district-details-table td {
        padding: 0.5rem !important;
        font-size: 0.75rem;
    }
}


/* State picker bar — always visible at top of state view */
.state-picker-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.state-picker-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.state-picker-select {
    flex: 1;
    max-width: 260px;
    height: 30px;
    padding: 0 8px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.state-picker-select:hover { border-color: var(--accent); }
.state-picker-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px oklch(from var(--accent) l c h / 0.15); }

/* Hide the sidebar state dropdown on lg+ since the inline picker is there */
@media (min-width: 1024px) {
    #stateControls > .control-card:first-child {
        display: none;
    }
}

/* Mobile Styles */
@media (max-width: 768px) {
    .state-st-container,
    .state-language-container {
        height: calc(100vh - 44px) !important;
        display: flex;
        flex-direction: column;
    }

    #stateSTStats,
    #stateLanguageStats {
        margin-left: 0 !important;
        text-align: center;
        font-size: 12px;
        padding-top: 4px;
        border-top: 1px solid var(--border);
    }

    .state-map-section,
    .state-language-map-section {
        flex: 1;
        min-height: 300px;
    }

    #stateSTMap,
    #stateLanguageMap {
        width: 100%;
        height: 100%;
    }

    #stateSTTitle,
    #stateLanguageTitle {
        font-size: 14px !important;
        padding: 8px 12px;
    }

    #stateSTDetailsContainer,
    #stateLanguageDetailsContainer {
        max-height: 50vh;
        width: calc(100% - 20px);
        left: 10px;
        right: 10px;
        bottom: 60px;
    }

    .language-section { margin-bottom: 16px; }
    .language-section h4 { font-size: 12px; padding-bottom: 8px; }

    .grid.grid-cols-1.lg\\:grid-cols-\\[1fr_250px\\] {
        grid-template-columns: 1fr !important;
    }

    #controlsSidebar { display: none !important; }

    .drawer-handle {
        width: 36px;
        height: 4px;
        background: var(--border-strong);
        border-radius: 2px;
        margin: 10px auto 0;
        flex-shrink: 0;
    }

    .sub-tab-btn {
        padding: 8px 12px !important;
        font-size: 12px !important;
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    nav .text-xl { font-size: 16px !important; }

    #mobileTabSelect {
        font-size: 14px;
        padding: 8px 12px;
        max-width: 140px;
    }

    .tooltip,
    .language-tooltip {
        position: fixed !important;
        bottom: 80px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        top: auto !important;
        max-width: calc(100vw - 40px);
        z-index: 500;
    }

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

    .browse-table th,
    .browse-table td {
        padding: 8px 6px !important;
        font-size: 11px !important;
    }

    #isolatedView {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 64px);
    }

    #isolatedView .map-section { flex: 1; min-height: 200px; }
    #isolatedView .isolated-table-section { max-height: 40vh; overflow-y: auto; }

    footer { padding: 8px 12px !important; font-size: 10px !important; }
    footer .text-blue-600 { font-size: 10px; }

    .district-label-group .district-name { font-size: 7px !important; font-weight: 600 !important; }
    .district-label-group .district-value { font-size: 6px !important; font-weight: 500 !important; }
}

/* ── Mobile Filter Button ─────────────────────────────── */
.mobile-filter-btn {
    display: none;
}

@media (max-width: 1023px) {
    .mobile-filter-btn {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 0 12px;
        height: 32px;
        font-size: 12px;
        font-weight: 500;
        color: var(--text-primary);
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        transition: background 0.15s, border-color 0.15s;
        white-space: nowrap;
    }

    .mobile-filter-btn:hover {
        background: var(--surface-hover);
        border-color: var(--border-strong);
    }

    .mobile-filter-btn:active {
        background: var(--surface-hover);
        transform: scale(0.97);
    }

    .mobile-filter-badge {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--accent);
        position: absolute;
        top: 5px;
        right: 5px;
        border: 1.5px solid var(--bg);
    }
}

/* ── Mobile Drawer (Bottom Sheet) ────────────────────── */
#mobileDrawer {
    display: none;
}

@media (max-width: 1023px) {
    #mobileDrawer {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 600;
        pointer-events: none;
    }

    #mobileDrawer.is-open {
        pointer-events: auto;
    }

    #drawerOverlay {
        position: absolute;
        inset: 0;
        background: var(--overlay);
        opacity: 0;
        transition: opacity 0.25s var(--ease-in-out);
    }

    #mobileDrawer.is-open #drawerOverlay {
        opacity: 1;
    }

    #drawerContent {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 80vh;
        background: var(--bg);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -4px 24px oklch(0% 0 0 / 0.14);
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform 0.3s var(--ease-out-quart);
        overflow: hidden;
    }

    #mobileDrawer.is-open #drawerContent {
        transform: translateY(0);
    }

    .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 16px 12px;
        flex-shrink: 0;
        border-bottom: 1px solid var(--border);
    }

    .drawer-title {
        font-size: 13px;
        font-weight: 600;
        color: var(--text-primary);
        letter-spacing: -0.01em;
    }

    .drawer-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        color: var(--text-secondary);
        background: var(--surface);
        transition: background 0.15s;
    }

    .drawer-close svg { width: 14px; height: 14px; }

    .drawer-close:hover { background: var(--surface-hover); }

    #drawerBody {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px 12px 24px;
        flex: 1;
        overscroll-behavior: contain;
    }

    .mobile-action-row {
        display: flex;
        gap: 8px;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    nav h1 { font-size: 14px !important; }

    #mobileTabSelect {
        font-size: 12px;
        padding: 6px 8px;
        max-width: 120px;
    }

    .sub-tab-btn { flex: 0 0 auto; white-space: nowrap; }

    .district-label-group .district-name {
        font-size: 5px !important;
        font-weight: 700 !important;
    }

    .district-label-group .district-value {
        font-size: 4px !important;
        font-weight: 600 !important;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .state-st-container,
    .state-language-container { height: calc(100vh - 44px) !important; }

    #stateSTStats,
    #stateLanguageStats { width: 100%; border-top: none; padding-top: 0; }
    nav .h-16 { height: 48px !important; }
}

@media (hover: none) and (pointer: coarse) {
    .tab-btn,
    .sub-tab-btn,
    button { min-height: 44px; }
    select { min-height: 44px; }
    th.sortable { min-height: 44px; height: 44px; }
    .browse-search, .input { min-height: 44px; }
    .tab-btn:hover,
    .sub-tab-btn:hover { background: inherit; }
    .tab-btn.active,
    .sub-tab-btn.active { background: var(--accent); color: var(--bg); }
}

/* ============================================================
   FEATURE: Rich District Tooltip
   ============================================================ */

.tooltip {
    min-width: 200px;
    max-width: 280px;
    padding: 10px 12px;
}

.tooltip-district {
    font-size: 13px;
    font-weight: 600;
    color: var(--bg);
    margin-bottom: 1px;
    line-height: 1.2;
}

.tooltip-state {
    font-size: 11px;
    color: var(--dark-fg-dim);
    margin-bottom: 8px;
}

.tooltip-subject-line {
    font-size: 12px;
    font-weight: 500;
    color: var(--dark-fg-strong);
    margin-bottom: 8px;
}

.tooltip-bars {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.tooltip-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tooltip-bar-label {
    font-size: 10px;
    color: var(--dark-fg-mid);
    width: 80px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tooltip-bar-track {
    flex: 1;
    height: 4px;
    background: var(--dark-fg-faint);
    border-radius: 2px;
    overflow: hidden;
}

.tooltip-bar-fill {
    height: 100%;
    width: 100%;
    border-radius: 2px;
    background: var(--dark-fg-bar);
    transform-origin: left center;
    transition: transform 0.2s var(--ease-out-quart);
    will-change: transform;
}

.tooltip-bar-val {
    font-size: 10px;
    font-weight: 600;
    color: var(--dark-fg-strong);
    width: 36px;
    text-align: right;
    flex-shrink: 0;
}

.tooltip-sample-size {
    font-size: 10px;
    color: var(--dark-fg-dim, rgba(255,255,255,.45));
    margin-top: 6px;
    font-style: italic;
}

/* ============================================================
   FEATURE: Category Comparison Strip
   ============================================================ */

.category-strip {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    contain: layout style;
    border-top: 1px solid var(--border);
    z-index: 150;
    transform: translateY(100%);
    transition: transform 0.35s var(--ease-out-expo);
    box-shadow: 0 -4px 20px oklch(0% 0 0 / 0.08);
    max-height: 36vh;
    overflow: hidden;
    contain: layout paint;
    display: flex;
    flex-direction: column;
}

.category-strip.all-items-open {
    max-height: 72vh;
}

.category-strip.open {
    transform: translateY(0);
}

.category-strip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 6px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.category-strip-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.strip-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.strip-back-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.strip-back-btn:active { transform: scale(0.93); }
.strip-back-btn svg { width: 13px; height: 13px; }

/* Body clips both panels side-by-side for slide transition */
.strip-body {
    display: flex;
    overflow: hidden;
    flex: 1;
    position: relative;
}

.category-strip-title {
    font-family: 'Sora', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.category-strip-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.strip-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.strip-all-btn {
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    color: var(--accent);
    background: oklch(from var(--accent) l c h / 0.08);
    border: 1px solid oklch(from var(--accent) l c h / 0.2);
    border-radius: 10px;
    padding: 3px 9px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.strip-all-btn:hover { background: oklch(from var(--accent) l c h / 0.14); }
.strip-all-btn:active { transform: scale(0.95); }

/* All-items panel — slides in from the right, same as items-panel */
.all-items-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.28s var(--ease-out-quart), opacity 0.2s;
    pointer-events: none;
    overflow: hidden;
}

.strip-body.all-items-open .all-items-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.strip-body.all-items-open .category-strip-scroll {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.all-items-scroll {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 4px 16px 12px;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.all-items-category-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 4px 3px;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 1;
}

.all-items-category-header:first-child { margin-top: 0; }

.all-items-category-total {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    text-transform: none;
    letter-spacing: 0;
}

.category-strip-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: 50%;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.category-strip-close svg { width: 14px; height: 14px; }

.category-strip-close:hover {
    color: var(--text-primary);
    background: var(--surface);
}

.category-strip-close:active {
    transform: scale(0.92);
}

.category-strip-scroll {
    display: flex;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 16px;
    scrollbar-width: none;
    flex-shrink: 0;
    width: 100%;
    transition: transform 0.28s var(--ease-out-quart), opacity 0.2s;
}

.category-strip-scroll::-webkit-scrollbar {
    display: none;
}

/* When items panel is open, slide categories out to the left */
.strip-body.items-open .category-strip-scroll {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

/* Items panel — slides in from the right */
.items-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.28s var(--ease-out-quart), opacity 0.2s;
    pointer-events: none;
    overflow: hidden;
}

.strip-body.items-open .items-panel {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.items-panel-scroll {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 8px 16px 10px;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    flex: 1;
}

.category-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-shrink: 0;
    width: 120px;
    padding: 0 12px 0 0;
    cursor: pointer;
    transition: opacity 0.15s;
}

.category-cell:hover {
    opacity: 0.75;
}

.category-cell-name {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.category-cell-bar-track {
    width: 100%;
    height: 6px;
    background: var(--surface);
    border-radius: 3px;
    margin-bottom: 4px;
    overflow: hidden;
}

.category-cell-bar-fill {
    height: 100%;
    width: 100%;
    border-radius: 3px;
    transform-origin: left center;
    transition: transform 0.4s var(--ease-out-quart);
    will-change: transform;
}

.category-cell-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.category-cell-rank {
    font-size: 9px;
    color: var(--text-tertiary);
    margin-top: 1px;
}

/* First cell (rank #1) gets warm amber highlight to signal top category */
.category-cell:first-child .category-cell-name {
    color: var(--accent-warm);
}

.category-cell:first-child .category-cell-rank {
    color: var(--accent-warm);
    font-weight: 600;
}

/* Category cells get a subtle drill-down caret to signal clickability */
.category-cell::after {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-right: 1.5px solid var(--text-tertiary);
    border-bottom: 1.5px solid var(--text-tertiary);
    transform: rotate(-45deg);
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.15s, transform 0.15s;
}

.category-cell:hover::after {
    opacity: 1;
    transform: rotate(-45deg) translate(1px, 1px);
}

/* ── Item rows ─────────────────────────────────────────── */
.item-row {
    display: grid;
    grid-template-columns: 1fr 56px 68px;
    align-items: center;
    gap: 8px;
    padding: 5px 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s;
}

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

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

.item-row.selected {
    background: var(--accent-dim);
}

.item-row-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-row-bar-wrap {
    height: 4px;
    background: var(--surface);
    border-radius: 2px;
    overflow: hidden;
}

.item-row-bar {
    height: 100%;
    border-radius: 2px;
    transform-origin: left;
    transition: transform 0.35s var(--ease-out-quart);
}

.item-row-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ── Map-it hint on items panel ──────────────────────── */
.items-panel-hint {
    font-size: 10px;
    color: var(--text-tertiary);
    padding: 2px 4px 6px;
    text-align: center;
    flex-shrink: 0;
}

/* ============================================================
   COMPONENT: Ghost Button (shared by Surprise Me + Share)
   ============================================================ */

.ghost-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    min-height: 44px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.ghost-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.ghost-btn:active {
    transform: scale(0.97);
}

.ghost-btn svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* Modifier: icon-only square (theme toggle) */
.ghost-btn--icon {
    padding: 5px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    justify-content: center;
}

.ghost-btn--icon svg {
    width: 14px;
    height: 14px;
}

/* First-load map hint */
.map-hint {
    position: absolute;
    bottom: var(--space-5);
    left: 30%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    background: var(--dark-surface-alpha);
    color: var(--dark-fg-mid);
    font-size: 12px;
    border-radius: 20px;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.35s var(--ease-in-out);
}
.map-hint svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    opacity: 0.7;
}
.map-hint.dismissed {
    opacity: 0;
}

/* Browse empty state suggestion pills */
.browse-suggestion-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}
.browse-suggestion-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
}

/* Modifier: spin icon on hover (surprise-me) */
#mobileMenuToggle {
    transition: background 0.15s, color 0.15s;
}

#mobileMenuToggle:hover {
    background: var(--surface-hover);
    color: var(--text-primary) !important;
}

#mobileMenuToggle:active {
    transform: scale(0.95);
}

.ghost-btn--surprise {
    color: var(--accent-warm);
    border-color: color-mix(in oklch, var(--accent-warm) 35%, transparent);
}

.ghost-btn--surprise:hover {
    background: color-mix(in oklch, var(--accent-warm) 8%, transparent);
    color: var(--accent-warm);
    border-color: color-mix(in oklch, var(--accent-warm) 65%, transparent);
}

.ghost-btn--surprise svg {
    transition: transform 0.5s var(--ease-out-quart);
}

.ghost-btn--surprise:hover svg {
    transform: rotate(45deg);
}

/* District spotlight flash */
@keyframes spotlight-pulse {
    0%   { stroke-width: 2; stroke-opacity: 1; }
    50%  { stroke-width: 4; stroke-opacity: 0.6; }
    100% { stroke-width: 2; stroke-opacity: 1; }
}

.district-spotlight {
    animation: spotlight-pulse 0.8s ease-in-out 2;
    stroke: var(--accent) !important;
    stroke-width: 2 !important;
}

/* ============================================================
   FEATURE: Share Card Generator
   ============================================================ */

.share-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--text-primary);
    color: var(--bg);
    font-size: 12px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s var(--ease-out-expo);
    pointer-events: none;
    z-index: 9999;
    white-space: nowrap;
}

.share-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   ACCESSIBILITY: Reduced Motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .category-strip {
        transition: none;
    }

    .tooltip-bar-fill,
    .category-cell-bar-fill {
        transition: none;
    }

    .share-toast {
        transition: opacity 0.01ms;
    }

    .ghost-btn--spin svg {
        transition: none;
    }

    .ghost-btn--surprise svg {
        transition: none;
        transform: none !important;
    }

    .spinner,
    .spinner-small,
    .loading-indicator {
        animation: none;
        border-color: var(--border);
        border-top-color: var(--accent);
    }

    @keyframes spotlight-pulse {
        0%, 100% { stroke-width: 2; stroke-opacity: 1; }
    }
}

/* ─── Touch target enlargement (coarse pointers: phones/tablets) ─── */
@media (pointer: coarse) {
    .sector-btn,
    .toggle-btn,
    .india-sector-btn {
        min-height: 44px;
        padding: 10px 4px;
    }

    .close-btn {
        min-width: 44px;
        min-height: 44px;
        padding: var(--space-3);
        margin: calc(-1 * var(--space-3));
    }

    .strip-back-btn {
        width: 44px;
        height: 44px;
    }

    .strip-all-btn {
        min-height: 44px;
        padding: 10px 10px;
    }

    .category-strip-close {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
}
