:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1d1d1f;
    --text2: #86868b;
    --accent: #0071e3;
    --orange: #ff9500;
    --green: #34c759;
    --red: #ff3b30;
    --yellow: #ffcc00;
    --border: rgba(0, 0, 0, 0.04);
    --radius: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

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

html,
body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding: 20px;
}

.app {
    max-width: 980px;
    margin: 0 auto;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}

.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.app-header .status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text2);
    font-weight: 500;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18);
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .4
    }
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.card-title {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    border-radius: 100px;
    margin-left: 4px;
}

@media (max-width: 640px) {
    body {
        padding: 12px;
    }

    .card {
        padding: 16px;
        border-radius: 16px;
    }

    .app-header h1 {
        font-size: 22px;
    }
}

/* Hero / Summary */
.hero {
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
}

.hero-main {
    flex: 1 1 auto;
}

.hero-emoji {
    font-size: 56px;
    line-height: 1;
    margin-bottom: 4px;
}

.hero-emoji img {
    width: 1em;
    height: 1em;
    object-fit: contain;
    display: block;
}

.hero-temp {
    font-size: 72px;
    font-weight: 300;
    letter-spacing: -2px;
    line-height: 1;
}

.hero-skycon {
    font-size: 18px;
    color: var(--text2);
    margin-top: 4px;
}

.hero-meta {
    flex: 1 1 260px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 12px;
    font-size: 13px;
}

.meta-row span {
    color: var(--text2);
}

.meta-row b {
    font-weight: 600;
}

@media (max-width: 640px) {
    .hero-temp {
        font-size: 56px;
    }

    .hero-emoji {
        font-size: 44px;
    }

    .hero-meta {
        grid-template-columns: 1fr;
    }
}

/* KV Grid */
.kv-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 640px) {
    .kv-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.kv {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px;
    background: var(--bg);
    border-radius: 12px;
}

.kv span {
    font-size: 12px;
    color: var(--text2);
}

.kv b {
    font-size: 15px;
    font-weight: 600;
}

/* Alerts */
.alert-item {
    padding: 16px;
    background: var(--bg);
    border-radius: 14px;
    border-left: 4px solid var(--text2);
    margin-bottom: 12px;
}

.alert-item:last-child {
    margin-bottom: 0;
}

.alert-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
}

.alert-desc {
    font-size: 13px;
    color: var(--text);
    line-height: 1.7;
}

.alert-foot {
    font-size: 12px;
    color: var(--text2);
    margin-top: 8px;
}

/* Charts */
.chart-wrap {
    position: relative;
    height: 260px;
}

.minichart-wrap {
    position: relative;
    height: 140px;
    margin-top: 12px;
}

@media (max-width: 640px) {
    .chart-wrap {
        height: 220px;
    }
}

/* Scroll list (hourly) */
.scroll-list {
    margin-top: 16px;
    max-height: 320px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    -webkit-overflow-scrolling: touch;
}

.hrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 4px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
    gap: 8px;
}

.hrow span {
    min-width: 0;
}

.hrow span:first-child {
    color: var(--text2);
    width: 100px;
    flex-shrink: 0;
}

.hrow span:nth-child(2) {
    flex: 1;
    text-align: center;
}

.hrow span:nth-child(3) {
    width: 60px;
    text-align: right;
    font-weight: 600;
}

.hrow span:nth-child(4) {
    width: 50px;
    text-align: right;
    color: var(--accent);
}

/* Daily grid */
.daily-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.ditem {
    background: var(--bg);
    border-radius: 16px;
    padding: 16px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ditem-date {
    font-size: 12px;
    color: var(--text2);
    font-weight: 500;
}

.ditem-sky {
    font-size: 13px;
    font-weight: 600;
}

.ditem-temp {
    font-size: 16px;
    font-weight: 700;
}

.ditem-prec {
    font-size: 11px;
    color: var(--accent);
}

.ditem-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin-top: 2px;
}

.tag {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 100px;
    background: rgba(0, 0, 0, 0.04);
    color: var(--text2);
    font-weight: 500;
}

/* Life index */
.life-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.ltag {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px;
    background: var(--bg);
    border-radius: 14px;
    text-align: center;
}

.ltag span {
    font-size: 12px;
    color: var(--text2);
}

.ltag b {
    font-size: 15px;
    font-weight: 600;
}

/* Summary extra */
.sum-extra {
    width: 100%;
    margin-top: 16px;
}

.sum-toggle {
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    background: var(--bg);
    border: none;
    border-radius: 12px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}

.sum-toggle:hover {
    background: rgba(0, 113, 227, 0.08);
}

/* Forecast tabs */
.forecast-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.forecast-tabs button {
    flex: 1;
    padding: 10px;
    background: var(--bg);
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    transition: all .2s;
}

.forecast-tabs button.active {
    background: var(--text);
    color: var(--surface);
}

/* Raw */
.raw-pre {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    overflow: auto;
    max-height: 80vh;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.error {
    color: var(--red);
}

#rawView,
#alertsCard {
    display: none;
}

#hourlyDesc {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 12px;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0, 0, 0, 0.08);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

#visualView {
    position: relative;
}

#visualView::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 113, 227, 0.05);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

#visualView.update-flash::before {
    animation: gentleFlash .6s ease;
}

@keyframes gentleFlash {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}