:root :where(.wp-block-woocommerce-checkout.wc-block-checkout) {
    .wp-block-woocommerce-checkout-order-summary-block {
        border-width: 0;
        border-radius: 1rem;
        /*
         * The design spaces this panel on a flat 40px rhythm -- title, the
         * line items, the coupon row, the summary lines, the total -- with
         * 40px either side of each of its two rules. Core has no gap and leans
         * on 16px of padding inside each block instead, which reads as about
         * 32px between some pairs and 22px between others. See the block
         * resets at the end of this file.
         */
        display: flex;
        flex-direction: column;
        gap: 40px;

        @media (width >= 1280px) {
            margin-left: 8px;
        }

        @media (width >= 768px) {
            padding: var(--wp--preset--spacing--12);
            background-color: var(--wp--preset--color--stone-50);
        }

        .checkout-order-summary-block-fill {
            border-width: 0;
        }

        &.checkout-order-summary-block-fill-wrapper {
            padding: var(--wp--preset--spacing--6);
            background-color: var(--wp--preset--color--stone-50);
        }

        .wc-block-components-checkout-order-summary__title {
            margin-top: 0;

            .wc-block-components-checkout-order-summary__title-text {
                margin-left: 0;
                /* The panel's gap owns the space below the title. */
                margin-bottom: 0;
                font-size: var(--wp--preset--font-size--2-xl);
                font-weight: 500;
                line-height: 1.25;
                font-family: var(--wp--preset--font-family--eb-garamond);

                @media (width >=768px) {
                    font-size: var(--wp--preset--font-size--3-5-xl);
                }
            }

            .wc-block-components-checkout-order-summary__title-icon {
                @media (width <= 767px) {
                    display: flex;
                }
            }
        }

        .wc-block-components-order-summary {
            padding: 0;
        }

        .wc-block-components-order-summary-item__individual-prices,
        .wc-block-components-order-summary-item__total-price {
            line-height: 1.55;
            display: inline-block;
            letter-spacing: 0.18px;
        }

        .wc-block-components-order-summary-item__individual-prices {
            .wc-block-components-formatted-money-amount {
                font-weight: 400;
            }

            ins {
                float: left;
                margin-left: 0;
                margin-right: 6px;
                color: var(--wp--preset--color--red-600);
            }

            del {
                color: var(--wp--preset--color--stone-600);
                font-size: 0.875rem;
            }
        }

        .wc-block-components-order-summary-item__total-price {
            .wc-block-components-formatted-money-amount {
                font-weight: 500;
            }
        }

        .wc-block-components-totals-wrapper:last-child {
            @media (width >= 768px) {
                padding-bottom: 0;
            }
        }

    }

    /*
     * The design underlines this with a 1px rule 2px under the text, which is
     * the same link treatment the cart uses for "Remove item". A border rather
     * than text-decoration, because an underline cannot be offset to a given
     * distance consistently across browsers -- and core ships this link with
     * text-decoration: none anyway, which is why the text-underline-offset
     * that used to sit here drew nothing at all.
     */
    .wc-block-components-checkout-return-to-cart-button {
        font-size: 1.125rem;
        font-weight: 500;
        line-height: 1.55;
        letter-spacing: .18px;
        color: var(--wp--preset--color--stone-950);
        padding: 0 0 2px;
        border-bottom: 1px solid var(--wp--preset--color--stone-950);
        text-decoration: none;
        width: fit-content;

        svg {display: none;}
    }

    .wc-block-checkout__actions {
        .wc-block-checkout__actions_row {
            /* The design sizes Place order to its content and sits it opposite
               the return link, which showReturnToCart in the checkout pattern
               is what actually switches on. */
            .wc-block-components-checkout-place-order-button {
                padding: 10px 28px;
                font-size: 18px;
                line-height: 28px;
                letter-spacing: 0.18px;
            }

            @media (width <= 767px) {
                margin-top: 2rem;
                align-items: stretch;
                gap: 10px;

                .wc-block-components-checkout-place-order-button {
                    width: 100%;
                }
            }
        }
    }

    @media (width <= 1023px) {
        .wc-block-components-sidebar-layout  {
            .wc-block-components-main,
            .wc-block-components-sidebar {
                padding: 0;
                width: 100%;
            }
        }
    }

    @media (768px <= width <= 1023px) {
        .wc-block-components-sidebar-layout {
            flex-direction: column-reverse;
            gap: 2rem;
        }
    }

    @media (1024px <= width <= 1279px) {
        .wc-block-components-sidebar-layout {
            .wc-block-components-main {
                width: 60%;
                padding-right: 2rem;
            }

            .wc-block-components-sidebar {
                width: 40%;
                padding-left:0;
            }
        }
    }

    .wc-block-checkout__form {
        @media (width >= 1280px) {
            margin-right: 2.375rem;
        }

        .wc-block-components-checkout-step__title {
            font-family: var(--wp--preset--font-family--eb-garamond);
            line-height: 1.33;
            font-weight: 500;
            font-size: var(--wp--preset--font-size--2-xl);
        }

        /*
         * The gap under a section title, split between two elements so both
         * kinds of section land on the design's numbers.
         *
         * The description sits inside the heading container, so its own margin
         * and the container's stack -- 32px + core's 16px was pushing the
         * fields 48px down. The container now owns the base 24px, which is the
         * gap the design gives sections that are only a title (Shipping
         * options), and the description adds the remaining 8px to reach the
         * 32px the design gives sections with body copy under the title.
         */
        .wc-block-components-checkout-step__heading-container {
            /* Flex with a gap, so the title-to-body spacing belongs here
               rather than on the description's margin -- the two stack. */
            gap: 12px;
            margin-bottom: 24px;
        }

        .wc-block-components-checkout-step__description {
            margin-bottom: 8px;
            letter-spacing: .16px;
            line-height: 1.62;
            font-size: 1rem;
        }

        .wc-block-components-checkout-step {
            @media (width >= 1280px) {
                margin-bottom: var(--wp--preset--spacing--16);
            }
        }
    }
    
    /*
     * The form, per the design: sections 64px apart, fields 28px apart inside
     * a section, and two-up rows 24px. Core ships a much tighter 12px rhythm.
     */
    /*
     * The field label doubles as the placeholder until the field has a value,
     * so it carries the placeholder colour. Only the colour: a font-size here
     * pins the label at placeholder size once it floats, and it then sits on
     * top of what the customer typed.
     */
    .wc-block-components-text-input label,
    .wc-blocks-components-select__label {
        color: var(--wp--preset--color--stone-600);
    }

    /* Shipping and payment options are cards in the design, not bare rows. */
    .wc-block-components-radio-control__option {
        border: 1px solid var(--wp--preset--color--stone-300);
        border-radius: 12px;
        /*
         * The design's card is 50px tall with 12px from the text to its edge.
         * Figma paints a stroke inside the frame, so in CSS the border has to
         * come out of the padding: 11px + the 1px border is the same 12px, and
         * 11 + 26 + 11 + 2 lands the box on 50 rather than 52.
         */
        padding: 11px 16px 11px 44px;
    }

    /* The terms line is body copy in the design, not fine print. */
    .wc-block-checkout__terms {
        font-size: 16px;
        line-height: 26px;
        letter-spacing: 0.16px;
        color: var(--wp--preset--color--stone-800);
    }

    .wc-block-components-sidebar {
        .slot-wrapper .wc-block-components-panel,
        .wc-block-components-panel,
        .wc-block-components-totals-coupon,
        .wc-block-components-totals-item {
            padding: 0;
        }

        /*
         * A summary line is 28px in the design -- one line of text. Core lays
         * it out as a wrapping flex row with a 4px row gap and always renders
         * an empty description alongside the label and amount, so that empty
         * child takes a second row and the 4px comes with it.
         */
        .wc-block-components-totals-item {
            row-gap: 0;

            > .wc-block-components-totals-item__description:empty {
                display: none;
            }
        }

        .wc-block-components-totals-coupon {
            .wc-block-components-panel__button {
                font-size: 1.125rem;
                font-weight: 500;
                color: var(--wp--preset--color--stone-950);
                margin-bottom: 0;
            }
        }
    }

    .wc-block-components-totals-wrapper {
        border-color: var(--wp--preset--color--stone-300);
    }

    .wp-block-woocommerce-checkout-order-summary-totals-block {
        font-size: 1.125rem;

        /* A regular label against a medium amount, as in the cart. */
        .wc-block-components-totals-item__label {
            font-weight: 400;
            line-height: 28px;
            letter-spacing: 0.18px;
        }

        /* The amount span carries both classes, so __value is enough -- and
           matching on .wc-block-components-formatted-money-amount here would
           undercut core's more specific rules for the item prices above. */
        .wc-block-components-totals-item__value {
            font-weight: 500;
            line-height: 28px;
            letter-spacing: 0.18px;
        }
    }

    /*
     * The blocks give up the padding they were using to stand in for a
     * gap, and the two rules the design keeps get their 40px below from
     * padding-top -- the flex gap supplies the 40px above. Core draws a
     * third rule over the coupon row that the design does not have.
     *
     * Scoped through __content so these are no less specific than the
     * :last-child rule above them; written plainer they descend below it
     * and stylelint fails.
     */
    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-checkout-order-summary__content {
        display: flex;
        flex-direction: column;
        gap: 40px;
    }

    /* The line items sit on the same 40px rhythm as everything else. */
    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-order-summary__content {
        display: flex;
        flex-direction: column;
        gap: 40px;
    }

    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-checkout-order-summary__content .wc-block-components-totals-wrapper {
        padding-top: 0;
        padding-bottom: 0;
        margin-bottom: 0;
    }

    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-checkout-order-summary__content .wp-block-woocommerce-checkout-order-summary-coupon-form-block {
        border-top: 0;
    }

    /*
     * The summary lines sit 16px apart. The empty blocks core always renders
     * for a discount and a fee have to be taken out of flow first, or the gap
     * counts them and the rows drift apart.
     */
    .wp-block-woocommerce-checkout-order-summary-block .wp-block-woocommerce-checkout-order-summary-totals-block {
        display: flex;
        flex-direction: column;
        gap: 16px;

        > :empty {
            display: none;
        }
    }

    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-checkout-order-summary__content > .wp-block-woocommerce-checkout-order-summary-totals-block,
    .wp-block-woocommerce-checkout-order-summary-block .wc-block-components-checkout-order-summary__content > .wc-block-components-totals-wrapper:last-child {
        padding-top: 40px;
        padding-bottom: 0;
    }


    .wc-block-components-totals-footer-item {
        /* A single row -- core's 4px row gap only adds height. */
        row-gap: 0;
        /*
         * Core calls this "Total" at checkout and "Estimated total" in the
         * cart; the design uses the cart's wording in both. The string comes
         * from Skinelle::print_store_labels() so it stays translatable, and
         * the row keeps its own markup and semantics either way.
         */
        .wc-block-components-totals-item__label {
            font-size: 0;
            line-height: 28px;
            letter-spacing: 0.18px;

            &::after {
                content: var(--skinelle-total-label, "Estimated total");
                font-size: 18px;
            }
        }
    }

    .wc-block-components-totals-coupon__form {
        flex-direction: column;
        gap: 16px;

        .wc-block-components-totals-coupon__input {
            flex:none;
        }
    }

    .wp-block-woocommerce-checkout-order-summary-cart-items-block {
        margin-bottom: 1.4rem;
    }

    .wc-block-components-order-summary {
        .wc-block-components-order-summary-item {
            /*
             * The design's card is as tall as its 100px photo. Core pads the
             * row and the description either side of it, which pushes the text
             * column past the photo and makes the card set its own height.
             */
            padding-top: 0;
            padding-bottom: 0;

            @media (width >= 768px) {
                font-size: 1.125rem;
            }

            .wc-block-components-order-summary-item__description {
                padding-top: 0;
                padding-bottom: 0;
            }

            .wc-block-components-product-metadata {
                font-size: 0.875rem;
                color: var(--wp--preset--color--stone-700);

                @media (width <= 767px) {
                    display: none;
                }
            }
        }

        .wc-block-components-product-name {
            font-size: 1.25rem;
            font-family: var(--wp--preset--font-family--eb-garamond);
            line-height: 1.4;
            font-weight: 500;
            margin: 0;
        }

        .wc-block-components-order-summary-item__image {
            /*
             * Core hangs 8px of margin above this and 16px of padding below,
             * which wraps the 100px photo in a 124px box and sets the row's
             * height. The design's card is the photo.
             */
            margin: 0;
            padding: 0;

            &,>img {
                @media (width >= 768px) {
                    width: 5.25rem;
                    height: auto;
                }
            }

            > img {
                max-width: 5.25rem;
                aspect-ratio: 21/25;
                object-fit: cover;
                border-radius: 8px;
            }            
        }

        .wc-block-components-order-summary-item__quantity {
            /*
             * The design hangs the bubble 10px off the corner of the photo.
             * Core also translates it 14px up and out, which would stack on
             * these offsets and float it clear of the image.
             */
            top: -10px;
            right: -10px;
            transform: none;
            width: 18px;
            height: 18px;
            background-color: var(--wp--preset--color--stone-600);
            border-width: 0;
            box-shadow: none;
            border-radius: 1000px;
            font-size: 0.875rem;
            line-height: 1.4;
            padding: 0;
            color: var(--wp--preset--color--white);

            @media (width >= 768px) {
                width: 28px;
                height: 28px;
            }
        }
    }

    .wc-block-components-form .wc-block-components-text-input,
    /*
     * Core puts `margin-top: 12px` on every field, which lands on top of the
     * form's own row gap and makes the rows 40px apart instead of the design's
     * 28px. The gap owns the rhythm here, so the margin goes -- from the text
     * inputs, the dropdowns, and the "add apartment" toggle alike.
     */
    .wc-block-components-address-form__address_2-toggle {
        margin-top: 0;
    }

    /*
     * Field height, per the design: 26px of text over 16px of space above the
     * rule, and nothing on top -- a 42px row rather than core's 50px.
     *
     * Core reserves that 16px of top padding so its label can shrink to a
     * caption above the value once the field is filled. With the padding gone
     * there is nowhere for the caption to sit, so the label becomes a plain
     * placeholder instead: shown while the field is empty, hidden once it is
     * active. The label stays in the DOM and every input keeps its own
     * aria-label, so assistive technology still announces the field; what a
     * sighted customer loses is the visible label on a filled field. That is
     * the trade the 42px row costs, and it is deliberate.
     */
    .wc-block-components-text-input {
        margin-top: 0;

        input[type=email],
        input[type=number],
        input[type=password],
        input[type=tel],
        input[type=text],
        input[type=url] {
            outline: none;
            /*
             * 26px of text over 15px, plus the 1px rule, is the design's 42px
             * row -- Figma paints the stroke inside the frame, so it comes out
             * of the 16px rather than adding to it. The transparent top border
             * core keeps for its focus state would add another pixel.
             */
            /*
             * !important, forced by one of core's own: it re-pads an active
             * field to 24px/8px to make room for the caption it floats, from a
             * selector carrying the input's type attribute. Matching that
             * specificity means restating all six type selectors, which reads
             * worse and buys nothing -- there is no caption to make room for.
             */
            border-top-width: 0 !important;
            padding-top: 0 !important;
            padding-bottom: 15px !important;
            line-height: 26px;
            height: auto;
        }

        /*
         * Core absolutely positions this at top: 25px -- the middle of the
         * 50px box it expects -- and transforms it between the placeholder and
         * caption positions. On a 42px box that lands it on the rule, so it is
         * pinned to the text line instead and simply fades out once the field
         * is in use.
         */
        label {
            top: 0;
            line-height: 26px;
            transform: none;
            transition: opacity 0.15s ease;
        }

    }

    .wc-blocks-components-select {
        margin-top: 0;

        .wc-blocks-components-select__select {
            border-color: transparent transparent var(--wp--preset--color--stone-300) transparent;
            border-radius: 0;
            outline: none;
            padding-inline: 0;
            /* Same 42px row as the text inputs. */
            border-top-width: 0 !important;
            padding-top: 0 !important;
            padding-bottom: 15px !important;
            line-height: 26px;
            height: auto;
        }

        .wc-blocks-components-select__expand {
            right: 0;
        }

        /*
         * Core marks the wrapper is-active once the control has a value, which
         * a country or state select always does -- so this label behaves as a
         * placeholder for an unset field and gets out of the way otherwise.
         */
        /*
         * A country or state select always carries a value, so its label has
         * nothing to stand in for and would sit on top of that value. It is
         * hidden outright rather than on a state class -- the visible label is
         * what the 42px row costs, and the select keeps its own aria-label.
         */
        label {
            left: 0;
            top: 0;
            line-height: 26px;
            transform: none;
            opacity: 0;
        }

    }

    .wc-block-components-form .wc-block-components-text-input:not(.has-error),
    .wc-block-components-text-input:not(.has-error) {
        input[type=email],
        input[type=number],
        input[type=password],
        input[type=tel],
        input[type=text],
        input[type=url] {
            border-color: transparent transparent var(--wp--preset--color--stone-300) transparent;
            background-color: transparent;
            padding-left: 0;
            border-radius: 0;

            &:focus-visible,
            &:focus {
                border-color: transparent transparent var(--wp--preset--color--stone-950) transparent;
            }
        }

        label {
            left: 0;
        }
    }

    @media (width >= 768px) {
        .wc-block-checkout__billing-fields .wc-block-components-address-form, 
        .wc-block-checkout__shipping-fields .wc-block-components-address-form {
            /* The design's field rhythm: 28px down, 24px across. */
            gap: 28px var(--wp--preset--spacing--6);
        }
    }

    .wc-block-components-radio-control--highlight-checked:after,
    .wc-block-components-radio-control--highlight-checked div.wc-block-components-radio-control-accordion-option:after {
        display: none;
    }

    .wc-block-components-radio-control--highlight-checked .wc-block-components-radio-control-accordion-option--checked-option-highlighted, 
    .wc-block-components-radio-control--highlight-checked label.wc-block-components-radio-control__option--checked-option-highlighted {
        box-shadow: inset 0 0 0 1px var(--wp--preset--color--stone-300);
    }

    .wc-block-components-radio-control-accordion-content {
        font-size: 0.875rem;
    }

    .wc-block-checkout__payment-method .wc-block-components-radio-control__option {
        padding-left: 2.6rem;
    }

    .wc-block-components-radio-control {
        > *:not(:last-child) {
            margin-bottom: 10px;
        }

        /* Core pins 4px on the label itself, so the card corner needs the
           extra class here to win rather than a bare selector above. */
        .wc-block-components-radio-control__option {
            border-radius: 12px;
        }

        /*
         * Core sets these at 13px/18. The design reads them as body copy at
         * 16/26, which is also what gives the option its height: 26px of text
         * inside 12px of padding.
         */
        .wc-block-components-radio-control__label,
        .wc-block-components-radio-control__secondary-label {
            color: var(--wp--preset--color--stone-950);
            font-size: 16px;
            line-height: 26px;
            letter-spacing: 0.16px;
        }

        /* Core draws separators between rows; the cards carry their own edge. */
        .wc-block-components-radio-control__option::after,
        .wc-block-components-radio-control-accordion-option::after {
            border: 0;
        }

        .wc-block-components-radio-control__input {
            height: 16px;
            width: 16px;
            min-width: 16px;
            min-height: 16px;

            &:checked {
                outline: none;

                border-color: var(--wp--preset--color--stone-300);

                &:before {
                    width: 10px;
                    height: 10px;
                    min-width: 10px;
                    min-height: 10px;
                    background-color: var(--wp--preset--color--stone-800);
                }
            }
        }

        .wc-block-components-radio-control-accordion-option {
            border-radius: 12px;
        }
    }

    /*
     * The placeholder gets out of the way once the field has a value. Kept at
     * the end of the file, and matched through .wc-block-components-form so it
     * is no less specific than core's own label rule above it -- otherwise
     * stylelint's no-descending-specificity fails on it.
     */
    .wc-block-components-form .wc-block-components-text-input.is-active label,
    .wc-block-components-form .wc-blocks-components-select.is-active label {
        opacity: 0;
    }
}
