:root {
    --bg: #edf4fb;
    --panel: rgba(248, 251, 255, 0.94);
    --line: rgba(148, 163, 184, 0.18);
    --text: #172554;
    --muted: #64748b;
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --shadow: 0 24px 60px rgba(15, 23, 42, 0.08);
    --radius-xl: 28px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 28%),
        radial-gradient(circle at top right, rgba(125, 211, 252, 0.06), transparent 22%),
        linear-gradient(180deg, #f8fbff 0%, #e7eef8 100%);
}

a {
    color: inherit;
}

.hidden {
    display: none !important;
}

.initial-loading {
    margin-top: 22px;
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--panel);
    box-shadow: var(--shadow);
    color: var(--muted);
    line-height: 1.8;
    text-align: center;
}

.bookshelf-root {
    margin-top: 22px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.shelf-section {
    padding: 28px;
}

.shelf-section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin: -28px -28px 24px;
    padding: 24px 28px;
    border-bottom: 1px solid var(--line);
}

.shelf-title-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.shelf-section-title h2 {
    margin: 0;
    font-size: 1.8rem;
    line-height: 1.2;
}

.shelf-count {
    flex-shrink: 0;
    color: var(--text);
    font-size: 1.08rem;
    font-weight: 700;
}

.shelf-admin-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid rgba(37, 99, 235, 0.22);
    border-radius: 10px;
    color: var(--accent);
    background: rgba(255, 255, 255, 0.78);
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
}

.shelf-admin-link:hover,
.shelf-admin-link:focus-visible {
    border-color: rgba(37, 99, 235, 0.38);
    background: rgba(239, 246, 255, 0.92);
}

.shelf-admin-link.is-active {
    border-color: rgba(37, 99, 235, 0.42);
    background: rgba(219, 234, 254, 0.95);
    color: var(--accent-strong);
}

.shelf-message {
    min-height: 20px;
    margin: -10px 0 18px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 600;
}

.shelf-message.is-error {
    color: #b91c1c;
}

.admin-only {
    display: none;
}

body.admin-mode .admin-only {
    display: inline-flex;
}

.bookshelf-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 28px 20px;
}

.book-card {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 235px;
    width: 100%;
    padding: 12px;
    justify-self: center;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.6);
    transition: all 0.25s ease;
}

.book-card:hover {
    transform: translateY(-4px);
    border-color: rgba(37, 99, 235, 0.2);
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
}

.bookshelf-grid.is-sorting .book-card {
    cursor: grab;
}

.bookshelf-grid.is-sorting .book-card:hover {
    transform: none;
}

.book-card.is-dragging {
    opacity: 0.5;
}

.book-card-main {
    display: block;
    text-decoration: none;
}

.book-card.has-actions .book-card-main {
    margin-bottom: 12px;
}

.book-cover-wrap {
    position: relative;
    aspect-ratio: 3 / 4;
    margin-bottom: 12px;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(224, 236, 255, 0.8), rgba(191, 219, 254, 0.8));
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

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

.book-cover-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    color: rgba(23, 37, 84, 0.7);
    font-family: "Songti SC", "STSong", serif;
    font-size: 1rem;
    line-height: 1.6;
    text-align: center;
    background: linear-gradient(180deg, rgba(239, 246, 255, 0.9), rgba(219, 234, 254, 0.9));
}

.book-meta {
    padding: 0 4px;
}

.book-title {
    display: block;
    margin-bottom: 4px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.5;
}

.book-author {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 400;
    line-height: 1.45;
}

.book-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.book-action {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 6px 12px;
    border: 1px solid rgba(37, 99, 235, 0.15);
    border-radius: 6px;
    background: transparent;
    color: var(--accent-strong);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.book-action.admin-only {
    display: none;
}

body.admin-mode .book-action.admin-only {
    display: inline-flex;
}

.book-action:hover,
.book-action:focus-visible {
    border-color: rgba(37, 99, 235, 0.25);
    background: rgba(37, 99, 235, 0.08);
}

.empty-state {
    padding: 18px;
    border-radius: 18px;
    background: rgba(239, 246, 255, 0.76);
    color: var(--muted);
}

body.dialog-open {
    overflow: hidden;
}

.read-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(10px);
}

.read-dialog {
    width: min(560px, 100%);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 18px;
    background: rgba(248, 251, 255, 0.98);
    box-shadow: 0 30px 70px rgba(15, 23, 42, 0.24);
}

.read-dialog-form {
    padding: 22px;
}

.read-dialog-head {
    margin-bottom: 18px;
}

.read-dialog-head h3 {
    margin: 0;
    color: var(--text);
    font-size: 1.18rem;
    line-height: 1.35;
}

.read-form-grid,
.read-file-grid {
    display: grid;
    gap: 14px;
}

.read-form-field {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 700;
}

.read-form-field input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid rgba(148, 163, 184, 0.34);
    border-radius: 9px;
    outline: none;
    background: rgba(255, 255, 255, 0.9);
    color: var(--text);
    font: inherit;
    font-weight: 500;
}

.read-form-field input:focus {
    border-color: rgba(37, 99, 235, 0.52);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.read-form-field small {
    min-height: 18px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 500;
}

.read-form-field small.is-error,
.read-dialog-message.is-error {
    color: #b91c1c;
}

.read-file-grid {
    margin-top: 14px;
}

.read-file-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.64);
}

.read-file-field input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    opacity: 0;
    pointer-events: none;
}

.read-file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 12px;
    border-radius: 8px;
    background: #172554;
    color: #fff;
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
}

.read-file-name {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.5;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.read-dialog-message {
    min-height: 20px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.read-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.read-dialog-button {
    min-width: 88px;
    min-height: 38px;
    padding: 8px 14px;
    border: 1px solid rgba(37, 99, 235, 0.24);
    border-radius: 9px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.read-dialog-button.primary {
    background: var(--accent);
    color: #fff;
}

.read-dialog-button.secondary {
    background: rgba(255, 255, 255, 0.84);
    color: var(--accent-strong);
}

.read-dialog-button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

.footer {
    margin-top: 24px;
    padding: 18px 8px 0;
    color: var(--muted);
    text-align: center;
    font-size: 0.94rem;
}

.footer-records {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px 28px;
}

.footer-record {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.footer-record-icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

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

.footer a:hover,
.footer a:focus-visible {
    text-decoration: none;
}

@media (max-width: 900px) {
    .shelf-section {
        padding: 24px;
    }

    .shelf-section-title {
        margin: -24px -24px 24px;
        padding: 22px 24px;
    }

    .bookshelf-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 640px) {
    .shelf-section {
        padding: 22px;
    }

    .shelf-section-title {
        margin: -22px -22px 22px;
        padding: 22px;
    }

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