/* =========================================
   VARIABILI DEL CIELO (cambiano con il meteo)
========================================= */

:root {
    --g1: #284f9d;
    --g2: #3865b5;
    --g3: #4a7fd0;
    --g4: #88bbee;

    --card: rgba(28, 58, 125, 0.38);
    --sheet: #2b5599;
    --ink: #ffffff;
    --ink-soft: rgba(255, 255, 255, 0.64);
    --line: rgba(255, 255, 255, 0.13);
    --footer-ink: #0f3366;
    --bg-img: url(img/bg/clear.svg);
}

html[data-sky="cloudy"] {
    --g1: #3d5b8c;
    --g2: #5573a0;
    --g3: #7e9ac0;
    --g4: #b4c8de;
    --card: rgba(32, 52, 92, 0.38);
    --sheet: #46628f;
}

html[data-sky="rain"] {
    --g1: #2c3b52;
    --g2: #3d4f69;
    --g3: #5a6e88;
    --g4: #8a9db3;
    --card: rgba(20, 32, 52, 0.40);
    --sheet: #3b4d66;
}

html[data-sky="snow"] {
    --g1: #5b7399;
    --g2: #7890b3;
    --g3: #a3b7d1;
    --g4: #d3deeb;
    --card: rgba(48, 66, 100, 0.34);
    --sheet: #5d7498;
    --footer-ink: #1c3558;
}

html[data-sky="fog"] {
    --g1: #5d6b7e;
    --g2: #77869a;
    --g3: #9aa8b9;
    --g4: #c5ced8;
    --card: rgba(48, 60, 80, 0.34);
    --sheet: #5f6f85;
}

html[data-sky="night"] {
    --g1: #0a1634;
    --g2: #15275a;
    --g3: #243d7c;
    --g4: #3d5c9f;
    --card: rgba(8, 18, 48, 0.46);
    --sheet: #1a2d62;
    --footer-ink: #dbe6ff;
}

html[data-sky="clear"]      { --bg-img: url(img/bg/clear.svg); }
html[data-sky="partly"]     { --bg-img: url(img/bg/partly.svg); }
html[data-sky="cloudy"]     { --bg-img: url(img/bg/cloudy.svg); }
html[data-sky="rain"]       { --bg-img: url(img/bg/rain.svg); }
html[data-sky="thunder"]    { --bg-img: url(img/bg/thunder.svg); }
html[data-sky="snow"]       { --bg-img: url(img/bg/snow.svg); }
html[data-sky="fog"]        { --bg-img: url(img/bg/fog.svg); }
html[data-sky="night"]      { --bg-img: url(img/bg/night.svg); }
html[data-sky="nightcloud"] { --bg-img: url(img/bg/nightcloud.svg); }

html[data-sky="partly"] {
    --g1: #1f4a9c; --g2: #3a6cc0; --g3: #5f9be0; --g4: #9ccaf2;
    --card: rgba(28, 58, 125, 0.40);
    --sheet: #2b5599;
}

html[data-sky="thunder"] {
    --g1: #141a2c; --g2: #26304a; --g3: #414f6c; --g4: #667791;
    --card: rgba(10, 16, 34, 0.46);
    --sheet: #2a3552;
}

html[data-sky="nightcloud"] {
    --g1: #070f27; --g2: #12245a; --g3: #223f80; --g4: #35579b;
    --card: rgba(8, 18, 48, 0.46);
    --sheet: #1a2d62;
    --footer-ink: #dbe6ff;
}


/* =========================================
   BASE
========================================= */

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--g4);
}

body {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    padding: 0;

    font-family: "Roboto", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    color: var(--ink);

    background-color: var(--g4);
    background-image:
        var(--bg-img),
        linear-gradient(180deg, var(--g1) 0%, var(--g2) 38%, var(--g3) 68%, var(--g4) 100%);
    background-size: cover, 100% 100%;
    background-position: center top, center;
    background-attachment: fixed;
    background-repeat: no-repeat;

    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button {
    font-family: inherit;
    color: inherit;
}

.app {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
}


/* =========================================
   SCHERMATA PRINCIPALE
========================================= */

.screen {
    position: relative;
    display: flex;
    flex-direction: column;

    min-height: 100vh;
    min-height: 100dvh;
    padding-top: env(safe-area-inset-top, 0px);
    overflow: hidden;
}

/* Effetti animati sopra lo sfondo (pioggia, neve) */

.sky i {
    display: none;
}

.sky::before,
.sky::after {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0;
}

html[data-sky="rain"] .sky::before,
html[data-sky="rain"] .sky::after,
html[data-sky="thunder"] .sky::before,
html[data-sky="thunder"] .sky::after {
    opacity: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='320'%3E%3Cg stroke='%23d5e6fb' stroke-linecap='round'%3E%3Cpath d='M20 10l-8 34' stroke-width='1.4' opacity='.45'/%3E%3Cpath d='M78 120l-9 38' stroke-width='1.2' opacity='.35'/%3E%3Cpath d='M130 40l-8 34' stroke-width='1.5' opacity='.5'/%3E%3Cpath d='M48 210l-9 36' stroke-width='1.2' opacity='.4'/%3E%3Cpath d='M112 250l-8 32' stroke-width='1.3' opacity='.45'/%3E%3Cpath d='M150 170l-8 30' stroke-width='1.1' opacity='.3'/%3E%3C/g%3E%3C/svg%3E");
    animation: rainFall 0.75s linear infinite;
}

html[data-sky="rain"] .sky::after,
html[data-sky="thunder"] .sky::after {
    background-size: 110px 220px;
    background-position: 40px 0;
    opacity: .7;
    animation-duration: 0.55s;
    animation-name: rainFallSmall;
}

@keyframes rainFall      { to { background-position: 0 320px; } }
@keyframes rainFallSmall { to { background-position: 40px 220px; } }

html[data-sky="snow"] .sky::before,
html[data-sky="snow"] .sky::after {
    opacity: 1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cg fill='%23fff'%3E%3Ccircle cx='24' cy='30' r='2.6' opacity='.9'/%3E%3Ccircle cx='96' cy='12' r='1.8' opacity='.7'/%3E%3Ccircle cx='160' cy='54' r='3' opacity='.85'/%3E%3Ccircle cx='60' cy='90' r='2' opacity='.75'/%3E%3Ccircle cx='128' cy='122' r='2.8' opacity='.9'/%3E%3Ccircle cx='18' cy='150' r='1.9' opacity='.7'/%3E%3Ccircle cx='90' cy='176' r='3.2' opacity='.85'/%3E%3Ccircle cx='176' cy='168' r='2' opacity='.7'/%3E%3C/g%3E%3C/svg%3E");
    animation: snowFall 9s linear infinite;
}

html[data-sky="snow"] .sky::after {
    background-size: 140px 140px;
    background-position: 60px 0;
    opacity: .75;
    animation-name: snowFallSmall;
    animation-duration: 6s;
}

@keyframes snowFall      { to { background-position: 0 200px; } }
@keyframes snowFallSmall { to { background-position: 60px 140px; } }

html[data-sky="thunder"] .sky {
    animation: flash 7s infinite;
}

@keyframes flash {
    0%, 92%, 96%, 100% { background: transparent; }
    93%                { background: rgba(255, 255, 255, 0.22); }
    94.5%              { background: transparent; }
    95%                { background: rgba(255, 255, 255, 0.14); }
}

/* =========================================
   BARRA IN ALTO
========================================= */

.topbar {
    position: relative;
    z-index: 5;

    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;

    height: 60px;
    padding: 0 14px 0 14px;
}

.topbar .icon-btn:first-child {
    margin-right: 0;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 44px;
    height: 44px;
    padding: 0;

    color: #ffffff;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.16);
}

.icon-btn:focus-visible,
.fc-more:focus-visible,
.fc-btn:focus-visible,
.sheet-close:focus-visible,
.menu button:focus-visible,
.menu a:focus-visible,
.search-results button:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.menu-wrap {
    position: relative;
}

.menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 220px;
    padding: 6px;

    background: rgba(24, 48, 100, 0.92);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.menu button,
.menu a {
    display: block;
    width: 100%;
    padding: 12px 14px;

    color: #ffffff;
    font-size: 15px;
    text-align: left;
    text-decoration: none;

    background: transparent;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

.menu button:active,
.menu a:active {
    background: rgba(255, 255, 255, 0.14);
}


/* =========================================
   METEO ATTUALE
========================================= */

.now {
    position: relative;
    z-index: 2;
    flex: 1 0 auto;

    padding: 50px 24px 28px;
}

.pager {
    position: absolute;
    left: 7px;
    top: 282px;

    width: 3px;
    height: 64px;

    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px;
}

.city {
    max-width: 88%;
    margin: 0;

    font-size: 18px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: 0;
    overflow-wrap: break-word;
}

.temp {
    display: flex;
    align-items: flex-start;

    margin: 22px 0 0 -4px;

    font-size: min(36vw, 172px);
    font-weight: 300;
    line-height: 0.82;
    letter-spacing: -0.01em;
    font-variant-numeric: lining-nums;
}

.temp-num {
    display: block;
}

.temp-deg {
    display: block;

    width: 0.15em;
    height: 0.15em;
    margin: 0.065em 0 0 0.075em;

    border: 0.032em solid #ffffff;
    border-radius: 50%;
}

.cond {
    margin-top: 22px;

    font-size: 19px;
    font-weight: 400;
    line-height: 1.3;
}

.cond:empty {
    display: none;
}

.aqi {
    display: inline-flex;
    align-items: center;
    gap: 7px;

    margin-top: 20px;
    padding: 5px 15px 5px 11px;

    color: #ffffff;
    font-size: 15px;
    line-height: 1.2;

    background: rgba(255, 255, 255, 0.17);
    border-radius: 999px;
}

.aqi b {
    font-weight: 700;
}

.aqi svg {
    flex: 0 0 auto;
    color: rgba(255, 255, 255, 0.9);
}


/* =========================================
   CARD PREVISIONI
========================================= */

.forecast {
    position: relative;
    z-index: 2;

    margin: 0 12px calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 22px 20px 19px;

    background: var(--card);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-radius: 28px;
}

.fc-head {
    display: flex;
    align-items: center;
    gap: 12px;

    min-height: 24px;
    margin-bottom: 8px;
    color: var(--ink-soft);
}

.fc-cal {
    flex: 0 0 auto;
    color: #ffffff;
}

.fc-head h2 {
    flex: 1 1 auto;
    margin: 0;

    font-size: 15px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink-soft);
}

.fc-more {
    display: inline-flex;
    align-items: center;
    gap: 7px;

    padding: 4px 0 4px 8px;

    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 400;

    background: transparent;
    border: 0;
    cursor: pointer;
}

.fc-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.fc-row {
    display: grid;
    grid-template-columns: 6.5fr 30px 1fr 32px 50px 34px;
    align-items: center;
    column-gap: 8px;

    min-height: 45px;
    border-top: 1px solid var(--line);
}

.fc-row:first-child {
    border-top: 0;
}

.fc-row.extra {
    display: none;
}

.fc-list.expanded .fc-row.extra {
    display: grid;
}

.fc-day {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
}

.fc-icon {
    width: 30px;
    height: 30px;
    object-fit: contain;
}

.fc-icon[hidden] {
    display: none;
}

.fc-min,
.fc-max {
    font-size: 15px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.fc-min {
    grid-column: 4;
    text-align: right;
}

.fc-max {
    grid-column: 6;
    text-align: right;
}

/* Barra delle temperature */

.fc-bar {
    grid-column: 5;

    position: relative;
    height: 5px;

    background: rgba(8, 28, 78, 0.28);
    border-radius: 999px;
}

.fc-seg {
    position: absolute;
    top: 0;
    bottom: 0;
    min-width: 8px;

    border-radius: 999px;
}

.fc-dot {
    position: absolute;
    top: 50%;

    width: 9px;
    height: 9px;
    margin: -4.5px 0 0 -4.5px;

    background: #ffffff;
    border: 2px solid rgba(40, 70, 110, 0.55);
    border-radius: 50%;
    box-sizing: content-box;
    transform: translate(-1px, -1px);
}

.fc-btn {
    display: block;
    width: 100%;
    margin-top: 22px;
    padding: 13px 16px;

    color: #ffffff;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;

    background: rgba(255, 255, 255, 0.2);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
}

.fc-btn:active {
    background: rgba(255, 255, 255, 0.3);
}


/* =========================================
   FOGLI A SCOMPARSA (ricerca e dettagli)
========================================= */

.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;

    background: rgba(5, 15, 40, 0.45);
}

.sheet {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 41;

    width: 100%;
    max-width: 520px;
    max-height: 86vh;
    max-height: 86dvh;
    padding: 8px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;

    color: #ffffff;
    background: var(--sheet);
    border-radius: 28px 28px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
    transform: translateX(-50%);

    animation: sheetUp 0.26s ease-out;
}

.sheet-tall {
    height: 86vh;
    height: 86dvh;
}

@keyframes sheetUp {
    from { transform: translate(-50%, 40px); opacity: 0; }
    to   { transform: translate(-50%, 0);    opacity: 1; }
}

.sheet-grip {
    width: 40px;
    height: 4px;
    margin: 4px auto 10px;

    background: rgba(255, 255, 255, 0.35);
    border-radius: 4px;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.sheet-head h2 {
    margin: 0;
    font-size: 19px;
    font-weight: 500;
}

.sheet-close {
    width: 40px;
    height: 40px;

    color: #ffffff;
    font-size: 18px;

    background: rgba(255, 255, 255, 0.14);
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.search-input {
    width: 100%;
    padding: 14px 18px;

    color: #ffffff;
    font-family: inherit;
    font-size: 17px;

    background: rgba(255, 255, 255, 0.16);
    border: 0;
    border-radius: 999px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.search-input::-webkit-search-cancel-button {
    filter: brightness(0) invert(1);
    opacity: 0.8;
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.search-input:focus-visible {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.search-results {
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.search-results li + li {
    border-top: 1px solid var(--line);
}

.search-results button {
    display: block;
    width: 100%;
    padding: 13px 6px;

    color: #ffffff;
    font-size: 16px;
    text-align: left;

    background: transparent;
    border: 0;
    cursor: pointer;
}

.search-results small {
    display: block;
    margin-top: 2px;
    color: var(--ink-soft);
    font-size: 13px;
}

.search-results .search-msg {
    padding: 13px 6px;
    color: var(--ink-soft);
    font-size: 15px;
}

/* Dettagli per giorno */

.details-list {
    display: flex;
    flex-direction: column;
}

.det-row {
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.det-row:first-child {
    border-top: 0;
}

.det-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.det-top img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.det-day {
    font-size: 16px;
    font-weight: 500;
}

.det-desc {
    margin-left: auto;
    color: var(--ink-soft);
    font-size: 14px;
    text-align: right;
}

.det-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;

    margin-top: 6px;
    color: rgba(255, 255, 255, 0.86);
    font-size: 14px;
}

.details-sub {
    margin: 18px 0 8px;
    font-size: 16px;
    font-weight: 500;
    color: var(--ink-soft);
}

.meteogram-wrap {
    position: relative;
    width: 100%;
    height: 300px;
}

#meteogram {
    display: block;
    width: 100% !important;
    height: 100% !important;
}


/* =========================================
   FOOTER
========================================= */

.site-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;

    padding: 18px 16px calc(22px + env(safe-area-inset-bottom, 0px));

    color: var(--footer-ink);
    text-align: center;
}

.footer-logo {
    display: inline-flex;
    padding: 6px 14px;

    background: #ffffff;
    border-radius: 12px;
}

.footer-logo img {
    display: block;
    height: 28px;
    width: auto;
    max-width: 100%;
}

.social-footer {
    display: flex;
    gap: 12px;
}

.social-footer a {
    display: inline-flex;
}

.social-footer img {
    display: block;
    width: 36px;
    height: 36px;
    object-fit: contain;
    background: #ffffff;
    border-radius: 50%;
}

.crediti_bis {
    font-size: 12px;
    line-height: 1.5;
}

.crediti a {
    color: var(--footer-ink);
    font-size: 14px;
    font-weight: 500;
    text-decoration: underline;
}


/* =========================================
   SCHERMI PICCOLI / PREFERENZE UTENTE
========================================= */

@media (max-width: 360px) {
    .fc-row {
        grid-template-columns: 5fr 28px 1fr 30px 44px 32px;
        column-gap: 6px;
    }

    .fc-day {
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sheet,
    .sky,
    .sky::before,
    .sky::after {
        animation: none !important;
    }
}
