:root {
    --bg: #0a0a0f;
    --surface: #12121a;
    --surface2: #1a1a24;
    --border: #2a2a3a;
    --text: #e4e4ef;
    --text-dim: #8a8a9f;
    --accent: #6e9eff;
    --snow: #a5d8ff;
    --precip: #51cf66;
    --temp: #ff8787;
    --wind: #ffd43b;
}

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

html {
    font-size: 16px;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 60px;
    line-height: 1.4;
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============ Header ============ */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.title .snow-alert {
    background: var(--snow);
    color: #000;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ============ Form Elements ============ */
select,
input[type="date"] {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 40px;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--accent);
}

select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn {
    background: var(--accent);
    color: #000;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 40px;
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

.btn-group {
    display: flex;
    background: var(--surface2);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.btn-group button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 40px;
}

.btn-group button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.btn-group button.active {
    background: var(--accent);
    color: #000;
    font-weight: 600;
}

.time-display {
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.85rem;
    color: var(--text-dim);
    background: var(--surface2);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    min-height: 40px;
    display: flex;
    align-items: center;
}

/* Custom Station Input */
#customStation {
    width: 60px;
    min-width: 60px;
    max-width: 60px;
    text-align: center;
    text-transform: uppercase;
    font-weight: 500;
    font-family: inherit;
    font-size: 0.9rem;
    /* Reset browser defaults aggressively */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: transparent !important;
    background: transparent !important;
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    color: var(--text) !important;
    padding: 0.5rem;
    height: 40px;
    box-sizing: border-box;
    margin: 0;
}

#customStation::placeholder {
    color: var(--text-dim);
    opacity: 0.6;
}

#customStation:focus {
    outline: none;
    background-color: rgba(128, 128, 128, 0.15) !important;
}

/* Custom Station Go Button */
#customStationBtn {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    min-height: 40px;
}

/* Help Button */
.help-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 50%;
    min-height: auto;
}

/* ============ Weather Summary Bar ============ */
.summary-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1rem;
    text-align: center;
    font-size: 0.95rem;
}

.summary-bar .snow-icon {
    margin-right: 0.3rem;
}

.summary-bar .high-confidence {
    color: var(--precip);
}

.summary-bar .moderate-confidence {
    color: var(--wind);
}

.summary-bar .low-confidence {
    color: var(--temp);
}

.summary-bar .trend-text {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

/* Run comparison toggle colors */
.run-toggle-03 {
    color: #ff9f43;
}

.run-toggle-09 {
    color: #10ac84;
}

.run-toggle-15 {
    color: #ee5a24;
}

.run-toggle-21 {
    color: #8854d0;
}

.run-comparison {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    margin-left: 1.5rem;
    font-size: 0.85rem;
    border-left: 1px solid var(--border);
    padding-left: 1rem;
}

.comp-label {
    color: var(--text-dim);
    font-weight: 500;
}

.run-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.run-toggle:hover,
.run-toggle:has(input:checked) {
    opacity: 1;
}

.run-toggle input {
    accent-color: currentColor;
    cursor: pointer;
}

/* Chart Mode Toggle */
.chart-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: 0.5rem;
    padding-left: 0.8rem;
    border-left: 1px solid var(--border);
}

.mode-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}

.mode-btn:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

.mode-btn.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* ============ Tooltips ============ */
.tooltip-trigger {
    position: relative;
    cursor: help;
}

.tooltip-trigger::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    z-index: 1000;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 250px;
    white-space: normal;
    text-align: left;
}

.tooltip-trigger:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Download Button - in summary row, right-aligned */
.download-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: auto;
    white-space: nowrap;
}

.download-btn:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* ============ Main Content ============ */
.main {
    padding: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

.chart-section {
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
    flex-wrap: wrap;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.view-toggle {
    display: flex;
    background: var(--surface2);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.view-toggle button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.view-toggle button:hover {
    color: var(--text);
}

.view-toggle button.active {
    background: var(--accent);
    color: #000;
    font-weight: 500;
}

.mean-legend {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-left: auto;
}

.mean-line {
    width: 20px;
    height: 3px;
    background: #fff;
    border-radius: 2px;
}

/* ============ Chart Cards ============ */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.chart-card.featured {
    border-color: var(--snow);
    box-shadow: 0 0 20px rgba(165, 216, 255, 0.1);
}

.chart-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chart-title-area {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.chart-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.chart-subtitle {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.unit-toggle {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    margin-left: 0.3rem;
}

.unit-toggle:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.chart-actions {
    display: flex;
    gap: 0.4rem;
}

.chart-actions button {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chart-actions button:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

.chart-actions button.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 500;
}

.chart-body {
    padding: 0.75rem;
    height: 300px;
    position: relative;
}

.chart-card.featured .chart-body {
    height: 360px;
}

.axis-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-align: center;
    padding: 0.4rem 0;
    border-top: 1px solid var(--border);
}

/* ============ Loading States ============ */
.loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1rem;
    flex-direction: column;
    gap: 0.5rem;
}

.loading.hidden {
    display: none;
}

.error {
    color: #ff6b6b;
}

/* ============ Skeleton Loaders ============ */
.skeleton {
    background: linear-gradient(90deg, var(--surface2) 25%, var(--surface) 50%, var(--surface2) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-chart {
    height: 100%;
    width: 100%;
    border-radius: 8px;
}

.skeleton-summary {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface2);
}

.skeleton-stat {
    width: 60px;
    height: 32px;
}

/* ============ Summary Row ============ */
.summary-row {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    flex-wrap: wrap;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.summary-label {
    color: var(--text-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.summary-value {
    font-weight: 700;
    font-size: 1.25rem;
}

.summary-value.snow {
    color: var(--snow);
}

.summary-value.precip {
    color: var(--precip);
}

.summary-value.temp {
    color: var(--temp);
}

.summary-value.wind {
    color: var(--wind);
}

/* ============ Grid Layout ============ */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1rem;
}

/* ============ Status Bar ============ */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ============ Run Status Indicator ============ */
.run-status {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.run-status.available {
    background: rgba(81, 207, 102, 0.2);
    color: var(--precip);
}

.run-status.unavailable {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

/* ============ Mobile Responsive ============ */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }

    .header {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .title {
        font-size: 1.1rem;
        width: 100%;
    }

    .controls {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 0.5rem;
    }

    .btn-group {
        grid-column: span 3;
        justify-content: center;
    }

    .main {
        padding: 0.5rem;
        max-width: 100%;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .chart-card {
        max-width: 100%;
        overflow: hidden;
    }

    .chart-body {
        height: 260px;
    }

    .chart-card.featured .chart-body {
        height: 300px;
    }

    .summary-row {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
        text-align: center;
    }

    .summary-item {
        align-items: center;
    }

    .summary-value {
        font-size: 1.1rem;
    }

    .time-display {
        display: none;
    }

    .mean-legend {
        display: none;
    }

    .chart-title {
        font-size: 1rem;
    }

    .chart-actions button {
        min-width: 44px;
        min-height: 36px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .title {
        font-size: 1rem;
    }

    .title .snow-alert {
        font-size: 0.7rem;
    }

    .btn-group button {
        padding: 0.5rem 0.7rem;
        font-size: 0.85rem;
    }

    .chart-body {
        height: 240px;
        padding: 0.5rem;
    }

    .chart-card.featured .chart-body {
        height: 280px;
    }

    .summary-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .chart-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    select,
    input[type="date"] {
        font-size: 16px;
        /* Prevents iOS zoom */
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 0.4rem 0.75rem;
    }

    .chart-body {
        height: 200px;
    }

    .chart-card.featured .chart-body {
        height: 220px;
    }

    body {
        padding-bottom: 45px;
    }
}

/* Light mode - responds to system preference */
@media (prefers-color-scheme: light) {
    :root {
        --bg: #f5f5f7;
        --surface: #ffffff;
        --surface2: #e8e8ed;
        --border: #d1d1d6;
        --text: #1c1c1e;
        --text-dim: #6e6e73;
        --accent: #0066cc;
        --snow: #0066cc;
        --precip: #34a853;
        --temp: #ea4335;
        --wind: #f9ab00;
    }

    .chart-card {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .chart-card.featured {
        border-color: var(--accent);
        box-shadow: 0 2px 8px rgba(0, 102, 204, 0.15);
    }

    .title .snow-alert {
        background: var(--accent);
        color: #fff;
    }

    .btn-group button.active,
    .view-toggle button.active,
    .chart-actions button.active {
        background: var(--accent);
        color: #fff;
    }

    .unit-toggle {
        color: var(--accent);
    }

    .unit-toggle:hover {
        background: var(--accent);
        color: #fff;
    }

    .mean-line {
        background: #333;
    }

    /* Light mode: custom station input */
    #customStation {
        color: var(--text-dim);
        background: rgba(0, 0, 0, 0.05);
    }

    #customStation:focus {
        background: rgba(0, 0, 0, 0.08);
        color: var(--text);
    }

    /* Light mode: modal */
    .modal-overlay {
        background: rgba(0, 0, 0, 0.5);
    }

    /* Light mode: download button */
    .download-btn {
        border-color: var(--border);
        color: var(--text-dim);
    }

    .download-btn:hover {
        background: var(--surface2);
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Safe area insets for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: max(0.75rem, env(safe-area-inset-top));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .status-bar {
        padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    body {
        padding-bottom: max(60px, calc(60px + env(safe-area-inset-bottom)));
    }
}

/* ============ Modal ============ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--text);
    font-size: 1.25rem;
}

.modal-content h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
    font-size: 1rem;
}

.modal-content p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.modal-content ul {
    color: var(--text-dim);
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}

.modal-content li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

.modal-content .btn {
    margin-top: 1rem;
    width: 100%;
}