:root {
    --bg: #eef3f8;
    --card: #ffffff;
    --card-2: #f5f8fb;
    --text: #13212e;
    --muted: #5b6b7a;
    --line: #dde5ec;
    --accent: #1b6fd1;
    --accent-text: #ffffff;
    --warm: #c2410c;
    --cold: #1d5fb8;
    --rain: #2f80ed;
    --rain-bg: rgba(47, 128, 237, 0.14);
    --range: linear-gradient(90deg, #5aa0f0, #f2b134);
    --danger: #b42318;
    --shadow: 0 1px 2px rgba(16, 33, 48, 0.06), 0 6px 20px rgba(16, 33, 48, 0.07);
    --radius: 20px;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1720;
        --card: #18222d;
        --card-2: #1f2b37;
        --text: #e7edf3;
        --muted: #93a3b3;
        --line: #2a3846;
        --accent: #4d9bf0;
        --accent-text: #0b1520;
        --warm: #fb923c;
        --cold: #7ab4ff;
        --rain: #64a6ff;
        --rain-bg: rgba(100, 166, 255, 0.16);
        --range: linear-gradient(90deg, #4f8fdc, #e0a43a);
        --danger: #f97066;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0f1720; --card: #18222d; --card-2: #1f2b37; --text: #e7edf3; --muted: #93a3b3; --line: #2a3846;
    --accent: #4d9bf0; --accent-text: #0b1520; --warm: #fb923c; --cold: #7ab4ff; --rain: #64a6ff;
    --rain-bg: rgba(100, 166, 255, 0.16); --range: linear-gradient(90deg, #4f8fdc, #e0a43a); --danger: #f97066;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
}
a { color: inherit; }
button {
    font: inherit;
    border: 0;
    border-radius: 999px;
    padding: 0.5em 1em;
    cursor: pointer;
    color: var(--text);
    background: var(--card-2);
}
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, .hours:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Page chrome */
.top {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    max-width: 1240px; margin: 0 auto; padding: 16px 16px 4px;
}
.top h1 { font-size: 1.25rem; margin: 0; letter-spacing: 0.01em; }
.top-actions { display: flex; gap: 8px; }
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
    gap: 16px;
    align-items: start;
    max-width: 1240px; margin: 0 auto; padding: 12px 16px 16px;
}
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.page-foot { max-width: 1240px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: 0.8rem; }

/* Card = the widget */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px 10px;
    min-width: 0;
    overflow: hidden;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.place { min-width: 0; }
.place h2 { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place .pin { color: var(--accent); font-size: 0.8em; }
.region { color: var(--muted); font-size: 0.8rem; }
.menu-btn { background: transparent; padding: 0 8px; font-size: 1.3rem; line-height: 1; color: var(--muted); margin: -4px -8px 0 0; }
.card-foot { display: flex; justify-content: flex-end; gap: 8px; font-size: 0.7rem; color: var(--muted); margin-top: 8px; }
.card-foot a { text-decoration: none; }
.card-foot a:hover { text-decoration: underline; }
.stale { color: var(--warm); margin-right: auto; }
.msg { padding: 28px 0; text-align: center; color: var(--muted); }
.msg.error { color: var(--danger); }
.sym { display: inline-block; flex: none; line-height: 0; }
.sym img { display: block; }

/* Now block */
.now {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "icon main" "details details" "source source";
    align-items: center;
    column-gap: 10px;
    margin-top: 4px;
}
.now > .sym { grid-area: icon; margin: -6px -4px -6px -8px; }
.now-main { grid-area: main; min-width: 0; }
.now-temp { font-size: 2.6rem; font-weight: 650; line-height: 1.05; letter-spacing: -0.02em; }
.now-text { color: var(--muted); font-size: 0.9rem; }
.now-details > span { white-space: nowrap; }
.now-details { grid-area: details; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 0.9rem; }
.now-source { grid-area: source; color: var(--muted); font-size: 0.72rem; margin-top: 2px; }
.now.compact { grid-template-columns: auto auto 1fr; grid-template-areas: "icon main details" "source source source"; }
.now.compact .now-temp { font-size: 2rem; }
.now.compact .now-details { flex-direction: column; align-items: flex-end; gap: 0; margin: 0; font-size: 0.82rem; text-align: right; }
.wind { white-space: nowrap; }
.wind small { color: var(--muted); }
.warrow { vertical-align: -2px; margin-right: 2px; color: var(--muted); }

/* Hourly strip */
.hours {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    margin: 10px -16px 0;
    padding: 0 10px 4px;
    scrollbar-width: thin;
    border-top: 1px solid var(--line);
}
.hour {
    flex: 0 0 52px;
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding-top: 8px;
    scroll-snap-align: start;
    font-size: 0.82rem;
}
.hour.midnight { border-left: 1px solid var(--line); }
.h-time { color: var(--muted); height: 1.3em; }
.h-time b { color: var(--text); font-weight: 600; }
.h-temp { font-weight: 600; font-size: 0.95rem; }
.warm { color: var(--warm); }
.cold { color: var(--cold); }
.h-wind { font-size: 0.75rem; padding-bottom: 4px; }
.h-rain { position: relative; width: 26px; height: 26px; margin-top: 2px; display: flex; align-items: flex-end; justify-content: center; }
.h-rain i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--rain-bg); border-radius: 3px 3px 0 0; }
.h-rain span { position: relative; font-size: 0.68rem; color: var(--rain); font-weight: 600; }

/* 3 days */
.days3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.day { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; background: var(--card-2); border-radius: 14px; padding: 8px 4px; min-width: 0; }
.d-name { font-weight: 600; font-size: 0.88rem; text-transform: capitalize; white-space: nowrap; }
.d-name small { color: var(--muted); font-weight: 400; }
.d-temps .max, .days10 .max { font-weight: 650; }
.d-temps { font-size: 1.05rem; }
.d-extra { font-size: 0.72rem; color: var(--muted); }
.d-extra .rain, .days10 .rain { color: var(--rain); font-weight: 600; }

/* 10 days */
.days10 { margin-top: 10px; border-top: 1px solid var(--line); }
.drow {
    display: grid;
    grid-template-columns: 4.6em 32px 2.6em 1fr 2.6em 3.8em;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    border-bottom: 1px solid var(--line);
    font-size: 0.88rem;
}
.drow:last-child { border-bottom: 0; }
.drow .d-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
.drow .min, .drow .max { text-align: right; }
.drow .rain { text-align: right; font-size: 0.75rem; white-space: nowrap; }
.drow .rain small { font-weight: 400; color: var(--muted); }
.trange { position: relative; height: 6px; border-radius: 3px; background: var(--card-2); }
.trange i { position: absolute; top: 0; bottom: 0; border-radius: 3px; background: var(--range); }

/* Dialog */
dialog {
    border: 0; border-radius: var(--radius); padding: 0;
    background: var(--card); color: var(--text);
    width: min(420px, calc(100vw - 32px));
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(10, 20, 30, 0.45); }
#card-form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
#card-form h2 { margin: 0; font-size: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.field input {
    font: inherit; font-size: 1rem; color: var(--text); background: var(--card-2);
    border: 1px solid var(--line); border-radius: 12px; padding: 0.6em 0.8em;
}
.field input:disabled { opacity: 0.5; }
.check { display: flex; align-items: center; gap: 8px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.variants { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.variants label { display: flex; align-items: center; gap: 6px; background: var(--card-2); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.form-error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 0.85rem; }
.edit-only { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-only[hidden] { display: none; }
.edit-only .danger { margin-left: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Single-card embed page */
body.single { background: transparent; padding: 8px; }
body.single .card { max-width: 480px; margin: 0 auto; }

@media (max-width: 380px) {
    .card { padding: 12px 12px 8px; }
    .hours { margin: 10px -12px 0; }
    .drow { grid-template-columns: 3.8em 28px 2.4em 1fr 2.4em 3em; gap: 4px; }
}
