/* ---------------------------- */
/*             RESET            */
/* ---------------------------- */

/* https://piccalil.li/blog/a-modern-css-reset/ */

/* Box sizing */
/* Pseudo elements are also included since it is not automatically selected. */
*,
*::before,
*::after {
    box-sizing: border-box;
    /* Calculating widths & heights easier */
}

/* Reset margins */
/* Can be used to battle "collapsing margins" */
body,
h1,
h2,
h3,
h4,
h5,
p,
figure,
picture {
    margin: 0;
}


/* Design requires no bold to be used. */
h1,
h2,
h3,
h4,
h5,
h6,
p {
    font-weight: 400;
}


/* Make images easier to work with */
img,
picture {
    max-width: 100%;
    /* display: block; */
    /* This element has been commented out, since the "hidden" attribute won't work when display block is enabled. */
}

/* Make forms elements easier to work with */
input,
button,
textarea,
select {
    font: inherit;
    /* Default: font properties are not inherited for these elements */
}

/* Remove animations for people who've turned them off */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ---------------------------- */
/*      CUSTOM PROPERTIES       */
/* ---------------------------- */
:root {
    transition-behavior: allow-discrete;
    /* Allow for discrete rules to be animatable. Copy this to the location where it is used. This property is not inherited.*/
    interpolate-size: allow-keywords;
    /* Allows for animating to height auto */

    /* Colors */
    /* -- Primary -- */
    --clr-lime: hsl(61, 70%, 52%);
    --clr-lime-pass: hsla(61, 70%, 52%, 0.1);
    --clr-red: hsl(4, 69%, 50%);

    /* -- Neutral -- */
    --clr-white: hsl(0, 0%, 100%);
    --clr-black-pass: hsla(0, 0%, 0%, 0.3);
    --clr-slate-100: hsl(202, 86%, 94%);
    --clr-slate-300: hsl(203, 41%, 72%);
    --clr-slate-500: hsl(200, 24%, 40%);
    --clr-slate-700: hsl(200, 24%, 40%);
    --clr-slate-900: hsl(202, 55%, 16%);

    --fs-p: 1rem;
    --fs-h1: 1.5rem;
    --fs-h3: 2.5rem;
    --fs-h4: 1.5rem;

    --ff: "Plus Jakarta Sans", sans-serif;
    --fw-500: 500;
    --fw-700: 700;

    /* Padding */
    --p-input: 0.75rem;

    --b-radius: 4px;
    --b-radius-big: 2rem;
}

/* ---------------------------- */
/*       UTILITY CLASSES        */
/* ---------------------------- */
.hidden {
    display: none !important;
}

/* ---------------------------- */
/*        PAGE SPECIFICS        */
/* ---------------------------- */
/* Body element */
body {
    /* Set font */
    font-family: var(--ff);
    font-size: var(--fs-p);
    color: var(--clr-slate-700);
    /* set accent color */
    accent-color: var(--clr-lime);

    /* Set flex container */
    display: flex;
    flex-direction: column;
    align-items: center;

    background-color: var(--clr-slate-100);
}

/* All sections */
section {
    padding: 1rem;

    button {
        background-color: transparent;
        border: none;
        color: inherit;
        cursor: pointer;
        padding-bottom: 1rem;
        padding-inline: 0;
    }
}

/* Form section */
section#form {
    background-color: var(--clr-white);
}

section#no-result,
section#result {
    background-color: var(--clr-slate-900);
    display: flex;
    flex-direction: column;
}

section#no-result {
    text-align: center;
    align-items: center;
    justify-content: center;
}

h1, h2, h3, h4 {
    font-weight: var(--fw-700);
    font-size: var(--fs-h1);
    padding-block: 1rem;
}

section#form h1 {
    color: var(--clr-slate-900);
}

section#no-result h2,
section#result h2,
section#result h4 {
    color: var(--clr-white);
}

section#result h3 {
    font-size: var(--fs-h3);
    color: var(--clr-lime);
}

section#no-result p,
section#result p {
    color: var(--clr-slate-300);
    font-size: var(--fs-p);
}

/* Style article - containing the calculated data */
section#result article {
    margin-block: 2rem;
    background-color: var(--clr-black-pass);
    border-radius: var(--b-radius);
    padding: 1rem;

    box-shadow: 0 -4px var(--clr-lime);
}

/* Form related styling */
section#form button[type="reset"] {
    text-decoration: underline;
}

section#form div:has(input[type="number"]) {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-block: 0.5rem;

    /* Removal of arrows/spinners: https://www.w3schools.com/howto/howto_css_hide_arrow_number.asp */
    /* Chrome, Safari, Edge, Opera */
    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        appearance: none;
        margin: 0;
    }

    /* Firefox */
    input[type="number"] {
        font-weight: var(--fw-700);
        color: var(--clr-slate-900);
        -moz-appearance: textfield;
    }

}

/* A before pseudo element cannot be set to an input! Therefore another solution needs to be used. */
section#form div:has(input[type="number"]) div {
    display: flex;
    flex-direction: row;
    align-items: center;
    border: 1px solid var(--clr-slate-700);
    border-radius: var(--b-radius);
    padding: 0;

    span {
        padding: var(--p-input);
        background-color: var(--clr-slate-100);
        border-radius: var(--b-radius);
        }

    input {
        padding: var(--p-input);
        width: 100%;
        border: 0;
        outline: none;
    }
}
section#form div:has(input[type="number"]:focus) {
        border-color: var(--clr-lime);
    
        span {
            background-color: var(--clr-lime);
        }
}

/*     &:focus-visible,
    &:hover {
        border-color: var(--clr-lime);
    
        span {
            background-color: var(--clr-lime);
        }
    }; */

/* Boxes as radio buttons */
fieldset {
    border: none;
    margin: 0;
    padding: 0;
    legend {
        padding: 0;
    }
}

/* Select button itself */
[type="radio"] {
    margin-left: 1rem;
    width: 1.25em;
}

.form-group:has([type="radio"]) {
    border: 1px solid var(--clr-slate-700);
    border-radius: var(--b-radius);
    margin-block: 0.5rem;
    display: flex;
    gap: 1ch;

    &:focus-visible,
    &:hover {
        border-color: var(--clr-lime);
    };


    label {
        width: 100%;
        padding: 0.75rem;
        font-weight: var(--fw-700);

    };

}

/* Check if any child contains radio button + checked (within has) */
.form-group:has([type="radio"]:checked) {
    border-color: var(--clr-lime);
    background-color: var(--clr-lime-pass);
}

button[type="submit"] {
    background-color: var(--clr-lime);
    margin-block: 1rem;
    padding-inline: 2rem;
    padding-block: 0.75rem;
    border-radius: 2rem;

    font-weight: var(--fw-700);
    color: var(--clr-slate-900);
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    width: 100%;
}

hr {
    border-color: var(--clr-slate-900);
    background-color: var(--clr-slate-900);
    color: var(--clr-slate-900);
}

section#form div:has(input[type="number"]).error {
    & div {
        border: 1px solid var(--clr-red); 
    }
    & span {
        background-color: var(--clr-red);
        color: var(--clr-white);
    }
}

.error-msg {
    color: var(--clr-red);
    font-weight: var(--fw-700);
    font-size: 0.85rem;
}

footer {
    text-align: center;

    a,
    a:visited {
        text-decoration: none;
        color: inherit;
    };

    a:hover,
    a:active {
        text-decoration: underline;
    }    

}

/* Media query */
@media ( width > 700px ) {

    body {
        justify-content: center;
        height: 100vh;
    }

    main {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        max-width: 52rem;
        margin: 1rem;
        background-color: white;
        border-radius: var(--b-radius-big);
    }
    
    header {
        display: flex;
        justify-content: space-between;
        align-items: center;

        button {
            padding: 0;
        }
    }

    section#form form {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1em;
    }

    /* Select first item */
    section#form div:has(input[type="number"]):nth-of-type(1) {
        grid-column: 1 / -1;
    }

    section#form form div:has(fieldset) {
        grid-column: 1 / -1;
    }

    section#form form button {
        grid-column: 1 / -1;
        width: max-content;
    }

    section#no-result,
    section#result {
        padding-inline: 2rem;
        border-bottom-left-radius: 5rem;
        border-start-end-radius: var(--b-radius-big);
        border-end-end-radius: var(--b-radius-big);
    }

    section#form {
        padding-inline: 2rem;
        border-top-left-radius: var(--b-radius-big);
        border-bottom-left-radius: var(--b-radius-big);
    }
}