body { padding-block-end: var(--cookie-banner-space, 0px); }

.cookie-banner {
    position: fixed;
    z-index: 40;
    inset-inline: 0;
    inset-block-end: max(.5rem, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .55rem 1.15rem;
    width: min(50rem, calc(100% - 1rem));
    max-height: 75dvh;
    margin-inline: auto;
    padding: .5rem .85rem .7rem;
    overflow: auto;
    color: var(--ink);
    background: #fffdfa;
    border: 1px solid var(--line);
    border-block-start: 2px solid var(--wine);
    border-radius: .65rem;
    box-shadow: 0 6px 26px #29192220;
}

.cookie-banner h2, .cookie-dialog h2 {
    color: var(--wine-deep);
    font: 700 1.23rem/1.25 var(--sans);
    letter-spacing: -.025em;
}

.cookie-banner p, .cookie-dialog p {
    margin: .35rem 0 .4rem;
    color: var(--muted);
    font-size: .9rem;
    line-height: 1.45;
}

.cookie-banner-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0 .65rem;
}

.cookie-banner-heading h2 { font-size: 1.05rem; }
.cookie-banner-heading .cookie-text-button { min-height: 2.75rem; }
.cookie-banner p { margin: 0; font-size: .85rem; }
.cookie-banner p a { white-space: nowrap; font-size: inherit; }

.cookie-banner a, .cookie-dialog a, .cookie-text-button {
    color: var(--wine);
    font: 650 .84rem/1.4 var(--sans);
    text-decoration: underline;
    text-underline-offset: .2em;
}

.cookie-text-button {
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.cookie-banner-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .45rem;
}

.cookie-banner-actions .outline-link {
    width: 100%;
    min-height: 2.75rem;
    padding: .35rem .65rem;
    border-color: var(--wine);
    color: var(--wine-deep);
    background: #f8ede9;
    font-size: .81rem;
    text-align: center;
    white-space: normal;
}

.cookie-banner-actions .outline-link:hover { background: #eddbd6; }
.footer-legal .cookie-text-button { min-height: 2.25rem; color: #e4d6d3; }
.footer-legal .cookie-text-button:hover { color: var(--peach); }
.reader-saved-link.cookie-text-button { min-height: 2.75rem; }
.legal-cookie-settings { margin-top: .75rem; }

body:has(.cookie-dialog[open]) { overflow: hidden; }

.cookie-dialog {
    position: fixed;
    inset: 0;
    --cookie-dialog-edge: max(.5rem, env(safe-area-inset-bottom));
    width: min(29rem, calc(100% - 1rem));
    max-width: none;
    max-height: calc(100dvh - var(--cookie-dialog-edge) - .5rem);
    margin: auto;
    padding: 0;
    overflow: hidden;
    color: var(--ink);
    background: #fffdfa;
    border: 1px solid var(--line);
    border-radius: .7rem;
    box-shadow: 0 14px 50px #29192238;
}

.cookie-dialog[open] { display: grid; grid-template-rows: minmax(0, 1fr); }
.cookie-dialog form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.cookie-dialog::backdrop { background: #2618249c; }
.cookie-dialog-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: .7rem;
    padding: .65rem clamp(.75rem, 3vw, 1rem);
    background: #f7eee8;
    border-bottom: 1px solid var(--line);
}

.cookie-dialog-header h2 { font-size: 1.3rem; }
.cookie-dialog-header p { margin: .2rem 0 0; }
.cookie-dialog-close {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    border: 1px solid var(--line);
    border-radius: .35rem;
    background: var(--white);
    color: var(--wine-deep);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.cookie-dialog-close:hover { background: #eddbd6; }
.cookie-options {
    display: grid;
    align-content: start;
    gap: .4rem;
    min-height: 0;
    padding: .55rem clamp(.75rem, 3vw, 1rem);
    overflow: auto;
    overscroll-behavior: contain;
}
.cookie-option { min-width: 0; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: .35rem; overflow-wrap: anywhere; }
.cookie-option p { margin: .2rem 0 0; font-size: .84rem; }
.cookie-option-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--wine-deep); font: 700 .94rem/1.3 var(--sans); }
.cookie-option-heading h3 { font: inherit; }
.cookie-option-heading h3 + span { padding: .25rem .4rem; border-radius: .25rem; color: #644253; background: #f0e6eb; font-size: .73rem; text-align: center; }
.cookie-option label { min-height: 2.75rem; margin-block: -.3rem; cursor: pointer; }

.cookie-option input[role="switch"] {
    appearance: none;
    display: grid;
    flex: 0 0 auto;
    align-items: center;
    width: 2.6rem;
    height: 1.45rem;
    margin: 0;
    padding-inline: .15rem;
    border: 1px solid #7c676e;
    border-radius: 2rem;
    background: #e5dddc;
    cursor: pointer;
}

.cookie-option input[role="switch"]::before { content: ""; width: 1rem; height: 1rem; border-radius: 50%; background: #fffdfa; border: 1px solid #7c676e; }
.cookie-option input[role="switch"]:checked { background: var(--wine); border-color: var(--wine); }
.cookie-option input[role="switch"]:checked::before { justify-self: end; border-color: #fffdfa; }
.cookie-banner :focus-visible, .cookie-dialog :focus-visible, .cookie-text-button:focus-visible { outline: 2px solid #aa705a; outline-offset: 3px; }

.cookie-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .2rem .65rem;
    padding: .45rem clamp(.75rem, 3vw, 1rem);
    border-top: 1px solid var(--line);
}
.cookie-dialog-actions a { display: inline-flex; align-items: center; min-height: 2.75rem; }
.cookie-dialog-actions .button { min-height: 2.75rem; padding-inline: .75rem; text-align: center; white-space: normal; }

@media (max-width: 43rem) {
    .cookie-banner { grid-template-columns: minmax(0, 1fr); padding: .1rem .75rem .65rem; }
    .cookie-dialog { inset-block: auto var(--cookie-dialog-edge); margin-block: 0; }
}

@media (max-height: 25rem) and (min-width: 31rem) {
    .cookie-dialog { width: min(34rem, calc(100% - 1rem)); }
    .cookie-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
