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

:root {
    --accent: #EA580C;
    --accent-hover: #c2410c;
    --text: #e4e4e7;
    --text-muted: #8b8b96;
    --text-bright: #fff;
    --bg: #0a0f1a;
    --bg-card: #111827;
    --bg-subtle: #1a2236;
    --border: #1e293b;
    --green: #16a34a;
    --yellow: #eab308;
    --red: #dc2626;
    --blue: #3b82f6;
    --orange: #ea580c;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

/* Header */
header {
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    background: var(--bg-card);
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-link {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

.nav-link:hover {
    color: var(--accent);
}

/* National average ticker */
.ticker {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.5rem;
}

.ticker-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.ticker-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.ticker-label {
    color: var(--text-muted);
}

.ticker-price {
    font-weight: 600;
    color: var(--text-bright);
    font-size: 1rem;
}

.ticker-change {
    font-size: 0.8rem;
    font-weight: 500;
}

.ticker-change.up {
    color: var(--red);
}

.ticker-change.down {
    color: var(--green);
}

.ticker-change.flat {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
    padding: 0.75rem;
    font-size: 1rem;
}

/* Main */
main {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 2.5rem;
}

/* Map */
#map-container {
    position: relative;
    width: 100%;
    overflow: visible;
}

#map-container svg {
    width: 100%;
    height: auto;
    touch-action: pan-y;
}

/* Map legend - right side */
.map-legend {
    position: absolute;
    right: -80px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.map-legend-label {
    text-align: center;
    line-height: 1.3;
    margin-bottom: 2px;
}

.map-legend-price {
    font-size: 11px;
    color: var(--text);
}

.map-legend-bar {
    width: 12px;
    height: 120px;
    border-radius: 4px;
    background: linear-gradient(to bottom, #dc2626, #eab308, #16a34a);
    flex-shrink: 0;
}

.map-legend-note {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.map-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: #2a2a3a;
}

/* Chart toolbar */
.chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

/* Chart legend */
.chart-legend {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text);
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chart-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* Time range toggle */
.time-range-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.range-btn {
    padding: 0.25rem 0.7rem;
    font-size: 0.75rem;
    font-family: inherit;
    border: none;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.range-btn + .range-btn {
    border-left: 1px solid var(--border);
}

.range-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Tooltip - dark mode redesigned */
.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.5;
    display: none;
    z-index: 10;
    white-space: nowrap;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.tooltip .tt-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-bright);
    margin-bottom: 4px;
}

.tooltip .tt-price {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-bright);
}

.tooltip .tt-rank {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tooltip .tt-change {
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 2px;
}

.tooltip .tt-change.up { color: var(--red); }
.tooltip .tt-change.down { color: var(--green); }
.tooltip .tt-change.flat { color: var(--text-muted); }

.tooltip .tt-week {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.tooltip .tt-regional {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Chart */
#chart-container {
    margin-top: 2.5rem;
    text-align: center;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

#chart-container h3 {
    font-size: 15px;
    font-weight: 500;
    margin: 0;
    color: var(--text);
}

.btn-small {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-small:hover {
    background: var(--bg-subtle);
}

#national-chart {
    width: 100%;
}

#national-chart svg {
    width: 100%;
    height: auto;
}

/* D3 axis styling for dark mode */
.x-axis text, .y-axis text {
    fill: var(--text-muted);
}
.x-axis line, .y-axis line,
.x-axis path, .y-axis path {
    stroke: var(--border);
}

/* Slider */
.slider-container {
    margin: 1.5rem 0 0;
    text-align: center;
}

.slider-container label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#week-slider {
    flex: 1;
    accent-color: var(--accent);
}

.play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.play-btn:hover {
    background: var(--bg-subtle);
    border-color: var(--accent);
}

.play-btn.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.slider-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* History page */
.history-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-bright);
}

.history-page > p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

#history-chart {
    width: 100%;
}

#history-chart svg {
    width: 100%;
    height: auto;
}

.extremes-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 2.5rem 0 1rem;
    color: var(--text);
}

#extremes-table-wrap {
    overflow-x: auto;
}

.extremes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.extremes-table th,
.extremes-table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.extremes-table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.extremes-table td {
    color: var(--text);
}

.extremes-table tr:hover {
    background: var(--bg-subtle);
}

/* About section */
.about-section {
    background: var(--bg-card);
    padding: 2rem 1.5rem;
    margin-top: 2.5rem;
    border-top: 1px solid var(--border);
}

.about-inner {
    max-width: 900px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 2rem;
}

.about-col h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.about-col p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.about-col a {
    color: var(--accent);
    text-decoration: none;
}

.about-col a:hover {
    text-decoration: underline;
}

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

/* 404 page */
.error-page {
    text-align: center;
    padding: 4rem 0;
}

.error-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-bright);
}

.error-page p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Alerts page */
.alerts-page {
    max-width: 480px;
    margin: 0 auto;
}

.alerts-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-bright);
}

.alerts-page > p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.alert-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.form-group input,
.form-group select {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--bg-subtle);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.25);
}

.current-price {
    padding: 0.75rem;
    background: var(--bg-subtle);
    border-radius: 6px;
    font-size: 0.9rem;
}

.alert-message {
    padding: 0.75rem;
    background: rgba(22, 163, 74, 0.1);
    border: 1px solid rgba(22, 163, 74, 0.3);
    border-radius: 6px;
    color: #4ade80;
    margin-bottom: 1rem;
}

.form-message {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

.form-message.success {
    background: rgba(22, 163, 74, 0.1);
    border: 1px solid rgba(22, 163, 74, 0.3);
    color: #4ade80;
}

.form-message.error {
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #f87171;
}

/* Rankings row below map */
.rankings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.rankings-col h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.rankings-expensive h4 { color: var(--red); }
.rankings-cheapest h4 { color: var(--green); }

.rankings-col ol {
    list-style: none;
    font-size: 0.85rem;
}

.rankings-col ol li {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--border);
}

.rankings-col ol li .rank-name {
    color: var(--text);
}

.rankings-expensive ol li .rank-price { color: var(--red); font-weight: 600; }
.rankings-cheapest ol li .rank-price { color: var(--green); font-weight: 600; }

.rank-wow {
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 4px;
}
.rank-wow.up { color: var(--red); }
.rank-wow.down { color: var(--green); }
.rank-wow.flat { color: var(--text-muted); }

/* Slide-in state panel */
.state-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 100;
    padding: 1.5rem;
    overflow-y: auto;
    transition: right 0.3s ease;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.state-panel.open {
    right: 0;
}

.state-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.state-panel-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-bright);
    margin: 0;
}

.panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.panel-close:hover {
    color: var(--text-bright);
}

.panel-prices {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-price-item {
    flex: 1;
    background: var(--bg-subtle);
    border-radius: 6px;
    padding: 0.75rem;
    text-align: center;
}

.panel-price-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
}

.panel-price-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-bright);
    display: block;
    margin-top: 2px;
}

#panel-chart {
    width: 100%;
}

#panel-chart svg {
    width: 100%;
    height: auto;
}

.panel-state-link {
    display: block;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
}

.panel-state-link:hover {
    text-decoration: underline;
}

.panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    display: none;
}

.panel-overlay.open {
    display: block;
}

/* State landing page */
.state-page {
    max-width: 900px;
}

.back-link {
    display: inline-block;
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.back-link:hover {
    text-decoration: underline;
}

.state-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 1rem;
}

.state-prices {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.state-price-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.state-price-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.state-price-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-bright);
}

.state-chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
}

#state-chart {
    width: 100%;
}

#state-chart svg {
    width: 100%;
    height: auto;
}

.state-footer {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.state-footer a {
    color: var(--accent);
    text-decoration: none;
}

/* Embed widget page */
.embed-page {
    max-width: 700px;
}

.embed-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 0.25rem;
}

.embed-page > p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.embed-page h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 1.5rem 0 0.75rem;
}

.embed-preview {
    border-radius: 8px;
    overflow: hidden;
}

.embed-code-wrap {
    display: flex;
    flex-direction: column;
}

.embed-code {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: monospace;
    font-size: 0.8rem;
    padding: 0.75rem;
    resize: none;
}

/* Responsive */
@media (max-width: 768px) {
    .about-inner {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

@media (max-width: 640px) {
    main {
        padding: 1rem;
    }

    .header-inner {
        height: auto;
        padding: 0.75rem 0;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .ticker-inner {
        gap: 1rem;
        font-size: 0.8rem;
    }

    .map-legend {
        position: static;
        transform: none;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 0.5rem;
        justify-content: flex-start;
    }

    .map-legend-bar {
        width: 80px;
        height: 10px;
        background: linear-gradient(to right, #16a34a, #eab308, #dc2626);
    }

    .alerts-page {
        max-width: 100%;
    }

    .chart-header {
        flex-direction: column;
        gap: 0.5rem;
    }

    .chart-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .chart-legend {
        justify-content: center;
    }

    .time-range-toggle {
        align-self: center;
    }

    .rankings-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Bottom sheet panel on mobile */
    .state-panel {
        width: 100%;
        height: 75vh;
        top: auto;
        right: 0;
        bottom: -75vh;
        transition: bottom 0.3s ease;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 12px 12px 0 0;
    }

    .state-panel.open {
        right: 0;
        bottom: 0;
    }

    .state-prices {
        flex-direction: row;
    }

    #map-container {
        overflow: hidden;
    }

    #map-container svg {
        max-width: 100vw;
        min-height: 350px;
    }

    .slider-row {
        gap: 0.5rem;
    }

    .play-btn {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    #week-slider {
        height: 32px;
    }
}
