:root {
    --bg: #0a0e17;
    --bg-card: #111827;
    --bg-card-hover: #1a2332;
    --border: #1e293b;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-bright: #f8fafc;
    --accent: #22d3ee;
    --accent-dim: rgba(34, 211, 238, 0.15);
    --warn: #f59e0b;
    --success: #10b981;
    --error: #ef4444;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --max-w: 1800px;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

header {
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 2rem;
    background: linear-gradient(180deg, #111827 0%, var(--bg) 100%);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-inner {
    max-width: var(--max-w);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.header-stats {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    gap: 0.3rem 1.25rem;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}
.header-stat {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    white-space: nowrap;
}
.header-stat .stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin: 0;
}
.header-stat .stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-bright);
    text-transform: capitalize;
}
.header-stat .stat-change {
    font-size: 0.68rem;
    margin: 0;
}

.logo { display: flex; align-items: center; gap: 0.5rem; }
.logo-text { font-weight: 700; font-size: 1.25rem; color: var(--text-bright); }
.logo-sep { color: var(--text-dim); }
.logo-sub { color: var(--text-dim); font-size: 0.9rem; }

.header-controls { display: flex; align-items: center; gap: 0.75rem; }
.year-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); }
.header-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  margin-left: 8px;
}
.header-link:hover { background: rgba(255,255,255,0.16); }

select {
    background: var(--bg-card);
    color: var(--text-bright);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
}
select:focus { outline: 1px solid var(--accent); }

main {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 1.5rem 2rem 3rem;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-bright);
}
.stat-change { font-size: 0.75rem; margin-top: 0.25rem; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--error); }
.stat-change.neutral { color: var(--text-dim); }

.grid-map-sidebar {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.sidebar-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 720px;
    overflow-y: auto;
}
.side-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.side-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-bright);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.grid-bottom {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-bright);
}
.card-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-bright);
}
.card-hint {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.map-card { padding: 0; overflow: hidden; }
.map-card .card-header { padding: 1rem 1.25rem 0; }

.map-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mode-toggle {
    display: inline-flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
}
.mode-btn {
    background: transparent;
    border: 0;
    color: var(--text-dim);
    padding: 0.4rem 1rem;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 999px;
    transition: all 0.15s ease;
}
.mode-btn.active {
    background: var(--accent);
    color: #082f3a;
    font-weight: 600;
}
.mode-btn:not(.active):hover { color: var(--text-bright); }

#rasterMap {
    height: 640px;
    width: 100%;
    background: var(--bg);
}

.leaflet-container { background: var(--bg) !important; }

.legend {
    display: grid;
    gap: 0.35rem;
}
.legend-item {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    padding: 4px 0;
}
.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.1);
}
.legend-bar-col {
    position: relative;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.legend-name {
    text-transform: capitalize;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    font-size: 0.8rem;
    line-height: 1;
}
.legend-bar-wrap {
    height: 6px;
    background: rgba(255,255,255,0.04);
    border-radius: 3px;
    overflow: hidden;
}
.legend-bar {
    height: 100%;
    border-radius: 3px;
    min-width: 2px;
    transition: width 0.3s ease;
}
.legend-area {
    text-align: right;
    color: var(--text-dim);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    white-space: nowrap;
}

.side-header-right {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.side-close {
    background: rgba(34, 211, 238, 0.1);
    color: var(--accent);
    border: 1px solid rgba(34, 211, 238, 0.25);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.side-close:hover {
    background: rgba(34, 211, 238, 0.2);
    color: var(--text-bright);
}
.hidden { display: none !important; }

.side-hint {
    color: var(--text-dim);
    font-size: 0.73rem;
    font-style: italic;
    margin-top: 0.6rem;
}

.chart-container { position: relative; }
.chart-wide { height: 300px; }
.chart-medium { height: 260px; }
.chart-short { height: 320px; }

.model-card { margin-bottom: 1.5rem; }
.model-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.model-stat {
    text-align: center;
    padding: 0.75rem;
    background: rgba(34, 211, 238, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(34, 211, 238, 0.1);
}
.model-stat .stat-label { color: var(--accent); }
.model-stat .stat-value { font-size: 1.25rem; }

.model-subsection {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 0.5rem;
}
.model-subsection h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.per-crop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.5rem;
}
.per-crop-row {
    display: grid;
    grid-template-columns: 16px 1fr auto auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: rgba(255,255,255,0.02);
    border-radius: 6px;
    font-size: 0.82rem;
}
.per-crop-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.1);
}
.per-crop-name { text-transform: capitalize; color: var(--text); }
.per-crop-f1 {
    color: var(--text-bright);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-left: 0.5rem;
}
.per-crop-bar-wrap {
    height: 4px;
    background: rgba(255,255,255,0.05);
    border-radius: 2px;
    overflow: hidden;
    grid-column: 1 / -1;
    margin-top: 0.35rem;
}
.per-crop-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

.model-note {
    margin-top: 1rem;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-style: italic;
}

footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 2rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.county-popup {
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
}
.county-popup strong {
    font-size: 1rem;
    display: block;
    margin-bottom: 0.25rem;
}
.county-popup-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.pixel-popup .leaflet-popup-content-wrapper {
    background: rgba(17, 24, 39, 0.96);
    color: var(--text-bright);
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.5);
}
.pixel-popup .leaflet-popup-tip { background: rgba(17, 24, 39, 0.96); }
.pixel-popup-inner { font-family: 'Inter', sans-serif; font-size: 0.85rem; }
.pixel-popup-title { display: flex; align-items: center; gap: 0.5rem; }
.pixel-popup-swatch {
    display: inline-block;
    width: 14px; height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.15);
}
.pixel-popup-crop {
    text-transform: capitalize;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-bright);
}
.pixel-popup-dim {
    color: var(--text-dim);
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    margin-top: 0.3rem;
    display: block;
}

.county-tooltip {
    background: rgba(17, 24, 39, 0.9) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    color: #e2e8f0 !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 0.8rem !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}

.year-slider {
    -webkit-appearance: none;
    width: 160px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg);
}
.year-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg);
}

@media (max-width: 1280px) {
    .grid-map-sidebar { grid-template-columns: 1fr; }
    .grid-bottom { grid-template-columns: 1fr; }
    .sidebar-card { max-height: none; }
}

@media (max-width: 1024px) {
    header { padding: 0.75rem 1rem; }
    main { padding: 1rem; }
    #rasterMap { height: 520px; }
}

@media (max-width: 640px) {
    .header-stats { justify-content: flex-start; gap: 0.2rem 0.8rem; }
    .header-stat .stat-value { font-size: 0.85rem; }
    #rasterMap { height: 400px; }
    .map-controls { width: 100%; justify-content: space-between; }
}
