/* =========================================================
   TIP CALCULATOR APP – Mobile-first CSS
   Author: You
   ========================================================= */

/* ------------------ */
/* 1. RESET & ROOT    */
/* ------------------ */
:root {
    /* Colors (from style guide) */
    --clr-green-400: hsl(172, 67%, 45%);
    --clr-green-900: hsl(183, 100%, 15%);
    --clr-grey-500: hsl(186, 14%, 43%);
    --clr-grey-400: hsl(184, 14%, 56%);
    --clr-grey-200: hsl(185, 41%, 84%);
    --clr-grey-50: hsl(189, 47%, 97%);
    --clr-white: hsl(0, 100%, 100%);

    --shadow-card: 0 0.5rem 1.5rem hsl(183, 100%, 15%, 0.1);

    /* Font */
    --ff-base: 'Space Mono', monospace;
    --fw-bold: 700;

    /* Sizing scale */
    --radius: 0.5rem;
    --transition: 0.25s ease;
    --container-max: 70rem;
}

/* Modern reset */
:where(*, *::before, *::after) {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
font-size: clamp(0.875rem, 1.5vw, 1.125rem);
    /* 0.875rem ≈ 14px, 1.125rem ≈ 18px */
}
body {
    font-family: var(--ff-base);
    font-weight: var(--fw-bold);
    color: var(--clr-green-900);
    background-color: var(--clr-grey-200);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    display: grid;
    place-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

/* Remove default form quirks */
:where(input, button, select, textarea) {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

/* Accessible focus */
:focus-visible {
    outline: 2px solid var(--clr-green-400);
    outline-offset: 2px;
}

/* ------------------ */
/* 2. UTILITIES       */
/* ------------------ */
/* Visually hidden but accessible to screen readers */

.sr-only {
    position: absolute;
    width: 0.0625rem;
    /* 1px = 1/16rem */
    height: 0.0625rem;
    /* same logic */
    padding: 0;
    margin: -0.0625rem;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* flow spacing utility */
.flow>*+* {
    margin-block-start: var(--flow-space, 1em);
}

/* ------------------ */
/* 3a. HEADER / LOGO  */
/* ------------------ */
.header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-block-end: 2rem;
}

.header__logo {
    max-width: 5rem;
    height: auto;
}

/* ------------------ */
/* 3. LAYOUT          */
/* ------------------ */
.main {
    width: min(100%, var(--container-max));
}

.calculator {
    display: grid;
    gap: 2rem;
    background: var(--clr-white);
    padding: clamp(1.5rem, 2vw + 1rem, 2rem);
    border-radius: 1.5rem;
    box-shadow: var(--shadow-card);
}

/* ------------------ */
/* 4. FORM SECTION    */
/* ------------------ */
.calculator__form {
    display: grid;
    gap: 1.5rem;
}

.calculator__fieldset {
    border: none;
    padding: 0;
    margin: 0;
    min-inline-size: auto;
    /* prevents weird shrinking in Safari */
}

.calculator__label {
    color: var(--clr-grey-500);
    font-size: clamp(0.75rem, 1vw + 0.5rem, 0.875rem);
    margin-block-end: 0.5rem;
    display: block;
}

.calculator__input {
    width: 100%;
    text-align: right;
    font-size: clamp(1.25rem, 2vw + 1rem, 1.5rem);
    background-color: var(--clr-grey-50);
    color: var(--clr-green-900);
    padding: 0.5em 0.75em;
    border-radius: var(--radius);
    caret-color: var(--clr-green-400);
    transition: box-shadow var(--transition);
    cursor: auto;
}

.calculator__input:focus-visible {
    box-shadow: 0 0 0 2px var(--clr-green-400);
}


/* Hover effect for inputs (Bill & People) */
.calculator__input:hover {
    box-shadow: 0 0 0 2px var(--clr-grey-400);
    cursor: pointer;
}

/* Prevent hover effects for disabled or error inputs */
.calculator__input:disabled,
.calculator__input--error:hover {
    box-shadow: none;
    cursor: not-allowed;
}
/* Error State (active state design) */

.calculator__input--error {
    border: 2px solid hsl(12, 100%, 50%);
    background-color: hsl(0, 100%, 98%);
}
.calculator__label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.calculator__error {
    color: hsl(12, 100%, 50%);
    /* red-orange like design */
    font-size: 0.75rem;
    display: none;
    /* hidden by default */
}


/* When error is active */
.calculator__fieldset--error .calculator__error {
    display: inline;
}

.calculator__help {
    color: var(--clr-grey-400);
    font-size: 0.75rem;
}


/* Input wrapper & icon positioning */
.calculator__input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* Icon inside the input (left side) */
.calculator__icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.75rem;
    height: auto;
    pointer-events: none;
    /* prevent blocking clicks */
    opacity: 0.75;
}

/* Reserve space for the icon */
.calculator__input--bill,
.calculator__input--people {
    padding-inline-start: 2rem;
}

/* Subtle animation on focus */
.calculator__input-wrapper:focus-within .calculator__icon {
    opacity: 1;
    transform: translateY(-50%) scale(1.05);
    transition: transform 160ms ease, opacity 160ms ease;
}

/* Tip Options */
.calculator__tip-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

@media (min-width: 26em) {
    .calculator__tip-options {
        grid-template-columns: repeat(3, 1fr);
    }
}

.calculator__tip-option {
    position: relative;
}

.calculator__radio {
    position: absolute;
    opacity: 0;
}

.calculator__tip-label {
    display: block;
    text-align: center;
    background-color: var(--clr-green-900);
    color: var(--clr-white);
    padding-block: 0.5em;
    border-radius: var(--radius);
    font-size: 1.25rem;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}

/* Hover effect */
.calculator__tip-label:hover,
.calculator__tip-label:focus-visible {
    background-color: var(--clr-green-400);
    color: var(--clr-green-900);
}

/* Checked (active) state */
.calculator__radio:checked+.calculator__tip-label {
    background-color: var(--clr-green-400);
    color: var(--clr-green-900);
}




/* Custom Tip Input */
.calculator__input--custom {
    width: 100%;
    text-align: center;
font-size: clamp(1rem, 1.5vw + 0.75rem, 1.25rem);
    background-color: var(--clr-grey-50);
    color: var(--clr-green-900);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding-block: 0.5em;
    transition: border-color var(--transition),
        box-shadow var(--transition),
        background-color var(--transition);
}

/* Placeholder (light gray text) */
.calculator__input--custom::placeholder {
    color: var(--clr-grey-400);
}

/* Hover effect */
.calculator__input--custom:hover {
    border-color: var(--clr-grey-400);
}

/* Focus (active) effect */
.calculator__input--custom:focus-visible {
    border-color: var(--clr-green-400);
    box-shadow: 0 0 0 2px var(--clr-green-400);
    outline: none;
}



/* ------------------ */
/* 5. RESULTS PANEL   */
/* ------------------ */
.calculator__results {
    background-color: var(--clr-green-900);
    border-radius: var(--radius);
    padding: clamp(1.5rem, 2vw + 1rem, 2rem);
    display: grid;
    gap: 1.5rem;
}

.calculator__results-title {
    color: var(--clr-grey-200);
    font-size: clamp(1rem, 1vw + 0.75rem, 1.125rem);
}

.calculator__result {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.calculator__result-label {
    color: var(--clr-white);
    font-size: clamp(0.875rem, 0.5vw + 0.75rem, 1rem);
}

.calculator__result-sub {
    color: var(--clr-grey-400);
    font-size: clamp(0.75rem, 0.5vw + 0.5rem, 0.875rem);
}

.calculator__output {
    color: var(--clr-green-400);
    font-size: clamp(1.5rem, 3vw + 1rem, 2.5rem);
    text-align: right;
}

/* ------------------ */
/* 6. BUTTONS         */
/* ------------------ */
.calculator__button {
    width: 100%;
    background-color: var(--clr-green-400);
    color: var(--clr-green-900);
    border-radius: var(--radius);
    text-transform: uppercase;
    font-size: 1rem;
    padding-block: 0.75em;
    cursor: pointer;
    transition: opacity var(--transition);
}

.calculator__button:hover,
.calculator__button:focus-visible {
    opacity: 0.8;
}

/* Reset button states */
.calculator__button--reset {
    background-color: var(--clr-green-400);
    color: var(--clr-green-900);
    text-transform: uppercase;
font-size: clamp(0.875rem, 1vw + 0.75rem, 1rem);
    border-radius: var(--radius);
    padding-block: 0.75em;
    transition: background-color var(--transition), opacity var(--transition);
}

/* Hover / active */
.calculator__button--reset:hover,
.calculator__button--reset:focus-visible {
    background-color: hsl(172, 67%, 55%);
    opacity: 0.9;
}

/* Disabled state */
.calculator__button--reset:disabled {
    background-color: hsl(183, 79%, 24%);
    color: hsl(183, 15%, 60%);
    opacity: 0.5;
    cursor: not-allowed;
}

/* ------------------ */
/* 7. FOOTER          */
/* ------------------ */
.attribution {
    text-align: center;
    font-size: clamp(0.75rem, 0.5vw + 0.5rem, 0.875rem);
    margin-block-start: 2rem;
    color: var(--clr-grey-500);
}

.attribution a {
    color: var(--clr-green-400);
    text-decoration: underline;
}

/* ------------------ */
/* 8. DESKTOP MEDIA   */
/* ------------------ */
@media (min-width: 64em) {
    body {
        padding: 2rem;
    }

    .calculator {
        grid-template-columns: 1fr 1fr;
        gap: 2rem;
        max-width: 60rem;
    }

    .calculator__results {
        padding: 2.5rem;

        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .calculator__results-group {
        display: grid;
        gap: 1.0rem;
        /* nice spacing for the top results */
    }

    .calculator__button--reset {
        margin-top: auto;
    }

    .calculator__form {
        gap: 2rem;

    }

    .calculator__tip-options {
        grid-template-columns: repeat(3, 1fr);
    }

    .calculator__button {
        margin-block-start: auto;
    }

    .calculator__icon {
        left: 1.25rem;
        width: 0.85rem;
    }

    .calculator__input--bill,
    .calculator__input--people {
        padding-inline-start: 2.25rem;
    }
}

/* =========================================================
   ACCESSIBILITY: Respect user "prefers-reduced-motion"
   ========================================================= */
@media (prefers-reduced-motion: reduce) {

    /* Disable or soften transitions and animations sitewide */
    *,
    *::before,
    *::after {
        transition: none;
        animation: none;
        scroll-behavior: auto;
    }

    /* Optional: gentle alternative for elements that animate */
    .calculator__input-wrapper:focus-within .calculator__icon {
        transform: translateY(-50%);
        /* no scale pop */
        opacity: 1;
        /* keep visible but static */
    }

    .calculator__button,
    .calculator__button--reset {
        transition: opacity 0.1s linear;
    }
}