/* ============================================================
   8个8阅读网 · 现代化深色主题
   ------------------------------------------------------------
   设计要点:
   - 深色基底 + 柔和靛蓝强调色,阅读区使用暖色衬线字
   - 卡片化界面,圆角 + 微妙阴影 + 悬停反馈
   - Firefox 兼容:scrollbar-color / background-clip: text 等
     均已提供标准写法,WebKit 私有写法仅作前缀补充
   ============================================================ */

/* ---------- 主题变量 ---------- */
:root {
    color-scheme: dark;

    /* 背景与表面 */
    --bg-0: #0b0e14;
    --bg-1: #10141c;
    --surface-1: #161b26;
    --surface-2: #1d2431;
    --surface-3: #252d3d;
    --border: #262e3f;
    --border-strong: #333d52;

    /* 文字 */
    --text-1: #e8ebf2;
    --text-2: #a8b0c2;
    --text-3: #6f788c;

    /* 强调色:柔和靛蓝 + 暖琥珀(阅读) */
    --accent: #7c9cf5;
    --accent-strong: #9db4ff;
    --accent-deep: #5b7ce8;
    --accent-soft: rgba(124, 156, 245, 0.14);
    --accent-glow: rgba(124, 156, 245, 0.35);
    --amber: #f0b45f;
    --danger: #f87171;
    --success: #4ade80;

    /* 阴影与圆角 */
    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.45);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* 字体 */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
    --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC",
        STSong, "SimSun", Georgia, "Times New Roman", serif;
}

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

html {
    scroll-behavior: smooth;
    /* Firefox 滚动条(WebKit 版见下方 ::-webkit-scrollbar) */
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) var(--bg-1);
}

body {
    font-family: var(--font-sans);
    color: var(--text-1);
    line-height: 1.6;
    min-height: 100vh;
    background:
        radial-gradient(1100px 560px at 88% -12%, rgba(124, 156, 245, 0.08), transparent 60%),
        radial-gradient(900px 520px at -12% 112%, rgba(240, 180, 95, 0.05), transparent 55%),
        var(--bg-1);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: var(--accent-glow);
    color: #fff;
}

/* 键盘导航焦点(替代 outline:none 无痕样式) */
:focus-visible {
    outline: 2px solid var(--accent-strong);
    outline-offset: 2px;
}

/* ---------- WebKit 滚动条 ---------- */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: var(--bg-1);
}
::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 5px;
    border: 2px solid var(--bg-1);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

.container {
    min-height: 100vh;
    position: relative;
}

/* ============================================================
   侧边栏
   ============================================================ */
.sidebar {
    width: 240px;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    color: var(--text-1);
    padding: 24px 14px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1001;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 7, 11, 0.62);
    z-index: 1000;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show {
    display: block;
}

.logo {
    font-size: 22px;
    font-weight: 800;
    text-align: center;
    margin: 10px 0 38px;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--accent-strong), var(--amber));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-2);
    text-decoration: none;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    transition: background-color 0.25s, color 0.25s, transform 0.15s;
}

.nav-link::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.45;
    transition: opacity 0.25s, box-shadow 0.25s;
    flex-shrink: 0;
}

.nav-link:hover {
    background: var(--surface-2);
    color: var(--text-1);
}
.nav-link:active {
    transform: scale(0.98);
}
.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 600;
}
.nav-link.active::before {
    opacity: 1;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
}

/* ============================================================
   汉堡按钮
   ============================================================ */
.sidebar-toggle {
    position: fixed;
    top: 16px;
    z-index: 1002;
    width: 44px;
    height: 44px;
    background: var(--surface-2);
    color: var(--text-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    box-shadow: var(--shadow-1);
    transition: left 0.3s ease, background-color 0.25s, border-color 0.25s,
        color 0.25s, transform 0.15s, box-shadow 0.25s;
}

.sidebar-toggle:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    color: var(--accent-strong);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.sidebar-toggle:active {
    transform: scale(0.94);
}

/* ============================================================
   正文区域
   ============================================================ */
.main-content {
    min-height: 100vh;
    padding: 64px 40px 88px;
    transition: margin-left 0.3s ease;
}

/* 内容列宽上限,避免超宽屏幕下排版过散 */
.main-content > .page,
.main-content > #chapter-list,
.main-content > #read-content {
    max-width: 1180px;
    margin: 0 auto;
}
.main-content > #read-content {
    max-width: 780px;
}

/* ---------- 页面切换 ---------- */
.page {
    display: none;
}
.page.active {
    display: block;
    animation: pageIn 0.35s ease;
}

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

/* ---------- 搜索栏 ---------- */
#search-bar {
    position: relative;
    z-index: 100;
    margin-bottom: 32px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

#search-input {
    flex: 1;
    min-width: 200px;
    padding: 12px 18px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-1);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s, background-color 0.25s;
}

#search-input::placeholder {
    color: var(--text-3);
}
#search-input:hover {
    border-color: var(--border-strong);
}
#search-input:focus {
    border-color: var(--accent);
    background: var(--surface-2);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

#search-btn {
    padding: 12px 30px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(124, 156, 245, 0.32);
    transition: transform 0.15s, box-shadow 0.25s, filter 0.25s;
}

#search-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(124, 156, 245, 0.45);
}
#search-btn:active {
    transform: translateY(0) scale(0.97);
}

/* ---------- 通用提示文本 ---------- */
.empty-hint {
    text-align: center;
    color: var(--text-3);
    font-size: 15px;
    padding: 40px 0;
}

/* ============================================================
   图书列表
   ============================================================ */
.book-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.book-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    cursor: pointer;
    transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
}

.book-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: var(--shadow-2), 0 0 0 1px var(--accent-soft);
}
.book-card:active {
    transform: translateY(-1px) scale(0.99);
}

.book-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-1);
    transition: color 0.25s;
}
.book-card:hover .book-title {
    color: var(--accent-strong);
}

.book-author {
    color: var(--text-2);
    font-size: 14px;
    margin-bottom: 6px;
}

.book-category {
    display: inline-block;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 12.5px;
    padding: 3px 11px;
    border-radius: 999px;
    margin-bottom: 12px;
}

.book-description {
    color: var(--text-3);
    font-size: 14px;
    line-height: 1.7;
}

/* ============================================================
   分类列表
   ============================================================ */
.category-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.category-item {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    cursor: pointer;
    transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
}

.category-item:hover {
    transform: translateY(-3px);
    border-color: var(--amber);
    box-shadow: var(--shadow-2);
}
.category-item:active {
    transform: translateY(-1px) scale(0.99);
}

.category-item h3 {
    color: var(--text-1);
    font-size: 17px;
    margin-bottom: 8px;
}

.category-item p {
    color: var(--text-3);
    font-size: 14px;
    line-height: 1.6;
}

/* ============================================================
   章节列表
   ============================================================ */
#chapter-list > h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    color: var(--text-1);
    margin-bottom: 6px;
}
#chapter-list > .book-author {
    color: var(--text-2);
    margin-bottom: 26px;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chapter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 16px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    cursor: pointer;
    transition: background-color 0.25s, border-color 0.25s,
        transform 0.2s, box-shadow 0.25s;
}

.chapter-item:hover {
    background: var(--surface-2);
    border-color: var(--accent);
    transform: translateX(4px);
    box-shadow: var(--shadow-2);
}
.chapter-item:active {
    transform: translateX(4px) scale(0.99);
}

.chapter-item h3 {
    color: var(--text-1);
    font-size: 16.5px;
    font-weight: 600;
    margin-bottom: 3px;
}

.chapter-num {
    flex-shrink: 0;
    color: var(--text-3);
    font-size: 13px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
    transition: color 0.25s, background-color 0.25s, border-color 0.25s;
}

.chapter-item:hover .chapter-num {
    color: var(--accent-strong);
    background: var(--accent-soft);
    border-color: var(--accent);
}

/* ============================================================
   阅读页
   ============================================================ */
#read-content {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 56px 56px;
    box-shadow: var(--shadow-1);
}

#read-content h2 {
    font-family: var(--font-serif);
    font-size: 26px;
    color: var(--text-1);
    text-align: center;
    letter-spacing: 2px;
    margin-bottom: 28px;
}

.read-text {
    font-family: var(--font-serif);
    font-size: 18px;
    line-height: 2.05;
    letter-spacing: 0.02em;
    color: #d5dae5;
    word-break: break-word;
}

.chapter-nav {
    margin-top: 40px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.chapter-nav a {
    display: inline-block;
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 500;
    padding: 11px 24px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
    transition: background-color 0.25s, color 0.25s, transform 0.15s,
        box-shadow 0.25s;
}

.chapter-nav a:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}
.chapter-nav a:active {
    transform: translateY(0) scale(0.97);
}

/* ============================================================
   下载按钮
   ============================================================ */
#downloadBtn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    border: none;
    padding: 12px 22px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(124, 156, 245, 0.38);
    transition: transform 0.2s, box-shadow 0.25s, filter 0.25s;
}

#downloadBtn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(124, 156, 245, 0.5);
}
#downloadBtn:active {
    transform: translateY(0) scale(0.96);
}

/* ============================================================
   看板娘(主页右下角)
   ============================================================ */
#board-girl-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 280px;
    height: 360px;
    z-index: 999;
    background: transparent;
    /* 容器不拦截点击,仅模型画布可交互 */
    pointer-events: none;
}

#board-girl-container canvas {
    cursor: pointer;
    pointer-events: auto;
}

/* ============================================================
   桌面端(>768px)
   ============================================================ */
@media (min-width: 769px) {
    .sidebar {
        transform: translateX(0);
        transition: transform 0.3s ease;
    }
    .sidebar.collapsed {
        transform: translateX(-100%);
    }
    .main-content {
        margin-left: 240px;
        padding-top: 64px;
    }
    /* 侧边栏收起时正文铺满,增加上边距避免按钮遮挡搜索框 */
    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
        padding-top: 88px;
    }
    .sidebar-toggle {
        left: 252px;
    }
    .sidebar.collapsed ~ .sidebar-toggle {
        left: 20px;
    }
}

/* ============================================================
   手机端(<=768px)
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 260px;
        box-shadow: 6px 0 30px rgba(0, 0, 0, 0.5);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
        padding: 72px 16px 24px;
    }
    .sidebar-toggle {
        left: 14px;
        top: 14px;
    }
    #search-bar {
        flex-direction: column;
    }
    #search-btn {
        width: 100%;
    }
    .book-list,
    .category-list {
        grid-template-columns: 1fr;
    }
    #read-content {
        padding: 24px 20px 32px;
    }
    #read-content h2 {
        font-size: 21px;
    }
    .read-text {
        font-size: 16.5px;
        line-height: 1.95;
    }
    .chapter-nav {
        flex-direction: column;
    }
    .chapter-nav a {
        text-align: center;
    }
    #board-girl-container {
        width: 220px;
        height: 283px;
        bottom: 10px;
        right: 10px;
    }
}

/* ============================================================
   无障碍:减弱动态效果
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
