/* =========================================================
   Root & Global Defaults
   ========================================================= */

:root {
    --footer-color: #2f2a26;
    --footer-paddin: 0rem;

    --order-color: #3f4032;

    --book-width-desktop: clamp(10rem, 18vw, 14rem);
    --book-width-single-col: clamp(10rem, 34vw, 14rem);
    --single-column-max-width: 38rem;
    --main-max-width: 84rem;
    --book-width: var(--book-width-desktop);
    --book-height-factor: 1.48;
    --intro-image-display: flex;
    --main-margin: 4rem;
    --main-margin-inline: 7rem;
    --main-columns: 2;
    --main-gap: 3rem;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
}

body {
    font-family: "IBM Plex Sans", sans-serif;
    font-optical-sizing: auto;
    font-style: normal;
    font-variation-settings: "wdth" 100;
}

/* =========================================================
   Breakpoints
   ========================================================= */

/* <= 1320px: hide intro image in tighter two-column layouts */
@media (max-width: 1320px) {
    :root {
        --intro-image-display: none;
    }
}

/* <= 1100px: reduce horizontal page gutters */
@media (max-width: 1100px) {
    :root {
        --main-margin-inline: 3rem;
        --main-gap: 1rem;
    }
}

/* <= 990px: switch to single column and show intro image again */
@media (max-width: 990px) {
    :root {
        --main-columns: 1;
        --book-width: var(--book-width-single-col);
        --intro-image-display: flex;
        --main-margin-inline: 2rem;
        --main-max-width: var(--single-column-max-width);
    }
}

/* <= 650px: show no intro image and switch to stacked footer controls */
@media (max-width: 650px) {
    :root {
        --main-margin: 0rem;
        --intro-image-display: none;
        --footer-paddin: 0.45rem;
    }

    footer {
        position: sticky;
        bottom: 0;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0.45rem;
    }

    .cart-summary {
        display: none;
    }

    footer .locale-selects {
        display: flex;
        width: 100%;
        max-width: 100%;
        flex: 1 1 auto;
        align-self: stretch;
    }

    footer .locale-selects .country-select {
        flex: 1 1 0;
        min-width: 0;
    }

    footer .locale-selects .country-select select {
        width: 100%;
        max-width: 100%;
    }

    #order-button {
        width: 100%;
        justify-content: center;
    }

    .error-message {
        width: 100%;
    }
}

/* <= 480px: reduce margins for phone screens */
@media (max-width: 480px) {
    :root {
        --main-gap: 0.5rem;
        --main-margin-inline: 0rem;
    }
}

/* =========================================================
   Layout
   ========================================================= */

main {
    display: grid;
    grid-template-columns: repeat(var(--main-columns), 1fr);
    gap: var(--main-gap);

    width: min(calc(100% - (2 * var(--main-margin-inline))), var(--main-max-width));
    margin: var(--main-margin) auto;
    margin-bottom: var(--main-margin);
}


/* =========================================================
   Book Card
   ========================================================= */

.book {
    display: flex;
    padding: 0.8rem;
    gap: 1rem;
    align-items: flex-start;
}

.book:hover {
    background-color: #ededed;
    transition-duration: 300ms;
}

.image {
    flex: 0 0 var(--book-width);
    width: var(--book-width);
    height: calc(var(--book-width) * var(--book-height-factor));
    min-height: 260px;

    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.intro-card .image {
    display: var(--intro-image-display);
}

.info {
    flex: 1;
}

.title {
    margin: 1rem;
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: right;
}

.subtitle {
    font-size: 1.08rem;
    font-weight: 500;
}

.description > * {
    display: block;
}

header>p {
    text-align: justify;
    hyphens:auto
}

/* =========================================================
   Footer
   ========================================================= */

footer {
    position: fixed;
    inset: auto 0 0 0;

    padding: var(--footer-paddin) 0.8rem;

    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;

    background-color: var(--footer-color);
    color: #fff;
    font-size: 0.9rem;
}

footer > p {
    margin: 0.6rem;
}

/* =========================================================
   Footer Error Message
   ========================================================= */

.error-message {
    margin: 0;
    color: #ffdddd;
    font-weight: 600;
}

/* =========================================================
   Footer Controls
   ========================================================= */

#order-button {
    height: 1.4rem;
    padding: 0.1rem 1rem;

    display: inline-flex;
    align-items: center;

    border: 1.5px solid currentColor;
    background: none;

    font: inherit;
    color: inherit;
    cursor: pointer;

    transition:
        background-color 160ms ease-out,
        color 160ms ease-out,
        border-color 160ms ease-out;
}

#order-button:hover {
    background-color: #fff;
    color: var(--footer-color);
    border-color: var(--footer-color);
}

#order-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

#order-button:disabled:hover {
    background: none;
    color: inherit;
    border-color: currentColor;
}


/* =========================================================
   Country Select
   ========================================================= */

.locale-selects {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    width: auto;
    flex: 0 0 auto;
}

.country-select {
    position: relative;

    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;

    height: 1.4rem;
    padding: 0 1.6rem 0 0.6rem;

    border: 1.5px solid currentColor;
    color: #fff;

    cursor: pointer;
}

#territory-select-wrap[hidden] {
    display: none;
}

.country-select select {
    appearance: none;
    border: none;
    background: none;
    outline: none;
    min-width: 0;

    font: inherit;
    color: inherit;
    cursor: inherit;
}

.country-select select:required:invalid {
    font-style: italic;
}

.country-select::after {
    content: "▾";
    position: absolute;
    right: 0.5rem;

    font-size: 0.75rem;
    opacity: 0.8;
    pointer-events: none;
}

.country-select:hover,
.country-select:focus-within {
    background-color: #fff;
    color: var(--footer-color);
}


/* =========================================================
   Book Order Control
   ========================================================= */

.book-order {
    display: inline-flex;
    align-items: center;

    height: 1.8rem;

    border: 1px solid var(--order-color);
    color: var(--order-color);

    font-size: 0.9rem;
    line-height: 1;
}

.qty-btn {
    width: 1.8rem;
    height: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    border: none;
    background: none;

    color: inherit;
    text-decoration: none;
    user-select: none;
    cursor: pointer;

    transition:
        background-color 140ms ease-out,
        color 140ms ease-out;
}

.qty-btn:hover {
    background-color: var(--order-color);
    color: #fff;
}

.qty-input {
    width: 2.4rem;
    height: 100%;

    border: none;
    border-left: 1px solid var(--order-color);
    border-right: 1px solid var(--order-color);
    background: none;

    font: inherit;
    color: inherit;
    text-align: center;

    appearance: textfield;
}

.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button {
    appearance: none;
    margin: 0;
}

.book-order:focus-within {
    outline: 1px solid var(--order-color);
    outline-offset: 2px;
}

.inventory-note {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
    color: #6b645f;
}

.inventory-note.sold-out {
    color: #8a2f2f;
}

.qty-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
