:root {
    /* Ultra Dark Mode - Maximum Comfort */
    --bg-base: #0B0C10;
    --bg-sidebar: #121418;
    --bg-card: rgba(46, 57, 68, 0.3);
    --primary: #748D92;
    --primary-glow: rgba(116, 141, 146, 0.2);
    --accent-orange: #D19A66;
    --accent-purple: #9380B8;
    --accent-cyan: #124E66;
    --text-main: #D3D9D4;
    --text-muted: rgba(211, 217, 212, 0.55);
    --border: rgba(116, 141, 146, 0.25);
    --glass-bg: rgba(30, 38, 48, 0.65);
    --blur: 25px;
    --base-font-size: 16px;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Sophisticated hierarchical design tokens for sidebar */
    --bg-course: rgba(18, 20, 24, 0.95);
    --bg-chapter: rgba(116, 141, 146, 0.04);
    --bg-section: rgba(18, 78, 102, 0.04);

    /* Typography hierarchy */
    --font-course: 0.95rem;
    --font-chapter: 0.85rem;
    --font-section: 0.78rem;

    /* Spacing rhythm */
    --space-course: 16px;
    --space-chapter: 32px;
    --space-section: 52px;

    /* Border accents */
    --border-course: rgba(116, 141, 146, 0.2);
    --border-chapter: rgba(116, 141, 146, 0.12);
    --border-section: rgba(116, 141, 146, 0.05);

    /* Hierarchical text colors */
    --text-course: #D3D9D4;
    --text-chapter: rgba(211, 217, 212, 0.85);
    --text-section: rgba(211, 217, 212, 0.7);
}

[data-theme="light"] {
    /* 背景統一冷青色系，紫色僅作點綴 */
    --bg-base: #EAF1F1;
    --bg-sidebar: #DEEAEA;
    --bg-card: rgba(204, 222, 222, 0.35);
    --primary: #5E8A8A;
    --primary-glow: rgba(94, 138, 138, 0.12);
    --accent-orange: #B8845A;
    --accent-purple: #8E7A95;
    --accent-cyan: #4D7E7E;
    --text-main: #2A3338;
    --text-muted: #6B7578;
    --border: rgba(94, 138, 138, 0.18);
    --glass-bg: rgba(255, 255, 255, 0.55);
    --shadow-soft: 0 6px 24px rgba(40, 55, 55, 0.12);

    /* 側邊欄層級 — 同為冷青階梯 */
    --bg-course: rgba(204, 222, 222, 0.5);
    --bg-chapter: rgba(214, 229, 229, 0.4);
    --bg-section: rgba(229, 238, 238, 0.35);

    /* Typography hierarchy */
    --font-course: 0.95rem;
    --font-chapter: 0.85rem;
    --font-section: 0.78rem;

    /* Spacing rhythm */
    --space-course: 16px;
    --space-chapter: 32px;
    --space-section: 52px;

    /* Border accents */
    --border-course: rgba(94, 138, 138, 0.18);
    --border-chapter: rgba(94, 138, 138, 0.12);
    --border-section: rgba(94, 138, 138, 0.06);

    /* Hierarchical text colors */
    --text-course: #2A3338;
    --text-chapter: #4A5558;
    --text-section: #6B7578;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* removed transition: background-color 0.3s, color 0.3s, border-color 0.3s, transform 0.2s; */
}

html {
    font-size: var(--base-font-size);
}

body {
    font-family: 'JetBrains Mono', 'Space Mono', 'Noto Sans TC', monospace;
    font-size: 1rem;
    background: var(--bg-base);
    color: var(--text-main);
    overflow: hidden;
    line-height: 1.6;
    position: relative;
}

#app {
    display: flex;
    height: 100vh;
}

/* 玻璃磨砂效果 */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .glass {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(94, 138, 138, 0.2);
    box-shadow: 0 8px 32px 0 rgba(40, 55, 55, 0.1);
}

/* Sidebar */
#sidebar {
    width: 320px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
    /* removed transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), margin 0.3s ease, opacity 0.3s ease; */
    flex-shrink: 0;
    overflow: visible;
    z-index: 100;
    position: relative;
}

#sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 2px;
    height: 100%;
    background: var(--primary);
    z-index: 1;
}

#sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 4px;
    width: 1px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    z-index: 1;
}

#sidebar.collapsed {
    width: 0 !important;
    opacity: 0;
    border-right: none;
}

.sidebar-header {
    padding: 28px 24px;
    border-bottom: 2px solid var(--border);
    background: var(--bg-sidebar);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.logo {
    font-family: 'Crimson Text', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    /* removed transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
    letter-spacing: -0.02em;
}

.logo i {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.logo:hover {
    transform: scale(1.05) rotate(-1deg);
    filter: drop-shadow(0 4px 12px var(--primary-glow));
    text-shadow: 0 0 8px var(--primary-glow);
}
.search-box { position: relative; margin-top: 15px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-box input { 
    width: 100%; 
    padding: 10px 10px 10px 36px; 
    border-radius: 10px; 
    border: 1px solid var(--border); 
    background: var(--bg-base); 
    color: var(--text-main); 
    outline: none; 
    transition: all 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
    background: var(--bg-sidebar);
    box-shadow: 0 0 12px rgba(116, 141, 146, 0.1);
}

#sidebar-menu { flex: 1; overflow-y: auto; padding: 15px; }
.sidebar-chapter {
    margin-bottom: 6px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-chapter);
    border: 1px solid var(--border-chapter);
}

.chapter-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-chapter);
    padding: 11px 16px;
    background: transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    /* removed transition: all 0.2s; */
    border: 1px solid transparent;
    letter-spacing: 0.005em;
}

.chapter-title:hover {
    background: rgba(116, 141, 146, 0.1);
    color: var(--text-main);
}

.chapter-title .arrow {
    font-size: 0.7rem;
    /* removed transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
    color: var(--text-muted);
}

.sidebar-chapter.expanded .chapter-title {
    color: var(--primary);
}

.sidebar-chapter.expanded .arrow {
    transform: rotate(90deg);
    color: var(--primary);
}

.section-list {
    display: none;
    padding: 6px 0 8px 0;
    background: var(--bg-section);
    border: 1px solid var(--border-section);
    border-radius: 6px;
    margin: 2px 4px 4px 16px;
}

.sidebar-chapter.expanded .section-list {
    display: block;
}

.section-item {
    padding: 10px 16px 10px 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 1px 8px;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(51, 65, 85, 0.3);
}

.section-item::before {
    content: '◦';
    position: absolute;
    left: 16px;
    color: #94a3b8;
    font-size: 0.7rem;
    opacity: 0.8;
    top: 50%;
    transform: translateY(-50%);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.section-item:hover {
    background: rgba(116, 141, 146, 0.15);
    color: var(--text-main);
    border-left: 2px solid var(--primary);
    transform: translateX(2px);
}

.section-item:hover::before {
    color: var(--primary);
    opacity: 1;
}

.section-item.active {
    background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--bg-base) 100%);
    color: var(--text-main);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    border-left: 3px solid var(--primary);
    transform: translateX(3px);
}

/* ── 主要內容 ── */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

#top-bar {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    gap: 16px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur));
    border: none;
    border-bottom: 4px solid var(--primary);
    position: relative;
    overflow: hidden;
}

#top-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--primary-glow);
    z-index: -1;
}

#top-bar::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    animation: borderGlow 3s ease-in-out infinite alternate;
}

@keyframes borderGlow {
    0% { opacity: 0.6; transform: scaleX(1); }
    100% { opacity: 1; transform: scaleX(1.02); }
}

#top-bar .left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;        /* 允許 flex 縮小，避免撐開 top-bar */
    flex: 1;
    overflow: hidden;
}

#top-bar .left #breadcrumb-display {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

#content { flex: 1; overflow-y: auto; padding: 40px; }

/* ── Dashboard ── */
.dashboard { max-width: 1200px; margin: 0 auto; padding-bottom: 50px; }

.welcome-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 64px;
    border-radius: 16px;
    margin-bottom: 56px;
    background: var(--bg-card);
    border: 4px solid var(--primary);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.welcome-hero::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-glow);
    z-index: 0;
}

/* Removed the unnecessary decorative square element */

.hero-content { position: relative; z-index: 1; max-width: 60%; }
.badge {
    display: inline-block;
    padding: 8px 20px;
    background: var(--primary);
    color: var(--bg-base);
    border: 2px solid var(--accent-cyan);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 24px;
    box-shadow: 4px 4px 0px var(--accent-cyan);
    /* removed transition: all 0.3s; */
    position: relative;
}

.badge:hover {
    transform: translateY(-2px) rotate(-1deg);
    box-shadow: 0 0 8px var(--primary-glow);
}
.hero-content h1 {
    font-family: 'Crimson Text', serif;
    font-size: 4.2rem;
    font-weight: 600;
    margin-bottom: 20px;
    line-height: 0.95;
    letter-spacing: -0.03em;
    text-shadow: 2px 2px 0px var(--primary-glow);
}

.hero-content h1 span {
    color: var(--primary);
    text-shadow: 0 0 8px var(--primary-glow);
    position: relative;
}

.hero-content h1 span::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
    border-radius: 2px;
}
.hero-content p { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 30px; }

.hero-stats { display: flex; gap: 40px; }
.h-stat { display: flex; flex-direction: column; }
.h-stat .num { font-size: 2.2rem; font-weight: 900; color: var(--text-main); }
.h-stat .lab { font-size: 0.8rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }

.hero-visual { font-size: 6rem; color: var(--primary); opacity: 0.08; transform: rotate(-8deg); flex-shrink: 0; }

.section-label { font-size: 1.2rem; font-weight: 800; margin-bottom: 25px; display: flex; align-items: center; gap: 12px; }

.chapters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 24px;
}

.chapter-card {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 28px;
    border-radius: 12px;
    cursor: pointer;
    /* removed transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); */
    background: var(--bg-card);
    border: 3px solid var(--primary);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.chapter-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary-glow);
    /* removed transition: left 0.6s; */
}

.chapter-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    background: rgba(116, 141, 146, 0.05);
}

.chapter-card:hover::before {
    left: 100%;
}

.chapter-card:active {
    opacity: 0.8;
}

.card-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-sidebar);
    border: 3px solid var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: var(--primary);
    flex-shrink: 0;
    /* removed transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); */
    box-shadow: 4px 4px 0px var(--primary-glow);
    position: relative;
    overflow: hidden;
}

.card-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: var(--primary-glow);
    /* removed transition: all 0.4s; */
    transform: translate(-50%, -50%);
}

.chapter-card:hover .card-icon {
    background: var(--primary);
    color: var(--bg-base);
    border-color: var(--primary);
}

.chapter-card:hover .card-icon::before {
    width: 120%;
    height: 120%;
}

.card-info { flex: 1; min-width: 0; }
.card-info h3 { font-size: 1.1rem; font-weight: 800; margin-bottom: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-meta { display: flex; align-items: center; gap: 15px; }
.p-bar-bg { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.p-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; /* removed transition: width 1s ease; */ }
.p-text { font-size: 0.75rem; font-weight: 800; color: var(--text-muted); min-width: 35px; }

.card-arrow { font-size: 1rem; color: var(--text-muted); opacity: 0.7; }
.chapter-card:hover .card-arrow { opacity: 1; color: var(--primary); }

/* ── 字體調節組件 ── */
.font-controls {
    display: flex;
    align-items: center;
    background: var(--bg-sidebar);
    border: 2px solid var(--primary);
    border-radius: 8px;
    padding: 6px;
    gap: 6px;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.font-controls::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--primary-glow);
    z-index: 0;
}

#font-size-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 28px;
    text-align: center;
    user-select: none;
    text-shadow: 0 0 8px var(--primary-glow);
    position: relative;
    z-index: 1;
}

.font-controls button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.8rem;
    /* removed transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
    position: relative;
    z-index: 1;
}

.font-controls button:hover {
    background: var(--primary);
    color: var(--bg-base);
    border-color: var(--primary);
    box-shadow: 0 0 16px var(--primary-glow);
    transform: scale(1.1) rotate(-3deg);
}

.font-controls button:active {
    transform: scale(1.05) rotate(-1deg);
}

.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid var(--primary);
    background: var(--bg-card);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* removed transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.icon-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary-glow);
    /* removed transition: left 0.5s; */
}

.icon-btn:hover {
    background: rgba(116, 141, 146, 0.2);
    color: var(--primary);
    transform: translateY(-3px) rotate(5deg);
    box-shadow:
        var(--shadow-soft),
        0 0 15px rgba(116, 141, 146, 0.1);
    border-color: var(--primary);
}

.icon-btn:hover::before {
    left: 100%;
}

.icon-btn:active {
    transform: translateY(-1px) rotate(2deg);
}

/* ── 章節內容 ── */
.section-container { max-width: 900px; margin: 0 auto; }
.section-block { 
    padding: 50px; 
    margin-bottom: 40px; 
    border-radius: 32px; 
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}
.section-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; gap: 20px; }
.section-header h1 { font-size: 2.4rem; font-weight: 900; line-height: 1.2; color: var(--text-main); }

table {
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    margin: 48px 0 !important;
    background: var(--bg-card) !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    border: 3px solid var(--primary) !important;
    box-shadow: var(--shadow-soft) !important;
    position: relative;
}

table::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
}

th, td {
    padding: 14px 20px !important;
    border-bottom: 2px solid var(--border) !important;
    font-family: 'JetBrains Mono', 'Noto Sans TC', monospace;
}

th {
    background: var(--primary) !important;
    color: var(--bg-base) !important;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    border: none !important;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

td {
    font-size: 0.85rem;
    /* removed transition: all 0.2s; */
}

tr:last-child td { border-bottom: none !important; }

tr:nth-child(even) {
    background: rgba(116, 141, 146, 0.05);
}

tr:hover td {
    background: rgba(18, 78, 102, 0.15);
    color: var(--primary);
}

.section-content h2, .section-content h3 { margin: 50px 0 25px; color: var(--primary); border-left: 6px solid var(--primary); padding-left: 20px; font-weight: 800; }

.section-content strong {
    color: var(--primary);
    font-weight: 800;
}

[data-theme="dark"] .section-content strong {
    text-shadow: 0 0 10px var(--primary-glow);
}

/* ── 導航按鈕優化 ── */
.section-nav {
    display: flex;
    justify-content: space-between;
    gap: 25px;
    margin: 50px 0 100px;
}

.nav-btn {
    flex: 1;
    padding: 24px 32px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    border: 3px solid var(--primary);
    background: var(--bg-sidebar);
    /* removed transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); */
    max-width: 360px;
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
}

.nav-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary-glow);
    /* removed transition: left 0.6s; */
}

.nav-btn:hover {
    background: rgba(116, 141, 146, 0.15);
    border-color: var(--primary);
    color: var(--text-main) !important;
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.nav-btn:hover::before {
    left: 100%;
}

.nav-btn:active {
    transform: translateY(-5px) scale(1.01) rotate(-0.5deg);
}

.nav-btn i { font-size: 0.9rem; /* removed transition: transform 0.3s; */ }
.nav-btn.prev:hover i { transform: translateX(-5px); }
.nav-btn.next:hover i { transform: translateX(5px); }
.nav-btn.next { margin-left: auto; }

/* 完成按鈕 */
.btn-done {
    padding: 12px 24px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    /* removed transition: all 0.3s; */
}

.btn-done.active { background: #10b981; color: white; border-color: transparent; box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3); }

/* ── 筆記區塊 ── */
.note-area {
    margin-top: 40px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.note-header {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 8px 0;
    user-select: none;
    /* removed transition: color 0.2s; */
}

.note-header:hover { color: var(--primary); }
.note-header i:first-child { color: var(--primary); }
.note-header span { flex: 1; }

.note-arrow {
    font-size: 0.75rem;
    /* removed transition: transform 0.3s; */
}

.note-body {
    display: none;
    margin-top: 12px;
}

.note-body.open { display: block; }

.note-body.open ~ .note-header .note-arrow,
.note-header:has(+ .note-body.open) .note-arrow {
    transform: rotate(180deg);
}

.note-body textarea {
    width: 100%;
    min-height: 120px;
    padding: 14px 16px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-main);
    font-family: 'Noto Sans TC', sans-serif;
    font-size: 0.9rem;
    line-height: 1.7;
    resize: vertical;
    outline: none;
    /* removed transition: border-color 0.2s; */
}

.note-body textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.note-body textarea::placeholder { color: var(--text-muted); opacity: 0.6; }

/* ── 響應式優化 ── */
@media (max-width: 1024px) {
    #sidebar {
        position: fixed;
        left: -320px;
        z-index: 1000;
        height: 100vh;
        width: 320px;
    }
    #sidebar.open { transform: translateX(320px); }
    #sidebar-overlay.active {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.7);
        backdrop-filter: blur(4px);
        z-index: 900;
    }

    #top-bar {
        padding: 0 16px;
        height: 64px;
    }

    .icon-btn {
        width: 44px;
        height: 44px;
    }

    #content { padding: 24px 20px; }

    /* Hero 響應式 */
    .welcome-hero {
        flex-direction: column;
        align-items: flex-start;
        padding: 36px 28px;
        border-radius: 12px;
        margin-bottom: 32px;
    }

    .hero-content { max-width: 100%; }

    .hero-content h1 {
        font-size: 2.8rem;
        line-height: 1.1;
        margin-bottom: 16px;
    }

    .hero-content p {
        font-size: 1rem;
        margin-bottom: 24px;
    }

    .hero-stats { gap: 28px; }
    .h-stat .num { font-size: 1.8rem; }
    .hero-visual { display: none; }

    /* 卡片響應式 */
    .chapters-grid { grid-template-columns: 1fr; gap: 18px; }

    .chapter-card {
        padding: 24px;
        border-radius: 12px;
        gap: 20px;
    }

    .card-icon {
        width: 56px;
        height: 56px;
    }

    /* 章節內容響應式 */
    .section-block {
        padding: 28px 24px;
        border-radius: 12px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .section-header h1 {
        font-size: 2rem;
        line-height: 1.2;
    }

    .btn-done {
        width: 100%;
        justify-content: center;
    }

    /* 導航按鈕響應式 */
    .nav-btn {
        padding: 20px 24px;
        max-width: 100%;
    }

    /* 表格響應式 */
    table {
        font-size: 0.8rem !important;
    }

    th, td {
        padding: 16px 20px !important;
    }

    /* 字體控制在小螢幕隱藏 */
    .font-controls { display: none; }
}

.fade-in { animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1); }

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 全局脈衝動畫 */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* 全局發光動畫 */
@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--primary-glow); }
    50% { box-shadow: 0 0 8px var(--primary-glow); }
}

/* 文字發光動畫 */
@keyframes textGlow {
    0%, 100% { text-shadow: 0 0 5px var(--primary-glow); }
    50% { text-shadow: 0 0 15px var(--primary-glow); }
}

/* 邊框流動動畫 */
@keyframes borderFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 添加一些微妙的動效到重要元素 */
.logo span {
    animation: textGlow 4s ease-in-out infinite;
}

/* Removed pulse animation for stable positioning */

/* 自定義滾動條 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-sidebar);
}

::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
    border: 1px solid var(--accent-cyan);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
    box-shadow: 0 0 10px var(--primary-glow);
}

/* ══════════════════════════════════════════════
   Sidebar：科目快捷導航
   ══════════════════════════════════════════════ */
#sidebar-subjects { 
    flex: 1; 
    overflow-y: auto; 
}

/* ══════════════════════════════════════════════
   樹狀目錄與動畫過渡樣式
   ══════════════════════════════════════════════ */
#sidebar-chapter-menu {
    padding: 4px 0 10px 0; 
    position: relative;
    max-height: 2000px; 
    overflow: hidden;
    /* removed transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s, margin-bottom 0.4s; */
    opacity: 1;
    margin-bottom: 12px; 
}

/* 收合狀態 */
#sidebar-chapter-menu.collapsed {
    max-height: 0;
    padding-bottom: 0;
    margin-bottom: 0; 
    opacity: 0;
}

/* 章節與小節樣式調整 */
#sidebar-chapter-menu .sidebar-chapter {
    margin-bottom: 8px;
    background: transparent;
    border: none;
    border-radius: 12px;
    box-shadow: none;
    overflow: hidden;
}

/* Chapter Level - Mid hierarchy */
#sidebar-chapter-menu .chapter-title {
    padding: 12px var(--space-chapter) 12px var(--space-chapter);
    font-size: var(--font-chapter);
    font-weight: 650;
    color: var(--text-main);
    border-radius: 10px;
    background: var(--bg-chapter);
    border-left: 2px solid var(--border-chapter);
    margin: 2px 0 3px 0;
    letter-spacing: 0.015em;
    line-height: 1.35;
    position: relative;
    opacity: 0.92;
    backdrop-filter: blur(4px);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#sidebar-chapter-menu .chapter-title:hover {
    color: var(--text-main);
    background: var(--primary);
    color: white;
    border-left-color: var(--accent-cyan);
    opacity: 1;
    box-shadow: 0 2px 8px rgba(74, 111, 165, 0.15);
    transform: translateX(2px);
}

#sidebar-chapter-menu .section-list {
    margin-left: 0;
    padding-left: 0;
}

/* Section Level - Bottom hierarchy */
#sidebar-chapter-menu .section-item {
    padding: 10px 16px 10px 32px;
    font-size: var(--font-section);
    font-weight: 500;
    color: #e2e8f0;
    border-radius: 6px;
    background: rgba(51, 65, 85, 0.4);
    border-left: 2px solid transparent;
    margin: 1px 8px 1px 12px;
    position: relative;
    line-height: 1.5;
    letter-spacing: 0.01em;
    backdrop-filter: blur(1px);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar-chapter-menu .section-item::before {
    content: '◦';
    position: absolute;
    left: 16px;
    color: #94a3b8;
    font-size: 0.7rem;
    opacity: 0.8;
    top: 50%;
    transform: translateY(-50%);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar-chapter-menu .section-item:hover {
    background: rgba(116, 141, 146, 0.2);
    color: var(--text-main);
    border-left-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateX(2px);
}

#sidebar-chapter-menu .section-item:hover::before {
    color: var(--primary);
    opacity: 1;
    transform: translateY(-50%) scale(1.05);
}

/* Active chapter state - 當前章節活躍狀態 */
#sidebar-chapter-menu .chapter-title.active {
    background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--bg-base) 100%);
    color: var(--text-main);
    border-left: 4px solid var(--primary);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    font-weight: 700;
    transform: translateX(2px);
}

#sidebar-chapter-menu .chapter-title.active .arrow {
    color: var(--primary);
    transform: rotate(90deg) scale(1.05);
}

/* Active section state - 當前小節活躍狀態 */
#sidebar-chapter-menu .section-item.active {
    background: linear-gradient(135deg, var(--bg-base) 0%, var(--bg-sidebar) 100%);
    color: var(--text-main);
    border-left: 3px solid var(--primary);
    box-shadow:
        0 3px 12px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    font-weight: 600;
    transform: translateX(3px);
    position: relative;
}

#sidebar-chapter-menu .section-item.active::before {
    content: '●';
    color: var(--primary);
    opacity: 1;
    font-size: 0.65rem;
    transform: translateY(-50%);
    text-shadow: 0 0 6px var(--primary-glow);
}


#sidebar-menu { display: none; } /* 確保舊的容器不干擾 */

/* 隱藏滾動條但保持功能 (可選) */
#sidebar-subjects::-webkit-scrollbar { width: 4px; }
#sidebar-subjects::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-subjects-nav {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

/* 科目分類標籤 */
.sidebar-category {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 12px 14px 4px;
}

/* 摺疊面板設定 */
.sidebar-coming-group { margin-top: 5px; }

.coming-summary {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none; /* 隱藏原生箭頭 */
    /* removed transition: color 0.2s; */
}

.coming-summary::-webkit-details-marker { display: none; }
.coming-summary:hover { color: var(--text-main); }
.coming-summary i { font-size: 0.7rem; /* removed transition: transform 0.3s; */ }

/* 展開時箭頭旋轉 */
.sidebar-coming-group[open] .coming-summary i { transform: rotate(180deg); }

.coming-list { padding-top: 4px; }

.sidebar-home-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    /* removed transition: all 0.2s; */
}

.sidebar-home-btn:hover,
.sidebar-home-btn.active {
    background: var(--primary);
    color: white;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* Course Level - Top hierarchy */
.sidebar-subject-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px var(--space-course);
    border-radius: 14px;
    cursor: pointer;
    font-size: var(--font-course);
    font-weight: 700;
    color: var(--text-main);
    background: var(--bg-course);
    border: 1px solid var(--border-course);
    border-left: 4px solid var(--border-course);
    margin-bottom: 8px;
    position: relative;
    letter-spacing: 0.025em;
    line-height: 1.4;
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.sidebar-subject-item:hover {
    background: rgba(116, 141, 146, 0.1);
    color: var(--primary);
    border-color: var(--primary);
    border-left-color: var(--primary);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transform: translateX(3px);
}

.sidebar-subject-item.active {
    background: rgba(18, 78, 102, 0.2);
    color: var(--text-main);
    border-color: rgba(116, 141, 146, 0.3);
    border-left-color: var(--primary);
    box-shadow: 
        0 4px 20px rgba(0, 0, 0, 0.3),
        inset 0 0 15px rgba(18, 78, 102, 0.1);
}

.sidebar-subject-item.coming {
    opacity: 0.55;
    cursor: default;
}

.sidebar-lock {
    font-size: 0.65rem;
    margin-left: auto;
    color: var(--text-muted);
}

#sidebar-menu { flex: 1; overflow-y: auto; padding: 10px; }

/* Breadcrumb */
.bc-home { color: var(--text-muted); font-size: 0.85rem; }
.bc-home i { margin-right: 6px; }
.bc-link { color: var(--primary); font-size: 0.85rem; cursor: pointer; }
.bc-link:hover { text-decoration: underline; }
.bc-sep { color: var(--text-muted); font-size: 0.85rem; }
.bc-current { color: var(--text-main); font-size: 0.85rem; font-weight: 700; }

/* Subject Dashboard */
.subject-dashboard {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 60px;
}

/* Hero */
.subject-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 56px 60px;
    border-radius: 40px;
    margin-bottom: 52px;
    background: var(--glass-bg);
    position: relative;
    overflow: hidden;
}

.subject-hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse 80% 50% at 85% 50%, rgba(74, 111, 165, 0.08) 0%, transparent 70%);
    z-index: 0;
    pointer-events: none;
}

.subject-hero .hero-content { position: relative; z-index: 1; max-width: 60%; }

.hero-brand {
    display: inline-block;
    padding: 5px 16px;
    background: var(--primary);
    color: white;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 20px;
}

.subject-hero h1 {
    font-size: 3.2rem;
    font-weight: 900;
    line-height: 1.15;
    margin-bottom: 14px;
}

.subject-hero h1 span { color: var(--primary); }

.subject-hero p { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 30px; }

.subject-hero .hero-visual {
    font-size: 5.5rem;
    color: var(--primary);
    opacity: 0.06;
    transform: rotate(-10deg);
    flex-shrink: 0;
    z-index: 0;
}

/* 科目分組 */
.subjects-section { margin-bottom: 44px; }

.subjects-section-label {
    font-size: 0.8rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.cat-accent {
    display: inline-block;
    width: 24px;
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
    flex-shrink: 0;
}

/* 科目卡片 grid */
.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

/* 科目卡片 */
.subject-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0;
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    overflow: hidden;
    /* removed transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s, border-color 0.3s; */
}

.subject-card:hover {
    transform: translateY(-6px) scale(1.015);
    border-color: var(--subject-color, var(--primary));
    box-shadow: 0 16px 40px rgba(0,0,0,0.25),
                0 0 0 1px var(--subject-color, var(--primary));
}

.subject-card.coming {
    opacity: 0.6;
    cursor: default;
    pointer-events: none;
}

.subject-card.coming:hover { transform: none; box-shadow: none; }

/* 左側 accent bar */
.subject-card-accent {
    width: 5px;
    align-self: stretch;
    background: var(--subject-color, var(--primary));
    flex-shrink: 0;
    border-radius: 0;
    /* removed transition: width 0.3s; */
}

.subject-card:hover .subject-card-accent { width: 7px; }

/* Icon */
.subject-card-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--subject-color, var(--primary));
    flex-shrink: 0;
    margin: 20px 0 20px 18px;
    /* removed transition: all 0.3s; */
}

.subject-card:hover .subject-card-icon {
    background: var(--subject-color, var(--primary));
    color: white;
    transform: rotate(-8deg) scale(1.05);
}

/* Body */
.subject-card-body {
    flex: 1;
    padding: 20px 40px 20px 16px;
    min-width: 0;
}

.subject-card-body h3 {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.subject-subtitle {
    font-size: 0.75rem;
    color: var(--subject-color, var(--primary));
    font-weight: 700;
    margin-bottom: 8px;
    opacity: 0.85;
}

.subject-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Tags */
.subject-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.subject-tag {
    padding: 3px 10px;
    border-radius: 50px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Progress */
.subject-progress { display: flex; align-items: center; gap: 10px; }

.subject-p-bar {
    flex: 1;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.subject-p-fill {
    height: 100%;
    border-radius: 3px;
    /* removed transition: width 0.8s ease; */
}

.subject-p-text { font-size: 0.72rem; font-weight: 800; color: var(--text-muted); min-width: 32px; }

/* Coming badge */
.coming-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 50px;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Arrow */
.subject-card-arrow {
    position: absolute;
    top: 24px;
    right: 20px;
    color: var(--text-muted);
    opacity: 0;
    transform: translate(-8px, 4px); /* 稍微從左下方滑入 */
    /* removed transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); */
    font-size: 1.1rem;
}

.subject-card:hover .subject-card-arrow {
    opacity: 1;
    transform: translate(0, 0);
    color: var(--subject-color, var(--primary));
}

/* Toast 通知 */
.tn-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    opacity: 0;
    /* removed transition: opacity 0.35s, transform 0.35s; */
    z-index: 9999;
    white-space: nowrap;
}

.tn-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ══════════════════════════════════════════════
   響應式補充
   ══════════════════════════════════════════════ */
@media (max-width: 768px) {
    .subject-hero { flex-direction: column; padding: 36px 28px; }
    .subject-hero .hero-content { max-width: 100%; }
    .subject-hero .hero-visual { display: none; }
    .subject-hero h1 { font-size: 2.2rem; }
    .subjects-grid { grid-template-columns: 1fr; }
}
