@font-face {
    font-family: 'Kai';
    src: url('/assets/fonts/kaiu.ttf') format('truetype');
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: 'Kai', 'DFKai-SB', serif;
    color: #333;
}

/* ==================== Banner 橫幅區域 ==================== */
.banner-container {
    position: relative;
    width: 100%;
    max-width: 100vw;
}

.banner-container a {
    text-decoration: none;
    color: white;
}

.banner {
    width: 100%;
    display: block;
    margin: 0 auto;
}

.vertical-text-large {
    position: absolute;
    top: 20px;
    left: 20px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 2rem;
    color: white;
    font-weight: bold;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.vertical-text-small {
    position: absolute;
    top: 80px;
    left: 80px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 1.2rem;
    color: #fefefe;
    font-weight: normal;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

/* ====================================
   🎵 Spotify 專輯連結樣式
   ==================================== */

/* 桌面版 Spotify 連結 */
.spotify-link {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: rgba(30, 215, 96, 0.95);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(30, 215, 96, 0.4);
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.spotify-link:hover {
    background: rgba(30, 215, 96, 1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 215, 96, 0.6);
}

.spotify-link:active {
    transform: translateY(0) scale(0.98);
}

.spotify-icon {
    font-size: 20px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.spotify-text {
    font-family: 'Kai', 'DFKai-SB', sans-serif;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ====================================
   深色模式
   ==================================== */

.dark-mode .spotify-link {
    background: rgba(30, 215, 96, 0.9);
    box-shadow: 0 4px 12px rgba(30, 215, 96, 0.5);
}

.dark-mode .spotify-link:hover {
    background: rgba(30, 215, 96, 1);
    box-shadow: 0 6px 16px rgba(30, 215, 96, 0.7);
}

/* ====================================
   📱 手機響應式
   ==================================== */

/* 平板 */
@media screen and (max-width: 1024px) {
    .spotify-link {
        bottom: 16px;
        right: 16px;
        padding: 9px 16px;
        font-size: 15px;
    }

    .spotify-icon {
        font-size: 18px;
    }
}

/* 手機 */
@media screen and (max-width: 768px) {
    .spotify-link {
        bottom: 12px;
        right: 12px;
        padding: 8px 14px;
        font-size: 13px;
        border-radius: 20px;
        gap: 6px;
    }

    .spotify-icon {
        font-size: 16px;
    }

    .spotify-text {
        font-size: 13px;
    }
}

/* 小螢幕手機 */
@media screen and (max-width: 480px) {
    .spotify-link {
        bottom: 10px;
        right: 10px;
        padding: 6px 12px;
        font-size: 12px;
        border-radius: 18px;
        gap: 5px;
    }

    .spotify-icon {
        font-size: 14px;
    }

    .spotify-text {
        font-size: 12px;
    }
}

/* 超小螢幕 - 只顯示圖標 */
@media screen and (max-width: 360px) {
    .spotify-link {
        padding: 8px;
        gap: 0;
    }

    .spotify-text {
        display: none;
    }

    .spotify-icon {
        font-size: 20px;
    }
}

/* 橫屏模式 */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .spotify-link {
        bottom: 8px;
        right: 8px;
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* 觸控優化 */
@media (hover: none) and (pointer: coarse) {
    .spotify-link {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
        min-height: 44px;
        /* Apple HIG 最小觸控區域 */
    }

    .spotify-link:active {
        transform: scale(0.95);
        background: rgba(30, 215, 96, 1);
    }
}

/* 高解析度螢幕優化 */
@media screen and (min-resolution: 2dppx) {
    .spotify-link {
        box-shadow: 0 4px 16px rgba(30, 215, 96, 0.5);
    }
}

/* 無障礙支援 */
@media (prefers-reduced-motion: reduce) {
    .spotify-link {
        transition: none;
    }

    .spotify-icon {
        animation: none;
    }
}

/* Focus 狀態（鍵盤導航） */
.spotify-link:focus {
    outline: 2px solid rgba(30, 215, 96, 1);
    outline-offset: 2px;
}

.spotify-link:focus:not(:focus-visible) {
    outline: none;
}

/* ==================== 目錄 TOC ==================== */
.toc {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background-color: rgba(57, 25, 42, 0.3);
    padding: 40px;
    border: 1px solid #ff69b4;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 999;
}

.toc.collapsed {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 40px;
    max-height: 60px !important;
    min-height: 0;
    box-shadow: none;
    background-color: rgba(57, 25, 42, 0.18);
    border: 1px solid #ff69b4;
    border-radius: 10px;
}

.toc-action-group {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.toc.collapsed .toc-grid {
    display: none !important;
}

.toc.collapsed #current-chapter {
    position: static;
    background: #fff;
    color: #333;
    border: none;
    padding: 8px 8px;
    margin-left: 10px;
    font-size: 1rem;
    box-shadow: none;
}

.toc-toggle-btn {
    background: #d90076;
    color: white;
    border: none;
    border-radius: 10px;
    font-family: 'Kai', 'DFKai-SB', Arial, Helvetica, sans-serif;
    font-size: 16px;
    padding: 5px 10px;
    cursor: pointer;
    margin-bottom: 10px;
    display: inline-flex;
    align-items: center;
}

#toggleDarkBtn {
    background: #222;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: 'Kai', 'DFKai-SB', Arial, Helvetica, sans-serif;
    font-size: 16px;
    padding: 5px 10px;
    cursor: pointer;
    margin-left: 10px;
    margin-bottom: 10px;
    transition: background 0.2s, color 0.2s;
    display: inline-flex;
    align-items: center;
}

.toc-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 20px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    max-height: 1000px;
}

.toc-grid.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border: none;
}

.toc-item {
    text-align: center;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 10px;
    background-color: #f9f9f9;
}

.toc-chapter {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #ff69b4;
}

.toc-part {
    font-size: 18px;
    display: block;
    color: #666;
    text-decoration: none;
}

.chapter-anchor {
    scroll-margin-top: 150px;
}

.toc-part:hover {
    color: #ff69b4;
}

.toc #current-chapter {
    position: absolute;
    bottom: 10px;
    right: 36px;
    background: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: bold;
    white-space: nowrap;
}

/* ==================== 閱讀區域 ==================== */
.reading-area {
    max-width: 1600px;
    margin: 20px auto;
    padding: 40px;
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.chapter-title {
    font-size: 32px;
    text-align: center;
    margin: 40px 0 20px;
    color: #ff69b4;
}

.part-title {
    font-size: 24px;
    margin: 30px 0 15px;
    color: #333;
}

.content p {
    font-size: 20px;
    line-height: 1.8;
    margin-bottom: 20px;
    text-align: justify;
}

hr {
    border: none;
    border-top: 4px dotted #ff69b4;
    height: 0;
    margin: 20px 0;
    box-shadow: 0 2px 5px rgba(255, 105, 180, 0.3);
    position: relative;
    animation: wiggle 2s infinite ease-in-out;
}

@keyframes wiggle {

    0%,
    100% {
        transform: translateX(0);
    }

    50% {
        transform: translateX(5px);
    }
}

audio {
    margin-left: 10px;
    vertical-align: middle;
}

/* ==================== 播放按鈕 ==================== */
.banner-play-button {
    width: 30px;
    height: 30px;
    background: #ffffff;
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: inline-block;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}

.banner-play-button:hover,
.banner-play-button:focus {
    background: #ff69b4;
    outline: none;
}

.play-icon {
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 11px solid #ff69b4;
    margin-left: 2px;
    display: inline-block;
}

.play-icon:hover {
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 11px solid #ffffff;
    margin-left: 2px;
}

/* ==================== Modal 音樂播放器 ==================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    padding-top: 60px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    text-align: center;
    position: relative;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#audioPlayer {
    width: 90%;
    margin-bottom: 20px;
}

.lyrics-div {
    background-color: #f9f9f9;
    padding: 10px;
    border-radius: 5px;
    max-height: 300px;
    overflow-y: auto;
    font-size: 18px;
    line-height: 1.2;
    color: #333;
}

.modal-content.mini-player {
    width: 380px;
    max-width: 90vw;
    height: auto;
    max-height: none;
    position: fixed;
    right: 24px;
    bottom: 24px;
    top: auto;
    left: auto;
    margin: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    border-radius: 20px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .42);
    transition: all 0.2s;
    background: #23223a;
    z-index: 1010;
    position: relative;
}

.mini-player .lyrics-div {
    display: none;
}

.mini-player .close {
    position: absolute;
    top: 8px;
    right: 12px;
    float: none;
    margin: 0;
}

.mini-player .close:hover,
.mini-player .close:focus {
    color: #ff69b4;
}

.mini-player .restore-btn {
    position: absolute;
    top: 16px;
    left: 12px;
    float: none;
    margin: 0;
    z-index: 1011;
}

.modal.mini-bg-hide {
    background: transparent !important;
    pointer-events: none;
}

.modal.mini-bg-hide .modal-content {
    pointer-events: auto;
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1010;
}

.restore-btn {
    background: none;
    border: none;
    color: #ff69b4;
    font-size: 22px;
    cursor: pointer;
    margin: 0 10px 0 0;
    padding: 0;
    float: left;
    transition: color 0.2s;
}

.restore-btn:hover {
    color: #ff1493;
}

.mini-player .player-container {
    margin-top: 32px;
    width: 100%;
}

.mini-player audio {
    width: 100% !important;
    margin: 0 !important;
}

.mini-player #spotifyContainer {
    width: 100% !important;
    margin-top: 10px;
}

/* ==================== Blockquote 引用區塊 ==================== */
blockquote {
    background: repeating-linear-gradient(-8deg, #faf3e6 0px, #f2e6c3 45px, #f6eedc 80px),
        radial-gradient(circle, rgba(255, 255, 230, 0.26) 60%, rgba(0, 0, 0, 0) 100%);
    color: #5a4324;
    padding: 2em 2em 1.8em 2.6em;
    margin: 32px 0;
    border-left: 15px solid #ccb97e;
    border-radius: 16px 36px 19px 32px / 23px 18px 34px 35px;
    box-shadow: 0 5px 24px 0 rgba(64, 40, 9, 0.13), 0 0 0 2px #d3c9aa inset;
    font-family: 'Kai', 'DFKai-SB', 'serif';
    font-size: 1.15em;
    line-height: 1.85;
    position: relative;
    overflow: auto;
}

blockquote::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('https://www.transparenttextures.com/patterns/old-mathematics.png');
    opacity: 0.32;
    pointer-events: none;
    mix-blend-mode: multiply;
}

/* ==================== 註解 Note ==================== */
.note {
    position: relative;
    display: inline-block;
    cursor: pointer;
    color: #ff69b4;
    font-weight: bold;
    font-size: 0.9em;
    margin-left: 4px;
}

.note::after {
    content: "✿";
    font-size: 0.9em;
    vertical-align: super;
}

.note-popup {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #fff8fb;
    color: #333;
    font-size: 1rem;
    line-height: 1.4;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #ff69b4;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    width: 240px;
    text-align: left;
    z-index: 999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.note-popup::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px;
    border-style: solid;
    border-color: #fff8fb transparent transparent transparent;
}

.note:hover .note-popup {
    visibility: visible;
    opacity: 1;
}

/* ==================== 副標題 Subheading ==================== */
.subheading {
    position: relative;
    display: inline-block;
    font-size: 22px;
    font-weight: bold;
    color: #ff69b4;
    margin: 40px 0 20px;
    padding: 8px 20px 8px 28px;
    background: rgba(255, 240, 250, 0.7);
    border-left: 6px solid #ff69b4;
    border-radius: 8px;
    box-shadow: 0 3px 8px rgba(255, 105, 180, 0.25);
    transition: all 0.3s ease;
    letter-spacing: 1px;
}

.subheading:hover {
    background: rgba(255, 240, 250, 0.9);
    box-shadow: 0 4px 12px rgba(255, 105, 180, 0.4);
    transform: translateY(-2px);
}

/* ====================================
   Dark Mode 夜間模式
   ==================================== */

body.dark-mode {
    background-image: none;
    background-color: #181824;
    color: #d0d0dc;
}

.dark-mode .banner-container a {
    color: #ffb6ef;
}

.dark-mode .banner {
    filter: brightness(0.8) contrast(1.2);
}

.dark-mode .vertical-text-large,
.dark-mode .vertical-text-small {
    color: #ffb6ef;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.7);
}

.dark-mode .toc {
    background-color: rgba(47, 20, 34, 0.7);
    border-color: #ff69b4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.dark-mode .toc-toggle-btn {
    background: #d90076;
    color: #fff;
}

.dark-mode .toc-item {
    background-color: #23223a;
    border-color: #555;
    color: #f2b4ef;
}

.dark-mode .toc-chapter,
.dark-mode .toc-part:hover {
    color: #ff69b4;
}

.dark-mode .toc-part {
    color: #bbb;
}

.dark-mode .toc #current-chapter {
    background: #333;
    color: #ffd7ef;
    border: none;
}

.dark-mode .reading-area {
    background-color: #23223a;
    color: #dad3ef;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.32);
}

.dark-mode .chapter-title {
    color: #ff69b4;
}

.dark-mode .part-title {
    color: #f0cfff;
}

.dark-mode .content p {
    color: #dad3ef;
}

.dark-mode hr {
    border-top: 4px dotted #ff69b4;
    box-shadow: 0 2px 6px rgba(255, 105, 180, 0.35);
}

.dark-mode audio {
    background: #23223a;
    color: #fff;
}

.dark-mode .banner-play-button {
    background: #48475e;
    color: #ffd7ef;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.3);
}

.dark-mode .banner-play-button:hover,
.dark-mode .banner-play-button:focus {
    background: #ff69b4;
    color: #48475e;
}

.dark-mode .modal {
    background-color: rgba(0, 0, 0, 0.8);
}

.dark-mode .modal-content {
    background-color: #23223a;
    border-color: #ff69b4;
    color: #e7c4fc;
}

.dark-mode .close {
    color: #d7aaff;
}

.dark-mode .close:hover,
.dark-mode .close:focus {
    color: #ff69b4;
}

.dark-mode .lyrics-div {
    background-color: #1e1b29;
    color: #f3eaff;
    border: 1px solid #ff69b4;
}

.dark-mode .play-icon {
    border-left: 11px solid #ff69b4;
}

.dark-mode .play-icon:hover {
    border-left: 11px solid #fff;
}

.dark-mode .note-popup {
    background-color: #23223a;
    color: #f3eaff;
    border: 1px solid #ff69b4;
    box-shadow: 0 4px 16px rgba(255, 105, 180, 0.3);
}

.dark-mode .note-popup::after {
    border-color: #23223a transparent transparent transparent;
}

.dark-mode .subheading {
    background: rgba(50, 30, 55, 0.7);
    color: #ffb6ef;
    border-left-color: #ff69b4;
    box-shadow: 0 4px 10px rgba(255, 105, 180, 0.25);
}

body.dark-mode #toggleDarkBtn {
    background: #fff;
    color: #23223a;
}

body.dark-mode #toggleDarkBtn:hover,
body.dark-mode #toggleDarkBtn:focus {
    background: #fff;
    color: #23223a;
}

body.dark-mode blockquote {
    background: #292217;
    color: #d9cdb5;
    border-left: 15px solid #907c51;
    box-shadow: 0 5px 24px 0 rgba(0, 0, 0, 0.26);
}

/* ====================================
   📱 手機響應式設計 (Mobile Responsive)
   ==================================== */

/* 平板設備 (768px - 1024px) */
@media screen and (max-width: 1024px) {
    .toc-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        padding: 0 15px;
    }

    .reading-area {
        padding: 30px 25px;
        margin: 15px;
    }

    .chapter-title {
        font-size: 28px;
    }

    .part-title {
        font-size: 22px;
    }

    .content p {
        font-size: 18px;
    }
}

/* 手機設備 (最大寬度 768px) */
@media screen and (max-width: 768px) {

    /* 防止水平滾動 */
    body {
        overflow-x: hidden;
        width: 100%;
    }

    /* Banner 橫幅調整 */
    .banner-container {
        overflow: hidden;
    }

    .vertical-text-large {
        font-size: 1.8rem;
        top: 50px;
        left: 10px;
    }

    .vertical-text-small {
        font-size: 0.8rem;
        top: 70px;
        left: 70px;
    }

    /* 目錄區域 */
    .toc {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        z-index: 999;
        transition: all 0.3s ease;
    }

    /* 目錄收起時：只顯示底部浮動按鈕 */
    .toc.collapsed {
        padding: 0;
        background: transparent;
        border: none;
    }

    /* 頂部控制列（收起時隱藏） */
    .toc-action-group {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
        background: linear-gradient(135deg, #ff69b4 0%, #ff1493 100%);
        color: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(255, 105, 180, 0.3);
    }

    .toc.collapsed .toc-action-group {
        display: none;
    }

    /* 目錄展開時的背景遮罩 */
    .toc::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        pointer-events: none;
        z-index: -1;
    }

    .toc:not(.collapsed)::before {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* 浮動目錄按鈕（收起時顯示）*/
    .toc-float-button {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
        background: linear-gradient(135deg, #ff69b4 0%, #ff1493 100%);
        border-radius: 50%;
        box-shadow: 0 4px 20px rgba(255, 105, 180, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 1000;
        transition: all 0.3s ease;
        border: none;
        color: white;
        font-size: 24px;
    }

    .toc-float-button:active {
        transform: scale(0.95);
    }

    .toc:not(.collapsed) .toc-float-button {
        display: none;
    }

    /* 按鈕組 */
    .toc-action-buttons {
        display: flex;
        gap: 10px;
    }

    .toc-toggle-btn,
    #toggleDarkBtn {
        background: rgba(255, 255, 255, 0.2);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 20px;
        font-size: 14px;
        padding: 8px 16px;
        margin: 0;
        backdrop-filter: blur(10px);
        white-space: nowrap;
    }

    .toc-toggle-btn:active,
    #toggleDarkBtn:active {
        background: rgba(255, 255, 255, 0.3);
    }

    .toc-action-group span {
        display: none;
        /* 隱藏提示文字 */
    }

    /* 目錄網格容器 - 全新手機設計 */
    .toc-grid {
        display: block;
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        background: white;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
        -webkit-overflow-scrolling: touch;
    }

    .toc.collapsed .toc-grid {
        display: none;
    }

    /* 章節容器 - 手風琴式設計 */
    .toc-item {
        padding: 0;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        border-radius: 0;
        background: white;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .toc-item:last-child {
        border-bottom: none;
    }

    /* 章節標題 - 可點擊展開/收起 */
    .toc-chapter {
        font-size: 18px;
        font-weight: bold;
        color: #ff69b4;
        margin: 0;
        padding: 18px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
        background: white;
        transition: background 0.2s;
        position: relative;
        border: none;
        width: 100%;
        text-align: left;
    }

    .toc-chapter:active {
        background: #fff5f9;
    }

    /* 章節展開指示器 */
    .toc-chapter::after {
        content: '▼';
        font-size: 12px;
        color: #ff69b4;
        transition: transform 0.3s;
        margin-left: auto;
        padding-left: 10px;
    }

    .toc-item.expanded .toc-chapter::after {
        transform: rotate(180deg);
    }

    /* 段落列表容器 */
    .toc-parts-container {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        background: #fafafa;
    }

    .toc-item.expanded .toc-parts-container {
        max-height: 1000px;
        /* 足夠大以容納所有段落 */
    }

    /* 段落連結 */
    .toc-part {
        font-size: 16px;
        display: block;
        color: #666;
        text-decoration: none;
        padding: 14px 20px 14px 40px;
        border-bottom: 1px solid #f0f0f0;
        transition: all 0.2s;
        position: relative;
    }

    .toc-part::before {
        content: '•';
        position: absolute;
        left: 25px;
        color: #ff69b4;
        font-size: 20px;
    }

    .toc-part:active {
        background: white;
        color: #ff69b4;
    }

    .toc-part:last-child {
        border-bottom: none;
    }

    /* 當前章節指示器 - 改為小標籤 */
    .toc #current-chapter {
        position: fixed;
        bottom: 90px;
        right: 20px;
        background: rgba(255, 105, 180, 0.95);
        color: white;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: bold;
        box-shadow: 0 2px 10px rgba(255, 105, 180, 0.3);
        max-width: calc(100% - 100px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        z-index: 998;
        opacity: 0.9;
        backdrop-filter: blur(10px);
    }

    .toc.collapsed #current-chapter {
        display: block;
    }

    .toc:not(.collapsed) #current-chapter {
        display: none;
    }

    /* 滾動條美化 */
    .toc-grid::-webkit-scrollbar {
        width: 4px;
    }

    .toc-grid::-webkit-scrollbar-track {
        background: #f0f0f0;
    }

    .toc-grid::-webkit-scrollbar-thumb {
        background: #ff69b4;
        border-radius: 2px;
    }

    .toc-grid::-webkit-scrollbar-thumb:hover {
        background: #ff1493;
    }

    /* 閱讀區域 */
    .reading-area {
        margin: 10px 5px;
        padding: 20px 12px;
        border-radius: 12px;
        width: calc(100% - 10px);
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .chapter-title {
        font-size: 24px;
        margin: 30px 0 15px;
    }

    .part-title {
        font-size: 20px;
        margin: 25px 0 12px;
    }

    .chapter-anchor {
        scroll-margin-top: 100px;
    }

    /* 內容段落 */
    .content p {
        font-size: 17px;
        line-height: 1.75;
        margin-bottom: 16px;
        text-align: justify;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }

    /* 副標題 */
    .subheading {
        font-size: 19px;
        padding: 6px 15px 6px 20px;
        margin: 30px 0 15px;
    }

    /* 引用區塊 */
    blockquote {
        padding: 1.5em 1.2em 1.3em 1.8em;
        margin: 24px 0;
        font-size: 1.05em;
        border-left: 10px solid #ccb97e;
        width: 100%;
        box-sizing: border-box;
        overflow-x: auto;
    }

    /* 註解彈出框 */
    .note-popup {
        width: 200px;
        font-size: 0.9rem;
        padding: 8px 12px;
    }

    /* 播放按鈕 */
    .banner-play-button {
        width: 28px;
        height: 28px;
    }

    .play-icon {
        border-top: 6px solid transparent;
        border-bottom: 6px solid transparent;
        border-left: 10px solid #ff69b4;
    }

    /* Modal 音樂播放器 */
    .modal {
        padding-top: 20px;
    }

    .modal-content {
        width: 92%;
        max-width: none;
        margin: 10% auto;
        padding: 15px;
    }

    #audioPlayer {
        width: 100%;
    }

    .lyrics-div {
        max-height: 250px;
        font-size: 16px;
        padding: 8px;
    }

    .close {
        font-size: 24px;
    }

    /* Mini Player 調整 */
    .modal-content.mini-player {
        width: calc(100% - 20px);
        max-width: 350px;
        right: 10px;
        bottom: 10px;
        padding: 10px 15px;
        height: 150px;
    }

    .restore-btn {
        font-size: 18px;
        margin-right: 8px;
        margin-left: 5px;
    }

    .mini-player .close {
        font-size: 20px;
        margin-left: 5px;
    }

    /* 分隔線動畫調整 */
    hr {
        border-top: 3px dotted #ff69b4;
        margin: 15px 0;
    }

    @keyframes wiggle {

        0%,
        100% {
            transform: translateX(0);
        }

        50% {
            transform: translateX(3px);
        }
    }
}

/* 超小螢幕手機 (最大寬度 480px) */
@media screen and (max-width: 480px) {

    body {
        overflow-x: hidden;
    }

    .vertical-text-large {
        font-size: 1.6rem;
        top: 70px;
        left: 8px;
    }

    .vertical-text-small {
        font-size: 0.8rem;
        top: 280px;
        left: 24px;
    }

    .toc {
        padding: 15px 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .toc-grid {
        padding: 0 3px;
    }

    .toc-action-group span {
        font-size: 0.75rem;
    }

    .reading-area {
        margin: 8px 4px;
        padding: 15px 10px;
        width: calc(100% - 8px);
        box-sizing: border-box;
    }

    .chapter-title {
        font-size: 22px;
        margin: 25px 0 12px;
    }

    .part-title {
        font-size: 18px;
        margin: 20px 0 10px;
    }

    .content p {
        font-size: 16px;
        line-height: 1.7;
        margin-bottom: 14px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .subheading {
        font-size: 17px;
        padding: 5px 12px 5px 16px;
        width: calc(100% - 28px);
        box-sizing: border-box;
    }

    blockquote {
        padding: 1.2em 1em 1em 1.5em;
        margin: 20px 0;
        font-size: 1em;
        border-left: 8px solid #ccb97e;
        width: 100%;
        box-sizing: border-box;
    }

    .note-popup {
        width: 180px;
        font-size: 0.85rem;
    }

    .modal-content.mini-player {
        width: calc(100% - 16px);
        right: 8px;
        bottom: 8px;
        padding: 8px 12px;
        height: 150px;
    }

    .lyrics-div {
        font-size: 15px;
    }
}

/* 橫向模式優化 (手機橫屏) */
@media screen and (max-width: 768px) and (orientation: landscape) {

    .toc-grid {
        grid-template-columns: repeat(2, 1fr);
        max-height: none !important;
        /* 橫屏也移除高度限制 */
    }

    .modal-content {
        margin: 5% auto;
    }

    .lyrics-div {
        max-height: 180px;
    }

    .chapter-anchor {
        scroll-margin-top: 80px;
    }
}

/* 觸控設備優化 */
@media (hover: none) and (pointer: coarse) {

    /* 增加可點擊區域 */
    .toc-part {
        padding: 10px 5px;
        margin: 5px 0;
    }

    .banner-play-button {
        width: 36px;
        height: 36px;
    }

    .play-icon {
        border-top: 8px solid transparent;
        border-bottom: 8px solid transparent;
        border-left: 12px solid #ff69b4;
    }

    .toc-toggle-btn,
    #toggleDarkBtn {
        padding: 10px 15px;
        min-height: 44px;
    }

    /* 註解改為點擊顯示而非 hover */
    .note-popup {
        visibility: visible;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .note.active .note-popup {
        opacity: 1;
        pointer-events: auto;
    }
}

/* 高解析度螢幕優化 */
@media screen and (min-resolution: 2dppx) {
    .banner {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* 深色模式下的手機優化 */
@media screen and (max-width: 768px) {
    body.dark-mode .toc {
        background-color: rgba(47, 20, 34, 0.85);
    }

    body.dark-mode .toc-action-group {
        background: linear-gradient(135deg, #d90076 0%, #c1006a 100%);
    }

    body.dark-mode .toc-grid {
        background: #23223a;
    }

    body.dark-mode .toc-item {
        background: #23223a;
        border-bottom-color: #3a3950;
    }

    body.dark-mode .toc-chapter {
        background: #23223a;
        color: #ff69b4;
    }

    body.dark-mode .toc-chapter:active {
        background: #2a2940;
    }

    body.dark-mode .toc-parts-container {
        background: #1a1928;
    }

    body.dark-mode .toc-part {
        color: #bbb;
        border-bottom-color: #3a3950;
    }

    body.dark-mode .toc-part:active {
        background: #23223a;
        color: #ff69b4;
    }

    body.dark-mode #current-chapter {
        background: rgba(217, 0, 118, 0.95);
    }

    body.dark-mode .reading-area {
        background-color: #1a1928;
    }

    body.dark-mode .modal-content {
        background-color: #1a1928;
    }
}

/* 超小螢幕優化 */
@media screen and (max-width: 480px) {
    .toc-float-button {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
        font-size: 22px;
    }

    .toc #current-chapter {
        bottom: 82px;
        right: 16px;
        font-size: 11px;
        padding: 6px 12px;
    }

    .toc-chapter {
        font-size: 16px;
        padding: 16px 16px;
    }

    .toc-part {
        font-size: 15px;
        padding: 12px 16px 12px 36px;
    }

    .toc-part::before {
        left: 20px;
    }

    .toc-action-buttons {
        gap: 8px;
    }

    .toc-toggle-btn,
    #toggleDarkBtn {
        font-size: 13px;
        padding: 7px 14px;
    }
}

/* 橫屏模式 */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .toc-grid {
        max-height: calc(100vh - 150px);
    }

    .toc-action-group {
        padding: 12px 20px;
    }
}

/* 觸控反饋優化 */
@media (hover: none) and (pointer: coarse) {

    .toc-chapter,
    .toc-part,
    .toc-toggle-btn,
    #toggleDarkBtn,
    .toc-float-button {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }
}

/* Print 列印樣式 */
@media print {

    .toc,
    .banner-play-button,
    .modal,
    #toggleDarkBtn,
    #toggleTocBtn {
        display: none !important;
    }

    .reading-area {
        box-shadow: none;
        max-width: 100%;
        padding: 20px;
    }

    .content p {
        font-size: 12pt;
        line-height: 1.6;
    }

    body {
        background: white;
        color: black;
    }
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}