/* ============================================================
   BOOK.CSS — "Dusky Binding" Design System for Tonya's Books
   Replaces: normalize.min.css, milligram.min.css, cake.css
   ============================================================ */

/* --- Custom Properties --- */
:root {
    /* Core palette */
    --leather-dark: #231A2E;
    --leather-warm: #4A3328;
    --gold-brand: #CFA750;
    --gold-bright: #E8D5A3;
    --parchment: #F0E6D4;
    --parchment-light: #FBF6EE;
    --plum: #6B2D3E;
    --cream: #D4C4A8;
    --brown-muted: #8B7355;

    /* Semantic aliases */
    --text-primary: #231A2E;
    --text-secondary: #4A3328;
    --bg-page: #F0E6D4;
    --bg-input: #FBF6EE;
    --border-decorative: #8B7355;
    --color-success: #2E6B45;
    --color-warning: #8B6914;
    --color-error: #6B2D3E;
    --color-info: #2C5065;

    /* Status colors */
    --status-reading: #2E6B45;
    --status-reading-bg: rgba(46, 107, 69, 0.1);
    --status-want: #2C5065;
    --status-want-bg: rgba(44, 80, 101, 0.1);
    --status-read: #8B6914;
    --status-read-bg: rgba(139, 105, 20, 0.1);
    --status-dnf: #8B7355;
    --status-dnf-bg: rgba(139, 115, 85, 0.12);

    /* Typography scale */
    --text-xs: 12px;
    --text-sm: 14px;
    --text-base: 17px;
    --text-lg: 18px;
    --text-xl: 22px;
    --text-2xl: 26px;
    --text-3xl: 30px;
    --text-brand: 24px;

    /* Font stack */
    --font-family: 'Libre Baskerville', Georgia, 'Times New Roman', serif;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Radii */
    --radius-tag: 2px;
    --radius-input: 4px;
    --radius-flash: 6px;
    --radius-button: 10px;
    --radius-card: 8px;
}

/* --- Skip Link (Accessibility) --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    background: var(--leather-dark);
    color: var(--gold-bright);
    padding: var(--space-sm) var(--space-md);
    border-radius: 0 0 var(--radius-input) var(--radius-input);
    font-size: var(--text-sm);
    font-weight: 700;
    z-index: 1000;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    color: var(--gold-bright);
}

/* Alpine.js cloak */
[x-cloak] {
    display: none !important;
}

/* --- CSS Reset (replaces normalize.min.css) --- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-family);
    font-size: var(--text-base);
    font-weight: 400;
    line-height: 1.75;
    color: var(--text-secondary);
    background-color: var(--bg-page);
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: var(--space-md);
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
}

p {
    margin-top: 0;
    margin-bottom: var(--space-md);
}

a {
    color: var(--leather-warm);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--leather-dark);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

ul, ol {
    margin-top: 0;
    margin-bottom: var(--space-md);
    padding-left: var(--space-lg);
}

hr {
    border: none;
    border-top: 1px solid var(--border-decorative);
    margin: var(--space-lg) 0;
}

blockquote {
    margin: 0 0 var(--space-md);
    padding: var(--space-sm) var(--space-lg);
    border-left: 3px solid var(--gold-brand);
    color: var(--text-secondary);
    font-style: italic;
}

/* --- Typography Scale --- */
h1 {
    font-size: var(--text-3xl);
    letter-spacing: 0.5px;
}

h2 {
    font-size: var(--text-2xl);
    letter-spacing: 0.5px;
}

h3 {
    font-size: var(--text-xl);
}

h4 {
    font-size: var(--text-lg);
}

h5 {
    font-size: var(--text-base);
}

h6 {
    font-size: var(--text-sm);
}

small {
    font-size: var(--text-sm);
}

/* --- Animations --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes flashIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes flashOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* --- Page Layout --- */
.top-nav {
    background-color: var(--leather-dark);
    background-image:
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.01) 2px,
            rgba(255, 255, 255, 0.01) 4px
        );
    padding: var(--space-md) 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(35, 26, 46, 0.15);
}

.top-nav-title {
    color: var(--gold-brand);
    font-size: var(--text-brand);
    font-weight: 700;
    letter-spacing: 2px;
    text-decoration: none;
}

.top-nav-title:hover {
    color: var(--gold-bright);
}

.top-nav-links {
    display: flex;
    gap: var(--space-lg);
    align-items: center;
}

.top-nav-links a {
    color: var(--cream);
    font-size: 16px;
    letter-spacing: 1px;
    text-decoration: none;
    position: relative;
    padding-bottom: 4px;
    transition: color 0.2s ease;
}

.top-nav-links a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--gold-brand);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.25s ease;
}

.top-nav-links a:hover::after,
.top-nav-links a.active::after {
    transform: scaleX(1);
}

.top-nav-links a:hover {
    color: var(--gold-bright);
}

.top-nav-links a.active {
    color: var(--gold-brand);
}

.top-nav-links a.logout-icon {
    font-size: 20px;
    line-height: 1;
    vertical-align: middle;
    letter-spacing: 0;
    opacity: 0.7;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.top-nav-links a.logout-icon::after {
    display: none;
}

.top-nav-links a.logout-icon:hover {
    opacity: 1;
}

/* Hamburger menu toggle */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-sm);
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--cream);
    border-radius: 1px;
    transition: transform 0.25s ease, opacity 0.2s ease;
    transform-origin: center;
}

.nav-toggle.open span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.nav-toggle.open span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.nav-toggle.open span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* --- Page Background Texture --- */
.main {
    min-height: calc(100vh - 60px);
    background-image:
        radial-gradient(
            ellipse at 50% 50%,
            rgba(74, 51, 40, 0.03) 0%,
            transparent 70%
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 3px,
            rgba(139, 115, 85, 0.015) 3px,
            rgba(139, 115, 85, 0.015) 4px
        );
}

/* --- Content Container --- */
.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: var(--space-xl) 28px;
}

.content {
    background: var(--parchment);
    padding: var(--space-xl) 28px;
    box-shadow:
        inset 0 1px 3px rgba(35, 26, 46, 0.06),
        0 1px 4px rgba(35, 26, 46, 0.08);
    border-radius: var(--radius-input);
    animation: fadeInUp 0.3s ease-out;
}

/* --- Footer --- */
footer {
    border-top: 1px solid var(--gold-brand);
    padding: var(--space-lg) 28px;
    text-align: center;
    color: var(--brown-muted);
    font-size: var(--text-sm);
    letter-spacing: 0.5px;
}

footer span {
    color: var(--gold-brand);
}

/* --- Decorative Divider --- */
.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: var(--space-lg) 0;
    color: var(--border-decorative);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-decorative);
}

.divider::before {
    margin-right: var(--space-md);
}

.divider::after {
    margin-left: var(--space-md);
}

.divider-ornament {
    font-size: var(--text-sm);
    color: var(--gold-brand);
    letter-spacing: 4px;
}

/* --- Buttons --- */
.button,
button[type="submit"]:not(.action-icon-btn),
input[type="submit"] {
    display: inline-block;
    font-family: var(--font-family);
    font-size: 15px;
    letter-spacing: 0.5px;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-button);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    line-height: 1.4;
    text-align: center;

    /* Primary (default) */
    background-color: var(--leather-dark);
    color: var(--gold-bright);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.button:hover,
button[type="submit"]:not(.action-icon-btn):hover,
input[type="submit"]:hover {
    background-color: #2F2339;
    color: var(--gold-bright);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

.button:active,
button[type="submit"]:not(.action-icon-btn):active,
input[type="submit"]:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.button-secondary {
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--leather-warm);
    box-shadow: none;
}

.button-secondary:hover {
    background-color: rgba(74, 51, 40, 0.06);
    color: var(--text-primary);
    box-shadow: none;
}

.button-danger {
    background-color: var(--plum);
    color: var(--parchment);
}

.button-danger:hover {
    background-color: #7D3548;
    color: var(--parchment);
}

.button-small {
    font-size: var(--text-sm);
    padding: 6px 16px;
}

.button-group {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    align-items: center;
}

/* --- Tags --- */
.tag {
    display: inline-block;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    letter-spacing: 0.5px;
    padding: var(--space-xs) 12px;
    border: 1px dotted var(--brown-muted);
    border-radius: var(--radius-tag);
    line-height: 1.4;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.tag:hover {
    border-color: var(--gold-brand);
    background-color: rgba(207, 167, 80, 0.08);
}

.tag-status {
    color: var(--plum);
}

/* Status-specific tag styles */
.tag-reading {
    color: var(--status-reading);
    border-color: var(--status-reading);
    background-color: var(--status-reading-bg);
    border-style: solid;
}

.tag-want-to-read {
    color: var(--status-want);
    border-color: var(--status-want);
    background-color: var(--status-want-bg);
    border-style: solid;
}

.tag-read {
    color: var(--status-read);
    border-color: var(--status-read);
    background-color: var(--status-read-bg);
    border-style: solid;
}

.tag-dnf {
    color: var(--status-dnf);
    border-color: var(--status-dnf);
    background-color: var(--status-dnf-bg);
    border-style: solid;
}

/* --- Star Ratings --- */
.star-rating {
    color: var(--plum);
    font-size: var(--text-2xl);
    letter-spacing: 3px;
    line-height: 1;
}

.star-rating-sm {
    font-size: var(--text-base);
    letter-spacing: 1px;
}

/* --- Forms --- */
label {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    font-weight: 700;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="url"],
input[type="search"],
input[type="tel"],
textarea,
select {
    display: block;
    width: 100%;
    font-family: var(--font-family);
    font-size: var(--text-base);
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--brown-muted);
    border-radius: var(--radius-input);
    padding: 10px 14px;
    margin-bottom: var(--space-md);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--gold-brand);
    box-shadow: 0 0 0 3px rgba(207, 167, 80, 0.2);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234A3328' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

select[multiple] {
    background-image: none;
    padding-right: 14px;
    min-height: 120px;
}

/* Custom checkboxes */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border: 1px solid var(--leather-dark);
    border-radius: var(--radius-input);
    background: var(--bg-input);
    cursor: pointer;
    vertical-align: middle;
    position: relative;
    flex-shrink: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="checkbox"]:checked {
    background-color: var(--leather-dark);
    border-color: var(--leather-dark);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid var(--gold-bright);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

input[type="checkbox"]:focus {
    box-shadow: 0 0 0 3px rgba(207, 167, 80, 0.2);
}

/* Checkbox wrapper for label+checkbox inline layout */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-weight: 400;
}

/* Form input wrapper */
.input {
    margin-bottom: var(--space-md);
}

.input.error input,
.input.error select,
.input.error textarea {
    border-color: var(--color-error);
}

.error-message {
    color: var(--color-error);
    font-size: var(--text-sm);
    margin-top: calc(-1 * var(--space-sm));
    margin-bottom: var(--space-md);
}

/* File input */
input[type="file"] {
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

fieldset {
    border: none;
    padding: 0;
    margin: 0 0 var(--space-lg);
}

legend {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
    padding: 0;
}

/* --- Search bar in page header --- */
.header-search {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    max-width: 320px;
}

.header-search input[type="text"] {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid rgba(139, 115, 85, 0.35);
    border-radius: var(--radius-input);
    background: var(--parchment-light);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}

.header-search input[type="text"]:focus {
    outline: none;
    border-color: var(--leather-warm);
    box-shadow: 0 0 0 2px rgba(139, 115, 85, 0.12);
}

/* --- Filter Panel (details/summary) --- */
details.filter-panel {
    border: 1px solid rgba(139, 115, 85, 0.25);
    border-radius: var(--radius-input);
    margin-bottom: var(--space-md);
    background: var(--parchment-light);
    overflow: visible;
    display: inline-block;
}

details.filter-panel summary {
    padding: 6px 12px;
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--brown-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    transition: background-color 0.2s ease, color 0.2s ease;
    list-style: none;
    white-space: nowrap;
    border-radius: var(--radius-input);
}

details.filter-panel summary::-webkit-details-marker {
    display: none;
}

details.filter-panel summary::before {
    display: none;
}

details.filter-panel[open] summary {
    color: var(--text-primary);
    background-color: rgba(139, 115, 85, 0.1);
}

details.filter-panel summary:hover {
    background-color: rgba(74, 51, 40, 0.06);
    color: var(--text-primary);
}

details.filter-panel .filter-body {
    padding: var(--space-md);
    position: absolute;
    z-index: 50;
    background: var(--parchment-light);
    border: 1px solid rgba(139, 115, 85, 0.3);
    border-radius: var(--radius-card);
    box-shadow: 0 4px 20px rgba(35, 26, 46, 0.12);
    min-width: 340px;
    max-width: 480px;
    margin-top: 4px;
}

.filter-panel-wrap {
    position: relative;
    display: inline-block;
}

/* --- Active Filter Chips --- */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(207, 167, 80, 0.12);
    border: 1px solid rgba(207, 167, 80, 0.35);
    color: var(--text-primary);
    font-size: var(--text-sm);
    padding: var(--space-xs) 12px;
    border-radius: 14px;
    line-height: 1.4;
    animation: fadeInUp 0.2s ease-out;
}

.filter-chip-label {
    font-weight: 700;
    color: var(--brown-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(74, 51, 40, 0.1);
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
    cursor: pointer;
}

.filter-chip-remove:hover {
    background: rgba(107, 45, 62, 0.15);
    color: var(--plum);
}

.filter-chips-clear {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    padding: var(--space-xs) var(--space-sm);
    transition: color 0.15s ease;
}

.filter-chips-clear:hover {
    color: var(--plum);
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.filter-field label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--brown-muted);
    margin-bottom: 4px;
}

.filter-rating-range {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-rating-range input {
    flex: 1;
    min-width: 0;
}

.filter-rating-sep {
    color: var(--brown-muted);
    flex-shrink: 0;
}

.filter-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
}

/* --- Tables --- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--space-lg);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}

thead th {
    background-color: var(--leather-dark);
    color: var(--cream);
    font-weight: 700;
    font-size: var(--text-sm);
    letter-spacing: 0.5px;
    text-align: left;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
}

thead th a {
    color: var(--cream);
}

thead th a:hover {
    color: var(--gold-bright);
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(139, 115, 85, 0.3);
    vertical-align: top;
}

tbody tr {
    transition: background-color 0.15s ease;
}

tbody tr:nth-child(even) {
    background-color: rgba(74, 51, 40, 0.03);
}

tbody tr:hover {
    background-color: rgba(207, 167, 80, 0.08);
}

/* Action links in table cells */
.col-actions {
    white-space: nowrap;
}

.col-actions a {
    margin-right: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--leather-warm);
}

.col-actions a:hover {
    color: var(--leather-dark);
}

.col-actions a.button-danger {
    color: var(--parchment);
}

.col-actions a.button-danger:hover {
    color: var(--parchment);
}

/* --- Flash Messages --- */
.message {
    padding: 12px 16px;
    padding-right: 40px;
    margin-bottom: var(--space-md);
    border-radius: var(--radius-flash);
    font-size: var(--text-base);
    border-left: 3px solid;
    cursor: pointer;
    overflow: hidden;
    max-height: 200px;
    position: relative;
    animation: flashIn 0.3s ease-out;
    transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.3s ease, margin-bottom 0.3s ease, padding 0.3s ease;
}

.message::after {
    content: '\00d7';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    opacity: 0.4;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.message:hover::after {
    opacity: 0.8;
}

.message.dismissing {
    animation: flashOut 0.3s ease-out forwards;
}

.message.hidden {
    display: none;
}

.message.success {
    background-color: rgba(46, 107, 69, 0.1);
    border-left-color: var(--color-success);
    color: var(--color-success);
}

.message.warning {
    background-color: rgba(139, 105, 20, 0.1);
    border-left-color: var(--color-warning);
    color: var(--color-warning);
}

.message.error {
    background-color: rgba(107, 45, 62, 0.1);
    border-left-color: var(--color-error);
    color: var(--color-error);
}

.message.info {
    background-color: rgba(44, 80, 101, 0.1);
    border-left-color: var(--color-info);
    color: var(--color-info);
}

/* --- Toast Progress Bar --- */
@keyframes toastCountdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

.message .toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    transform-origin: left;
    animation: toastCountdown 5s linear forwards;
    border-radius: 0 0 var(--radius-flash) var(--radius-flash);
}

.message.error .toast-progress {
    display: none;
}

/* --- Smooth Toast Collapse --- */
.message.collapsing {
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

/* --- Pagination --- */
.paginator {
    text-align: center;
    margin: var(--space-lg) 0;
}

.paginator ul {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-xs) 0;
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.paginator li {
    display: inline-block;
}

.paginator li a,
.paginator li span {
    display: inline-block;
    padding: 6px 12px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    text-decoration: none;
    border-radius: var(--radius-flash);
    transition: background-color 0.2s ease, transform 0.15s ease;
    color: var(--text-secondary);
    border: 1px solid var(--leather-warm);
}

.paginator li a:hover {
    background-color: rgba(74, 51, 40, 0.06);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.paginator li.active a,
.paginator li.active span {
    background-color: var(--leather-dark);
    color: var(--gold-bright);
    border-color: var(--leather-dark);
}

.paginator li.disabled span {
    color: var(--brown-muted);
    border-color: rgba(139, 115, 85, 0.3);
    cursor: default;
    background-color: transparent;
}

.paginator p {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin: var(--space-xs) 0 0 0;
}

/* --- Dashboard --- */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-card {
    background: var(--parchment-light);
    border: 1px solid rgba(139, 115, 85, 0.25);
    border-radius: var(--radius-card);
    padding: var(--space-md) var(--space-lg);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(35, 26, 46, 0.1);
}

.stat-number {
    display: block;
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--leather-dark);
    line-height: 1.2;
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    letter-spacing: 0.5px;
}

.dashboard-section {
    margin-bottom: var(--space-lg);
    background: var(--parchment-light);
    border: 1px solid rgba(139, 115, 85, 0.15);
    border-radius: var(--radius-card);
    padding: var(--space-md) var(--space-lg);
    transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.dashboard-section:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(35, 26, 46, 0.08);
}

.dashboard-section h4 {
    margin-bottom: var(--space-md);
}

/* --- Scroll-Triggered Reveal --- */
.reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- Progress Ring --- */
.progress-ring {
    display: block;
    margin: 0 auto var(--space-xs);
}

.progress-ring-bg {
    fill: none;
    stroke: rgba(139, 115, 85, 0.15);
}

.progress-ring-fill {
    fill: none;
    stroke: var(--gold-brand);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.8s ease-out;
}

.stat-card-ring {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-card-ring .stat-number {
    font-size: var(--text-xl);
}

/* --- Cover Image Lightbox --- */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(35, 26, 46, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: var(--space-xl);
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-card);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    cursor: default;
}

.lightbox-close {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    color: var(--parchment);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background-color 0.2s ease;
}

.lightbox-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* --- Prose Truncation --- */
.prose-truncate {
    position: relative;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.prose-truncate.collapsed {
    max-height: 10em;
}

.prose-truncate.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4em;
    background: linear-gradient(transparent, var(--parchment));
    pointer-events: none;
}

.prose-toggle {
    display: inline-block;
    margin-top: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--leather-warm);
    cursor: pointer;
    font-weight: 700;
    transition: color 0.2s ease;
    background: none;
    border: none;
    font-family: var(--font-family);
    padding: 0;
}

.prose-toggle:hover {
    color: var(--leather-dark);
}

/* --- Tag Picker --- */
.tag-picker {
    position: relative;
    margin-bottom: var(--space-md);
}

.tag-picker-input-wrap {
    position: relative;
}

.tag-picker-label {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    font-weight: 700;
}

.tag-picker-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--space-sm);
}

.tag-picker-pills:empty {
    display: none;
}

.tag-picker-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(207, 167, 80, 0.12);
    border: 1px solid rgba(207, 167, 80, 0.35);
    color: var(--text-primary);
    font-size: var(--text-sm);
    padding: var(--space-xs) 10px;
    border-radius: 14px;
    line-height: 1.4;
    animation: fadeInUp 0.15s ease-out;
}

.tag-picker-pill-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(74, 51, 40, 0.1);
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border: none;
    padding: 0;
    font-family: var(--font-family);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.tag-picker-pill-remove:hover {
    background: rgba(107, 45, 62, 0.2);
    color: var(--plum);
}

.tag-picker-input {
    display: block;
    width: 100%;
    font-family: var(--font-family);
    font-size: var(--text-base);
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--brown-muted);
    border-radius: var(--radius-input);
    padding: 10px 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tag-picker-input:focus {
    outline: none;
    border-color: var(--gold-brand);
    box-shadow: 0 0 0 3px rgba(207, 167, 80, 0.2);
}

.tag-picker-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 50;
    background: var(--bg-input);
    border: 1px solid rgba(139, 115, 85, 0.3);
    border-top: none;
    border-radius: 0 0 var(--radius-input) var(--radius-input);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
}

.tag-picker-option {
    padding: 10px 14px;
    cursor: pointer;
    font-size: var(--text-base);
    color: var(--text-primary);
    transition: background-color 0.1s ease;
    border-bottom: 1px solid rgba(139, 115, 85, 0.08);
}

.tag-picker-option:last-child {
    border-bottom: none;
}

.tag-picker-option:hover,
.tag-picker-option.highlighted {
    background: rgba(207, 167, 80, 0.1);
}

.tag-picker-option mark {
    background: rgba(207, 167, 80, 0.3);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.tag-picker-empty {
    padding: 10px 14px;
    color: var(--brown-muted);
    font-style: italic;
    font-size: var(--text-sm);
}

.tag-picker select[multiple] {
    display: none;
}

/* --- Floating Labels --- */
.floating-label {
    position: relative;
    margin-bottom: var(--space-md);
}

.floating-label > label {
    position: absolute;
    left: 14px;
    top: 12px;
    font-size: var(--text-base);
    font-weight: 400;
    color: var(--brown-muted);
    pointer-events: none;
    transition: all 0.2s ease;
    transform-origin: left top;
    z-index: 1;
    margin-bottom: 0;
}

.floating-label > input,
.floating-label > textarea {
    padding-top: 22px;
    padding-bottom: 6px;
}

.floating-label:focus-within > label,
.floating-label:has(input:not(:placeholder-shown)) > label,
.floating-label:has(textarea:not(:placeholder-shown)) > label {
    top: 4px;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--text-secondary);
}

/* --- Form Hero (Cover + Title/Author side-by-side) --- */
.form-hero {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: var(--space-lg);
    align-items: start;
    margin-bottom: var(--space-md);
}

.form-hero-cover {
    position: sticky;
    top: var(--space-lg);
}

.form-hero-cover .cover-upload {
    margin: 0;
}

.form-hero-fields {
    display: flex;
    flex-direction: column;
    gap: 0;
}

@media (max-width: 600px) {
    .form-hero {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .form-hero-cover {
        position: static;
        max-width: 200px;
        margin: 0 auto;
    }
}

/* --- Two-column field rows --- */
.isbn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

@media (max-width: 600px) {
    .isbn-row {
        grid-template-columns: 1fr;
        gap: 0;
    }
}

/* --- Collapsible details section --- */
.form-details-section {
    margin-top: var(--space-sm);
}

.form-details-section summary {
    cursor: pointer;
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--text-secondary);
    padding: var(--space-sm) 0;
    user-select: none;
    list-style: none;
}

.form-details-section summary::-webkit-details-marker {
    display: none;
}

.form-details-section summary::before {
    content: '▸';
    display: inline-block;
    margin-right: var(--space-sm);
    transition: transform 0.2s ease;
    font-size: var(--text-sm);
}

.form-details-section[open] summary::before {
    transform: rotate(90deg);
}

.form-details-section summary:hover {
    color: var(--gold-brand);
}

.form-details-body {
    padding-top: var(--space-sm);
}

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

.book-list li {
    padding: 10px var(--space-md);
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius-input) var(--radius-input) 0;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.book-list li:hover {
    background-color: rgba(207, 167, 80, 0.06);
    border-left-color: var(--gold-brand);
}

.book-list li + li {
    border-top: 1px solid rgba(139, 115, 85, 0.15);
}

.book-list a {
    font-weight: 700;
}

.book-list em {
    color: var(--brown-muted);
    font-size: var(--text-sm);
}

/* --- Book View Hero --- */
.book-hero {
    display: flex;
    gap: var(--space-xl);
    margin-bottom: var(--space-lg);
}

.book-cover {
    flex-shrink: 0;
    width: 200px;
}

.book-cover img {
    width: 100%;
    border-radius: var(--radius-input);
    box-shadow: 4px 4px 16px rgba(35, 26, 46, 0.2), 0 0 0 1px rgba(139, 115, 85, 0.15);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.book-cover img:hover {
    transform: scale(1.02);
    box-shadow: 6px 6px 20px rgba(35, 26, 46, 0.25), 0 0 0 1px rgba(139, 115, 85, 0.2);
}

.book-cover-sm {
    width: 150px;
}

.book-meta {
    flex: 1;
    min-width: 0;
}

.book-meta-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid rgba(139, 115, 85, 0.15);
    gap: var(--space-md);
}

.book-meta-row:last-child {
    border-bottom: none;
}

.book-meta-label {
    flex-shrink: 0;
    width: 100px;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--brown-muted);
    padding-top: 2px;
}

.book-meta-value {
    flex: 1;
    min-width: 0;
}

.book-meta-value a {
    font-weight: 700;
}

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--brown-muted);
    font-style: italic;
}

.empty-state::before {
    content: '✦';
    display: block;
    font-size: var(--text-2xl);
    color: var(--gold-brand);
    font-style: normal;
    margin-bottom: var(--space-sm);
    opacity: 0.5;
}

/* --- Login Page --- */
.users.login {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
}

.login-wrapper {
    max-width: 400px;
    width: 100%;
}

.login-wrapper::before {
    content: '✦  ✦  ✦';
    display: block;
    text-align: center;
    font-size: var(--text-xl);
    color: var(--gold-brand);
    letter-spacing: 8px;
    margin-bottom: var(--space-lg);
}

.login-wrapper h3 {
    text-align: center;
    margin-bottom: var(--space-lg);
    font-size: var(--text-2xl);
}

/* --- Cover Selection (Lookup) --- */
.cover-options {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-bottom: var(--space-md);
}

.cover-option {
    cursor: pointer;
    position: relative;
}

.cover-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cover-option img {
    max-width: 100px;
    border: 3px solid transparent;
    border-radius: var(--radius-input);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.cover-option input[type="radio"]:checked + img {
    border-color: var(--gold-brand);
    box-shadow: 0 0 0 2px rgba(207, 167, 80, 0.3);
}

.cover-option:hover img {
    transform: scale(1.03);
    box-shadow: 0 2px 8px rgba(35, 26, 46, 0.15);
}

/* --- Cover Upload --- */
.cover-upload {
    margin: var(--space-md) 0;
}

.cover-upload-input {
    display: none;
}

.cover-upload-zone {
    border: 2px dashed var(--brown-muted);
    border-radius: var(--radius-card);
    padding: var(--space-xl);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    background: rgba(251, 246, 238, 0.5);
}

.cover-upload-zone:hover {
    border-color: var(--gold-brand);
    background: rgba(207, 167, 80, 0.06);
}

.cover-upload-zone.dragging {
    border-color: var(--gold-brand);
    background: rgba(207, 167, 80, 0.12);
    border-style: solid;
}

.cover-upload-zone.has-preview {
    border-style: solid;
    border-color: rgba(139, 115, 85, 0.25);
    padding: var(--space-md);
    cursor: default;
}

.cover-upload-preview {
    position: relative;
    display: inline-block;
    max-width: 180px;
}

.cover-upload-preview img {
    width: 100%;
    border-radius: var(--radius-input);
    box-shadow: 4px 4px 16px rgba(35, 26, 46, 0.2), 0 0 0 1px rgba(139, 115, 85, 0.15);
}

.cover-upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    background: rgba(35, 26, 46, 0.6);
    border-radius: var(--radius-input);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cover-upload-preview:hover .cover-upload-overlay {
    opacity: 1;
}

.cover-upload-action {
    background: var(--parchment-light);
    color: var(--text-primary);
    border: 1px solid var(--brown-muted);
    border-radius: var(--radius-button);
    padding: 6px 20px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease;
    min-width: 100px;
}

.cover-upload-action:hover {
    background: var(--gold-bright);
}

.cover-upload-remove {
    background: transparent;
    color: var(--parchment-light);
    border-color: rgba(240, 230, 212, 0.5);
}

.cover-upload-remove:hover {
    background: var(--color-error);
    border-color: var(--color-error);
    color: var(--parchment-light);
}

.cover-upload-placeholder {
    padding: var(--space-md) 0;
}

.cover-upload-icon {
    color: var(--brown-muted);
    margin-bottom: var(--space-sm);
    transition: color 0.2s ease;
}

.cover-upload-zone:hover .cover-upload-icon {
    color: var(--gold-brand);
}

.cover-upload-text {
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 var(--space-xs);
    font-size: var(--text-base);
}

.cover-upload-hint {
    color: var(--brown-muted);
    font-size: var(--text-sm);
    margin: 0;
}

.cover-upload-url-toggle {
    background: none;
    border: none;
    color: var(--brown-muted);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    cursor: pointer;
    padding: var(--space-sm) 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cover-upload-url-toggle:hover {
    color: var(--gold-brand);
}

.cover-url-input {
    margin-top: var(--space-sm);
}

/* --- Scanner Section --- */
.scanner-section {
    max-width: 500px;
}

.scanner-reader {
    width: 100%;
    max-width: 500px;
}

.scanner-status {
    margin-top: var(--space-sm);
    font-style: italic;
    color: var(--brown-muted);
}

/* --- Import Info Box --- */
.info-box {
    background: var(--parchment-light);
    border: 1px solid rgba(139, 115, 85, 0.25);
    border-radius: var(--radius-card);
    padding: var(--space-md) var(--space-lg);
    margin-bottom: var(--space-lg);
    font-size: var(--text-sm);
    line-height: 1.8;
}

/* --- Responsive --- */
/* Desktop: backdrop is hidden */
.nav-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .nav-toggle {
        display: flex;
    }

    .top-nav {
        flex-wrap: nowrap;
        padding: var(--space-sm) var(--space-md);
    }

    .top-nav-title {
        flex: 1;
    }

    /* Off-canvas drawer */
    .top-nav-links {
        display: flex;
        flex-direction: column;
        gap: 0;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 280px;
        max-width: 80vw;
        background: var(--leather-dark);
        background-image:
            repeating-linear-gradient(
                45deg,
                transparent,
                transparent 2px,
                rgba(255, 255, 255, 0.01) 2px,
                rgba(255, 255, 255, 0.01) 4px
            );
        padding: 72px var(--space-lg) var(--space-lg);
        z-index: 200;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
    }

    .top-nav-links.open {
        transform: translateX(0);
    }

    .top-nav-links a {
        display: block;
        padding: 14px var(--space-lg);
        border-bottom: 1px solid rgba(207, 167, 80, 0.1);
        font-size: var(--text-lg);
    }

    .top-nav-links a:last-child {
        border-bottom: none;
    }

    /* Backdrop */
    .nav-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(35, 26, 46, 0.5);
        z-index: 150;
        opacity: 0;
        transition: opacity 0.25s ease;
    }

    .nav-backdrop.visible {
        display: block;
        opacity: 1;
    }

    /* Body scroll lock */
    body.nav-open {
        overflow: hidden;
    }

    .container {
        padding: 12px 0;
    }

    .content {
        padding: 0 16px;
        background: none;
        box-shadow: none;
        border-radius: 0;
    }

    .checkbox-group {
        flex-direction: column;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group .button {
        text-align: center;
    }

    .book-hero {
        flex-direction: row;
        gap: var(--space-md);
        align-items: flex-start;
    }

    .book-cover {
        width: 90px;
        min-width: 90px;
    }

    .book-meta-row {
        flex-direction: row;
        gap: var(--space-sm);
        padding: 6px 0;
    }

    .book-meta-label {
        width: 80px;
        min-width: 80px;
        font-size: var(--text-xs);
    }

    .book-meta-value {
        font-size: 14px;
    }

    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .book-card-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: var(--space-md);
    }

    .breadcrumbs {
        display: none;
    }

    .dashboard-section {
        padding: var(--space-sm) var(--space-md);
    }

    .filter-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .filter-field-rating {
        grid-column: 1 / -1;
    }

    .filter-grid select,
    .filter-grid input {
        font-size: 14px;
        padding: 6px 8px;
    }

    .page-header {
        gap: var(--space-md);
    }
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

/* --- Staggered Animations --- */
.stagger > * {
    opacity: 0;
    animation: fadeInUp 0.3s ease-out forwards;
}

.stagger > :nth-child(1) { animation-delay: 0s; }
.stagger > :nth-child(2) { animation-delay: 0.04s; }
.stagger > :nth-child(3) { animation-delay: 0.08s; }
.stagger > :nth-child(4) { animation-delay: 0.12s; }
.stagger > :nth-child(5) { animation-delay: 0.16s; }
.stagger > :nth-child(6) { animation-delay: 0.2s; }
.stagger > :nth-child(7) { animation-delay: 0.24s; }
.stagger > :nth-child(8) { animation-delay: 0.28s; }
.stagger > :nth-child(9) { animation-delay: 0.32s; }
.stagger > :nth-child(10) { animation-delay: 0.36s; }
.stagger > :nth-child(n+11) { animation-delay: 0.4s; }

/* --- Book Subtitle --- */
.book-subtitle {
    margin-top: -12px;
    color: var(--brown-muted);
    font-style: italic;
    font-size: var(--text-lg);
}

/* --- Prose Content --- */
.prose {
    line-height: 1.85;
    color: var(--text-secondary);
}

.prose p {
    margin-bottom: var(--space-md);
}

.prose p:last-child {
    margin-bottom: 0;
}

/* --- Animated Link Underlines --- */
.book-list a,
.book-meta-value a,
.prose a,
table td a:not(.button) {
    background-image: linear-gradient(var(--gold-brand), var(--gold-brand));
    background-size: 0% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 0.3s ease, color 0.2s ease;
}

.book-list a:hover,
.book-meta-value a:hover,
.prose a:hover,
table td a:not(.button):hover {
    background-size: 100% 1px;
}

/* --- Custom Scrollbar --- */
.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: rgba(139, 115, 85, 0.08);
    border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(139, 115, 85, 0.25);
    border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 115, 85, 0.4);
}

/* --- Filter Active Badge --- */
.filter-active-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--gold-brand);
    color: var(--leather-dark);
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    padding: 0 6px;
    margin-left: var(--space-sm);
    vertical-align: middle;
}

/* --- Loading Button State --- */
.button.loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}

.button.loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: var(--space-sm);
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Smooth Details Reveal --- */
details.filter-panel[open] .filter-body {
    animation: filterReveal 0.2s ease-out;
}

@keyframes filterReveal {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Breadcrumbs --- */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    font-size: var(--text-sm);
    color: var(--brown-muted);
}

.breadcrumbs a {
    color: var(--brown-muted);
    transition: color 0.2s ease;
}

.breadcrumbs a:hover {
    color: var(--leather-dark);
}

.breadcrumbs .separator {
    opacity: 0.4;
    font-size: var(--text-xs);
    transition: opacity 0.2s ease;
}

.breadcrumbs:hover .separator {
    opacity: 0.65;
}

.breadcrumbs .current {
    color: var(--text-primary);
    font-weight: 700;
}

/* --- View Toggle --- */
.view-toggle {
    display: inline-flex;
    gap: 2px;
    background: rgba(139, 115, 85, 0.1);
    border-radius: var(--radius-flash);
    padding: 2px;
}

.view-toggle button {
    padding: 5px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--brown-muted);
    border-radius: var(--radius-input);
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    line-height: 1.4;
}

.view-toggle button:hover {
    color: var(--text-primary);
}

.view-toggle button.active {
    background: var(--parchment);
    color: var(--text-primary);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* --- Mobile List (Genres, Series) --- */
.mobile-list {
    display: none;
}

.mobile-list-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 12px 4px;
    border-bottom: 1px solid var(--border-light);
    text-decoration: none;
    color: var(--text-primary);
}

.mobile-list-item:last-child {
    border-bottom: none;
}

.mobile-list-name {
    flex: 1;
    font-weight: 600;
}

.mobile-list-meta {
    font-size: var(--text-sm);
    color: var(--brown-muted);
}

.mobile-list-number {
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    font-weight: 600;
    color: var(--brown-muted);
    font-size: var(--text-sm);
}

.mobile-list-chevron {
    color: var(--brown-muted);
    font-size: 18px;
    line-height: 1;
}

/* --- View Crossfade Transition --- */
.book-card-grid,
.book-table-view {
    transition: opacity 0.2s ease;
}

.view-fade-out {
    opacity: 0;
}

/* --- Book Card Grid --- */
.book-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.view-hidden {
    display: none !important;
}

.book-card {
    background: var(--parchment-light);
    border: 1px solid rgba(139, 115, 85, 0.18);
    border-radius: var(--radius-card);
    overflow: hidden;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    text-decoration: none;
    color: inherit;
    display: block;
}

.book-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(35, 26, 46, 0.1);
    color: inherit;
}

.book-card-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    background: linear-gradient(135deg, rgba(139, 115, 85, 0.08), rgba(139, 115, 85, 0.04));
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.book-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.book-card:hover .book-card-cover img {
    transform: scale(1.03);
}

.book-card-cover .no-cover {
    font-size: var(--text-3xl);
    color: var(--brown-muted);
    opacity: 0.2;
}

.book-card-body {
    padding: var(--space-sm) var(--space-md) var(--space-md);
}

.author-card .book-card-body {
    padding: var(--space-md);
    text-align: center;
}

.book-card-title {
    font-weight: 700;
    font-size: var(--text-sm);
    line-height: 1.35;
    margin-bottom: 2px;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card-author {
    font-size: var(--text-xs);
    color: var(--brown-muted);
    font-style: italic;
    margin-bottom: var(--space-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.book-card-footer .star-rating-sm {
    font-size: var(--text-xs);
    letter-spacing: 0;
}

/* --- Dashboard Book Cards (horizontal with cover) --- */
.dashboard-book-cards {
    list-style: none;
    padding: 0;
    margin: 0;
}

.dashboard-book-card {
    display: flex;
    gap: var(--space-md);
    padding: 10px var(--space-sm);
    border-radius: var(--radius-input);
    transition: background-color 0.2s ease, border-color 0.2s ease;
    align-items: center;
    border-left: 3px solid transparent;
}

.dashboard-book-card + .dashboard-book-card {
    border-top: 1px solid rgba(139, 115, 85, 0.12);
}

.dashboard-book-card:hover {
    background-color: rgba(207, 167, 80, 0.06);
    border-left-color: var(--gold-brand);
}

.dashboard-book-card-cover {
    width: 36px;
    flex-shrink: 0;
    border-radius: 2px;
    overflow: hidden;
    box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.12);
    aspect-ratio: 2 / 3;
    background: rgba(139, 115, 85, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dashboard-book-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.dashboard-book-card-cover .no-cover-sm {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    opacity: 0.3;
}

.dashboard-book-card-info {
    flex: 1;
    min-width: 0;
}

.dashboard-book-card-info a {
    font-weight: 700;
}

.dashboard-book-card-meta {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    font-style: italic;
}

/* --- Star Rating Picker --- */
.star-picker-wrap {
    margin-bottom: var(--space-md);
}

.star-picker-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.star-picker-header label {
    font-weight: 700;
    margin: 0;
}

.star-picker-header .rating-text {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    font-style: italic;
}

.star-picker-header .rating-clear {
    margin-left: auto;
    font-size: var(--text-lg);
    line-height: 1;
    color: var(--brown-muted);
    opacity: 0;
    cursor: pointer;
    transition: opacity 0.2s ease, color 0.2s ease;
    border: none;
    background: none;
    font-family: var(--font-family);
    padding: 0 4px;
}

.star-picker-header .rating-clear.visible {
    opacity: 0.4;
}

.star-picker-header .rating-clear.visible:hover {
    opacity: 1;
    color: var(--color-error);
}

.star-picker {
    display: flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
}

.star-picker label[data-value] {
    cursor: pointer;
    font-size: 32px;
    color: var(--cream);
    transition: color 0.12s ease, transform 0.12s ease;
    line-height: 1;
    padding: 2px 1px;
    user-select: none;
}

.star-picker label[data-value]:hover {
    transform: scale(1.15);
}

/* Hover: light up hovered + all to its right (lower values via ~ in reversed order) */
.star-picker:hover label[data-value] {
    color: var(--cream);
}

.star-picker label[data-value]:hover,
.star-picker label[data-value]:hover ~ label[data-value] {
    color: var(--gold-brand);
}

/* Active selection (JS-managed) */
.star-picker:not(:hover) label[data-value].active,
.star-picker:not(:hover) label[data-value].active ~ label[data-value] {
    color: var(--plum);
}

/* --- Clickable Table Rows --- */
tr[data-href] {
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: border-color 0.2s ease;
}

tr[data-href]:hover {
    border-left-color: var(--gold-brand);
}

tr[data-href]:active {
    background-color: rgba(207, 167, 80, 0.15) !important;
}

/* --- Enhanced Empty States --- */
.empty-state .empty-cta {
    margin-top: var(--space-md);
    font-style: normal;
}

/* --- Accessible Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- Inline Replacements --- */
.inline-form {
    display: inline;
}

.hidden-form {
    display: none;
}

.book-cover-clickable {
    cursor: pointer;
}

/* --- Utility Classes --- */
.text-center {
    text-align: center;
}

.text-sm {
    font-size: var(--text-sm);
}

.text-muted {
    color: var(--brown-muted);
}

.mb-0 {
    margin-bottom: 0;
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

/* Focus visible for keyboard accessibility */
:focus-visible {
    outline: 2px solid var(--gold-brand);
    outline-offset: 2px;
}

button:focus-visible,
.button:focus-visible {
    outline: 2px solid var(--gold-brand);
    outline-offset: 2px;
}

/* --- Book View: Floating Action Icons --- */
.book-view-header {
    position: relative;
}

.action-icons {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

.action-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    appearance: none;
    padding: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(139, 115, 85, 0.3);
    background: var(--parchment-light);
    color: var(--brown-muted);
    font-size: 16px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    line-height: 1;
}

.action-icon-btn:hover {
    background-color: rgba(139, 115, 85, 0.1);
    color: var(--text-primary);
    border-color: var(--leather-warm);
    box-shadow: 0 2px 6px rgba(35, 26, 46, 0.08);
}

.action-icon-btn svg {
    display: block;
}

.action-icon-btn[type="submit"] {
    font-family: var(--font-family);
}

/* --- Book View: Delete Link (subtle) --- */
.delete-link-wrap {
    margin-top: var(--space-lg);
    text-align: center;
}

.delete-link {
    font-size: var(--text-sm);
    color: var(--brown-muted);
    opacity: 0.6;
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--font-family);
    padding: 0;
    text-decoration: underline;
    text-decoration-style: dotted;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.delete-link:hover {
    opacity: 1;
    color: var(--plum);
}

/* --- Confirm Delete Modal Overlay --- */
.confirm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(35, 26, 46, 0.55);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.confirm-modal {
    background: var(--parchment);
    border: 1px solid rgba(139, 115, 85, 0.3);
    border-radius: var(--radius-card);
    padding: var(--space-lg) var(--space-xl);
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(35, 26, 46, 0.2);
    text-align: center;
}

.confirm-modal h4 {
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.confirm-modal p {
    color: var(--brown-muted);
    font-size: var(--text-sm);
    margin-bottom: var(--space-lg);
}

.confirm-modal .button-group {
    justify-content: center;
}

/* === Mobile Enhancements === */

.filter-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(35, 26, 46, 0.4);
    z-index: 250;
}

.filter-backdrop.visible {
    display: block;
}

.filter-sheet-header {
    display: none;
}

@media (max-width: 768px) {
    /* Typography — scale down for mobile */
    body { font-size: 15px; }
    h1 { font-size: var(--text-2xl); }
    h2 { font-size: var(--text-xl); }
    h3 { font-size: var(--text-lg); }

    /* Hide table views and toggle on mobile, show mobile list */
    .book-table-view { display: none !important; }
    .desktop-table { display: none; }
    .mobile-list { display: block; }
    .view-toggle { display: none; }

    /* Restyle grid as compact list (Gmail-style rows) */
    .book-card-grid {
        display: flex !important;
        flex-direction: column;
        gap: 0;
        margin-bottom: var(--space-md);
    }

    .book-card-grid.stagger > * {
        animation: none;
        opacity: 1;
    }

    .book-card {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: var(--space-sm);
        padding: 10px var(--space-sm);
        border-radius: 0;
        border: none;
        border-bottom: 1px solid rgba(139, 115, 85, 0.12);
        background: transparent;
    }

    .book-card:last-child {
        border-bottom: none;
    }

    .book-card:hover {
        transform: none;
        box-shadow: none;
        background: rgba(207, 167, 80, 0.06);
    }

    .book-card:active {
        background: rgba(207, 167, 80, 0.12);
    }

    .book-card-cover {
        width: 40px;
        min-width: 40px;
        aspect-ratio: 2 / 3;
        border-radius: 3px;
        flex-shrink: 0;
    }

    .book-card-cover .no-cover {
        font-size: var(--text-sm);
    }

    .book-card:hover .book-card-cover img {
        transform: none;
    }

    .book-card-body {
        flex: 1;
        min-width: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: 1px;
    }

    .book-card-title {
        font-size: 14px;
        -webkit-line-clamp: 1;
        line-height: 1.3;
        margin-bottom: 0;
    }

    .book-card-author {
        font-size: var(--text-xs);
        margin-bottom: 0;
    }

    .book-card-footer {
        gap: var(--space-xs);
        margin-top: 2px;
    }

    .book-card-footer .tag {
        font-size: 10px;
        padding: 1px 6px;
    }

    .book-card-footer .star-rating-sm {
        display: none;
    }

    /* Author cards in list mode */
    .author-card .book-card-body {
        padding: 0;
        text-align: left;
    }

    /* Page header — compact layout */
    .page-header {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: var(--space-sm);
        align-items: center;
    }

    .page-header h3 { margin-bottom: 0; }

    .page-header > .button-group {
        justify-self: end;
    }

    .header-search {
        grid-column: 1 / -1;
        max-width: none;
    }

    /* Filter panel — bottom sheet */
    details.filter-panel {
        display: block;
        border: none;
        background: none;
    }

    details.filter-panel summary {
        display: inline-flex;
        border: 1px solid rgba(139, 115, 85, 0.25);
        border-radius: var(--radius-input);
        background: var(--parchment-light);
    }

    details.filter-panel .filter-body {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        min-width: unset;
        max-width: unset;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 24px rgba(35, 26, 46, 0.2);
        margin-top: 0;
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        z-index: 300;
        animation: sheetUp 0.25s ease-out;
    }

    @keyframes sheetUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    details.filter-panel .filter-body .button-group {
        flex-direction: row;
        justify-content: center;
        padding-top: var(--space-sm);
    }

    .filter-sheet-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
        padding-bottom: 8px;
        border-bottom: 1px solid rgba(139, 115, 85, 0.2);
    }

    .filter-sheet-header span {
        font-size: var(--text-lg);
        font-weight: 700;
        color: var(--text-primary);
    }

    .filter-sheet-close {
        background: none;
        border: none;
        font-size: 28px;
        color: var(--brown-muted);
        cursor: pointer;
        line-height: 1;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: var(--font-family);
        border-radius: 50%;
        transition: background-color 0.15s ease, color 0.15s ease;
    }

    .filter-sheet-close:hover {
        color: var(--text-primary);
        background: rgba(139, 115, 85, 0.1);
    }

    /* Touch targets — 44px minimum per Apple/Google guidelines */
    .nav-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .paginator li a,
    .paginator li span {
        padding: 10px 14px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .filter-chip {
        padding: 6px 14px;
    }

    .filter-chip-remove {
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .action-icon-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
        border-color: transparent;
        background: transparent;
    }

    .star-picker label[data-value] {
        font-size: 30px;
        padding: 4px 2px;
    }

    .tag-picker-pill-remove {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }

    .paginator p {
        font-size: var(--text-xs);
    }

    /* Action icons inline with title on mobile */
    .action-icons {
        position: static;
        margin-bottom: 0;
    }

    .book-view-header {
        display: flex;
        align-items: center;
        gap: var(--space-xs);
        margin-bottom: var(--space-sm);
    }

    .book-view-header h3 {
        flex: 1;
        min-width: 0;
        margin-bottom: 0;
        font-size: 16px;
    }

    .book-subtitle {
        font-size: 14px;
        margin-top: -8px;
    }

    .divider {
        margin: var(--space-md) 0;
    }

    .delete-link-wrap {
        margin-top: var(--space-md);
    }

    /* Confirm modal buttons stay horizontal */
    .confirm-modal .button-group {
        flex-direction: row;
        justify-content: center;
    }

    /* Dashboard bottom CTA — full-width stacked */
    .dashboard > .button-group {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard > .button-group .button {
        text-align: center;
    }

    /* Safe area insets for notched phones */
    .top-nav {
        padding-left: max(var(--space-md), env(safe-area-inset-left, 0px));
        padding-right: max(var(--space-md), env(safe-area-inset-right, 0px));
    }

    .container {
        padding-left: max(16px, env(safe-area-inset-left, 0px));
        padding-right: max(16px, env(safe-area-inset-right, 0px));
    }

    footer {
        padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom, 0px));
    }

    .top-nav-links {
        padding-right: max(var(--space-lg), env(safe-area-inset-right, 0px));
    }
}

/* Extra-small phones (< 400px) */
@media (max-width: 400px) {
    body { font-size: 14px; }

    .top-nav-title {
        font-size: 20px;
        letter-spacing: 1px;
    }

    .stat-number {
        font-size: var(--text-2xl);
    }

    .dashboard-stats {
        gap: var(--space-sm);
    }

    .paginator li a,
    .paginator li span {
        padding: 8px 10px;
        font-size: var(--text-xs);
        min-height: 40px;
    }
}

/* ============================================================
   SCAN MODE
   ============================================================ */

.scan-mode-body {
    background: #1a1225;
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100dvh;
    color: #e8ddd0;
    font-family: var(--font-family);
}

.scan-mode {
    position: relative;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.scan-close {
    position: fixed;
    top: 12px;
    top: max(12px, env(safe-area-inset-top, 12px));
    right: 12px;
    z-index: 100;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    color: #e8ddd0;
    text-decoration: none;
    font-size: 28px;
    line-height: 1;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* --- Viewfinder --- */
.scan-viewfinder {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #0a0a0a;
}

#scan-reader {
    position: absolute;
    inset: 0;
}

#scan-reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    min-height: 100%;
}

#scan-reader > div {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
}

#scan-reader img[alt="scan-region-shade"] {
    display: none !important;
}

#scan-reader > div > div {
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.scan-viewfinder-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-target {
    width: 260px;
    height: 110px;
    position: relative;
}

.scan-target-corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: var(--gold-brand);
    border-style: solid;
    border-width: 0;
}

.scan-target-corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-radius: 6px 0 0 0; }
.scan-target-corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-radius: 0 6px 0 0; }
.scan-target-corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 6px; }
.scan-target-corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 6px 0; }

.scan-line {
    position: absolute;
    left: 10%;
    right: 10%;
    height: 2px;
    top: 50%;
    background: linear-gradient(90deg, transparent, var(--gold-brand), transparent);
    animation: scanPulse 2s ease-in-out infinite;
}

@keyframes scanPulse {
    0%, 100% { opacity: 0.3; transform: scaleX(0.7); }
    50% { opacity: 1; transform: scaleX(1); }
}

.scan-status-text {
    margin-top: 24px;
    font-size: var(--text-sm);
    color: rgba(232, 221, 208, 0.7);
    text-align: center;
}

/* --- Searching overlay --- */
.scan-searching {
    position: absolute;
    inset: 0;
    background: rgba(26, 18, 37, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.scan-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid transparent;
    border-top-color: var(--gold-brand);
    border-radius: 50%;
    animation: scanSpin 0.8s linear infinite;
}

@keyframes scanSpin {
    to { transform: rotate(360deg); }
}

.scan-searching-text {
    margin-top: 16px;
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--gold-brand);
}

.scan-searching-isbn {
    margin-top: 4px;
    font-size: var(--text-sm);
    color: rgba(232, 221, 208, 0.5);
}

/* --- Result card --- */
.scan-result {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 85dvh;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    background: #1a1225;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.scan-result.visible {
    transform: translateY(0);
}

.scan-result-header {
    text-align: center;
    margin-bottom: 16px;
}

.scan-result-icon {
    font-size: 32px;
    margin-bottom: 4px;
}

.scan-result-title {
    font-size: var(--text-lg);
    font-weight: 700;
    margin: 0;
}

/* State-specific borders */
.scan-result[data-state="success"] { border-top: 3px solid #4a9; }
.scan-result[data-state="success"] .scan-result-title { color: #4a9; }

.scan-result[data-state="duplicate"] { border-top: 3px solid #c44; }
.scan-result[data-state="duplicate"] .scan-result-title { color: #c44; }

.scan-result[data-state="possible"] { border-top: 3px solid #d9a020; }
.scan-result[data-state="possible"] .scan-result-title { color: #d9a020; }

.scan-result[data-state="not-found"] { border-top: 3px solid rgba(232, 221, 208, 0.3); }
.scan-result[data-state="not-found"] .scan-result-title { color: rgba(232, 221, 208, 0.8); }

.scan-result[data-state="error"] { border-top: 3px solid #c44; }
.scan-result[data-state="error"] .scan-result-title { color: #c44; }
.scan-result[data-state="error"] .scan-error-message { color: rgba(232, 221, 208, 0.8); }

/* --- Book info inside result --- */
.scan-book-cover {
    display: block;
    max-width: 100px;
    max-height: 150px;
    margin: 0 auto 12px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.scan-book-title {
    font-size: var(--text-base);
    font-weight: 700;
    text-align: center;
    margin: 0;
    color: #e8ddd0;
}

.scan-book-author {
    font-size: var(--text-sm);
    text-align: center;
    color: rgba(232, 221, 208, 0.7);
    margin-top: 2px;
}

/* --- Star rating in scan mode --- */
.scan-stars {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 12px;
}

.scan-stars button {
    background: none;
    border: none;
    padding: 4px 2px;
    font-size: 28px;
    color: rgba(232, 221, 208, 0.25);
    cursor: pointer;
    transition: color 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.scan-stars button.active {
    color: var(--gold-brand);
}

.scan-stars button:active {
    transform: scale(1.2);
}

/* --- Read checkbox --- */
.scan-read-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    font-size: var(--text-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.scan-read-toggle input[type="checkbox"] {
    display: none;
}

.scan-read-check {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid rgba(232, 221, 208, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: transparent;
    transition: all 0.15s;
}

.scan-read-toggle input:checked + .scan-read-check {
    background: #4a9;
    border-color: #4a9;
    color: #1a1225;
}

/* --- Duplicate comparison --- */
.scan-compare {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: flex-start;
    margin: 12px 0;
}

.scan-compare-item {
    text-align: center;
    flex: 0 0 auto;
}

.scan-compare-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.scan-compare-cover {
    width: 60px;
    height: 85px;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.scan-compare-divider {
    align-self: center;
    font-size: 20px;
    color: #d9a020;
}

.scan-existing-date {
    font-size: var(--text-sm);
    color: rgba(232, 221, 208, 0.5);
    margin-top: 4px;
    text-align: center;
}

/* --- Action buttons --- */
.scan-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.scan-buttons .btn-secondary {
    flex: 0 1 auto;
    padding: 12px 20px;
    border-radius: var(--radius-button);
    border: 1px solid rgba(232, 221, 208, 0.2);
    background: rgba(255, 255, 255, 0.06);
    color: #e8ddd0;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-buttons .btn-primary {
    flex: 1;
    padding: 12px 20px;
    border-radius: var(--radius-button);
    border: none;
    background: var(--gold-brand);
    color: var(--leather-dark);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-buttons .btn-success {
    flex: 1;
    padding: 12px 20px;
    border-radius: var(--radius-button);
    border: none;
    background: #4a9;
    color: #1a1225;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Not-found ISBN display */
.scan-isbn-display {
    font-family: monospace;
    font-size: var(--text-sm);
    color: rgba(232, 221, 208, 0.6);
    text-align: center;
    margin-top: 8px;
}

.scan-error-message {
    font-size: var(--text-sm);
    color: rgba(232, 221, 208, 0.6);
    text-align: center;
    margin-top: 4px;
}

/* Scan link — mobile only */
.scan-link {
    display: none;
}

@media (max-width: 1024px) and (pointer: coarse) {
    .scan-link {
        display: inline-flex;
    }
}
