/* learned from https://www.w3schools.com/css/css_selectors.asp - universal selector */
*,
*::before,
*::after {
    /* https://www.w3schools.com/css/css_margin.asp */
    margin: 0;
    /* https://www.w3schools.com/css/css_padding.asp */
    padding: 0;
    /* https://www.w3schools.com/css/css3_box-sizing.asp */
    box-sizing: border-box;
}

/* https://www.w3schools.com/css/css3_variables.asp - css custom variables */
:root {
    --bg-1: #0f0c29;
    --bg-2: #302b63;
    --bg-3: #24243e;
    --accent: #6c63ff;
    --accent-light: #8b83ff;
    --accent-glow: rgba(108, 99, 255, 0.4);
    --text: #f0f0ff;
    --text-muted: rgba(240, 240, 255, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --radius: 24px;
}

/* https://www.w3schools.com/css/css_font.asp */
body {
    font-family: 'Inter', -apple-system, sans-serif;
    /* https://www.w3schools.com/css/css_rwd_viewport.asp - vh unit */
    min-height: 100vh;
    /* https://www.w3schools.com/css/css3_flexbox.asp */
    display: flex;
    justify-content: center;
    align-items: center;
    /* https://www.w3schools.com/css/css3_gradients.asp */
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2), var(--bg-3));
    background-size: 400% 400%;
    /* https://www.w3schools.com/css/css3_animations.asp */
    animation: gradientShift 15s ease infinite;
    overflow: hidden;
    padding: 20px;
}

/* https://www.w3schools.com/css/css3_animations.asp */
@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* stars background - https://www.w3schools.com/css/css_positioning.asp */
.stars {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

/* https://www.w3schools.com/css/css_pseudo_elements.asp - ::before and ::after */
.stars::before,
.stars::after {
    content: '';
    position: absolute;
    inset: 0;
    /* https://www.w3schools.com/css/css3_gradients_radial.asp - radial gradient */
    background-image:
        radial-gradient(2px 2px at 20px 30px, #eee, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, #fff, transparent),
        radial-gradient(1px 1px at 130px 80px, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 160px 30px, #ddd, transparent);
    background-size: 200px 100px;
    /* https://www.w3schools.com/css/css_background_repeat.asp */
    background-repeat: repeat;
    /* https://www.w3schools.com/css/css_image_transparency.asp */
    opacity: 0.5;
    animation: twinkle 4s ease-in-out infinite alternate;
}

.stars::after {
    background-position: 100px 50px;
    animation-delay: 2s;
    opacity: 0.3;
}

@keyframes twinkle {
    0% { opacity: 0.3; }
    100% { opacity: 0.7; }
}

/* https://www.w3schools.com/css/css_positioning.asp */
.container {
    position: relative;
    /* https://www.w3schools.com/css/css_z-index.asp */
    z-index: 1;
    width: 100%;
    /* https://www.w3schools.com/css/css_max-width.asp */
    max-width: 440px;
    text-align: center;
}

/* glass card - https://www.w3schools.com/css/css3_backgrounds.asp */
.glass-card {
    background: var(--glass-bg);
    /* https://www.w3schools.com/css/css3_backgrounds.asp */
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    /* https://www.w3schools.com/css/css_border.asp */
    border: 1px solid var(--glass-border);
    /* https://www.w3schools.com/css/css3_borders.asp - border-radius */
    border-radius: var(--radius);
    padding: 48px 36px 40px;
    /* https://www.w3schools.com/css/css3_shadows.asp - box-shadow */
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: floatIn 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes floatIn {
    from {
        opacity: 0;
        /* https://www.w3schools.com/css/css3_2dtransforms.asp - transform */
        transform: translateY(40px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* clock icon circle */
.icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    /* https://www.w3schools.com/css/css3_flexbox.asp */
    display: flex;
    align-items: center;
    justify-content: center;
    /* https://www.w3schools.com/css/css3_borders.asp */
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    color: white;
    box-shadow: 0 0 40px var(--accent-glow);
    animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
    50% { box-shadow: 0 0 50px var(--accent-glow); }
}

h1 {
    font-size: 28px;
    /* https://www.w3schools.com/css/css_font.asp - font-weight */
    font-weight: 700;
    color: var(--text);
    /* https://www.w3schools.com/css/css_text_spacing.asp - letter-spacing */
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 6px;
    font-weight: 300;
}

.input-group {
    margin-top: 32px;
    text-align: left;
}

/* https://www.w3schools.com/css/css_form.asp - styling labels */
.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    /* https://www.w3schools.com/css/css_text_transformation.asp */
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* https://www.w3schools.com/css/css_form.asp - styling date input */
.input-group input[type="date"] {
    /* https://www.w3schools.com/css/css_dimension.asp */
    width: 100%;
    padding: 14px 18px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    /* https://www.w3schools.com/css/css_outline.asp */
    outline: none;
    /* https://www.w3schools.com/css/css3_transitions.asp */
    transition: all 0.3s ease;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

/* https://www.w3schools.com/css/css_pseudo_elements.asp - styling the calendar picker icon */
.input-group input[type="date"]::-webkit-calendar-picker-indicator {
    /* https://www.w3schools.com/css/css_image_transparency.asp - filter property */
    filter: invert(0.8);
    cursor: pointer;
}

/* https://www.w3schools.com/css/css_pseudo_classes.asp - :focus */
.input-group input[type="date"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: rgba(255, 255, 255, 0.08);
}

/* https://www.w3schools.com/css/css_pseudo_classes.asp - :hover */
.input-group input[type="date"]:hover {
    border-color: rgba(255, 255, 255, 0.25);
}

/* main button and clear button share these styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
    width: 100%;
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 20px var(--accent-glow);
    position: relative;
    overflow: hidden;
}

/* shiny overlay effect on button */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.15) 50%, transparent 70%);
    background-size: 200% 100%;
    background-position: 100% 0;
    transition: background-position 0.6s ease;
}

.btn:hover::after {
    background-position: 0 0;
}

.btn:hover {
    /* https://www.w3schools.com/css/css3_2dtransforms.asp */
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-icon {
    font-size: 18px;
    transition: transform 0.3s ease;
}

.btn:hover .btn-icon {
    transform: translateX(4px);
}

/* clear button - hidden by default, fades in when needed */
.btn-clear {
    margin-top: 12px;
    padding: 10px 32px;
    width: auto;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: none;
    font-weight: 400;
    font-size: 14px;
    opacity: 0;
    display: none;
    transition: opacity 0.4s ease, border-color 0.3s ease;
}

.btn-clear.visible {
    display: inline-flex;
    opacity: 1;
}

.btn-clear::after {
    display: none;
}

.btn-clear:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.3);
    transform: none;
    box-shadow: none;
}

/* Result section - hidden by default, shown via JS */
#result {
    margin-top: 32px;
    display: none;
}

#result.visible {
    display: block;
}

.result-hidden {
    display: none;
}

/* https://www.w3schools.com/css/css_grid.asp */
.result-grid {
    display: grid;
    /* https://www.w3schools.com/css/css_grid.asp - grid-template-columns */
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.result-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 18px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: transform 0.3s ease, background 0.3s ease;
}

.result-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.result-value {
    font-size: 36px;
    font-weight: 900;
    /* https://www.w3schools.com/css/css3_gradients.asp - gradient text */
    background: linear-gradient(135deg, var(--accent-light), #c4b5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.result-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-top: 4px;
}

.total-days {
    margin-top: 20px;
    padding: 14px;
    background: rgba(108, 99, 255, 0.1);
    border: 1px solid rgba(108, 99, 255, 0.2);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.total-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.total-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 400;
}

/* error message styling */
#error {
    margin-top: 36px;
    padding: 12px 18px;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 12px;
    color: #fca5a5;
    font-size: 14px;
    font-weight: 500;
    display: none;
}

#error.visible {
    display: block;
}

/* feedback message when user clicks calc with no date */
#feedback {
    margin-top: 16px;
    padding: 12px 18px;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.25);
    border-radius: 12px;
    color: #fcd34d;
    font-size: 14px;
    font-weight: 500;
    display: none;
}

#feedback.visible {
    display: block;
}

/* https://www.w3schools.com/tags/tag_footer.asp */
footer {
    margin-top: 24px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 300;
    font-style: italic;
    letter-spacing: 0.3px;
}

/* counter animation - each number pops in one by one */
@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in .result-item {
    animation: countUp 0.4s ease forwards;
    opacity: 0;
}

.animate-in .result-item:nth-child(1) { animation-delay: 0.05s; }
.animate-in .result-item:nth-child(2) { animation-delay: 0.15s; }
.animate-in .result-item:nth-child(3) { animation-delay: 0.25s; }

.result-hidden, .error-hidden { display: none; }

/* https://www.w3schools.com/css/css_rwd_mediaqueries.asp - responsive for small screens */
@media (max-width: 480px) {
    .glass-card {
        padding: 32px 24px 28px;
    }

    .result-value {
        font-size: 28px;
    }

    h1 {
        font-size: 24px;
    }
}
