:root {
    --bg-color: #0b0a0e;
    --text-color: #d1cbb8;
    --accent-red: #8b0000;
    --accent-red-deep: #5a0000;
    --gold: #c29f60;
    --gold-dim: #7a633c;
    --wood-hi: #43301c;
    --wood: #2c1f11;
    --wood-lo: #17100a;
    --modal-bg: #110e14;
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --noise-tex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 50% -20%, #1b1a22, transparent 70%),
        linear-gradient(to bottom, transparent, #050406 100%);
    color: var(--text-color);
    font-family: 'Crimson Text', 'Noto Serif SC', 'Songti SC', serif;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

body.modal-open {
    overflow: hidden;
}

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
    border-radius: 4px;
}

/* ========== 背景氛围层 ========== */

.bg-stone {
    position: fixed;
    inset: 0;
    background-image: var(--noise-tex);
    opacity: 0.05;
    pointer-events: none;
    z-index: 0;
}

.fog {
    position: fixed;
    width: 120vw;
    height: 60vh;
    border-radius: 50%;
    filter: blur(60px);
    pointer-events: none;
    z-index: 1;
}

.fog-1 {
    top: 10vh;
    left: -20vw;
    background: radial-gradient(ellipse at center, rgba(110, 100, 130, 0.07), transparent 65%);
    animation: fog-drift 55s ease-in-out infinite alternate;
}

.fog-2 {
    bottom: 5vh;
    right: -20vw;
    background: radial-gradient(ellipse at center, rgba(60, 50, 90, 0.06), transparent 65%);
    animation: fog-drift 70s ease-in-out infinite alternate-reverse;
}

@keyframes fog-drift {
    from { transform: translateX(-6%) translateY(0); }
    to { transform: translateX(6%) translateY(-4%); }
}

.candle-glow {
    position: fixed;
    bottom: -14vmax;
    width: 48vmax;
    height: 48vmax;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 146, 48, 0.13), rgba(255, 100, 20, 0.05) 45%, transparent 68%);
    filter: blur(10px);
    pointer-events: none;
    z-index: 1;
    animation: candle-flicker 5s ease-in-out infinite;
}

.candle-left { left: -14vmax; }
.candle-right { right: -14vmax; animation-delay: 2.3s; }

@keyframes candle-flicker {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    20% { opacity: 0.55; transform: scale(0.97); }
    40% { opacity: 0.9; transform: scale(1.02); }
    60% { opacity: 0.6; }
    80% { opacity: 0.85; transform: scale(0.99); }
}

.particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    overflow: hidden;
}

.ember {
    position: absolute;
    bottom: -10px;
    left: var(--x);
    width: var(--s);
    height: var(--s);
    border-radius: 50%;
    background: radial-gradient(circle, #e8d5a8, rgba(200, 170, 100, 0.35) 55%, transparent 75%);
    opacity: 0;
    animation: ember-rise var(--d) linear infinite;
    animation-delay: var(--delay);
}

@keyframes ember-rise {
    0% { transform: translate(0, 0); opacity: 0; }
    10% { opacity: 0.8; }
    50% { transform: translate(calc(var(--sway) * -0.5), -55vh); opacity: 0.45; }
    100% { transform: translate(var(--sway), -108vh); opacity: 0; }
}

#overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.85) 100%);
    pointer-events: none;
    z-index: 60;
}

/* ========== 头部：彩窗 + 哥特黑体字 ========== */

header {
    text-align: center;
    padding: clamp(2rem, 5vw, 3.5rem) 1.5rem 2rem;
    position: relative;
    z-index: 10;
    overflow: hidden;
}

.stained-window {
    position: absolute;
    left: 50%;
    top: -5rem;
    translate: -50% 0;
    width: min(380px, 82vw);
    opacity: 0.42;
    filter: drop-shadow(0 0 45px rgba(70, 50, 120, 0.35));
    pointer-events: none;
    z-index: 0;
}

header h1,
.controls,
.result-count {
    position: relative;
    z-index: 1;
}

header h1 {
    font-family: 'UnifrakturMaguntia', 'Cinzel Decorative', cursive;
    font-weight: 400;
    font-size: clamp(2.6rem, 9vw, 5.5rem);
    color: var(--gold);
    text-shadow: 0 0 30px rgba(194, 159, 96, 0.35), 3px 3px 6px #000;
    margin-bottom: clamp(1.8rem, 4vw, 2.6rem);
    letter-spacing: clamp(1px, 0.6vw, 4px);
}

/* ========== 控制栏 ========== */

.controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1.25rem;
    max-width: 860px;
    margin: 0 auto;
}

.search-box {
    position: relative;
    flex: 1 1 300px;
    max-width: 460px;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    translate: 0 -50%;
    width: 18px;
    height: 18px;
    color: var(--gold-dim);
    pointer-events: none;
}

input, select {
    background-color: rgba(10, 8, 12, 0.8);
    border: 1px solid var(--gold-dim);
    color: var(--text-color);
    padding: 1rem 1.5rem;
    font-family: inherit;
    font-size: 1.05rem;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
    border-radius: 4px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
}

input:focus, select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(194, 159, 96, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.5);
    background-color: rgba(20, 16, 22, 0.9);
}

.search-box input {
    width: 100%;
    padding-left: 2.8rem;
    padding-right: 2.6rem;
    -webkit-appearance: none;
    appearance: none;
}

.search-box input::-webkit-search-cancel-button {
    display: none;
}

.clear-search {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    translate: 0 -50%;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--gold-dim);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.3s, background-color 0.3s;
}

.clear-search:hover {
    color: var(--accent-red);
    background: rgba(139, 0, 0, 0.15);
}

.sort-box select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 3rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1 L6 7 L11 1' stroke='%23c29f60' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1.1rem center;
}

.sort-box select option {
    background-color: #14101a;
    color: var(--text-color);
}

.result-count {
    margin-top: 1.3rem;
    min-height: 1.4em;
    font-style: italic;
    font-size: 0.95rem;
    color: #776f5e;
    letter-spacing: 1px;
}

/* ========== 橡木大书架 ========== */

main {
    padding-bottom: 7rem;
    position: relative;
    z-index: 10;
}

.bookcase {
    max-width: 1300px;
    margin: 0 auto;
    padding: 3.2rem clamp(0.75rem, 3vw, 2.5rem) 2rem;
    position: relative;
    background:
        var(--noise-tex),
        linear-gradient(to bottom, #241a0f, #1a120a 30%, #120c07);
    background-blend-mode: overlay, normal;
    border: 1px solid #4a3520;
    box-shadow:
        inset 0 0 0 7px var(--wood-lo),
        inset 0 0 0 8px rgba(194, 159, 96, 0.14),
        inset 0 0 80px rgba(0, 0, 0, 0.75),
        0 30px 60px rgba(0, 0, 0, 0.8);
}

/* 顶部飞檐：连续尖拱雕花 */
.bookcase::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 30px;
    background-color: var(--wood-lo);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='22'%3E%3Cpath d='M4 21 L4 12 Q4 6 22 2 Q40 6 40 12 L40 21' fill='none' stroke='%237a633c' stroke-width='1.4' opacity='0.6'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: center 4px;
    border-bottom: 1px solid rgba(194, 159, 96, 0.35);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.7);
}

#library {
    position: relative;
}

.empty-note {
    color: #6b6557;
    font-style: italic;
    font-size: 1.2rem;
    text-align: center;
    padding: 4rem 0;
}

/* 每一层隔板 */
.shelf-row {
    position: relative;
    padding: 0 clamp(0.3rem, 1.5vw, 1.2rem);
}

.books-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: 4px 5px;
    padding: 0 4px;
}

/* 装饰：横放的旧书堆 */
.decor-stack {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 2px;
    margin: 0 clamp(0.4rem, 2vw, 1.4rem);
    opacity: 0.85;
    pointer-events: none;
}

.decor-book {
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.65);
    background:
        linear-gradient(to bottom, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.35)),
        linear-gradient(to right, var(--c1), var(--c2));
    box-shadow: inset 6px 0 0 rgba(0, 0, 0, 0.4), inset 7px 0 0 rgba(210, 175, 105, 0.25), 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* 装饰：蜡烛 */
.decor-candle {
    position: relative;
    width: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-left: clamp(0.3rem, 1.5vw, 1rem);
    pointer-events: none;
}

.decor-candle .flame {
    width: 10px;
    height: 16px;
    border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
    background: radial-gradient(circle at 50% 70%, #fff3c8 0%, #ffb84d 45%, rgba(255, 110, 25, 0.6) 75%, transparent 100%);
    filter: drop-shadow(0 0 8px rgba(255, 170, 60, 0.8));
    animation: flame-sway 2.6s ease-in-out infinite;
}

.decor-candle .wax {
    width: 12px;
    height: 38px;
    border-radius: 3px 3px 2px 2px;
    background: linear-gradient(to right, #8a7a5c, #d8c9a3 40%, #b3a37e 70%, #6e6248);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.decor-candle .candle-base {
    width: 22px;
    height: 6px;
    border-radius: 50%;
    background: linear-gradient(to bottom, #6d5a33, #2e2413);
}

@keyframes flame-sway {
    0%, 100% { transform: scaleX(1) translateX(0); opacity: 0.95; }
    30% { transform: scaleX(0.82) translateX(0.8px); opacity: 0.8; }
    55% { transform: scaleX(1.1) translateX(-0.8px); opacity: 1; }
    80% { transform: scaleX(0.9) translateX(0.5px); opacity: 0.85; }
}

.shelf-board {
    height: 16px;
    margin-bottom: clamp(1.6rem, 3.5vw, 2.6rem);
    background: linear-gradient(to bottom, var(--wood-hi), var(--wood) 45%, var(--wood-lo));
    border-top: 1px solid rgba(220, 185, 120, 0.28);
    box-shadow: 0 12px 22px rgba(0, 0, 0, 0.85), inset 0 -4px 8px rgba(0, 0, 0, 0.6);
    position: relative;
    z-index: 5;
}

.shelf-row:last-child .shelf-board {
    margin-bottom: 0.5rem;
}

/* ========== 古籍书脊 ========== */

.book-wrapper {
    perspective: 900px;
    cursor: pointer;
    position: relative;
    animation: book-arrive 0.6s ease both;
    animation-delay: calc(var(--i, 0) * 45ms);
}

@keyframes book-arrive {
    from { opacity: 0; transform: translateY(22px); }
    to { opacity: 1; transform: translateY(0); }
}

.book {
    width: calc(var(--w) * 1px);
    height: calc(var(--h) * 1px);
    position: relative;
    transform-origin: center bottom;
    transform: rotate(var(--tilt, 0deg));
    transition: transform 0.4s var(--ease-spring), filter 0.4s ease;
    border-radius: 3px 3px 1px 1px;
    background:
        linear-gradient(to right, rgba(0, 0, 0, 0.55) 0%, rgba(255, 255, 255, 0.07) 18%, rgba(255, 255, 255, 0.02) 45%, rgba(0, 0, 0, 0.28) 82%, rgba(0, 0, 0, 0.6) 100%),
        repeating-linear-gradient(to bottom, transparent 0 15%, rgba(0, 0, 0, 0.5) 15%, rgba(226, 192, 124, 0.22) 16.5%, rgba(0, 0, 0, 0.4) 18%, transparent 19%),
        linear-gradient(to bottom, var(--c1), var(--c2));
    border: 1px solid rgba(0, 0, 0, 0.7);
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6), 2px 0 3px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14% 0 8%;
    overflow: hidden;
}

/* 皮革颗粒 */
.book::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: var(--noise-tex);
    opacity: 0.14;
    mix-blend-mode: overlay;
    pointer-events: none;
}

/* 顶底烫金饰线 */
.book::after {
    content: '';
    position: absolute;
    inset: 5% 12% auto;
    height: 0;
    border-top: 1px solid rgba(210, 175, 105, 0.55);
    box-shadow: 0 3px 0 rgba(210, 175, 105, 0.3);
    pointer-events: none;
}

.spine-deco {
    color: var(--gold);
    font-size: 11px;
    line-height: 1;
    text-shadow: 0 0 4px rgba(194, 159, 96, 0.5);
    margin-bottom: 10%;
    flex-shrink: 0;
}

.spine-title {
    writing-mode: vertical-rl;
    font-family: 'Cinzel Decorative', 'Crimson Text', serif;
    font-size: 0.72rem;
    letter-spacing: 2px;
    color: #e3cfa0;
    text-shadow: 1px 1px 2px #000;
    white-space: nowrap;
    flex-shrink: 0;
}

.spine-year {
    position: absolute;
    bottom: 7%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    letter-spacing: 1px;
    color: rgba(210, 175, 105, 0.6);
    z-index: 2;
}

/* 书签丝带 */
.ribbon {
    position: absolute;
    top: -3px;
    right: 18%;
    width: 7px;
    height: 42%;
    background: linear-gradient(to bottom, #7d1010, #4a0505);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 88%, 0 100%);
    box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.6);
    z-index: 2;
}

/* 悬停：从架上抽出 */
@media (hover: hover) and (pointer: fine) {
    .book-wrapper:hover .book {
        transform: translateY(-16px) rotateX(9deg) scale(1.05);
        filter: brightness(1.22) saturate(1.1);
        box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6), 0 18px 26px rgba(0, 0, 0, 0.85), 0 0 18px rgba(194, 159, 96, 0.18);
        z-index: 6;
    }
}

.book-wrapper:active .book {
    transform: translateY(-6px) scale(0.97);
}

/* 古籍皮革配色 */
.t-oxblood  { --c1: #4a1210; --c2: #230605; }
.t-forest   { --c1: #1c2e1a; --c2: #0a140a; }
.t-navy     { --c1: #182238; --c2: #080d1a; }
.t-umber    { --c1: #38240f; --c2: #190e05; }
.t-ebony    { --c1: #232326; --c2: #0d0d0f; }
.t-russet   { --c1: #47230f; --c2: #1f0e04; }
.t-hunter   { --c1: #14262c; --c2: #060f12; }
.t-midnight { --c1: #251a33; --c2: #0e0817; }

/* ========== 弹窗 Modal ========== */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--noise-tex), linear-gradient(135deg, var(--modal-bg), #050406);
    background-blend-mode: overlay, normal;
    border: 2px solid var(--gold-dim);
    border-radius: 4px;
    width: 85%;
    max-width: 1000px;
    max-height: 85vh;
    display: flex;
    box-shadow: 0 0 50px rgba(0, 0, 0, 1), 0 0 15px rgba(194, 159, 96, 0.1);
    position: relative;
    transform: scale(0.95) translateY(20px);
    transition: transform 0.4s var(--ease-spring);
}

.modal.show .modal-content {
    transform: scale(1) translateY(0);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 14px;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--gold-dim);
    font-size: 34px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.3s, transform 0.3s;
    font-family: sans-serif;
    text-shadow: 0 0 5px #000;
    z-index: 10;
}

.close-btn:hover {
    color: var(--accent-red);
    transform: rotate(90deg);
}

.nav-btn {
    position: absolute;
    top: 50%;
    translate: 0 -50%;
    width: 48px;
    height: 64px;
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    background: rgba(10, 8, 12, 0.85);
    color: var(--gold);
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 10;
}

.nav-btn:hover {
    background: rgba(90, 0, 0, 0.5);
    box-shadow: 0 0 15px rgba(194, 159, 96, 0.35);
}

.nav-prev { left: -66px; }
.nav-next { right: -66px; }

/* 弹窗左侧：古籍封面 */
.modal-left {
    padding: 3rem;
    background: rgba(0, 0, 0, 0.5);
    border-right: 1px solid var(--gold-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38%;
    flex-shrink: 0;
}

.modal-cover {
    position: relative;
    width: min(240px, 100%);
    aspect-ratio: 2 / 3;
    container-type: inline-size;
    filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.9));
    animation: cover-emerge 0.5s var(--ease-spring);
}

@keyframes cover-emerge {
    from { opacity: 0; transform: translateY(16px) rotateY(-20deg); }
    to { opacity: 1; transform: translateY(0) rotateY(0); }
}

/* 古籍装帧封面 */
.front-cover {
    position: absolute;
    inset: 0;
    border-radius: 2px 8px 8px 2px;
    border: 1px solid #222;
    border-left: 10px solid var(--c1);
    background:
        var(--noise-tex),
        linear-gradient(to right, rgba(0, 0, 0, 0.55), transparent 18%),
        linear-gradient(135deg, var(--c1), var(--c2));
    background-blend-mode: overlay, normal, normal;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55);
}

.front-frame {
    position: absolute;
    inset: 11px;
    border: 1px solid rgba(210, 175, 105, 0.55);
    border-radius: 2px 5px 5px 2px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 8% 9%;
}

.front-frame::after {
    content: '';
    position: absolute;
    inset: 5px;
    border: 1px solid rgba(210, 175, 105, 0.22);
    border-radius: 2px 4px 4px 2px;
    pointer-events: none;
}

.front-ornament {
    width: 30%;
    aspect-ratio: 1;
    color: var(--gold);
    margin-bottom: 10%;
    filter: drop-shadow(0 0 6px rgba(194, 159, 96, 0.4));
}

.front-ornament svg {
    width: 100%;
    height: 100%;
    display: block;
}

.front-title {
    font-family: 'Cinzel Decorative', cursive;
    color: var(--gold);
    font-size: 1.05rem;
    font-size: 9cqi;
    line-height: 1.3;
    margin-bottom: 6%;
    text-shadow: 2px 2px 5px #000;
    overflow-wrap: anywhere;
    min-width: 0;
}

.front-author {
    font-size: 0.85rem;
    font-size: 7.5cqi;
    font-style: italic;
    color: #a7a08e;
    overflow-wrap: anywhere;
    min-width: 0;
}

.front-year {
    position: absolute;
    bottom: 7%;
    font-size: 0.8rem;
    font-size: 6.5cqi;
    letter-spacing: 3px;
    color: rgba(210, 175, 105, 0.6);
}

/* 弹窗右侧：文字 */
.modal-right {
    padding: 3rem 3.5rem;
    width: 62%;
    overflow-y: auto;
}

.modal-right h2 {
    font-family: 'Cinzel Decorative', cursive;
    color: var(--gold);
    font-size: clamp(1.4rem, 3.5vw, 2.4rem);
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px #000;
    overflow-wrap: anywhere;
}

.modal-right .author {
    font-size: 1.1rem;
    color: #999;
    font-style: italic;
}

.modal-date {
    margin-top: 0.6rem;
    font-size: 0.85rem;
    letter-spacing: 2px;
    color: rgba(194, 159, 96, 0.6);
}

.divider {
    height: 1px;
    background: linear-gradient(to right, transparent, var(--gold-dim), transparent);
    margin: 1.8rem 0;
    opacity: 0.7;
}

.modal-right h3 {
    color: #a03c3c;
    font-family: 'Cinzel Decorative', cursive;
    font-size: 1.3rem;
    margin-top: 1.8rem;
    margin-bottom: 0.9rem;
    letter-spacing: 2px;
    text-shadow: 1px 1px 2px #000;
}

.modal-right p {
    line-height: 1.8;
    color: #ccc;
    font-size: 1.05rem;
    text-align: justify;
}

.text-placeholder {
    font-style: italic;
    color: #666;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-left: 3px solid #333;
}

.modal-hint {
    margin-top: 2.5rem;
    font-size: 0.8rem;
    font-style: italic;
    color: #555;
    text-align: center;
    letter-spacing: 1px;
}

/* ========== 页脚 ========== */

footer {
    position: relative;
    z-index: 10;
    text-align: center;
    padding: 2rem 1rem 2.5rem;
    color: #554e40;
    font-style: italic;
    font-size: 0.9rem;
    letter-spacing: 2px;
}

/* ========== 响应式 ========== */

@media (max-width: 1060px) {
    .nav-prev { left: 10px; }
    .nav-next { right: 10px; }
}

@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.9rem;
    }

    .search-box {
        max-width: none;
        flex: 0 0 auto;
    }

    .sort-box select {
        width: 100%;
    }

    main {
        padding-bottom: 4rem;
    }

    .bookcase {
        padding-top: 2.6rem;
    }

    .spine-title {
        font-size: 0.62rem;
        letter-spacing: 1px;
    }

    .modal-content {
        width: 100%;
        max-width: none;
        height: 100dvh;
        max-height: none;
        border: none;
        border-radius: 0;
        flex-direction: column;
    }

    .modal-left {
        width: 100%;
        padding: 3.5rem 1rem 1.25rem;
        border-right: none;
        border-bottom: 1px solid var(--gold-dim);
    }

    .modal-cover {
        width: 120px;
    }

    .modal-right {
        width: 100%;
        padding: 1.5rem 1.4rem 5.5rem;
        flex: 1;
    }

    .modal-right p {
        font-size: 1rem;
        text-align: left;
    }

    .nav-btn {
        top: auto;
        bottom: calc(0.9rem + env(safe-area-inset-bottom));
        translate: 0 0;
        width: 56px;
        height: 48px;
    }

    .nav-prev { left: 22%; }
    .nav-next { right: 22%; }

    .modal-hint {
        display: none;
    }
}

@media (max-width: 480px) {
    .books-row {
        gap: 3px 4px;
    }

    footer {
        font-size: 0.78rem;
    }
}

@media (max-width: 640px) {
    /* 窄屏：隐藏蜡烛与末端装饰书堆，把空间让给书脊 */
    .decor-candle {
        display: none;
    }

    .books-row .decor-stack ~ .decor-stack {
        display: none;
    }

    .decor-stack {
        margin: 0 0.4rem;
    }

    .book-wrapper {
        -webkit-tap-highlight-color: transparent;
    }
}

::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #0d0c11;
}
::-webkit-scrollbar-thumb {
    background: var(--gold-dim);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--gold);
}

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

/* ========== 管理权限页 ========== */

.admin-btn {
    cursor: pointer;
    background-color: rgba(10, 8, 12, 0.8);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    color: var(--gold);
    font-family: inherit;
    font-size: 1.05rem;
    letter-spacing: 2px;
    padding: 1rem 1.6rem;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
}

.admin-btn:hover {
    border-color: var(--gold);
    background-color: rgba(90, 0, 0, 0.35);
    box-shadow: 0 0 15px rgba(194, 159, 96, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.admin-content {
    flex-direction: column;
    width: min(92vw, 860px);
    max-height: 85vh;
    padding: 2.8rem 3rem 2.4rem;
    overflow-y: auto;
}

.admin-view h2 {
    font-family: 'Cinzel Decorative', 'Noto Serif SC', serif;
    color: var(--gold);
    font-size: clamp(1.3rem, 3vw, 1.9rem);
    letter-spacing: 2px;
    margin-bottom: 0.6rem;
    text-shadow: 2px 2px 8px #000;
}

.admin-note {
    color: #a7a08e;
    font-style: italic;
    margin-bottom: 1.4rem;
}

.admin-hint {
    margin-top: 1.2rem;
    font-size: 0.82rem;
    color: #776f5e;
    letter-spacing: 1px;
}

.admin-error {
    color: #d86a5a;
    font-size: 0.9rem;
    margin: -0.5rem 0 0.8rem;
}

.admin-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1rem;
}

.admin-field span {
    color: var(--gold);
    font-size: 0.88rem;
    letter-spacing: 2px;
}

.admin-field textarea {
    background-color: rgba(10, 8, 12, 0.8);
    border: 1px solid var(--gold-dim);
    color: var(--text-color);
    padding: 0.8rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    outline: none;
    border-radius: 4px;
    resize: vertical;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.admin-field textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(194, 159, 96, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.admin-field input[type="file"] {
    padding: 0.7rem 1rem;
    cursor: pointer;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 1.2rem;
}

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin: 0.6rem 0 1.4rem;
}

.admin-actions {
    display: flex;
    gap: 0.8rem;
    margin-top: 0.4rem;
}

.admin-btn-primary,
.admin-btn-ghost,
.admin-btn-danger {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.98rem;
    letter-spacing: 1px;
    border-radius: 4px;
    padding: 0.65rem 1.3rem;
    transition: all 0.3s;
}

.admin-btn-primary {
    background: linear-gradient(135deg, var(--accent-red-deep), #3a0505);
    border: 1px solid var(--gold-dim);
    color: #e8dfc8;
}

.admin-btn-primary:hover {
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(139, 0, 0, 0.55);
}

.admin-btn-ghost {
    background: transparent;
    border: 1px solid var(--gold-dim);
    color: var(--gold);
}

.admin-btn-ghost:hover {
    border-color: var(--gold);
    background: rgba(194, 159, 96, 0.1);
}

.admin-btn-danger {
    background: transparent;
    border: 1px solid rgba(139, 0, 0, 0.7);
    color: #d86a5a;
}

.admin-btn-danger:hover {
    background: rgba(139, 0, 0, 0.25);
    border-color: #d86a5a;
}

.admin-btn-small {
    padding: 0.4rem 0.9rem;
    font-size: 0.88rem;
    flex: none;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(122, 99, 60, 0.4);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
}

.admin-row-main {
    flex: 1;
    min-width: 0;
}

.admin-row-title {
    color: var(--gold);
    font-size: 1.02rem;
    overflow-wrap: anywhere;
}

.admin-row-meta {
    color: #8f8878;
    font-size: 0.85rem;
    font-style: italic;
    margin-top: 2px;
}

.admin-empty {
    color: #776f5e;
    font-style: italic;
    padding: 1rem 0;
}

/* 封面预览：相对定位容器，让 .front-cover 绝对填充 */
.cover-preview-row {
    display: flex;
    align-items: flex-end;
    gap: 1.2rem;
    margin: -0.4rem 0 1rem;
}

.cover-preview {
    position: relative;
    width: 110px;
    aspect-ratio: 5 / 7;
    flex: none;
    container-type: inline-size;
    overflow: hidden;
    border-radius: 2px 8px 8px 2px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.65);
}

/* 自定义封面图：覆盖皮革面，仅保留烫金框线 */
.front-cover-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 2px 8px 8px 2px;
}

.front-cover.has-image .front-ornament,
.front-cover.has-image .front-title,
.front-cover.has-image .front-author,
.front-cover.has-image .front-year {
    display: none;
}

.front-cover.has-image .front-frame {
    background: rgba(0, 0, 0, 0.12);
}

@media (max-width: 768px) {
    .admin-content {
        padding: 3.4rem 1.3rem 2rem;
        width: 100%;
    }

    .admin-grid {
        grid-template-columns: 1fr;
    }

    .admin-row {
        flex-wrap: wrap;
    }
}
