:root {
    --paper: #ebdcbf;
    --paper-deep: #e0cda9;
    --ink: #3a2c1c;
    --ink-soft: #65553f;
    --accent: #8c2f1e;
    --accent-ink: #fbf5e8;
    --rule: rgba(58, 44, 28, 0.22);
    --shadow: 0 1px 3px rgba(58, 44, 28, 0.25);
    --radius: 2px;
    --page-width: 1100px;
    --control-height: 2.5rem;
    --control-font: 1rem;
    --control-pad: clamp(10px, 2.5vw, 16px);
    --font: "Iowan Old Style", "Palatino Linotype", Palatino, "TeX Gyre Pagella", "Noto Serif Devanagari", Georgia, serif;
    --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.26 0 0 0 0 0.14 0 0 0 0.10 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    --paper-fibres: url("../images/paper-fibres.2ead0826c9aa.webp");
    --paper-blotches: url("../images/paper-blotches.360201b826a7.webp");
    --sheet-size: max(100vw, 100vh * 4 / 3) auto;
}

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

html {
    color-scheme: light;
}

.save-data body::before,
.save-data .site-header {
    background-image: var(--paper-grain);
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    font-size: 1.0625rem;
    line-height: 1.6;
    font-variant-numeric: oldstyle-nums;
    color: var(--ink);
    background-color: var(--paper);
    overflow-wrap: break-word; /* a long link, email or username breaks instead of widening the page */
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image: var(--paper-grain), var(--paper-fibres), var(--paper-blotches);
    background-size: auto, var(--sheet-size), var(--sheet-size);
}

a {
    color: var(--accent);
}

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

h1 {
    font-size: 1.6rem;
    line-height: 1.25;
    font-weight: 600;
    margin: 0 0 0.5em;
}

.page-heading {
    margin: 0 0 20px;
    padding-bottom: 6px;
    font-size: 1.35rem;
    font-weight: normal;
    font-style: italic;
    border-bottom: 3px double var(--rule);
}

input,
button {
    font: inherit;
}

.icon {
    width: 26px;
    height: 26px;
    flex: none;
}

[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 12px max(16px, calc((100% - var(--page-width)) / 2 + 16px));
    background-color: var(--paper);
    background-image: var(--paper-grain), var(--paper-fibres), var(--paper-blotches);
    background-size: auto, var(--sheet-size), var(--sheet-size);
    border-bottom: 1px solid var(--rule);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    text-decoration: none;
}

.brand-name {
    display: block;
    color: var(--ink);
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.brand-motto {
    display: block;
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-style: italic;
    line-height: 1.2;
    white-space: nowrap;
}

.search {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 420px;
    justify-self: center;
}

.search input {
    flex: 1;
    min-width: 0;
    height: var(--control-height);
    padding: 0 10px;
    font-size: var(--control-font);
    color: var(--ink);
    background: rgba(255, 252, 243, 0.5);
    border: 1px solid var(--rule);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
}

.search button {
    display: flex;
    align-items: center;
    padding: 0 10px;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer;
}

.search button:hover {
    background: rgba(255, 252, 243, 0.5);
}

.search button .icon {
    width: 18px;
    height: 18px;
}

.account {
    display: flex;
    align-items: center;
    gap: clamp(10px, 3vw, 18px);
    font-size: var(--control-font);
}

.account a {
    display: flex;
    align-items: center;
    min-height: var(--control-height);
    gap: 6px;
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
}

.account .account-sell {
    padding: 0 var(--control-pad) 2px;
    color: var(--accent);
    font-variant-caps: all-small-caps;
    letter-spacing: 0.08em;
    font-size: 1.05rem;
    border: 1.5px solid var(--accent);
    border-radius: 3px;
}

.account .account-sell:hover {
    color: var(--accent-ink);
    background: var(--accent);
}

.account a:hover .account-label {
    text-decoration: underline;
}

/* The bell, with the unread count stamped on its corner. */
.account .account-bell {
    position: relative;
}

.bell-count {
    position: absolute;
    top: 2px;
    right: -8px;
    min-width: 1.25rem;
    padding: 0 4px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25rem;
    font-variant-numeric: lining-nums;
    text-align: center;
    color: var(--accent-ink);
    background: var(--accent);
    border-radius: 0.65rem;
}

/* For sale · Library · Requests, under the header. Not sticky: on phones the header alone stays on screen. */
.sections {
    display: flex;
    gap: 28px;
    width: 100%;
    max-width: var(--page-width);
    margin: 0 auto;
    padding: 6px 16px 0;
}

.sections a {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height);
    color: var(--ink-soft);
    font-size: 1.1rem;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.08em;
    text-decoration: none;
    border-bottom: 2px solid transparent;
}

.sections a:hover {
    color: var(--ink);
}

.sections a[aria-current] {
    color: var(--ink);
    border-bottom-color: var(--accent);
}

@media (max-width: 640px) {
    .sections {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0;
        border-bottom: 1px solid var(--rule);
    }

    .sections a {
        justify-content: center;
        margin-bottom: -1px;
    }
}

@media (max-width: 640px) {
    .wide-only {
        display: none;
    }
}

@media (max-width: 359px) {
    .account-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

/* Phones: when space runs out (narrow screens, a larger text setting), the brand gives way, never the
   Sell / bell / profile links: its name and motto get smaller with the screen, then end in "…". */
@media (max-width: 640px) {
    .site-header {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "brand account"
            "search search";
        column-gap: 12px;
        row-gap: 10px;
    }

    .brand {
        grid-area: brand;
        min-width: 0;
    }

    .brand > span {
        min-width: 0;
    }

    .brand-name,
    .brand-motto {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand-name {
        font-size: clamp(1.1rem, 5.4vw, 1.35rem);
    }

    .brand-motto {
        font-size: clamp(0.7rem, 3.3vw, 0.8rem);
    }

    .search {
        grid-area: search;
        max-width: none;
    }

    .account {
        grid-area: account;
        gap: clamp(8px, 2.5vw, 18px);
    }
}

@media (max-width: 340px) {
    .brand-motto {
        display: none;
    }
}

body > main {
    flex: 1;
    width: 100%;
    max-width: var(--page-width);
    margin: 0 auto;
    padding: 20px 16px 48px;
}

.note,
.empty {
    color: var(--ink-soft);
    font-style: italic;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    padding: 0 var(--control-pad) 2px;
    font-size: var(--control-font);
    font-variant-caps: all-small-caps;
    letter-spacing: 0.06em;
    color: var(--accent-ink);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    text-decoration: none;
    cursor: pointer;
}

.button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.button-quiet {
    color: var(--ink);
    background: transparent;
    border-color: var(--rule);
}

.form-actions a,
.filter-actions a,
.heading-links a,
.pagination a,
.pagination span,
.owner-account a,
.link-button,
.report-link,
.chosen-book a,
.entry-actions a,
.danger-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height);
    font-size: var(--control-font);
}

.skip-link {
    position: absolute;
    top: 8px;
    left: 16px;
    z-index: 20;
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

.link-button {
    padding: 0;
    font-family: inherit;
    color: var(--accent);
    text-decoration: underline;
    background: none;
    border: 0;
    cursor: pointer;
}

.site-footer {
    padding: 20px 16px;
    text-align: center;
    font-size: 0.85rem;
    font-style: italic;
    color: var(--ink-soft);
    border-top: 1px solid var(--rule);
}

.site-footer p {
    margin: 0;
}

/* Listing cards*/
.card-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 28px 24px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.card {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-wrap: anywhere;
}

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

.card img,
.card .drawn-cover {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--paper-deep);
}

/* A book's own cover is shown whole (printed covers are about 2:3); the paper colour fills the margins. */
.card .cover-contain {
    object-fit: contain;
}

/* A book without a cover or a photo: its title on a cloth-coloured cover, one of eight tones by its id. */
.drawn-cover {
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: var(--accent-ink);
    text-align: center;
    overflow-wrap: anywhere;
}

.card .drawn-cover {
    display: flex;
    /* em, not %: a percentage is of the card's width, which on narrow phones is far wider than the cover. */
    padding: 0.9em;
    overflow: hidden;
    background: var(--tone);
    box-shadow: var(--shadow), inset 0 0 0 6px var(--tone), inset 0 0 0 7px var(--accent-ink);
}

.drawn-title {
    font-weight: 600;
    line-height: 1.25;
}

.card .drawn-title {
    font-size: 0.95rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    overflow: hidden;
}

.cover-tone-0 { --tone: #8c2f1e; }
.cover-tone-1 { --tone: #2b6235; }
.cover-tone-2 { --tone: #3a2c1c; }
.cover-tone-3 { --tone: #67561e; }
.cover-tone-4 { --tone: #4a5a7a; }
.cover-tone-5 { --tone: #7a4a6a; }
.cover-tone-6 { --tone: #2f4f4f; }
.cover-tone-7 { --tone: #6b3e26; }

/* Two lines at most; the post page shows the whole title. */
.card-title {
    font-size: 1rem;
    line-height: 1.3;
    margin: 10px 0 0;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.card-link:hover .card-title {
    text-decoration: underline;
}

.card-author {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.9rem;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Straight after the price, not pushed to the card's bottom: in a row where one title takes two lines, a
   bottom-aligned district left an empty line under the price on the cards with one-line titles. */
.card-meta {
    margin: 0;
    padding-top: 4px;
    display: flex;
    align-items: center;
    gap: 0.6em;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

/* The condition is stamped on the cover's top-left corner, in solid ink. */
.card-meta .badge {
    position: absolute;
    top: 8px;
    left: 8px;
    color: var(--accent-ink);
    background: var(--condition);
    border-color: var(--condition);
}

.card-district {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    color: var(--condition);
    white-space: nowrap;
}

.badge-like_new {
    --condition: #2b6235;
}

.badge-good {
    --condition: #67561e;
}

.badge-worn {
    --condition: #8c2f1e;
}

/* A request from the last few days, on the cover's corner like a post's condition. */
.badge-new {
    --condition: #4a5a7a;
}

.stamp,
.badge {
    display: inline-block;
    padding: 0 0.45em;
    line-height: 1.5;
    font-weight: 600;
    font-variant-caps: all-small-caps;
    font-variant-numeric: lining-nums;
    letter-spacing: 0.08em;
    border: 1.5px solid currentColor;
    border-radius: 3px;
    transform: rotate(-2deg);
    -webkit-mask-image: url("../images/stamp-ink.c60ddf24a330.webp");
    mask-image: url("../images/stamp-ink.c60ddf24a330.webp");
    -webkit-mask-size: auto 100%;
    mask-size: auto 100%;
}

/* Error pages */
.error-page .stamp {
    margin: 8px 0 20px;
    font-size: 1.15rem;
    color: var(--accent);
}

.error-page p {
    max-width: 60ch;
}

.messages {
    width: 100%;
    max-width: var(--page-width);
    margin: 16px auto 0;
    padding: 0 16px;
}

.message {
    margin: 0 0 8px;
    padding: 8px 14px;
    background: rgba(255, 252, 243, 0.55);
    border-left: 3px solid var(--ink-soft);
    border-radius: var(--radius);
}

.message-success {
    border-left-color: #2b6235;
}

.message-error {
    border-left-color: var(--accent);
}

.notice {
    padding: 8px 14px;
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
}

.card-offer {
    margin: 2px 0 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.card-offer span + span::before,
.card-stats span + span::before {
    content: " · ";
}

.card-reserved {
    color: #67561e;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.06em;
}

/* A book card's numbers: rating, copies available, members who want it. */
.card-stats {
    margin: 2px 0 0;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.card-stats > span:first-child > [aria-hidden] {
    color: var(--accent);
}

.library-more {
    margin-top: 32px;
    color: var(--ink-soft);
}

/* Notifications */
.notifications {
    max-width: 720px;
}

.notification-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.notification-list li {
    display: grid;
    gap: 2px;
    padding: 12px 0 12px 12px;
    border-bottom: 1px solid var(--rule);
    border-left: 3px solid transparent;
}

.notification-list li.unread {
    border-left-color: var(--accent);
}

.notification-list a {
    color: var(--ink);
}

.notification-date {
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.notification-date .stamp {
    font-size: 0.8rem;
    color: var(--accent);
}

.card-sold img {
    opacity: 0.55;
}

.card-sold .card-offer {
    color: var(--accent);
}

.reading-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.reading-list li {
    padding: 14px 0;
    border-bottom: 1px solid var(--rule);
}

.stars {
    display: flex;
    gap: 0.15em;
    margin: 2px 0;
    color: var(--accent);
}

.stars .star-empty,
.stars .star-half {
    color: transparent;
    -webkit-text-stroke: 1px var(--accent);
}

.stars .star-half {
    background: linear-gradient(90deg, var(--accent) 50%, transparent 50%);
    background-clip: text;
}

.review {
    max-width: 65ch;
    margin: 4px 0 0;
    white-space: pre-line;
}

.top-sellers {
    margin-top: 40px;
}

.seller-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0 24px;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: rank;
}

.seller-list li {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 10px;
    align-items: baseline;
    padding: 8px 0;
    border-top: 1px solid var(--rule);
    counter-increment: rank;
    overflow-wrap: anywhere;
}

.seller-list li::before {
    content: counter(rank);
    grid-row: span 2;
    font-size: 1.5rem;
    font-style: italic;
    color: var(--accent);
}

.seller-meta {
    color: var(--ink-soft);
    font-size: 0.9rem;
    font-style: italic;
}

/* Search pages */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 32px;
    color: var(--ink-soft);
}

.site-footer a {
    color: inherit;
}

.text-page {
    max-width: 720px;
}

.text-page h2 {
    margin: 28px 0 8px;
    font-size: 1.15rem;
}

.text-page p,
.text-page li {
    line-height: 1.6;
}

.text-page li + li {
    margin-top: 6px;
}

.browse {
    display: grid;
    gap: 16px 36px;
    align-content: start;
}

.browse .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

/* Phones: two columns, so the cards fill the width. */
@media (max-width: 480px) {
    .card-grid,
    .browse .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 22px 14px;
    }
}

/* Narrow phones (360 px and the like): one card per row, cover on the left. */
@media (max-width: 379px) {
    .card-grid,
    .browse .card-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 18px;
    }

    .card {
        --cover-width: clamp(96px, 28vw, 106px);
        min-height: calc(var(--cover-width) * 1.25);
        padding-left: calc(var(--cover-width) + 14px);
    }

    .card img,
    .card .drawn-cover {
        position: absolute;
        top: 0;
        left: 0;
        width: var(--cover-width);
    }

    .card-title {
        margin-top: 0;
    }

    .card-meta .badge {
        top: 6px;
        left: 6px;
        font-size: 0.75rem;
    }

    .card .drawn-cover {
        padding: 0.6em;
    }

    .card .drawn-title {
        font-size: 0.75rem;
        -webkit-line-clamp: 4;
        line-clamp: 4;
    }
}

.browse-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 20px;
    margin-bottom: 4px;
    border-bottom: 3px double var(--rule);
}

.browse-heading .page-heading {
    margin: 0;
    border-bottom: 0;
}

.heading-links {
    display: flex;
    gap: 16px;
    margin: 0;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-content: start;
}

.filter {
    display: grid;
    gap: 2px;
    min-width: 0;
    align-content: start;
}

.filter label {
    font-size: 0.8rem;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.filter select,
.filter input {
    width: 100%;
    height: var(--control-height);
    padding: 0 8px;
    font: inherit;
    font-size: var(--control-font);
    color: var(--ink);
    background: rgba(255, 252, 243, 0.6);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    align-self: end;
}

.filter-actions a {
    white-space: nowrap;
}

@media (max-width: 899px) {
    .filter label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

@media (min-width: 900px) {
    .browse {
        grid-template-columns: 11rem 1fr;
        align-items: start;
    }

    .browse-heading {
        grid-column: 2;
        grid-row: 1;
    }

    .filters {
        grid-column: 1;
        grid-row: 2;
        grid-template-columns: 1fr;
        gap: 8px;
        position: sticky;
        top: 88px;
    }

    .browse-results {
        grid-column: 2;
        grid-row: 2;
    }

    .filter-actions {
        margin-top: 2px;
    }
}

@supports (appearance: base-select) {
    @media (hover: hover) and (pointer: fine) {
        select,
        ::picker(select) {
            appearance: base-select;
        }

        select {
            align-items: center;
            white-space: nowrap;
        }

        ::picker(select) {
            max-height: 18rem;
            overflow-y: auto;
            padding: 4px 0;
            background: var(--paper);
            border: 1px solid var(--rule);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
        }

        option {
            padding: 4px 12px;
        }

        option:hover,
        option:focus-visible {
            color: var(--accent-ink);
            background: var(--accent);
        }

        option::checkmark {
            content: none;
        }
    }
}
