:root {
    --paper: #f7f3ec;
    --card: #fffdf9;
    --ink: #2a2118;
    --muted: #7a6e60;
    --line: #e7dfd2;
    --accent: #8a3b24;
    --accent-dark: #6d2c19;
    --accent-soft: #f3e4dc;
    --danger: #b3261e;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(42, 33, 24, 0.06), 0 8px 24px rgba(42, 33, 24, 0.07);
}

* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: 64px;
}

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

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

[hidden] {
    display: none !important;
}

.material-icons-round {
    font-size: 22px;
    line-height: 1;
    user-select: none;
}


/* HEADER */

.site-header {
    color: #f0d9a8; /* parchment gold */
    position: relative;
}

.header-art {
    background: linear-gradient(180deg, rgba(30, 18, 10, 0.5), rgba(30, 18, 10, 0.8)),
        url('../icons/header_background.png') center 20% / cover no-repeat;
    background-color: #2a1a10;
    inset: 0;
    position: absolute;
    /* eased fade so the image dissolves into the page with no visible edge */
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 38%, rgba(0, 0, 0, 0.85) 48%, rgba(0, 0, 0, 0.6) 58%, rgba(0, 0, 0, 0.35) 70%, rgba(0, 0, 0, 0.14) 82%, rgba(0, 0, 0, 0.04) 92%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 0%, #000 38%, rgba(0, 0, 0, 0.85) 48%, rgba(0, 0, 0, 0.6) 58%, rgba(0, 0, 0, 0.35) 70%, rgba(0, 0, 0, 0.14) 82%, rgba(0, 0, 0, 0.04) 92%, transparent 100%);
}

.header-inner {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: space-between;
    margin: 0 auto;
    max-width: 960px;
    padding: 44px 20px 120px;
    position: relative;
}

.brand {
    align-items: center;
    display: flex;
    gap: 14px;
}

.brand img {
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
    height: 44px;
    width: 44px;
}

.brand h1 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.8rem, 5vw, 2.6rem);
    font-weight: 700;
    letter-spacing: 0.01em;
    text-shadow: 0 2px 10px rgba(20, 10, 4, 0.7);
}

.stat {
    align-items: center;
    backdrop-filter: blur(6px);
    background: rgba(20, 10, 4, 0.35);
    border: 1px solid rgba(240, 217, 168, 0.4);
    border-radius: 999px;
    display: flex;
    gap: 8px;
    padding: 10px 20px;
}

.stat-number {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.6rem;
    font-variant-numeric: lining-nums; /* Playfair defaults to old-style numerals, which sit low */
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    line-height: 1;
    opacity: 0.85;
    text-transform: uppercase;
}


/* CONTENT */

.content {
    margin: -64px auto 0; /* pull the search bar up over the fading header */
    max-width: 960px;
    padding: 0 16px;
    position: relative;
}

.toolbar {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.search {
    flex: 1 1 280px;
    max-width: 420px;
    position: relative;
}

.search-icon {
    color: var(--muted);
    left: 12px;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.search-input {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.95rem;
    padding: 10px 16px 10px 42px;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

.search-input:focus,
.modal input:focus,
.modal select:focus,
.modal textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}

.result-count {
    color: var(--muted);
    font-size: 0.85rem;
}


/* TABLE */

.table-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.book-table {
    border-collapse: collapse;
    width: 100%;
}

.book-table th {
    background: #f1ebe0;
    border-bottom: 1px solid var(--line);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    padding: 0;
    text-align: left;
    text-transform: uppercase;
}

.sort-btn {
    align-items: center;
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    font-size: inherit;
    font-weight: 600;
    gap: 2px;
    letter-spacing: inherit;
    padding: 14px 16px;
    text-transform: inherit;
}

.sort-btn:hover,
th[aria-sort="ascending"] .sort-btn,
th[aria-sort="descending"] .sort-btn {
    color: var(--accent);
}

.sort-arrow {
    font-size: 16px;
    min-width: 16px;
}

.book-table td {
    border-bottom: 1px solid var(--line);
    font-size: 0.95rem;
    padding: 12px 16px;
    vertical-align: middle;
}

.book-table tbody tr:last-child td {
    border-bottom: 0;
}

.book-table tbody tr {
    transition: background 0.12s;
}

.book-table tbody tr:hover {
    background: #faf5ec;
}

.cell-title {
    font-weight: 500;
}

.cell-author {
    color: var(--muted);
}

.col-cover {
    white-space: nowrap;
}

.pill {
    background: var(--accent-soft);
    border-radius: 999px;
    color: var(--accent-dark);
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 10px;
}

.pill.paperback {
    background: #e9eee4;
    color: #43592f;
}

.col-actions {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}

.actions {
    display: inline-flex;
    gap: 2px;
}

.icon-btn {
    align-items: center;
    background: none;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    height: 36px;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    width: 36px;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
}

.icon-btn.remove:hover,
.icon-btn.remove:focus-visible {
    background: #fbe4e2;
    color: var(--danger);
}

.table-message {
    color: var(--muted);
    padding: 40px 16px;
    text-align: center;
}


/* ADD BUTTON */

.fab {
    align-items: center;
    background: var(--accent);
    border: 0;
    border-radius: 50%;
    bottom: 64px;
    box-shadow: 0 6px 18px rgba(138, 59, 36, 0.4);
    color: #fff;
    cursor: pointer;
    display: flex;
    height: 56px;
    justify-content: center;
    position: fixed;
    right: 20px;
    transition: transform 0.2s, background 0.2s;
    width: 56px;
    z-index: 10;
}

.fab .material-icons-round {
    font-size: 30px;
}

.fab:hover {
    background: var(--accent-dark);
    transform: scale(1.06);
}


/* MODALS */

.modal {
    background: var(--card);
    border: 0;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(42, 33, 24, 0.35);
    color: var(--ink);
    margin: auto;
    max-width: 440px;
    padding: 0;
    width: calc(100vw - 32px);
}

.modal[open] {
    animation: pop 0.18s ease-out;
}

.modal::backdrop {
    background: rgba(30, 18, 10, 0.55);
    backdrop-filter: blur(2px);
}

@keyframes pop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.modal-body {
    display: flex;
    flex-direction: column;
    padding: 28px 24px 24px;
    position: relative;
}

.modal h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.5rem;
    margin-bottom: 8px;
    padding-right: 32px;
}

.modal-close {
    background: none;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
    height: 36px;
    position: absolute;
    right: 12px;
    top: 12px;
    width: 36px;
}

.modal-close:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.modal label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    margin: 16px 0 6px;
    text-transform: uppercase;
}

.optional {
    font-weight: 400;
    text-transform: none;
}

.modal input,
.modal select,
.modal textarea {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1rem;
    padding: 10px 12px;
    width: 100%;
}

.modal textarea {
    resize: vertical;
}

.field-error {
    color: var(--danger);
    display: none;
    font-size: 0.82rem;
    margin-top: 4px;
}

.field-error.show {
    display: block;
}

.btn {
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 24px;
    padding: 12px 20px;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn:disabled {
    cursor: wait;
    opacity: 0.6;
}

.info-author {
    color: var(--muted);
    font-style: italic;
}

.info-list {
    display: grid;
    gap: 10px 16px;
    grid-template-columns: max-content 1fr;
    margin-top: 20px;
}

.info-list dt {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding-top: 2px;
    text-transform: uppercase;
}

.info-list dd {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}


/* TOAST */

.toast {
    background: var(--ink);
    border-radius: 999px;
    bottom: 72px;
    color: #fff;
    font-size: 0.9rem;
    left: 50%;
    opacity: 0;
    padding: 10px 20px;
    pointer-events: none;
    position: fixed;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s, transform 0.2s;
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.error {
    background: var(--danger);
}


/* FOOTER */

.site-footer {
    align-items: center;
    background: rgba(247, 243, 236, 0.92);
    backdrop-filter: blur(6px);
    border-top: 1px solid var(--line);
    bottom: 0;
    color: var(--muted);
    display: flex;
    font-size: 0.85rem;
    gap: 10px;
    justify-content: center;
    left: 0;
    padding: 12px 16px;
    position: fixed;
    width: 100%;
    z-index: 5;
}

.site-footer a {
    color: inherit;
    display: inline-flex;
}

.github-icon {
    transition: transform 0.3s ease-in-out, color 0.2s;
}

.github-icon:hover {
    color: var(--ink);
    transform: rotate(360deg) scale(1.15);
}

.link-btn {
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.link-btn:hover {
    color: var(--accent);
}


/* SMALL SCREENS */

@media (max-width: 560px) {
    .book-table td,
    .sort-btn {
        padding-left: 10px;
        padding-right: 8px;
    }
    .book-table td {
        font-size: 0.88rem;
    }
    .col-cover {
        display: none;
    }
    .stat {
        padding: 6px 16px;
    }
}

/* Keep icon buttons a fixed size even if the icon font is slow to load */
.icon-btn .material-icons-round {
    overflow: hidden;
    width: 22px;
}
