/* Wetter Tessin – base styles (no build step) */
@font-face {
    font-family: "Fredoka";
    src: url("../fonts/fredoka.woff") format("woff");
    font-weight: 300 700;
    font-stretch: 75% 125%;
    font-display: swap;
}
@font-face {
    font-family: "Nunito";
    src: url("../fonts/nunito.woff") format("woff");
    font-weight: 200 1000;
    font-display: swap;
}

/* Palette: Lago di Lugano – lake teal, pine green, Ticino stone, summer sun */
:root {
    --bg: #eaf4f5;
    --surface: #ffffff;
    --surface-2: #e1eff1;
    --text: #173340;
    --muted: #587482;
    --border: #cfe2e6;
    --accent: #137a89;
    --accent-contrast: #ffffff;
    --sun: #e9a52a;
    --sun-text: #a3620a;
    --pine: #2f6b4f;
    --ok: #1e8a4c;
    --warn: #b7791f;
    --bad: #c53030;
    --radius: 16px;
    --shadow: 0 1px 0 rgba(23, 51, 64, .06);
    --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --display: "Fredoka", "Nunito", system-ui, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1c24;
        --surface: #142a34;
        --surface-2: #1a3440;
        --text: #e4f0f2;
        --muted: #93aeb8;
        --border: #24424f;
        --accent: #4fb8c6;
        --accent-contrast: #0d1c24;
        --sun: #f3c25a;
        --sun-text: #f3c25a;
        --pine: #5fae86;
        --ok: #45c37b;
        --warn: #e0a43a;
        --bad: #f06a6a;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.55 var(--font);
}
a { color: var(--accent); }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .75rem; font-family: var(--display); font-weight: 600; letter-spacing: .005em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* Header: animated sky with lake, hills and tents */
.site-header { position: relative; background: var(--bg); }
.sky { position: relative; height: clamp(170px, 24vw, 260px); overflow: hidden; background: #8fcfdd; --l-far: #86b3a6; --l-hill: #3f7d5e; --l-meadow: #6aa565; --l-lake: #1f8b9b; --l-wave: #e9f6f7; --l-sand: #dcd3b0; --l-tree: #3a7a4c; --l-tree-dark: #2c633e; --l-palm: #2f7a45; --l-trunk: #7a5a3a; --l-white: #f5f7f8; --l-white-edge: #c6cfd4; }
.sky canvas, .sky .landscape { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sky .landscape { pointer-events: none; }
.scene-title { position: absolute; top: clamp(12px, 3vw, 28px); left: 0; right: 0; pointer-events: none; }
.brand { pointer-events: auto; text-decoration: none; color: #173340; display: inline-flex; flex-direction: column; }
.site-header.is-night .brand { color: #eef6f7; }
.brand { text-shadow: 0 1px 12px rgba(255, 255, 255, .35); }
.site-header.is-night .brand { text-shadow: 0 1px 12px rgba(0, 0, 0, .45); }
.brand strong { font-family: var(--display); font-weight: 600; font-size: clamp(1.6rem, 4vw, 2.6rem); line-height: 1; }
.brand span { font-size: clamp(.9rem, 1.6vw, 1.05rem); opacity: .85; margin-top: .3rem; }
.nav-bar { background: var(--bg); }
.nav { display: flex; flex-wrap: wrap; gap: .35rem; padding: .75rem 0 0; }
.nav a { font-family: var(--display); font-weight: 500; text-decoration: none; color: var(--text); padding: .4rem .95rem; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--border); }
.nav a:hover { border-color: var(--accent); }
.nav a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.nav a:focus-visible, .btn:focus-visible, .segmented a:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

main { padding: 1.5rem 0 3rem; }
.site-footer { color: var(--muted); font-size: .85rem; padding: 1.5rem 0 2rem; border-top: 1px solid var(--border); }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; }

/* Cards / grid */
.card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid .card { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.spacer { flex: 1; }

/* Weather values */
.module-card h2 { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.module-card h2 small { font-family: var(--font); font-weight: 400; color: var(--muted); font-size: .8rem; }
.module-card h2 .icon { width: 1.4em; height: 1.4em; vertical-align: -.3em; margin-right: .35rem; color: var(--accent); }
.module-card.outdoor { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.hilo .hi { color: var(--sun-text); font-weight: 700; }
.hilo .lo { color: var(--accent); font-weight: 700; }
.big-value { font-family: var(--display); font-size: 3rem; font-weight: 500; line-height: 1.1; margin: .25rem 0 .5rem; font-variant-numeric: tabular-nums; }
.big-value .unit { font-size: 1.3rem; color: var(--muted); font-weight: 400; margin-left: .15rem; }
.values { display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; margin: 0; }
.values dt { color: var(--muted); }
.values dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

/* Status badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.stale { color: var(--warn); }
.badge.missing, .badge.bad { color: var(--bad); }
.badge.off { color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field .hint { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], select, textarea {
    width: 100%; padding: .55rem .65rem; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
textarea { min-height: 8rem; font-family: var(--mono); font-size: .9rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.check input { width: 1.1rem; height: 1.1rem; }
.fields-2 { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.inline-form { display: inline; }

.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1.05rem; font: inherit; font-family: var(--display); font-weight: 500; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid; }
.alert.ok { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.alert.bad { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.alert ul { margin: 0; padding-left: 1.2rem; }

/* Segmented control (history ranges): single pills that wrap cleanly */
.segmented { display: flex; flex-wrap: wrap; gap: .35rem; }
.segmented a { font-family: var(--display); padding: .35rem .8rem; text-decoration: none; color: var(--muted); border: 1.5px solid var(--border); border-radius: 999px; background: var(--surface); white-space: nowrap; }
.segmented a:hover { border-color: var(--accent); color: var(--text); }
.segmented a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

.chart { width: 100%; height: 420px; }
@media (max-width: 600px) { .chart { height: 320px; } .big-value { font-size: 2.1rem; } }

/* Webcam / timelapse */
.webcam img { border-radius: var(--radius); width: 100%; }
.timelapse-stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.timelapse-stage img { width: 100%; height: 100%; object-fit: contain; }
.timelapse-stage .stamp { position: absolute; left: .75rem; bottom: .6rem; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; font-variant-numeric: tabular-nums; }
.timelapse-controls { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; margin-top: .75rem; }
.timelapse-controls input[type=range] { flex: 1; min-width: 160px; }

.embed-frame { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

/* Admin */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.admin-nav { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; }
.admin-nav .brand { padding: 0 .5rem 1rem; }
.admin-nav a.item { display: block; padding: .45rem .6rem; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.admin-nav a.item:hover { background: var(--surface-2); color: var(--text); }
.admin-nav a.item.active { background: var(--accent); color: var(--accent-contrast); }
.admin-nav .section { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; margin: 1rem .6rem .35rem; }
.admin-main { padding: 1.5rem; max-width: 1000px; width: 100%; }
@media (max-width: 800px) {
    .admin-layout { grid-template-columns: 1fr; }
    .admin-nav { border-right: 0; border-bottom: 1px solid var(--border); }
    .admin-main { padding: 1rem 16px; }
}

.auth-box { max-width: 460px; margin: 3rem auto; padding: 0 16px; }
.wind-arrow { display: inline-block; font-weight: 700; margin-left: .2rem; }

/* Nerd mode */
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.stat { background: var(--surface-2); border-radius: 12px; padding: .75rem .9rem; display: flex; flex-direction: column; gap: .15rem; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-family: var(--display); font-size: 1.5rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; font-family: var(--display); font-weight: 500; padding: .2rem .75rem; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); }

/* Nerd mode switch (persisted per visitor) */
.nerd-only { display: none !important; }
html.nerd .nerd-only { display: revert !important; }
html.nerd .nav a.nerd-only { display: inline-block !important; }
.nerd-switch { margin-left: auto; display: inline-flex; align-items: center; gap: .5rem; font: inherit; font-family: var(--display); font-weight: 500; color: var(--muted); background: none; border: 0; padding: .4rem .2rem; cursor: pointer; }
.nerd-switch .track { width: 2.4rem; height: 1.35rem; border-radius: 999px; background: var(--border); position: relative; transition: background .2s; }
.nerd-switch .knob { position: absolute; top: .175rem; left: .2rem; width: 1rem; height: 1rem; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.nerd-switch[aria-checked="true"] { color: var(--text); }
.nerd-switch[aria-checked="true"] .track { background: var(--accent); }
.nerd-switch[aria-checked="true"] .knob { transform: translateX(1rem); }
.nerd-switch:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) { .nerd-switch .track, .nerd-switch .knob { transition: none; } }
.nerd-note { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
.big-value + .nerd-note { margin: -.35rem 0 .5rem; }

.sky-controls { background: var(--surface); border-bottom: 1.5px solid var(--border); }
html.nerd .sky-controls.nerd-only { display: block !important; }
.sky-controls .container { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding-top: .6rem; padding-bottom: .6rem; }
.sky-controls label { margin: 0; font-family: var(--display); font-weight: 500; }
.sky-controls input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.sky-controls output { font-variant-numeric: tabular-nums; min-width: 6.5em; }
.sky-controls select { width: auto; }
html.nerd .nerd-note.nerd-only { display: block !important; }
.admin-nav .brand strong { font-size: 1.35rem; }
.admin-nav .brand { text-shadow: none; }

/* Info: status lists */
.status-grid { margin-bottom: 1rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.status-card h3 { margin-bottom: .5rem; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-row { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "dot name state" "dot age age"; column-gap: .65rem; row-gap: 0; align-items: center; padding: .6rem 0; border-top: 1px solid var(--border); }
.status-row:first-child { border-top: 0; }
.status-dot { grid-area: dot; width: .8rem; height: .8rem; border-radius: 50%; background: var(--muted); align-self: start; margin-top: .45rem; }
.status-row.ok .status-dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.status-row.stale .status-dot { background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 20%, transparent); }
.status-row.missing .status-dot { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 20%, transparent); }
.status-name { grid-area: name; font-weight: 600; }
.status-state { grid-area: state; font-family: var(--display); font-weight: 500; white-space: nowrap; }
.status-row.ok .status-state { color: var(--ok); }
.status-row.stale .status-state { color: var(--warn); }
.status-row.missing .status-state { color: var(--bad); }
.status-age { grid-area: age; color: var(--muted); font-size: .85rem; }
.status-grid { align-items: start; }
