
* {
    box-sizing: border-box;
}

:root {
    --ink: #171044;
    --purple: #302080;
    --violet: #5142b5;
    --pale: #edeaff;
    --soft: #e9e8ed;
    --muted: #77738b;
    --ease: cubic-bezier(.22, 1, .36, 1);
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: #f7f6fa;
    color: var(--ink);
    font-family: Poppins, Arial, sans-serif;
    font-size: 16px;
}

button, input {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    min-height: 66px;
    padding: 10px max(20px, calc((100vw - 980px)/2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid #eeedf3;
    transition: box-shadow .35s var(--ease);
}

.topbar:focus-within {
    box-shadow: 0 5px 20px #1710440a;
}

.brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--ink);
    min-width: 112px;
}

.brand-logo {
    width: 150px;
    height: auto;
    max-height: 54px;
    object-fit: contain;
}

.brand-fallback {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.brand-fallback b {
    font-size: 24px;
    letter-spacing: -1.8px;
}

.brand-fallback small {
    font-size: 6px;
    letter-spacing: 2px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #e9e7ef;
    border-radius: 24px;
    padding: 7px 12px;
    max-width: 260px;
    width: 100%;
    transition: border-color .3s var(--ease), box-shadow .3s var(--ease), background .3s var(--ease);
}

.search-box:focus-within {
    border-color: var(--violet);
    background: #fff;
    box-shadow: 0 0 0 4px #5142b512;
}

.search-box span {
    font-size: 23px;
}

.search-box input {
    border: 0;
    outline: 0;
    width: 100%;
    min-width: 0;
    font-size: 11px;
    color: var(--ink);
}

main {
    width: min(100%, 760px);
    margin: auto;
    background: white;
    min-height: calc(100vh - 110px);
    box-shadow: 0 0 30px #1710440a;
}

.page {
    display: none;
    padding: 24px 22px 40px;
}

.page.active {
    display: block;
    animation: page-enter .65s var(--ease) both;
}

.welcome {
    padding: 12px 3px 25px;
}

.eyebrow {
    font-size: 12px;
    letter-spacing: 1.5px;
    font-weight: 600;
    color: var(--violet);
    margin: 0 0 10px;
}

h1, h2, h3, p {
    margin-top: 0;
}

.welcome h1 {
    font-size: 32px;
    line-height: 1.35;
    margin-bottom: 8px;
    letter-spacing: -.8px;
}

.welcome > p:not(.eyebrow) {
    color: #6f6b80;
    font-size: 15px;
    line-height: 1.75;
}

.primary-button {
    border: 0;
    background: var(--ink);
    color: white;
    border-radius: 30px;
    padding: 11px 25px;
    font-size: 14px;
    font-weight: 600;
    transition: background .3s var(--ease), box-shadow .3s var(--ease), transform .3s var(--ease);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-heading h2, .chapter-section h2 {
    font-size: 18px;
    margin: 0;
}

.section-heading span {
    font-size: 12px;
    color: var(--muted);
}

.featured-section, .catalog-section {
    margin: 10px 0 28px;
}

.featured-card {
    display: flex;
    gap: 16px;
    background: linear-gradient(125deg, #f3f0fc, #eeecf7 60%, #e9e6f5);
    border-radius: 16px;
    padding: 16px;
    min-height: 160px;
    box-shadow: 0 4px 14px #1710440d;
    border: 1px solid #e9e5f5;
    transition: box-shadow .35s var(--ease), border-color .35s var(--ease);
}

.book-cover {
    background: var(--ink);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    letter-spacing: 2px;
    font-weight: 600;
    overflow: hidden;
    box-shadow: 0 5px 14px #17104422;
    isolation: isolate;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scale(1);
    transition: transform 1.4s cubic-bezier(.16, 1, .3, 1), filter 1.2s ease;
    will-change: transform;
}

.cover-small {
    width: 100px;
    min-width: 100px;
    height: 140px;
    border-radius: 9px;
    font-size: 10px;
}

.featured-info {
    padding: 4px 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.featured-info h3 {
    font-size: 15px;
    line-height: 1.4;
    margin: 0 0 8px;
}

.featured-info p {
    font-size: 11px;
    line-height: 1.65;
    color: #625e75;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-button {
    border: 0;
    background: var(--ink);
    color: white;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 10px;
    font-weight: 600;
    margin-top: auto;
    transition: background .3s var(--ease), box-shadow .3s var(--ease), transform .3s var(--ease);
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px 12px;
}

.book-tile {
    border: 0;
    background: none;
    padding: 0;
    text-align: left;
    color: var(--ink);
    min-width: 0;
}

.cover-grid {
    width: 100%;
    aspect-ratio: 3/4.2;
    border-radius: 9px;
    font-size: 11px;
}

.book-tile > span {
    display: block;
    font-size: 12px;
    margin-top: 8px;
    line-height: 1.5;
    transition: color .3s var(--ease);
}

.empty-state {
    border: 1px dashed #d8d5e5;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.75;
    grid-column: 1/-1;
}

.muted-note, .small-note {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
    margin: 12px 0 0;
}

.contribute-card {
    background: linear-gradient(135deg, #edeaff, #f3f0ff);
    border: 1px solid #e5e0fa;
    border-radius: 14px;
    padding: 18px;
    margin-top: 30px;
    transition: border-color .3s var(--ease), box-shadow .3s var(--ease);
}

.contribute-card h2 {
    font-size: 14px;
    margin-bottom: 6px;
}

.contribute-card p {
    font-size: 11px;
    line-height: 1.6;
    margin-bottom: 0;
}

.back-button {
    border: 0;
    background: none;
    color: var(--ink);
    padding: 4px 0;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: center;
    transition: color .25s var(--ease), transform .25s var(--ease);
}

.back-button span {
    font-size: 11px;
}

.detail-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 0 22px;
}

.cover-detail {
    width: min(58%, 220px);
    aspect-ratio: 3/4.2;
    border-radius: 10px;
    font-size: 15px;
}

.detail-hero h1 {
    font-family: "DM Serif Display", Georgia, serif;
    font-size: 22px;
    font-weight: 400;
    margin: 14px 0 0;
    text-align: center;
}

.detail-panel {
    background: var(--soft);
    border-radius: 15px;
    padding: 18px;
    margin: 0 -22px;
}

.meta-line {
    font-size: 13px;
    margin: 0 0 8px;
}

.tag-row {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin: 13px 0 18px;
}

.tag-row span {
    font-size: 11px;
    background: #77718e;
    color: white;
    border-radius: 20px;
    padding: 4px 10px;
    transition: background .3s var(--ease);
}

.detail-panel h2 {
    font-size: 14px;
    margin-bottom: 8px;
}

.synopsis-text {
    font-size: 14px;
    line-height: 1.85;
    color: #4e4a60;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

.synopsis-text.expanded {
    display: block;
    overflow: visible;
}

.synopsis-toggle {
    border: 0;
    background: none;
    color: var(--violet);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 0;
    margin-top: 2px;
}

.full-button {
    width: 100%;
    margin-top: 12px;
}

.chapter-section {
    padding: 22px 0;
}

.chapter-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.chapter-item {
    border: 1px solid #eeedf3;
    border-radius: 10px;
    padding: 12px;
    text-align: left;
    background: white;
    color: var(--ink);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    transition: border-color .3s var(--ease), background .3s var(--ease);
}

.chapter-item.is-hidden {
    display: none;
}

.chapter-item.is-hidden.is-visible {
    display: flex;
}

.chapter-more {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 11px;
    border: 1px solid #e5e1f2;
    border-radius: 10px;
    background: #f8f7fc;
    color: var(--violet);
    font-size: 12px;
    font-weight: 600;
    transition: background .3s var(--ease), border-color .3s var(--ease);
}

.reader-page {
    padding-top: 14px;
    min-height: 75vh;
}

.reader-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.reader-brand-logo {
    width: 120px;
    max-height: 44px;
    height: auto;
    object-fit: contain;
}

.reader-brand-fallback {
    font-weight: 700;
    font-size: 17px;
}

.reader-content {
    max-width: 600px;
    margin: 40px auto 50px;
}

.reader-content h1 {
    font-family: "DM Serif Display", Georgia, serif;
    font-size: 25px;
    font-weight: 400;
    margin-bottom: 25px;
}

.chapter-body {
    font-family: Georgia, serif;
    font-size: 18px;
    line-height: 1.9;
    color: #292638;
}

.chapter-body p {
    margin-bottom: 22px;
    text-indent: 1.5em;
}

.chapter-body h2, .chapter-body h3 {
    font-family: Poppins, Arial, sans-serif;
    font-size: 15px;
    text-indent: 0;
}

.reader-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-top: 1px solid #e9e7ef;
    padding-top: 16px;
}

.secondary-button {
    border: 0;
    background: var(--pale);
    color: var(--ink);
    border-radius: 25px;
    padding: 10px 13px;
    font-size: 10px;
    transition: background .3s var(--ease), transform .3s var(--ease), box-shadow .3s var(--ease);
}

.secondary-button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

#chapterProgress {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

footer {
    text-align: center;
    padding: 20px;
    color: #89859a;
    font-size: 12px;
}

footer span {
    font-weight: 700;
    color: var(--ink);
}

.brand-fallback[hidden], .reader-brand-fallback[hidden] {
    display: none;
}

.book-cover img + span {
    display: none;
}

.search-toggle {
    display: none;
    border: 0;
    background: transparent;
    color: #171044;
    font-size: 26px;
    cursor: pointer;
}

.search-back, .search-clear {
    display: none;
    border: 0;
    background: transparent;
    color: #171044;
    font-size: 22px;
    cursor: pointer;
}

.search-results-heading {
    margin: 20px 0;
}

.search-results-heading h1 {
    font-size: 23px;
    margin-bottom: 6px;
}

.search-results-heading p {
    color: var(--muted);
    font-size: 13px;
}

#searchInput::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

@keyframes page-enter {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (hover: hover) {
    .book-cover:hover img {
        transform: scale(1.045);
        filter: saturate(1.04);
    }

    .featured-card:hover {
        border-color: #dcd5f2;
        box-shadow: 0 12px 30px #17104412;
    }

    .book-tile:hover > span {
        color: var(--violet);
    }

    .primary-button:hover, .text-button:hover {
        background: var(--violet);
        box-shadow: 0 7px 18px #5142b533;
    }

    .chapter-item:hover {
        background: #f8f7fc;
        border-color: #d8d2ef;
    }

    .chapter-more:hover {
        background: var(--pale);
        border-color: #d8d0f4;
    }

    .contribute-card:hover {
        border-color: #d8d0f4;
        box-shadow: 0 8px 22px #1710440c;
    }

    .tag-row span:hover {
        background: var(--violet);
    }

    .back-button:hover {
        color: var(--violet);
        transform: translateX(-3px);
    }

    .secondary-button:not(:disabled):hover {
        background: #dcd7fa;
        box-shadow: 0 4px 12px #5142b51a;
    }
}

.book-tile:active, .primary-button:active, .text-button:active, .secondary-button:active:not(:disabled), .chapter-item:active {
    transform: scale(.98);
}

button:focus-visible, a:focus-visible {
    outline: 2px solid var(--violet);
    outline-offset: 4px;
}

@media (min-width: 600px) {
    .page {
        padding: 34px 40px 50px;
    }

    .detail-panel {
        margin: 0 -40px;
        padding: 24px 40px;
    }

    .welcome h1 {
        font-size: 38px;
    }

    .cover-detail {
        width: 190px;
    }
}

@media (max-width: 600px) {
    .topbar {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .search-toggle {
        display: block;
        margin-left: auto;
    }

    .search-box {
        display: none;
        flex: 1;
        min-width: 0;
        width: auto;
    }

    .topbar.search-active .brand, .topbar.search-active .search-toggle {
        display: none;
    }

    .topbar.search-active .search-box {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .topbar.search-active .search-back, .topbar.search-active .search-clear {
        display: block;
        flex-shrink: 0;
    }

    .search-box input {
        min-width: 0;
        width: 100%;
        flex: 1;
    }

    .topbar.search-active {
        padding-left: 16px;
        padding-right: 16px;
        justify-content: flex-start;
    }

    .topbar.search-active .search-box {
        flex: 1;
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    .topbar.search-active .search-box input {
        flex: 1;
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 380px) {
    .page {
        padding-left: 16px;
        padding-right: 16px;
    }

    .detail-panel {
        margin-left: -16px;
        margin-right: -16px;
        padding: 18px 16px;
    }

    .reader-nav {
        gap: 5px;
    }

    .secondary-button {
        padding: 9px 10px;
        font-size: 9px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
