:root {
    --ink: #f4ead4;
    --muted: #bfb19a;
    --paper: #f8f0da;
    --paper-ink: #241a14;
    --brass: #c7a45b;
    --green: #16423b;
    --teal: #1f6f70;
    --wine: #6f2432;
    --night: #111316;
    --shelf: #2c1c17;
    --shelf-edge: #5e3d2f;
    --shadow: rgba(0, 0, 0, 0.55);
    --panel-width: 340px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 50% -20%, rgba(210, 172, 92, 0.2), transparent 34rem),
        linear-gradient(135deg, rgba(31, 111, 112, 0.18), transparent 38%),
        linear-gradient(160deg, #101315 0%, #191211 52%, #101315 100%);
    font-family: "Songti SC", "SimSun", "Noto Serif SC", Georgia, serif;
}

button,
input,
select {
    font: inherit;
}

button {
    color: var(--paper-ink);
    background: var(--paper);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-right-color: rgba(0, 0, 0, 0.45);
    border-bottom-color: rgba(0, 0, 0, 0.45);
    padding: 6px 10px;
    cursor: pointer;
}

button:active {
    border-color: rgba(0, 0, 0, 0.45) rgba(255, 255, 255, 0.55) rgba(255, 255, 255, 0.55) rgba(0, 0, 0, 0.45);
}

.library-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.library-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    background:
        linear-gradient(90deg, rgba(22, 66, 59, 0.94), rgba(37, 27, 24, 0.96)),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 5px);
    border-bottom: 1px solid rgba(199, 164, 91, 0.38);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}

.library-brand {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 180px;
}

.brand-mark {
    color: var(--brass);
    font-size: 17px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.library-count {
    color: var(--muted);
    font-size: 12px;
}

.library-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 1;
}

.library-search,
.library-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.library-search input,
.library-filter select {
    height: 30px;
    color: var(--paper-ink);
    background: var(--paper);
    border: 2px inset #d8c9a6;
    padding: 4px 8px;
}

.library-search input {
    width: min(34vw, 340px);
}

.library-room {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--panel-width);
    gap: 18px;
    flex: 1;
    padding: 18px;
}

.shelf-zone {
    min-width: 0;
}

.shelf-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.shelf-head h1 {
    margin: 0;
    color: #fff8df;
    font-size: clamp(24px, 4vw, 48px);
    font-weight: 700;
}

.shelf-head p {
    margin: 4px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.shelf-meter {
    min-width: 92px;
    padding: 8px 10px;
    text-align: center;
    color: var(--paper);
    background: rgba(31, 111, 112, 0.36);
    border: 1px solid rgba(199, 164, 91, 0.35);
}

.shelf-meter span {
    display: block;
    font-size: 26px;
    line-height: 1;
    color: var(--brass);
}

.shelf-meter small {
    color: var(--muted);
}

.bookshelf-wrap {
    position: relative;
    min-height: 430px;
    padding: 28px 22px 34px;
    overflow: hidden;
    background:
        linear-gradient(to bottom, rgba(255, 255, 255, 0.04), transparent 18%),
        repeating-linear-gradient(to bottom, transparent 0 322px, rgba(199, 164, 91, 0.5) 322px 325px, var(--shelf-edge) 325px 345px, #160f0e 345px 350px),
        linear-gradient(90deg, rgba(22, 66, 59, 0.22), transparent 22%, rgba(111, 36, 50, 0.16));
    border: 1px solid rgba(199, 164, 91, 0.3);
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.38), 0 18px 44px rgba(0, 0, 0, 0.28);
    perspective: 1600px;
}

.bookshelf {
    display: flex;
    flex-wrap: wrap-reverse;
    align-content: flex-start;
    align-items: flex-start;
    gap: 34px 14px;
    min-height: 350px;
    padding-bottom: 18px;
    transform-style: preserve-3d;
}

.book {
    position: relative;
    width: 52px;
    height: var(--book-height);
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px 0 0;
    color: var(--book-text);
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.16), transparent 12%, rgba(0, 0, 0, 0.18) 58%, rgba(0, 0, 0, 0.38)),
        repeating-linear-gradient(to bottom, transparent 0 42px, rgba(255, 255, 255, 0.1) 42px 44px, transparent 44px 92px),
        var(--book-color);
    border: 1px solid rgba(0, 0, 0, 0.38);
    border-radius: 2px;
    box-shadow: inset 2px 0 5px rgba(255, 255, 255, 0.16), 8px 12px 22px var(--shadow);
    transform: rotateY(-24deg) rotateZ(var(--book-tilt));
    transform-style: preserve-3d;
    transition: transform 0.22s ease, filter 0.22s ease;
}

.book::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 0;
    width: 100%;
    height: 32px;
    transform: rotateX(-90deg);
    transform-origin: top;
    background:
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.08) 0 1px, transparent 1px 5px),
        #eadfc7;
}

.book::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 100%;
    width: 30px;
    transform: rotateY(90deg);
    transform-origin: left;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(255, 255, 255, 0.04)),
        var(--book-color);
}

.book:hover,
.book.is-selected {
    z-index: 5;
    filter: brightness(1.12);
    transform: rotateY(-17deg) rotateZ(0deg) translateY(-12px) translateZ(32px);
}

.spine-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    max-height: calc(100% - 30px);
    overflow: hidden;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.15;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.78);
    pointer-events: none;
}

.library-empty {
    display: none;
    position: absolute;
    left: 22px;
    right: 22px;
    top: 86px;
    padding: 18px;
    color: var(--paper-ink);
    background: var(--paper);
    border: 2px inset #d8c9a6;
}

.library-empty.is-visible {
    display: block;
}

.reading-panel {
    position: sticky;
    top: 76px;
    align-self: start;
    max-height: calc(100vh - 96px);
    overflow: auto;
    color: var(--paper-ink);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.58), transparent 42%),
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.025) 0 1px, transparent 1px 7px),
        var(--paper);
    border: 1px solid rgba(255, 255, 255, 0.65);
    box-shadow: 12px 16px 38px rgba(0, 0, 0, 0.28);
    padding: 18px;
}

.panel-grip,
.panel-close {
    display: none;
}

.panel-kicker,
.modal-kicker {
    color: var(--teal);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.reading-panel h2 {
    margin: 6px 0 4px;
    font-size: 24px;
    line-height: 1.25;
}

.reading-panel h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

#panel-author {
    margin: 0 0 10px;
    color: #6a5142;
}

.panel-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.panel-tag {
    padding: 2px 7px;
    color: #fff;
    background: var(--green);
    font-size: 12px;
}

.panel-note,
.modal-note {
    margin: 0 0 12px;
    color: #5d4a3d;
    line-height: 1.65;
}

.panel-actions {
    display: flex;
    gap: 8px;
    margin: 12px 0;
}

.panel-divider,
.divider {
    height: 1px;
    background: rgba(80, 52, 38, 0.22);
    margin: 14px 0;
}

.quote-line {
    margin: 0 0 10px;
    padding: 10px 12px;
    line-height: 1.72;
    background: rgba(255, 255, 255, 0.45);
    border-left: 3px solid var(--brass);
}

.same-author {
    margin-top: 16px;
}

.same-author-title {
    margin-bottom: 8px;
    color: var(--teal);
    font-size: 12px;
    font-weight: 700;
}

.same-author button {
    display: block;
    width: 100%;
    margin-bottom: 6px;
    text-align: left;
}

.quote-index {
    padding: 0 18px 22px;
}

.quote-index-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    border-top: 1px solid rgba(199, 164, 91, 0.34);
    padding-top: 16px;
}

.quote-index h2 {
    margin: 0 0 12px;
    color: var(--brass);
    font-size: 20px;
}

.quote-index-head span {
    color: var(--muted);
    font-size: 12px;
}

.quote-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}

.quote-card {
    min-height: 128px;
    padding: 14px;
    color: var(--paper-ink);
    background:
        linear-gradient(135deg, rgba(199, 164, 91, 0.18), transparent),
        var(--paper);
    border-left: 4px solid var(--wine);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    cursor: pointer;
}

.quote-card p {
    margin: 0 0 10px;
    line-height: 1.7;
}

.quote-card small {
    color: #6a5142;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(0, 0, 0, 0.78);
}

.overlay.active {
    display: flex;
}

.book-modal {
    position: relative;
    width: min(680px, 94vw);
    max-height: 88vh;
    overflow: auto;
    color: var(--paper-ink);
    background:
        radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.65), transparent 18rem),
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.025) 0 1px, transparent 1px 7px),
        var(--paper);
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.62);
    padding: 38px;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 14px;
    width: 34px;
    height: 34px;
    padding: 0;
    color: var(--paper-ink);
    background: transparent;
    border: 0;
    font-size: 28px;
}

.modal-content h2 {
    margin: 6px 0 6px;
    font-size: 32px;
    line-height: 1.2;
}

.modal-content h3 {
    margin: 0 0 12px;
    color: #6a5142;
    font-weight: 400;
}

.quote-item {
    margin-bottom: 16px;
    padding: 12px 14px;
    line-height: 1.82;
    background: rgba(255, 255, 255, 0.5);
    border-left: 3px solid var(--brass);
}

.modal-related {
    margin-top: 18px;
}

.modal-related button {
    margin: 0 6px 6px 0;
}

@media (max-width: 860px) {
    .library-toolbar {
        position: static;
        display: block;
    }

    .library-controls {
        justify-content: flex-start;
        flex-wrap: wrap;
        margin-top: 10px;
    }

    .library-search input {
        width: min(72vw, 420px);
    }

    .library-room {
        display: block;
        padding: 12px;
    }

    .bookshelf-wrap {
        min-height: 320px;
        padding: 18px 14px 28px;
        overflow: visible;
    }

    .bookshelf {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        min-height: auto;
    }

    .book {
        width: 100%;
        height: auto !important;
        min-height: 54px;
        display: block;
        padding: 12px 14px;
        transform: none;
    }

    .book::before,
    .book::after {
        display: none;
    }

    .book:hover,
    .book.is-selected {
        transform: none;
    }

    .spine-title {
        writing-mode: horizontal-tb;
        white-space: normal;
        max-height: none;
        font-size: 16px;
    }

    .reading-panel {
        position: fixed;
        z-index: 60;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        max-height: 74vh;
        border-radius: 0;
        transform: translateY(calc(100% - 52px));
        transition: transform 0.22s ease;
    }

    .reading-panel.is-open {
        transform: translateY(0);
    }

    .panel-grip {
        display: block;
        width: 42px;
        height: 4px;
        margin: 0 auto 10px;
        background: rgba(36, 26, 20, 0.35);
    }

    .panel-close {
        display: block;
        position: absolute;
        top: 8px;
        right: 10px;
        width: 34px;
        height: 34px;
        padding: 0;
        background: transparent;
        border: 0;
        font-size: 24px;
    }

    .quote-index {
        padding: 0 12px 84px;
    }
}

@media (max-width: 520px) {
    .shelf-head {
        display: block;
    }

    .shelf-meter {
        margin-top: 10px;
    }

    .library-search,
    .library-filter {
        width: 100%;
    }

    .library-search input,
    .library-filter select {
        flex: 1;
        width: 100%;
    }

    .book-modal {
        padding: 28px 20px;
    }
}
