/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-blue: #2980b9;
    --secondary-blue: #3498db;
    --light-blue: #74b9ff;
    --dark-blue: #0984e3;
    --white: #ffffff;
    --light-gray: #f8f9fa;
    --text-dark: #2d3436;
    --text-light: #636e72;
    --success: #00b894;
    --warning: #fdcb6e;
    --error: #e17055;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--light-blue) 0%, var(--dark-blue) 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Animation */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.sun {
    position: absolute;
    top: 5%;
    right: 5%;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #f1c40f, #e67e22);
    border-radius: 50%;
    box-shadow: 0 0 30px #f1c40f;
    animation: float 6s ease-in-out infinite;
}

.cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 40px;
    animation: float 8s ease-in-out infinite;
}

.cloud-1 {
    width: 80px;
    height: 30px;
    top: 15%;
    left: 5%;
    animation-delay: 0s;
}

.cloud-2 {
    width: 70px;
    height: 25px;
    top: 25%;
    right: 8%;
    animation-delay: 2s;
}

.cloud-3 {
    width: 100px;
    height: 35px;
    top: 10%;
    right: 20%;
    animation-delay: 4s;
}

.cloud::before,
.cloud::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
}

.cloud::before {
    width: 35px;
    height: 35px;
    top: -18px;
    left: 10px;
}

.cloud::after {
    width: 30px;
    height: 30px;
    top: -15px;
    right: 10px;
}

/* Floating Icons */
.floating-icons {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.floating-icon {
    position: absolute;
    font-size: 18px;
    color: rgba(255, 255, 255, 0.2);
    animation: floatAround 20s linear infinite;
}

.floating-icon:nth-child(1) { top: 15%; left: 8%; animation-delay: 0s; }
.floating-icon:nth-child(2) { top: 70%; left: 85%; animation-delay: 5s; }
.floating-icon:nth-child(3) { top: 85%; left: 15%; animation-delay: 10s; }
.floating-icon:nth-child(4) { top: 35%; left: 75%; animation-delay: 15s; }

/* Main App Container - Improved for Mobile */
.app-container {
    min-height: 100vh;
    display: flex;
    align-items: flex-start; /* Changed from center to flex-start */
    justify-content: center;
    padding: 10px;
    overflow-y: auto; /* Allow container to scroll if needed */
}

.weather-app {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px; /* Reduced max-width for better mobile fit */
    max-height: 90vh; /* Limit height to viewport */
    overflow-y: auto; /* Allow internal scrolling if needed */
    animation: slideUp 0.6s ease-out;
    display: flex;
    flex-direction: column;
}

/* Compact Header */
.app-header {
    background: linear-gradient(135deg, var(--primary-blue), var(--secondary-blue));
    color: var(--white);
    padding: 20px 15px 15px;
    text-align: center;
    position: relative;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.app-header::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    height: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    filter: blur(8px);
}

.app-title {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.app-title i {
    font-size: 1.2rem;
    animation: pulse 2s infinite;
}

.current-time {
    font-size: 0.8rem;
    opacity: 0.9;
    font-weight: 300;
    line-height: 1.3;
}

/* Compact Search Section */
.search-section {
    padding: 15px;
    background: var(--white);
    flex-shrink: 0; /* Prevent search from shrinking */
}

.search-container {
    margin-bottom: 15px;
}

.search-box {
    display: flex;
    background: var(--light-gray);
    border-radius: 12px;
    padding: 4px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    min-height: 50px;
}

.search-box:focus-within {
    border-color: var(--secondary-blue);
    transform: translateY(-1px);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.search-icon {
    padding: 10px 12px;
    color: var(--text-light);
    font-size: 1rem;
    display: flex;
    align-items: center;
}

#cityInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 0.95rem;
    color: var(--text-dark);
    outline: none;
    min-width: 0; /* Allow input to shrink properly */
}

#cityInput::placeholder {
    color: var(--text-light);
}

.search-button {
    background: linear-gradient(135deg, var(--secondary-blue), var(--primary-blue));
    color: var(--white);
    border: none;
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.search-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(52, 152, 219, 0.3);
}

/* Compact Quick Cities */
.quick-cities {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.city-chip {
    background: rgba(52, 152, 219, 0.1);
    border: 1.5px solid transparent;
    color: var(--primary-blue);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.city-chip:hover {
    background: var(--secondary-blue);
    color: var(--white);
    transform: translateY(-1px);
}

/* Weather Main - Optimized for Mobile */
.weather-main {
    padding: 0 15px 15px;
    flex: 1; /* Take remaining space */
    overflow-y: auto; /* Allow scrolling within main content */
    min-height: 0; /* Allow proper flex shrinking */
}

/* Compact Loading Animation */
.loading-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    padding: 20px 0;
}

.weather-loader {
    text-align: center;
}

.loader-circle {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(52, 152, 219, 0.2);
    border-top: 3px solid var(--secondary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

.loader-text {
    color: var(--text-light);
    font-size: 0.9rem;
    animation: pulse 2s infinite;
}

/* Compact Weather Card */
.weather-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 16px;
    padding: 20px;
    color: var(--white);
    text-align: center;
    box-shadow: var(--shadow);
    animation: fadeIn 0.6s ease-out;
    position: relative;
    overflow: hidden;
    margin-bottom: 10px;
}

.weather-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
}

.location-info {
    margin-bottom: 15px;
}

.city-name {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 3px;
    line-height: 1.2;
}

.country-name {
    font-size: 0.85rem;
    opacity: 0.9;
}

.weather-main-info {
    margin: 15px 0;
}

.temperature {
    font-size: 2.8rem;
    font-weight: 700;
    margin: 8px 0;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

.weather-condition {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 1rem;
    margin-bottom: 3px;
    flex-wrap: wrap;
}

.condition-icon {
    font-size: 2rem;
    animation: bounce 2s infinite;
}

.condition-text {
    font-weight: 500;
    font-size: 0.95rem;
}

/* Compact Weather Details */
.weather-details {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.detail-card {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
    transition: transform 0.3s ease;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.detail-card:hover {
    transform: translateY(-3px);
}

.detail-icon {
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.detail-label {
    font-size: 0.7rem;
    opacity: 0.9;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
}

/* Compact Error State */
.error-container {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    border-radius: 16px;
    padding: 20px;
    color: var(--white);
    text-align: center;
    animation: shake 0.5s ease-in-out;
    margin-bottom: 10px;
}

.error-icon {
    font-size: 2.2rem;
    margin-bottom: 10px;
}

.error-title {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.error-message {
    margin-bottom: 15px;
    opacity: 0.9;
    font-size: 0.9rem;
    line-height: 1.3;
}

.retry-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.retry-button {
    background: rgba(255, 255, 255, 0.2);
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    color: var(--white);
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.8rem;
}

.retry-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

/* Compact Footer */
.app-footer {
    background: var(--light-gray);
    padding: 12px 15px;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent footer from shrinking */
}

.footer-info {
    color: var(--text-light);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    line-height: 1.3;
}

.separator {
    opacity: 0.5;
}

/* Location Options - Optimized for Mobile */
.location-options {
    padding: 15px;
    text-align: center;
}

.options-header {
    margin-bottom: 15px;
}

.options-header .location-icon {
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.options-header h3 {
    color: #2d3436;
    margin-bottom: 3px;
    font-size: 1.3rem;
}

.options-header p {
    color: #636e72;
    font-size: 0.9rem;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.option-card {
    background: white;
    border-radius: 12px;
    padding: 15px 10px;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    min-height: 90px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.option-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
    border-color: #3498db;
}

.option-card.capital {
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
}

.option-card.city {
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    color: white;
}

.option-card.city .option-type,
.option-card.city .option-name {
    color: white;
}

.option-icon {
    font-size: 1.5rem;
    margin-bottom: 6px;
}

.option-type {
    font-size: 0.65rem;
    color: #636e72;
    margin-bottom: 3px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.option-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #2d3436;
    margin-bottom: 8px;
    line-height: 1.2;
}

.select-btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.75rem;
}

.select-btn:hover {
    background: #2980b9;
    transform: scale(1.05);
}

/* Animations - Optimized for performance */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(3deg); }
}

@keyframes floatAround {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(60px, 30px) rotate(90deg); }
    50% { transform: translate(30px, 60px) rotate(180deg); }
    75% { transform: translate(-30px, 30px) rotate(270deg); }
    100% { transform: translate(0, 0) rotate(360deg); }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
    60% { transform: translateY(-3px); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
    20%, 40%, 60%, 80% { transform: translateX(3px); }
}

@keyframes shine {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

/* Enhanced Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 8px;
        align-items: flex-start;
    }
    
    .weather-app {
        max-height: 95vh;
        border-radius: 16px;
        margin: 0;
    }
    
    .app-header {
        padding: 15px 12px 12px;
    }
    
    .app-title {
        font-size: 1.2rem;
    }
    
    .search-section {
        padding: 12px;
    }
    
    .weather-main {
        padding: 0 12px 12px;
    }
    
    .temperature {
        font-size: 2.4rem;
    }
    
    .weather-details {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .quick-cities {
        gap: 5px;
    }
    
    .city-chip {
        padding: 5px 10px;
        font-size: 0.7rem;
    }
    
    .options-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 5px;
    }
    
    .weather-app {
        max-height: 98vh;
        border-radius: 14px;
    }
    
    .search-box {
        flex-direction: row; /* Keep horizontal on mobile */
        min-height: 45px;
    }
    
    .search-button {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    #cityInput {
        font-size: 0.9rem;
    }
    
    .footer-info {
        flex-direction: column;
        gap: 3px;
    }
    
    .separator {
        display: none;
    }
    
    .temperature {
        font-size: 2.2rem;
    }
    
    .weather-condition {
        font-size: 0.9rem;
    }
    
    .condition-icon {
        font-size: 1.8rem;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .app-title {
        font-size: 1.1rem;
    }
    
    .temperature {
        font-size: 2rem;
    }
    
    .weather-details {
        grid-template-columns: 1fr;
    }
    
    .options-grid {
        grid-template-columns: 1fr;
    }
    
    .retry-buttons {
        grid-template-columns: 1fr;
    }
}

/* Prevent horizontal scrolling */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Smooth scrolling */
.weather-app {
    scroll-behavior: smooth;
}

/* Optimize for touch devices */
@media (hover: none) and (pointer: coarse) {
    .search-button:hover,
    .city-chip:hover,
    .detail-card:hover,
    .option-card:hover,
    .retry-button:hover,
    .select-btn:hover {
        transform: none;
    }
    
    .search-box:focus-within {
        transform: none;
    }
}