/* ==========================================================================
   Penumbra Works: store grid
   ========================================================================== */

/* --------------------------------------------------------------------------
   Palette

   Defined in global.css, which is declared as a dependency of this
   stylesheet in penumbra-products.php, so WordPress guarantees it has
   loaded before this file is parsed.

   It used to be duplicated here and in store.css, on the reasoning that
   neither was guaranteed present alongside the other. That was true, and
   it meant any page loading neither had no palette at all, which is
   what turned the About page white. Don't reintroduce a :root block
   here; change the value in global.css instead.
   -------------------------------------------------------------------------- */


.pw-store {
    width: 100%;
}


/* --------------------------------------------------------------------------
   Filter bar
   -------------------------------------------------------------------------- */

.pw-store-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 2rem;
    /* the open panel must not be clipped by anything here */
    position: relative;
    z-index: 5;
}


/* --------------------------------------------------------------------------
   Custom dropdown
   -------------------------------------------------------------------------- */

.pw-dd {
    position: relative;
}

.pw-dd-btn {
    display: flex;
    align-items: center;
    gap: .625rem;
    background: var(--pw-surface);
    border: .2rem solid var(--pw-line);
    border-radius: 2rem;
    color: var(--pw-text);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .75rem 1.25rem;
    cursor: pointer;
    transition: border-color .25s ease, background .25s ease;
    white-space: nowrap;
}

/* matches the load more button, fills accent on hover */
.pw-dd-btn:hover {
    background: var(--pw-accent);
    border-color: var(--pw-accent);
    color: var(--pw-text);
}

.pw-dd-btn:focus-visible {
    outline: none;
    border-color: var(--pw-accent);
    box-shadow: 0 0 0 2px var(--pw-ring);
}

.pw-dd.is-open .pw-dd-btn,
.pw-dd.has-value .pw-dd-btn {
    border-color: var(--pw-accent);
}

.pw-dd.has-value .pw-dd-btn {
    background: var(--pw-surface-hi);
}

/* Declared after has-value so the hover fill wins once a term is
   selected, otherwise the more specific rule above beats it. */
.pw-dd.has-value .pw-dd-btn:hover,
.pw-dd.is-open .pw-dd-btn:hover {
    background: var(--pw-accent);
    border-color: var(--pw-accent);
    color: var(--pw-text);
}

.pw-dd-caret {
    width: .4rem;
    height: .4rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translateY(-.1rem);
    transition: transform .25s ease;
}

.pw-dd.is-open .pw-dd-caret {
    transform: rotate(-135deg) translateY(-.1rem);
}

/* panel */
.pw-dd-panel {
    position: absolute;
    top: calc(100% + .5rem);
    left: 0;
    min-width: 100%;
    max-height: 18rem;
    overflow-y: auto;
    background: var(--pw-surface);
    border: .2rem solid var(--pw-line);
    border-radius: .75rem;
    padding: .375rem;
    z-index: 50;
    box-shadow: 0 .75rem 2rem rgba(0, 0, 0, .5);
}

/* flipped above the trigger when there's no room below */
.pw-dd--up .pw-dd-panel {
    top: auto;
    bottom: calc(100% + .5rem);
}

.pw-dd-panel[hidden] {
    display: none;
}

.pw-dd-opt {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .625rem .75rem;
    border-radius: .5rem;
    color: var(--pw-text-dim);
    font-size: .8rem;
    font-weight: 500;
    letter-spacing: .02em;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.pw-dd-opt:hover,
.pw-dd-opt.is-focused {
    background: var(--pw-surface-hi);
    color: var(--pw-text);
}

.pw-dd-opt[aria-selected="true"] {
    color: var(--pw-text);
}

.pw-dd-opt:focus-visible {
    outline: none;
    background: var(--pw-surface-hi);
    color: var(--pw-text);
}

.pw-dd-opt--clear {
    border-bottom: .2rem solid var(--pw-line);
    border-radius: .5rem .5rem 0 0;
    margin-bottom: .25rem;
    color: var(--pw-text-dim);
}

/* checkbox for multi-select.
   Border stays thin here: the box is only .875rem square, so a .2rem
   border on four sides leaves the tick no room to draw. */
.pw-dd-check {
    position: relative;
    flex: 0 0 auto;
    width: .875rem;
    height: .875rem;
    border: .0625rem solid var(--pw-text-dim);
    border-radius: .25rem;
    transition: background .15s ease, border-color .15s ease;
}

.pw-dd-opt[aria-selected="true"] .pw-dd-check {
    background: var(--pw-accent);
    border-color: var(--pw-accent);
}

.pw-dd-opt[aria-selected="true"] .pw-dd-check::after {
    content: "";
    position: absolute;
    top: .05rem;
    left: .28rem;
    width: .22rem;
    height: .45rem;
    border-right: 2px solid var(--pw-text);
    border-bottom: 2px solid var(--pw-text);
    transform: rotate(45deg);
}


/* --------------------------------------------------------------------------
   Search
   -------------------------------------------------------------------------- */

.pw-store-search {
    margin-left: auto;
}

.pw-store-search-input {
    background: var(--pw-surface);
    border: .2rem solid var(--pw-line);
    border-radius: 2rem;
    color: var(--pw-text);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .75rem 1.25rem;
    min-width: 12rem;
    transition: border-color .25s ease;
}

.pw-store-search-input::placeholder {
    color: var(--pw-text-dim);
}

.pw-store-search-input:focus {
    outline: none;
    border-color: var(--pw-accent);
}


/* --------------------------------------------------------------------------
   Grid
   -------------------------------------------------------------------------- */

.pw-store-grid {
    display: grid;
    grid-template-columns: repeat(var(--pw-store-cols, 3), 1fr);
    gap: 1.5rem;
}

.pw-card[hidden] {
    display: none;
}


/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.pw-card {
    background: var(--pw-surface);
    border-radius: .75rem;
    overflow: hidden;
    transition: transform .3s ease, box-shadow .3s ease;
}

.pw-card:hover {
    transform: translateY(-.25rem);
    box-shadow: 0 .75rem 2rem var(--pw-glow);
}

.pw-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* themes commonly re-add an underline on link hover, hold it off */
.pw-card-link:hover,
.pw-card-link:focus,
.pw-card-link:hover .pw-card-title,
.pw-card-link:hover .pw-card-more {
    text-decoration: none;
}

.pw-card-img {
    position: relative;
    display: block;
    aspect-ratio: 4 / 3;
    background: var(--pw-bg);
    overflow: hidden;
}

.pw-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .4s ease;
}

.pw-card:hover .pw-card-img img {
    transform: scale(1.04);
}

/* status badge, top left */
.pw-card-badge {
    position: absolute;
    top: .75rem;
    left: .75rem;
    background: var(--pw-accent);
    color: var(--pw-text);
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: .3rem .625rem;
    border-radius: 2rem;
    line-height: 1;
}

/* engine chips, top right, stacked.
   .pw-card-tags is the same thing on blog cards, carrying categories. */
.pw-card-engines,
.pw-card-tags {
    position: absolute;
    top: .75rem;
    right: .75rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .25rem;
}

.pw-card-engine,
.pw-card-tag {
    background: rgba(16, 16, 16, .85);
    border: 1px solid rgba(255, 255, 255, .2);
    color: var(--pw-text);
    font-size: .6rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: .25rem .5rem;
    border-radius: 2rem;
    line-height: 1;
    white-space: nowrap;
}

/* title left, price right */
.pw-card-body {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 1rem 1.125rem;
}

.pw-card-title {
    color: var(--pw-text);
    font-size: .9rem;
    font-weight: 600;
    letter-spacing: .02em;
}

.pw-card-price {
    color: var(--pw-text);
    font-size: .9rem;
    font-weight: 600;
    white-space: nowrap;
}


/* --------------------------------------------------------------------------
   Blog card

   Shares the card shell above; only the image ratio and the body
   layout differ. Product cards put title and price on one baseline;
   posts stack title, excerpt and a meta row.
   -------------------------------------------------------------------------- */

/* 16:9 suits article headers better than the 4:3 product crop */
.pw-card--post .pw-card-img {
    aspect-ratio: 16 / 9;
}

.pw-card--post .pw-card-body {
    flex-direction: column;
    align-items: stretch;
    gap: .5rem;
}

.pw-card--post .pw-card-title {
    font-size: .95rem;
    line-height: 1.4;
}

.pw-card-excerpt {
    color: var(--pw-text-dim);
    font-size: .8rem;
    line-height: 1.6;
    /* clamped so ragged excerpt lengths don't make the grid rows uneven */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.pw-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    margin-top: .25rem;
}

.pw-card-date {
    color: var(--pw-text-dim);
    font-size: .78rem;
    font-weight: 500;
    white-space: nowrap;
}

.pw-card-more {
    color: var(--pw-text);
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}

.pw-card--post:hover .pw-card-more {
    color: var(--pw-accent);
}


/* --------------------------------------------------------------------------
   Back link

   Sits above the title on single post and portfolio templates.
   -------------------------------------------------------------------------- */

.pw-back {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    color: var(--pw-text-dim);
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    text-decoration: none;
    transition: color .25s ease;
}

.pw-back:hover,
.pw-back:focus-visible {
    color: var(--pw-accent);
    text-decoration: none;
}

/* chevron drawn from two border edges, so it inherits the link colour */
.pw-back-arrow {
    width: .4rem;
    height: .4rem;
    border-left: .125rem solid currentColor;
    border-bottom: .125rem solid currentColor;
    transform: rotate(45deg);
    transition: transform .25s ease;
}

.pw-back:hover .pw-back-arrow {
    transform: rotate(45deg) translate(.125rem, .125rem);
}


/* --------------------------------------------------------------------------
   Standalone term chips

   [pw_post_terms] outside a card, same chip, laid out in a row rather
   than stacked over an image. Larger than the card version, which is
   sized to sit unobtrusively over a thumbnail.
   -------------------------------------------------------------------------- */

.pw-post-terms {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.pw-post-terms--center {
    justify-content: center;
}

.pw-post-terms .pw-card-tag {
    background: var(--pw-surface);
    border: .1rem solid var(--pw-accent);
    color: var(--pw-text-dim);
    font-size: .75rem;
    padding: .5rem 1rem;
}


/* --------------------------------------------------------------------------
   Related posts

   [pw_related_posts] reuses .pw-store-grid and the blog card above.
   [pw_related] on product pages uses the same heading and the same
   .pw-card, so the two related blocks are identical by construction.
   -------------------------------------------------------------------------- */

.pw-related-posts {
    width: 100%;
}

/* Shared with [pw_related] on product pages */
.pw-related-title,
.pw-related-posts-title {
    color: var(--pw-text);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: .02em;
    margin: 0 0 1.5rem;
}


/* --------------------------------------------------------------------------
   Empty state + load more
   -------------------------------------------------------------------------- */

.pw-store-empty {
    color: var(--pw-text-dim);
    font-size: .9rem;
    text-align: center;
    padding: 3rem 0;
    margin: 0;
}

.pw-store-more {
    display: flex;
    justify-content: center;
    margin-top: 2.5rem;
}

.pw-store-more[hidden] {
    display: none;
}

.pw-store-more-btn {
    background: var(--pw-surface);
    border: .2rem solid var(--pw-accent);
    border-radius: 2rem;
    color: var(--pw-text);
    font-family: inherit;
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: .875rem 2.5rem;
    cursor: pointer;
    transition: background .3s ease;
}

.pw-store-more-btn:hover {
    background: var(--pw-accent);
}


/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

/* 1240px, three product cards still fit a small laptop, but the
   filter bar starts crowding the search field. */
@media (max-width: 77.5rem) {

    .pw-store-grid {
        grid-template-columns: repeat(min(var(--pw-store-cols, 3), 3), 1fr);
        gap: 1.25rem;
    }
}

/* 1024px, tablet landscape. */
@media (max-width: 64rem) {

    .pw-store-grid {
        grid-template-columns: repeat(min(var(--pw-store-cols, 3), 2), 1fr);
    }
}

/* 768px, tablet portrait. Two cards still work at this width, but the
   bar above them does not: the search field was pushed to the end with
   margin-left: auto and had nowhere left to go. Previously nothing
   fired until 767px, so an iPad in portrait sat one pixel outside the
   only rule that would have helped it. */
@media (max-width: 48rem) {

    .pw-store-grid {
        gap: 1rem;
    }

    .pw-related-title,
    .pw-related-posts-title {
        font-size: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .pw-store-bar {
        gap: .5rem;
    }

    .pw-store-search {
        margin-left: 0;
        width: 100%;
    }

    .pw-store-search-input {
        width: 100%;
        min-width: 0;
    }

    /* a panel sized to its content runs off the edge once the button
       it hangs from is near the right margin */
    .pw-dd-panel {
        max-width: calc(100vw - 2rem);
    }
}

/* 600px, one card per row. */
@media (max-width: 37.5rem) {

    .pw-store-grid {
        grid-template-columns: 1fr;
    }

    /* The bar is a wrapping flex row, so at this width every control is
       already on its own line. Stretching them removes the ragged
       right edge that leaves. */
    .pw-store-bar {
        align-items: stretch;
    }

    .pw-card-body {
        padding: 1rem;
    }

    .pw-dd-btn {
        width: 100%;
        justify-content: space-between;
    }

    .pw-dd {
        width: 100%;
    }

    /* Anchored to .pw-dd, so once that is full width the panel can be
       too, and it stops being a narrow list floating under a wide
       button. */
    .pw-dd-panel {
        width: 100%;
        min-width: 0;
    }
}

/* Touch: the card lift is bound to :hover and sticks after a tap. */
@media (hover: none) {

    .pw-card:hover {
        transform: none;
        box-shadow: none;
    }

    .pw-card-img img {
        transform: none;
    }
}


@media (prefers-reduced-motion: reduce) {
    .pw-card,
    .pw-card-img img,
    .pw-dd-btn,
    .pw-dd-caret,
    .pw-dd-opt,
    .pw-dd-check,
    .pw-store-search-input,
    .pw-store-more-btn {
        transition: none;
    }
}
