/* --- RESET & FONTS --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Fredoka', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* Day Palette */
    --bg-sky: #87CEEB;
    --mountains: #a2d9ff;
    --hill-back: #6DD5FA;
    --hill-front: #2980B9;
    
    --card-bg: #FFFFFF;
    --text-color: #4A4A4A;
    --shadow: 0 10px 30px rgba(0,0,0,0.15);
}

/* Night Palette */
body.night-mode {
    --bg-sky: #1a1a2e;
    --mountains: #16213e;
    --hill-back: #0f3460;
    --hill-front: #533483;
    
    --card-bg: #e0e0e0;
    --text-color: #1a1a2e;
}

body {
    background: var(--bg-sky);
    overflow: hidden;
    transition: background 1.5s ease;
}

.hero {
    height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* --- TEXTURE --- */
.noise-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    /* Subtle paper grain texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 50;
}

/* --- STARS (Visible at Night) --- */
.stars {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 60%;
    z-index: 1;
    background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 3px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 2px),
        radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 3px);
    background-size: 550px 550px, 350px 350px, 250px 250px;
    background-position: 0 0, 40px 60px, 130px 270px;
    opacity: 0;
    transition: opacity 1.5s ease;
}

body.night-mode .stars {
    opacity: 1;
    animation: twinkle 4s infinite alternate;
}

@keyframes twinkle { 
    from { opacity: 0.7; } 
    to { opacity: 1; transform: scale(1.02); } 
}

/* --- CLOUDS --- */
.clouds-container {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2;
    pointer-events: none;
}

.cloud {
    position: absolute;
    background: white;
    border-radius: 50px;
    opacity: 0.8;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    transition: background 1.5s ease;
}

.cloud::after {
    content: ''; position: absolute;
    top: -50%; left: 15%;
    width: 60%; height: 100%;
    background: inherit;
    border-radius: 50%;
}

.cloud-1 { top: 15%; left: -20%; width: 120px; height: 40px; animation: float 25s linear infinite; }
.cloud-2 { top: 25%; left: -10%; width: 180px; height: 60px; animation: float 35s linear infinite; opacity: 0.6; }
.cloud-3 { top: 10%; left: -30%; width: 100px; height: 35px; animation: float 45s linear infinite; opacity: 0.4; }

body.night-mode .cloud { background: #5c5c7a; opacity: 0.3; }

@keyframes float { 
    0% { transform: translateX(0vw); } 
    100% { transform: translateX(120vw); } 
}

/* --- PAPER PLANE (REALISTIC FLIGHT) --- */
.paper-plane-container {
    position: absolute;
    top: 20%; 
    left: -10%;
    width: 40px; height: 40px;
    z-index: 20; /* High z-index to fly OVER the card */
    animation: realisticFlight 18s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
    animation-delay: 2s;
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.15));
    pointer-events: none;
    opacity: 0;
}
.plane-icon { width: 100%; height: 100%; }

@keyframes realisticFlight {
    0% {
        opacity: 0;
        transform: translate(-20vw, 0vh) rotate(5deg) scale(0.8);
    }
    5% { opacity: 1; }
    35% {
        /* Swoop down */
        transform: translate(40vw, 25vh) rotate(20deg) scale(1); 
    }
    65% {
        /* Lift up */
        transform: translate(70vw, 5vh) rotate(-5deg) scale(1.05);
    }
    100% {
        /* Glide out */
        transform: translate(120vw, 30vh) rotate(10deg) scale(0.9);
        opacity: 0;
    }
}

/* --- HANGING ORBS (Sun/Moon) --- */
.sky-orb-container {
    position: absolute;
    top: 0; left: 20%;
    display: flex; flex-direction: column; align-items: center;
    z-index: 3;
    animation: swing 6s ease-in-out infinite;
    transform-origin: top center;
}
.string { width: 2px; height: 120px; background: rgba(255,255,255,0.5); }
.orb {
    width: 100px; height: 100px;
    border-radius: 50%;
    position: relative;
    margin-top: -5px;
    box-shadow: 0 0 20px rgba(255,255,255,0.2);
}
.sun { background: #FFD93D; border: 4px solid #fff; }
.moon { background: #E0E0E0; border: 4px solid #fff; overflow: hidden;}
.crater { position: absolute; background: rgba(0,0,0,0.1); border-radius: 50%; }
.c1 { width: 20px; height: 20px; top: 20%; left: 25%; }
.c2 { width: 15px; height: 15px; bottom: 25%; right: 20%; }

@keyframes swing { 0%, 100% { transform: rotate(2deg); } 50% { transform: rotate(-2deg); } }

/* --- LANDSCAPE LAYERS --- */
.paper-layer {
    position: absolute;
    bottom: 0; left: 0; width: 100%;
    transition: background 1.5s ease;
}

.layer-mountains {
    height: 50%;
    background: var(--mountains);
    /* Jagged mountain shape */
    clip-path: polygon(0% 100%, 0% 20%, 20% 60%, 40% 10%, 60% 50%, 80% 20%, 100% 70%, 100% 100%);
    z-index: 1;
}

.layer-hills-back {
    height: 35%;
    background: var(--hill-back);
    border-radius: 50% 50% 0 0 / 30% 30% 0 0;
    z-index: 2;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.05);
}

.layer-hills-front {
    height: 15%;
    background: var(--hill-front);
    border-radius: 80% 20% 0 0 / 80% 50% 0 0;
    z-index: 3;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.05);
}

/* --- MAIN CARD --- */
.paper-card {
    position: relative;
    z-index: 10;
    background: var(--card-bg);
    border-radius: 24px;
    padding: 30px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow);
    text-align: center;
    transition: background 1.5s ease;
}

.mode-tabs { display: inline-flex; background: rgba(0,0,0,0.05); border-radius: 20px; padding: 4px; margin-bottom: 25px; }
.mode-tabs button { background: transparent; border: none; color: #888; padding: 8px 20px; border-radius: 16px; font-weight: 600; cursor: pointer; transition: 0.3s; }
.mode-tabs button.active { background: #fff; color: var(--text-color); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

.time-group { display: flex; justify-content: center; align-items: center; gap: 8px; }
#hours, #minutes, #seconds, #swTime { font-size: clamp(3rem, 10vw, 4.5rem); font-weight: 700; color: var(--text-color); letter-spacing: -2px; }
.digit-box p { font-size: 0.75rem; font-weight: 700; color: #999; letter-spacing: 2px; margin-top: 5px; }
.colon { font-size: 3rem; color: #ccc; margin-bottom: 15px; }
.ampm-tag { display: inline-block; background: #FF6B6B; color: white; padding: 3px 10px; border-radius: 6px; font-weight: 700; margin-top: 5px; transform: rotate(-5deg); }

/* Buttons */
.controls-wrapper { height: 50px; margin-top: 15px; }
.pill-btn { padding: 10px 20px; border: none; border-radius: 50px; cursor: pointer; font-weight: 600; margin: 0 4px; color: white; transition: 0.2s; box-shadow: 0 3px 5px rgba(0,0,0,0.1); }
.pill-btn:active { transform: scale(0.96); }
.blue-btn { background: #4D96FF; }
.green-btn { background: #6BCB77; }
.red-btn { background: #FF6B6B; }
.gray-btn { background: #bdc3c7; color: #555; }

/* Utils */
.hidden { display: none !important; }
.pop-in { animation: popUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes popUp { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

.footer-hint { margin-top: 30px; color: white; font-weight: 600; opacity: 0.9; text-shadow: 0 2px 4px rgba(0,0,0,0.1); z-index: 20;}

/* --- CREDIT TAG --- */
.credit-tag {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 6px 14px;
    border-radius: 20px 5px 20px 5px;
    color: var(--text-color);
    font-weight: 700;
    font-size: 0.9rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transform: rotate(-3deg);
    z-index: 20;
    transition: transform 0.2s;
    cursor: default;
}
.credit-tag:hover { transform: rotate(0deg) scale(1.05); }

/* --- MOBILE OPTIMIZATIONS --- */
@media (max-width: 480px) {
    .paper-card { 
        width: 95%; 
        padding: 25px 15px; 
    }
    
    .mobile-hide { 
        display: none; 
    }
    
    /* Shorten string & pull up orb so it doesn't hide behind card */
    .sky-orb-container { 
        left: 10%; 
        transform: scale(0.7); 
        top: -10px; 
        z-index: 5;
    }
    .string {
        height: 70px; /* Shorter string for mobile */
    }
    
    /* Adjust plane flight path for mobile height */
    .paper-plane-container {
        top: 10%; 
    }

    /* Center the credit tag on mobile */
    .credit-tag {
        position: relative;
        bottom: auto;
        right: auto;
        margin-top: 15px;
        background: rgba(255,255,255,0.9);
        transform: rotate(0deg);
        display: inline-block;
    }
}