:root {
    color-scheme: dark;
    --bg: #0d1526;
    --surface: #142140;
    --surface-2: #1a2a4e;
    --surface-3: #24365f;
    --border: rgba(148, 178, 255, 0.10);
    --border-strong: rgba(148, 178, 255, 0.22);
    --text: #ecf1fb;
    --text-2: #a9b7d6;
    --text-3: #7186ab;
    --accent: #93bdf5;
    /* warm = higher than reference, cold = lower */
    --warm: #f5a58f;
    --cold: #93bdf5;
    --rain: #82bcec;
    --gold: #e0ba70;
    --error-bg: #331b2a;
    --error-text: #f0abab;
    --radius: 14px;
    --radius-sm: 10px;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 0 14px calc(28px + env(safe-area-inset-bottom));
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.container,
.container-search {
    max-width: 640px;
    margin: 0 auto;
    position: relative;
}


/* ---------- Top bar / wordmark ---------- */

.search-mini {
    position: sticky;
    top: 0;
    z-index: 50;
    margin: 0 -14px 10px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.wordmark {
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.top-bar .icon-search {
    color: var(--text-2);
    display: block;
}


/* ---------- Search panel ---------- */

.app-header {
    display: none;
    padding: 18px 0 6px;
}

.app-title {
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -0.02em;
    margin-bottom: 16px;
}

.search-container {
    position: relative;
    margin-bottom: 16px;
}

.search-box {
    width: 100%;
    padding: 13px 16px 13px 42px;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    font-size: 16px;
    /* 16px prevents iOS zoom */
    font-family: inherit;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

.search-box::placeholder {
    color: var(--text-3);
}

.search-box:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
    pointer-events: none;
    display: flex;
}


/* ---------- Loading spinner ---------- */

.loading {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 100;
}

.search-container .loading {
    left: auto;
    right: 14px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    animation-name: spin-inline;
}

/* Main weather spinner sits in the flow below the header instead of
   hovering over it */
.container > .loading {
    position: static;
    transform: none;
    margin: 36px auto;
    animation-name: spin-static;
}

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

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

@keyframes spin-inline {
    from {
        transform: translateY(-50%) rotate(0deg);
    }
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}


/* ---------- Section labels ---------- */

.section-title,
.section h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
    margin: 20px 0 10px;
}


/* ---------- Location cards ---------- */

.location-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) {
    .location-card:hover {
        border-color: var(--border-strong);
        background: var(--surface-2);
    }
}

.location-card:active {
    background: var(--surface-2);
}

.location-details {
    font-size: 15px;
    font-weight: 550;
    margin-bottom: 3px;
}

.location-coords {
    font-size: 12px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.location-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}


/* ---------- Buttons ---------- */

.default-btn {
    background: var(--surface-3);
    color: var(--text-2);
    border: 1px solid transparent;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 550;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

@media (hover: hover) {
    .default-btn:hover {
        color: var(--text);
        border-color: var(--border-strong);
    }
}

.default-btn.is-default {
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 40%, transparent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.star-btn {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: var(--text-3);
    transition: color 0.15s ease;
}

.star-btn.starred {
    color: var(--gold);
}

.default-badge {
    display: inline-block;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-left: 6px;
    vertical-align: 2px;
}


/* ---------- Messages / empty state ---------- */

.error,
.error-message {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--error-text) 25%, transparent);
    font-size: 14px;
    text-align: center;
    margin-bottom: 16px;
}

.empty-state {
    text-align: center;
    color: var(--text-3);
    padding: 40px 20px;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 13px;
    line-height: 1.5;
    max-width: 34ch;
    margin: 0 auto;
}


/* ---------- Weather header ---------- */

.header {
    text-align: center;
    padding: 4px 0 2px;
}

.header h3 {
    font-size: 24px;
    font-weight: 650;
    letter-spacing: -0.02em;
}


/* ---------- Tables (shared) ---------- */

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 5px 2px;
    text-align: left;
}

th {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
}

td {
    font-size: 14px;
    border-top: 1px solid var(--border);
}

tbody tr:first-child td {
    border-top: none;
}

thead + tbody tr:first-child td {
    border-top: 1px solid var(--border);
}

.provider-name {
    font-weight: 550;
    color: var(--text-2);
    font-size: 12px;
}

.temp-cell {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.temp-zero {
    color: var(--text);
}

.temp-positive {
    color: var(--warm);
}

.temp-negative {
    color: var(--cold);
}

.rain-cell {
    color: var(--rain);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

/* Daily min/max range */

.temp-range-cell-1,
.temp-range-cell-3 {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.temp-range-cell-1 {
    color: var(--cold);
}

.temp-range-cell-3 {
    color: var(--warm);
}

.temp-range-cell-2 {
    width: 18px;
    text-align: center;
}

.temp-range-cell-2::after {
    content: "–";
    color: var(--text-3);
    font-weight: 400;
}


/* ---------- Card titles ---------- */

.hour-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    margin-bottom: 6px;
}

.hour-title::first-letter {
    text-transform: uppercase;
}


/* ---------- Overview (now, 2x2) ---------- */

.overview {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 14px 0 4px;
}

.overview-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    min-width: 0;
}

.overview .provider-name {
    font-size: 11px;
}

.overview td {
    font-size: 13px;
    padding: 4px 2px;
}

.overview .rain-cell {
    font-size: 11.5px;
}


/* ---------- Today ---------- */

.today-section {
    margin: 12px 0 4px;
}

.today-header {
    padding: 12px 14px 10px;
    font-size: 14px;
    font-weight: 600;
}


/* ---------- Daily forecast ---------- */

.daily-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.day-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.day-block {
    padding: 12px 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .day-block:hover {
        background: var(--surface-2);
    }
}

.day-block .hour-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 8px;
}

.day-block .chevron {
    color: var(--text-3);
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.day-block.show .chevron {
    transform: rotate(180deg);
}


/* ---------- Expanded day: comparison grid ---------- */

.extended-day-block {
    border-top: 1px solid var(--border);
    padding: 2px 14px 12px;
}

.day-grid {
    table-layout: fixed;
}

.day-grid th,
.day-grid td {
    text-align: center;
}

.day-grid th:first-child,
.day-grid td:first-child {
    text-align: left;
    width: 21%;
}

.day-grid th {
    padding: 10px 2px 7px;
}

.day-grid td {
    padding: 7px 2px;
    border-top: 1px solid var(--border);
}

.grid-time {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.grid-symbol {
    margin-left: 5px;
    font-size: 13px;
}

.g-temp {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.g-rain {
    font-size: 10.5px;
    color: var(--rain);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}

.g-rain-none {
    color: var(--text-3);
    opacity: 0.55;
}

.g-missing {
    color: var(--text-3);
    font-weight: 400;
}


/* ---------- Day chart ---------- */

.day-chart {
    padding: 10px 0 4px;
}

.day-chart-svg {
    width: 100%;
    height: auto;
    display: block;
    /* horizontal drags scrub, vertical drags scroll the page */
    touch-action: pan-y;
    cursor: crosshair;
}

.chart-readout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    min-height: 18px;
    margin-bottom: 4px;
    font-size: 11.5px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.chart-readout strong {
    color: var(--text);
    font-weight: 600;
}

.chart-key {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.chart-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.chart-grid {
    stroke: rgba(148, 178, 255, 0.12);
    stroke-width: 1;
}

.chart-label {
    fill: var(--text-3);
    font-size: 9px;
    font-family: inherit;
}

.chart-rain {
    fill: var(--rain);
    opacity: 0.45;
}

.chart-rain-text {
    color: var(--rain);
}

.chart-cursor {
    stroke: rgba(178, 200, 255, 0.45);
    stroke-width: 1;
}

/* Second-stage toggle: chart shows first, grid revealed on demand */
.grid-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 0 11px;
    margin: 0;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-2);
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.grid-toggle .chevron {
    transition: transform 0.18s ease;
}

.grid-collapse {
    display: none;
}

.extended-day-block.grid-open .grid-collapse {
    display: block;
}

.extended-day-block.grid-open .grid-toggle .chevron {
    transform: rotate(180deg);
}


/* ---------- Footer ---------- */

.last-updated {
    text-align: center;
    color: var(--text-3);
    font-size: 11px;
    margin-top: 24px;
    font-variant-numeric: tabular-nums;
}

.app-footer {
    text-align: center;
    color: var(--text-3);
    font-size: 11px;
    margin-top: auto;
    padding-top: 12px;
}

.info-bar {
    max-width: 640px;
    margin: 0 auto 10px;
    text-align: left;
}

.info-bar summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    list-style: none;
    -webkit-tap-highlight-color: transparent;
    color: var(--text-3);
    transition: color 0.15s ease;
}

.info-bar summary::-webkit-details-marker {
    display: none;
}

@media (hover: hover) {
    .info-bar summary:hover {
        color: var(--text-2);
    }
}

.info-bar[open] summary {
    color: var(--text-2);
}

.info-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-2);
}

.info-content p {
    margin: 0 0 6px;
}

.info-content p:last-child {
    margin-bottom: 0;
}

.info-content ul {
    list-style: none;
    margin: 0 0 6px;
}

.info-content a {
    color: var(--accent);
    text-decoration: none;
}

.app-footer a {
    color: var(--text-2);
    font-weight: 550;
    text-decoration: none;
}

@media (hover: hover) {
    .app-footer a:hover {
        color: var(--accent);
    }
}
