:root {
    --paper: #fdf6e3;
    --card-bg: #fffbef;
    --soft: #f4f0d9;
    --line: #e0dcc7;
    --ink: #2d353b;
    --quiet: #5c6a72;
    --key: #425047;
    --focus: #547540;
    --error: #9b403d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font:
        16px/1.48 'Segoe UI',
        Arial,
        sans-serif;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: clamp(34px, 4.4vw, 66px);
    line-height: 1.06;
    letter-spacing: -0.05em;
}

h2 {
    font-size: clamp(22px, 2.25vw, 29px);
    line-height: 1.18;
    letter-spacing: -0.035em;
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    color: #466844;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button,
summary,
select,
input[type='checkbox'] {
    cursor: pointer;
}

button {
    border: 0;
    background: none;
    padding: 0;
}

button:disabled {
    cursor: default;
}

fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

input[type='checkbox'] {
    accent-color: var(--key);
}

input:not([type='hidden']):not([type='checkbox']):not([type='search']),
select {
    min-width: 0;
    max-width: 100%;
    padding: 7px 9px;
    border: 1px solid #a8ac97;
    border-radius: 5px;
    background: var(--card-bg);
}

input[aria-invalid='true'],
select[aria-invalid='true'] {
    border-color: var(--error) !important;
}

.wrap {
    width: min(1376px, 92%);
    margin-inline: auto;
}

.skip {
    position: absolute;
    inset-inline-start: -9999px;
}

.skip:focus {
    inset-inline-start: 1rem;
    z-index: 3;
    padding: 8px 12px;
    background: white;
}

.visually-hidden,
.facet > fieldset > legend,
.isbn-facet > label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.site-header {
    border-bottom: 1px solid var(--line);
    background: var(--card-bg);
}

.top {
    display: grid;
    grid-template-columns: auto auto minmax(120px, 1fr) auto;
    align-items: center;
    min-height: 72px;
    gap: clamp(14px, 2.5vw, 44px);
}

.brand,
.site-nav,
.account,
.basket {
    display: flex;
    align-items: center;
}

.brand {
    gap: 9px;
    font-size: 25px;
    font-weight: 750;
    letter-spacing: -0.055em;
}

.brand img {
    width: 30px;
    height: 31px;
    object-fit: contain;
    mix-blend-mode: multiply;
}

.site-nav {
    gap: clamp(12px, 2.2vw, 26px);
    font-size: 15px;
}

.active {
    text-decoration: underline;
    text-decoration-color: var(--key);
    text-underline-offset: 6px;
    text-decoration-thickness: 2px;
}

.account {
    gap: 16px;
    justify-content: end;
    font-size: 15px;
}

.account form {
    margin: 0;
}

.basket {
    gap: 6px;
    min-height: 44px;
}

.basket img {
    width: 18px;
}

.basket-count {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    min-height: 22px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--key);
    color: var(--card-bg);
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.login {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    white-space: nowrap;
    padding: 6px 16px;
    border: 1px solid #a8ac97;
    border-radius: 24px;
}

.profile {
    position: relative;
}

.profile-avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--key);
    background: var(--key);
    color: var(--card-bg);
    font-size: 17px;
    font-weight: 700;
    list-style: none;
}

.profile-avatar::-webkit-details-marker {
    display: none;
}

.profile-avatar:hover,
.profile[open] .profile-avatar {
    background: #314438;
}

.profile-menu {
    position: absolute;
    inset-block-start: calc(100% + 8px);
    inset-inline-end: 0;
    z-index: 2;
    width: min(216px, 90vw);
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card-bg);
    box-shadow: 0 8px 24px #2d353b1a;
}

.profile-name {
    padding: 8px 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
    color: var(--quiet);
    overflow-wrap: anywhere;
}

.profile-menu a,
.profile-menu button {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: 4px;
    text-align: start;
}

.profile-menu a:hover,
.profile-menu button:hover {
    background: var(--soft);
    color: var(--ink);
}

.top form[role='search'] {
    width: 100%;
    max-width: 620px;
    margin-inline: auto;
}

.search-field {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    border-bottom: 1px solid #989d88;
    cursor: text;
}

.search-field img {
    width: 18px;
    flex: none;
}

.search-field input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    border: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.search-field input::placeholder {
    color: var(--quiet);
    opacity: 1;
}

.search-field:focus-within {
    border-color: var(--focus);
    box-shadow: inset 0 -1px var(--focus);
}

.search-field input:focus {
    outline: none;
}

@media (forced-colors: active) {
    .search-field:focus-within {
        outline: 2px solid Highlight;
    }
}

.hero {
    background: #f3eed9;
    border-bottom: 1px solid var(--line);
}

.hero-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 116px;
    padding-block: 8px;
}

.hero-inner h1 {
    font-size: clamp(27px, 4.4vw, 58px);
}

.isbn-request-link {
    margin-top: 8px;
}

.hero-inner::after {
    content: '';
    flex: 0 0 min(38%, 330px);
    height: 100px;
    background: url('forest-book-transparent.png') right center / contain no-repeat;
    opacity: 0.43;
    mix-blend-mode: multiply;
}

.layout {
    display: grid;
    grid-template-columns: clamp(192px, 18vw, 244px) minmax(0, 1fr);
    gap: clamp(22px, 3vw, 50px);
    padding-block: 32px 60px;
}

.catalog-sidebar {
    border-inline-end: 1px solid var(--line);
    padding-inline-end: 20px;
}

.filters-panel > summary {
    display: none;
}

.filters-panel > summary small {
    color: var(--quiet);
    font-size: 13px;
    font-weight: 400;
}

.filters-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 15px;
}

.filters-heading h2 {
    font-size: 23px;
}

.facet {
    border-top: 1px solid var(--line);
    padding-block: 5px;
}

.facet > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 42px;
    font-size: 16px;
    font-weight: 700;
    list-style: none;
}

.facet > summary::-webkit-details-marker {
    display: none;
}

.facet > summary::after {
    content: '';
    flex: none;
    width: 6px;
    height: 6px;
    margin-inline-end: 3px;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}

.facet[open] > summary::after {
    transform: rotate(225deg);
}

.facet[open] {
    padding-bottom: 11px;
}

.choice-facet label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    font-size: 15px;
    cursor: pointer;
}

.choice-facet input[type='checkbox'] {
    flex: none;
    width: 14px;
    height: 14px;
    margin: 0 0 0 3px;
}

.year-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.year-options label {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}

.year-options input,
.isbn-facet input {
    width: 100%;
}

.link {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.filter-reset {
    color: var(--quiet);
    font-size: 15px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin: 1px 0 18px;
}

.sort-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    gap: 6px 12px;
}

.sort-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 4px 10px;
}

.sort-field label {
    font-size: 15px;
    color: var(--quiet);
}

.sort-field select {
    width: 164px;
    min-height: 40px;
    padding-inline: 8px;
    border-color: #b8baa4;
}

.sort-field .errorlist {
    grid-column: 1 / -1;
}

.apply-filters {
    min-height: 40px;
    padding-inline: 2px;
    color: var(--key);
    font-size: 14px;
    font-weight: 650;
}

.apply-filters:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.primary,
.add {
    background: var(--key);
    color: var(--card-bg);
    font-weight: 650;
}

.primary,
.secondary {
    min-height: 40px;
    border-radius: 24px;
    padding: 7px 18px;
}

.secondary {
    border: 1px solid #a5ab96;
}

.primary:hover:not(:disabled) {
    background: #314438;
}

.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(196px, 100%), 1fr));
    grid-auto-rows: 1fr;
    gap: 20px 16px;
}

.card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--card-bg);
}

.book-link {
    display: block;
    border-radius: 9px;
}

.plate {
    display: grid;
    place-items: center;
    min-width: 0;
    background: var(--soft);
    overflow: hidden;
    aspect-ratio: 2 / 3;
    border-radius: 8px;
}

.plate > img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.missing {
    padding: 10px;
    text-align: center;
    color: var(--key);
}

.missing img {
    display: block;
    width: 38px;
    margin: 0 auto 4px;
    mix-blend-mode: multiply;
}

.missing span {
    font-size: 13px;
}

.card h3 {
    margin: 12px 14px 4px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    font-size: 17px;
    line-height: 1.26;
    letter-spacing: -0.02em;
}

.book-link:hover h3 {
    text-decoration: underline;
}

.byline,
.card-year,
.card-score,
.meta,
.author,
.stats,
.info dt {
    color: var(--quiet);
}

.byline {
    margin: 0 14px;
    font-size: 14px;
    overflow-wrap: anywhere;
}

.card-year {
    margin: 3px 14px 11px;
    font-size: 13px;
}

.card-actions {
    display: grid;
    gap: 8px;
    margin: auto 14px 14px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.purchase-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.card-score {
    font-size: 13px;
}

.card-actions button,
.card-actions a.buy,
.card-actions a.library-state {
    min-height: 40px;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 650;
}

.library-add {
    width: 100%;
}

.buy {
    display: inline-flex;
    align-items: center;
    background: var(--soft);
    border: 1px solid var(--line);
    color: var(--key);
}

.buy:hover {
    border-color: var(--key);
}

.card-actions button:disabled,
.actions button:disabled {
    opacity: 0.68;
}

.catalog-empty {
    padding: clamp(16px, 3vw, 28px);
    background: var(--card-bg);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.catalog-empty p {
    color: var(--quiet);
    margin-top: 5px;
}

.catalog-status {
    margin-bottom: 12px;
}

.catalog-status[role='alert'] {
    color: var(--error);
}

.catalog-unavailable {
    max-width: 720px;
    padding-block: clamp(30px, 7vw, 78px);
}

.catalog-unavailable h1 {
    margin-bottom: 18px;
    font-size: clamp(27px, 4.4vw, 46px);
}

.book-layout {
    display: grid;
    grid-template-columns: clamp(190px, 26%, 320px) minmax(0, 1fr);
    align-items: start;
    gap: clamp(24px, 3.5vw, 52px);
    padding-block: 30px 60px;
}

.book-layout .plate:has(> img) {
    display: block;
    border-radius: 0;
    background: none;
    aspect-ratio: auto;
}

.book-layout .plate > img {
    width: 100%;
    height: auto;
}

.info {
    min-width: 0;
    max-width: 730px;
    overflow-wrap: anywhere;
}

.info h1 {
    font-size: clamp(32px, 3.7vw, 55px);
    margin: 8px 0 12px;
}

.info .author {
    font-size: 19px;
}

.info .stats {
    margin-top: 8px;
    font-size: 14px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin: 18px 0 26px;
}

.basket-state {
    display: inline-flex;
    align-items: center;
    border-color: var(--key);
    background: var(--key);
    color: var(--card-bg);
}

.basket-state:hover {
    border-color: #314438;
    background: #314438;
    color: var(--card-bg);
}

[data-basket-add][aria-busy='true'] button {
    cursor: wait;
    opacity: 0.68;
}

.basket-add-error {
    margin-top: 6px;
    color: var(--error);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.library-state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: var(--soft);
    color: var(--key);
}

.library-state:hover {
    border-color: var(--key);
    color: var(--key);
}

.info [role='alert'],
.basket-page [role='alert'],
.library-page [role='alert'] {
    color: var(--error);
}

.info section {
    border-top: 1px solid var(--line);
    padding-block: 19px;
}

.info section h2 {
    margin-bottom: 11px;
    font-size: 23px;
}

.info section p + p {
    margin-top: 8px;
}

.info dl {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) 2fr;
    gap: 7px 14px;
    margin: 0;
}

.info dd {
    margin: 0;
}

.basket-page {
    max-width: 880px;
    padding-block: clamp(28px, 6vw, 64px);
}

.basket-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 24px;
    margin-bottom: 24px;
}

.basket-heading h1 {
    font-size: clamp(36px, 5vw, 61px);
}

.basket-items {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--line);
}

.basket-item {
    display: grid;
    grid-template-columns: clamp(70px, 12vw, 88px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px clamp(14px, 3vw, 28px);
    padding-block: 16px;
    border-bottom: 1px solid var(--line);
}

.basket-item .missing {
    padding: 4px;
}

.basket-item .missing img {
    width: 28px;
}

.basket-item .missing span {
    font-size: 11px;
}

.basket-book {
    overflow-wrap: anywhere;
}

.basket-book h2 {
    font-size: clamp(18px, 2.5vw, 24px);
}

.basket-book .author {
    margin-top: 6px;
}

.basket-remove,
.library-remove {
    min-height: 44px;
}

.basket-remove:hover,
.library-remove:hover {
    background: var(--soft);
}

.basket-notice {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card-bg);
}

.basket-notice p {
    margin-bottom: 10px;
}

.library-page {
    max-width: 720px;
    padding-block: clamp(28px, 6vw, 64px);
}

.library-page h2 {
    margin-block: 30px 12px;
}

.library-editions {
    margin: 0;
    padding: 0;
    list-style: none;
    border-top: 1px solid var(--line);
}

.library-editions li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-block: 10px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.library-editions form {
    flex: none;
}

.login-page,
.settings-page {
    max-width: 480px;
    padding-block: clamp(30px, 7vw, 78px);
}

.login-page h1,
.settings-page h1 {
    margin-bottom: 25px;
    font-size: clamp(31px, 4.8vw, 49px);
}

.login-form {
    display: grid;
    gap: 16px;
    padding: clamp(16px, 4vw, 28px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card-bg);
}

.login-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.login-form input:not([type='hidden']) {
    width: 100%;
    min-height: 44px;
}

.login-form button {
    justify-self: start;
}

.login-page [role='alert'],
.errorlist {
    color: var(--error);
}

.errorlist {
    margin: 5px 0;
    padding-inline-start: 20px;
    font-size: 14px;
}

.settings-list {
    margin: 0;
    border-top: 1px solid var(--line);
}

.settings-list > div {
    display: grid;
    grid-template-columns: minmax(70px, 1fr) minmax(0, 3fr);
    gap: 12px;
    padding-block: 12px;
    border-bottom: 1px solid var(--line);
}

.settings-list dt {
    color: var(--quiet);
}

.settings-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 1020px) {
    .top {
        grid-template-columns: auto 1fr auto;
        gap: 8px 18px;
        padding-block: 10px;
    }

    .top form[role='search'] {
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: none;
    }
}

@media (max-width: 820px) {
    .layout {
        grid-template-columns: 180px minmax(0, 1fr);
        gap: 17px;
    }

    .catalog-sidebar {
        padding-inline-end: 13px;
    }
}

@media (max-width: 700px) {
    .top {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .brand {
        font-size: 22px;
    }

    .site-nav {
        grid-row: 2;
        grid-column: 1 / -1;
    }

    .top form[role='search'] {
        grid-row: 3;
    }

    .account {
        grid-row: 1;
        grid-column: 2;
        gap: 8px;
        font-size: 14px;
    }

    .login {
        padding-inline: 10px;
    }

    .hero-inner {
        min-height: 82px;
        gap: 8px;
    }

    .hero-inner::after {
        height: 64px;
        flex-basis: min(31%, 170px);
    }

    .layout {
        display: block;
        padding-top: 16px;
    }

    .catalog-sidebar {
        padding: 0;
        border: 0;
    }

    .filters-panel > summary {
        display: list-item;
        margin-bottom: 15px;
        padding: 7px 13px;
        border: 1px solid var(--line);
        border-radius: 18px;
        font-size: 16px;
        font-weight: 700;
    }

    .filters-heading {
        justify-content: end;
        margin: 0 0 8px;
    }

    .filters-heading h2 {
        display: none;
    }

    .filters-panel[open] {
        margin-bottom: 15px;
    }

    .catalog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 16px 12px;
    }

    .card h3 {
        font-size: 16px;
    }

    .book-layout {
        display: block;
        padding-top: 22px;
    }

    .book-layout .plate {
        width: min(64%, 270px);
        margin: 0 auto 20px;
    }
}

@media (max-width: 440px) {
    .basket-item {
        grid-template-columns: 70px minmax(0, 1fr);
    }

    .basket-item .plate {
        grid-row: span 2;
    }

    .basket-item form {
        grid-column: 2;
    }

    .card h3,
    .byline,
    .card-year,
    .card-actions {
        margin-inline: 8px;
    }

    .card-actions button,
    .card-actions a.buy,
    .card-actions a.library-state {
        padding-inline: 7px;
    }

    .purchase-row {
        gap: 3px;
    }

    .sort-controls {
        width: 100%;
        column-gap: 8px;
    }

    .sort-field {
        column-gap: 8px;
    }
}

@media (max-width: 370px) {
    .top {
        column-gap: 10px;
    }

    .brand {
        font-size: 20px;
    }
}
