
/* =========================
   1. Global styles
========================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg-dark: #0b1120;
    --card-bg: rgba(15, 23, 42, 0.88);
    --surface: rgba(255, 255, 255, 0.06);
    --surface-hover: rgba(255, 255, 255, 0.11);
    --accent: #38bdf8;
    --accent-light: #7dd3fc;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.22);
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text-primary);
    background:
        radial-gradient(
            circle at 15% 15%,
            rgba(56, 189, 248, 0.18),
            transparent 35%
        ),
        linear-gradient(135deg, #080d1b, #142b55, #075985);
    background-attachment: fixed;
}

/* =========================
   2. Main application
========================= */

.weather-app {
    width: 100%;
    max-width: 560px;
    padding: 36px 30px;
    text-align: center;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 26px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    animation: app-appear 0.5s ease-out;
}

h1 {
    font-size: clamp(1.8rem, 5vw, 2.3rem);
    letter-spacing: -0.8px;
    margin-bottom: 12px;
}

.subtitle {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.96rem;
    margin-bottom: 28px;
}

/* =========================
   3. City search
========================= */

#weather-form {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

#city-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 14px 15px;
    border: 1px solid #475569;
    border-radius: 12px;
    outline: none;
    background: #111c31;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s ease,
                box-shadow 0.2s ease;
}

#city-input::placeholder {
    color: var(--text-muted);
}

#city-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

button {
    font: inherit;
}

#weather-form button {
    flex-shrink: 0;
    padding: 14px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--accent);
    color: #082f49;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease,
                transform 0.2s ease;
}

#weather-form button:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
}

#message {
    min-height: 22px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

/* =========================
   4. Current weather
========================= */

.weather-result,
#weather-result {
    margin-top: 25px;
    padding: 28px 20px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(
        145deg,
        rgba(255, 255, 255, 0.09),
        rgba(255, 255, 255, 0.035)
    );
}

.weather-result h2,
#weather-result h2 {
    font-size: 1.35rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    margin-bottom: 12px;
}

#temperature {
    font-size: clamp(3.2rem, 12vw, 4.5rem);
    font-weight: 800;
    letter-spacing: -3px;
    line-height: 1.2;
    margin: 12px 0;
    color: #ffffff;
}

#description {
    color: var(--accent-light);
    font-size: 1.05rem;
    margin-bottom: 18px;
}

.weather-result p,
#weather-result p {
    margin-top: 8px;
}

/* =========================
   5. Temperature toggle
========================= */

.temperature-toggle {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 16px 0 20px;
}

.unit-button {
    width: auto;
    min-width: 58px;
    padding: 9px 14px;
    border: 1px solid #475569;
    border-radius: 22px;
    background: #1e293b;
    color: var(--text-secondary);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease,
                color 0.2s ease,
                border-color 0.2s ease;
}

.unit-button:hover {
    border-color: var(--accent);
}

.unit-button.active {
    background: var(--accent);
    color: #082f49;
    border-color: var(--accent);
}

/* =========================
   6. Location and refresh
========================= */

.location-button,
.refresh-button {
    display: block;
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--accent);
    border-radius: 12px;
    color: var(--accent-light);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease,
                color 0.2s ease,
                border-color 0.2s ease;
}

.location-button {
    margin-top: 8px;
    margin-bottom: 18px;
    background: rgba(56, 189, 248, 0.07);
}

.location-button:hover,
.refresh-button:hover {
    background: rgba(56, 189, 248, 0.17);
    color: #ffffff;
}

.refresh-button {
    margin-top: 16px;
    background: rgba(56, 189, 248, 0.09);
}

.location-button:disabled,
.refresh-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* =========================
   7. Five-day forecast
========================= */

#forecast-section {
    margin-top: 30px;
}

.forecast-title {
    font-size: 1.3rem;
    margin-bottom: 18px;
}

.forecast-container {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 9px;
}

.forecast-day {
    min-width: 0;
    padding: 15px 7px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 15px;
    background: var(--surface);
    transition: transform 0.2s ease,
                background 0.2s ease;
}

.forecast-day:hover {
    transform: translateY(-3px);
    background: var(--surface-hover);
}

.forecast-day h3 {
    font-size: 0.83rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.forecast-icon {
    font-size: 1.65rem;
    margin-bottom: 10px;
}

.forecast-temps {
    font-size: 0.88rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.forecast-low {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 400;
}

.forecast-description {
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

/* =========================
   8. Recent searches
========================= */

.recent-section {
    margin-top: 30px;
    text-align: left;
}

.recent-section h2 {
    font-size: 1.15rem;
    margin-bottom: 14px;
}

.recent-cities {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.recent-city-button {
    width: auto;
    max-width: 100%;
    padding: 9px 14px;
    border: 1px solid #475569;
    border-radius: 24px;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 0.88rem;
    overflow-wrap: anywhere;
    cursor: pointer;
    transition: background 0.2s ease,
                border-color 0.2s ease;
}

.recent-city-button:hover {
    background: #334155;
    border-color: var(--accent);
}

/* =========================
   9. Accessibility and states
========================= */

button:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 3px;
}

[hidden] {
    display: none !important;
}

/* =========================
   10. Responsive layout
========================= */

@media (max-width: 520px) {
    body {
        padding: 20px 12px;
    }

    .weather-app {
        padding: 28px 18px;
        border-radius: 21px;
    }

    #weather-form {
        flex-direction: column;
    }

    #weather-form button {
        width: 100%;
    }

    .forecast-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .forecast-day {
        padding: 16px 10px;
    }

    .forecast-description {
        font-size: 0.78rem;
    }

    .recent-city-button {
        width: auto;
    }

    .unit-button {
        width: auto;
    }
}

@media (max-width: 340px) {
    .weather-app {
        padding: 24px 13px;
    }

    .weather-result,
    #weather-result {
        padding: 22px 12px;
    }

    .forecast-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@keyframes app-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
