/* style.css */
:root {
    color-scheme: light;
    --bg-primary: #6f482a;
    --bg-secondary: #dfbf87;
    --bg-card: rgba(249, 236, 203, 0.98);
    --text-primary: #3b291c;
    --text-secondary: #765a40;
    --accent-gold: #9d641f;
    --accent-purple: #7c4d28;
    --accent-cyan: #3f7163;
    --border: rgba(92, 58, 30, 0.24);
    
    --cat-mysql: #f59e0b;
    --cat-jvm: #ef4444;
    --cat-concurrent: #8b5cf6;
    --cat-redis: #ef4444;
    --cat-spring: #22c55e;
    --cat-distributed: #3b82f6;
    --cat-network: #06b6d4;
    --cat-other: #6b7280;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background-image:
        radial-gradient(circle at 18% 28%, rgba(255, 224, 164, 0.12), transparent 30%),
        radial-gradient(circle at 82% 76%, rgba(54, 29, 13, 0.18), transparent 32%),
        repeating-linear-gradient(105deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 5px);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--accent-purple);
    border-radius: 3px;
    opacity: 0.5;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-gold);
}

/* Typography & Core UI */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

button:focus-visible,
.kp:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 3px;
}

.icon-btn {
    font-size: 1.5rem;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
}
.icon-btn:hover {
    color: var(--accent-gold);
    text-shadow: 0 0 8px var(--accent-gold);
    background: rgba(255, 215, 0, 0.1);
}

.gold {
    color: var(--accent-gold);
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
}

/* Reading Progress Bar */
#reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-purple), var(--accent-gold));
    width: 0%;
    z-index: 1000;
    transition: width 0.1s linear;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 64px;
    z-index: 100;
}
.header-title {
    text-align: center;
}
.header-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--accent-gold);
}
.header-title .subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.header-nav {
    display: flex;
    gap: 1rem;
}

/* Layout */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebars */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 50;
}
.sidebar.right-sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
}

.sidebar-backdrop {
    position: absolute;
    inset: 0;
    z-index: 80;
    background: rgba(3, 3, 10, 0.68);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.sidebar.hidden.left-sidebar {
    transform: translateX(-100%);
    position: absolute;
    height: 100%;
}
.sidebar.hidden.right-sidebar {
    transform: translateX(100%);
    position: absolute;
    right: 0;
    height: 100%;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
    font-size: 1rem;
    color: var(--accent-gold);
}
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Reading Area */
.reading-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chapter-content {
    max-width: 800px;
    width: 100%;
    font-family: 'Noto Serif SC', serif;
    font-size: 18px;
    line-height: 2;
}

.chapter-content h1.chapter-title {
    font-size: 2.5rem;
    color: var(--accent-gold);
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
    text-align: center;
    margin-bottom: 1rem;
    margin-top: 2rem;
}

.epigraph {
    font-style: italic;
    text-align: center;
    color: var(--accent-gold);
    opacity: 0.8;
    margin: 0 auto 3rem;
    padding: 1rem;
    border-top: 1px solid rgba(255, 215, 0, 0.3);
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    max-width: 80%;
}

.chapter-content p {
    margin-bottom: 1.5rem;
    text-align: justify;
}

.scene-break {
    text-align: center;
    color: var(--accent-gold);
    font-size: 1.5rem;
    margin: 2rem 0;
    opacity: 0.6;
    letter-spacing: 0.5rem;
}

.system-msg {
    background: rgba(255, 215, 0, 0.05);
    border-left: 4px solid var(--accent-gold);
    padding: 1rem 1.5rem;
    margin: 1.5rem 0;
    color: var(--accent-gold);
    font-family: 'Inter', sans-serif;
    border-radius: 0 8px 8px 0;
}

/* Knowledge Point Highlights */
.kp {
    position: relative;
    color: #fff;
    cursor: pointer;
    background-image: linear-gradient(90deg, var(--accent-gold), var(--accent-purple));
    background-size: 100% 2px;
    background-repeat: no-repeat;
    background-position: 0 100%;
    transition: all 0.3s ease;
    padding: 0 2px;
}
.kp:hover {
    color: var(--accent-gold);
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
    background-size: 100% 100%;
    background-color: rgba(139, 92, 246, 0.2);
    border-radius: 4px;
}
.kp:focus-visible {
    color: var(--accent-gold);
    background-color: rgba(139, 92, 246, 0.22);
    border-radius: 4px;
}
@keyframes pulse {
    0% { opacity: 0.8; }
    50% { opacity: 1; text-shadow: 0 0 10px var(--accent-gold); }
    100% { opacity: 0.8; }
}
.kp.unlocked {
    color: var(--accent-gold);
}

.reading-footer {
    max-width: 800px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
    margin-bottom: 4rem;
}

.nav-btn {
    padding: 0.75rem 2rem;
    background: transparent;
    border: 1px solid var(--accent-purple);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 1rem;
}
.nav-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--accent-gold);
    color: var(--accent-gold);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 8, 15, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}
.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.kp-modal {
    background: var(--bg-card);
    border: 1px solid var(--accent-gold);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.15), inset 0 0 20px rgba(139, 92, 246, 0.1);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.hidden .kp-modal {
    transform: translateY(50px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
}
.modal-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.modal-title-group h2 {
    color: var(--accent-gold);
    margin: 0;
    font-size: 1.25rem;
}
.category-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
}

.modal-tabs {
    display: flex;
    padding: 1rem 1.5rem;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    font-weight: 500;
}
.tab-btn.active {
    background: var(--accent-purple);
    color: #fff;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}
.tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    line-height: 1.6;
}
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}
.tab-content.active {
    display: block;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Sidebar Chapter List */
.volume-group {
    margin-bottom: 1.5rem;
}
.volume-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-left: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.chapter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s;
}
.chapter-item:hover {
    background: rgba(255, 255, 255, 0.05);
}
.chapter-item.active {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-gold);
    border-left: 3px solid var(--accent-gold);
}
.chapter-item-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.read-check {
    color: var(--accent-cyan);
    font-size: 0.8rem;
    opacity: 0;
}
.chapter-item.read .read-check {
    opacity: 1;
}
.kp-count-badge {
    font-size: 0.7rem;
    background: rgba(139, 92, 246, 0.3);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 10px;
}

/* System Panel */
.system-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.realm-badge {
    text-align: center;
    padding: 1.5rem;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.2) 0%, transparent 70%);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}
.realm-badge::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: conic-gradient(transparent, rgba(255, 215, 0, 0.3), transparent 30%);
    animation: rotate 10s linear infinite;
    z-index: 0;
}
@keyframes rotate {
    100% { transform: rotate(360deg); }
}
.realm-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
    position: relative;
    z-index: 1;
}

.stats-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stat-label {
    color: var(--text-secondary);
}
.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
}

.system-section-title {
    font-size: 0.9rem;
    color: var(--accent-gold);
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    padding-bottom: 0.5rem;
}

.progress-item {
    margin-bottom: 1rem;
}
.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}
.progress-track {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-purple), var(--accent-gold));
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* Toasts */
#toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
    pointer-events: none;
}
.toast {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.9), rgba(139, 92, 246, 0.9));
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    animation: slideDownFade 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast.hiding {
    animation: fadeOutUp 0.3s ease forwards;
}
@keyframes fadeOutUp {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

/* Warm book theme */
.app-header {
    background:
        linear-gradient(180deg, rgba(255, 238, 197, 0.08), transparent 42%),
        linear-gradient(90deg, #4c2d1a, #6f4526 50%, #4c2d1a);
    border-bottom-color: rgba(39, 20, 9, 0.58);
    box-shadow: 0 4px 16px rgba(48, 27, 13, 0.28);
}

.header-title h1,
.app-header .icon-btn {
    color: #f4d99d;
    text-shadow: 0 1px 2px rgba(24, 12, 5, 0.65);
}

.header-title .subtitle {
    color: #cfb481;
}

.app-header .icon-btn:hover {
    color: #fff0c5;
    background: rgba(255, 232, 179, 0.12);
    text-shadow: 0 0 8px rgba(255, 222, 145, 0.38);
}

#reading-progress-bar {
    background: linear-gradient(90deg, #69401f, #d29a3f, #69401f);
}

.sidebar {
    background-color: #dfbf87;
    background-image:
        linear-gradient(90deg, rgba(80, 47, 23, 0.12), transparent 18%, transparent 82%, rgba(80, 47, 23, 0.09)),
        repeating-linear-gradient(0deg, rgba(84, 52, 28, 0.025) 0 1px, transparent 1px 4px);
    box-shadow: 0 0 24px rgba(57, 32, 15, 0.16);
}

.sidebar-header {
    background: rgba(112, 72, 37, 0.08);
}

.sidebar-header h2,
.system-section-title {
    color: #71451f;
}

.sidebar .icon-btn {
    color: #765438;
}

.sidebar-backdrop {
    background: rgba(45, 25, 12, 0.62);
}

.reading-area {
    background-color: #f1ddb1;
    background-image:
        linear-gradient(90deg, rgba(89, 53, 25, 0.14), transparent 5%, transparent 95%, rgba(89, 53, 25, 0.14)),
        radial-gradient(circle at 50% 0, rgba(255, 250, 226, 0.72), transparent 54%),
        repeating-linear-gradient(0deg, rgba(102, 69, 36, 0.025) 0 1px, transparent 1px 5px);
    box-shadow:
        inset 24px 0 34px -34px rgba(47, 25, 10, 0.8),
        inset -24px 0 34px -34px rgba(47, 25, 10, 0.8);
}

.chapter-content {
    color: #38271b;
    text-shadow: 0 1px 0 rgba(255, 250, 230, 0.4);
}

.chapter-content h1.chapter-title {
    color: #70431e;
    text-shadow: 0 1px 0 #fff2ce;
}

.epigraph {
    color: #8a5a28;
    border-color: rgba(125, 77, 31, 0.3);
}

.scene-break {
    color: #9a6429;
}

.system-msg {
    color: #704719;
    background: rgba(187, 132, 58, 0.12);
    border-left-color: #9d641f;
    box-shadow: inset 0 0 0 1px rgba(122, 75, 29, 0.08);
}

.kp {
    color: #432b18;
    background-image: linear-gradient(90deg, #b37524, #6d492d);
}

.kp:hover,
.kp:focus-visible,
.kp.unlocked {
    color: #754516;
    text-shadow: none;
    background-color: rgba(164, 105, 37, 0.13);
}

.reading-footer {
    border-top-color: rgba(92, 58, 30, 0.24);
}

.nav-btn {
    color: #57371f;
    border-color: #8b5a2b;
    background: rgba(255, 246, 218, 0.3);
}

.nav-btn:hover {
    color: #fff4d5;
    border-color: #6b421f;
    background: #7a4c28;
    box-shadow: 0 5px 14px rgba(76, 43, 20, 0.22);
}

.chapter-item:hover {
    background: rgba(112, 69, 31, 0.09);
}

.chapter-item.active {
    background: rgba(127, 77, 32, 0.14);
    color: #70431e;
    border-left-color: #8f5923;
}

.kp-count-badge,
.category-badge {
    background: rgba(105, 64, 29, 0.14);
}

.realm-badge {
    background: radial-gradient(circle, rgba(172, 113, 40, 0.2), transparent 70%);
    border-color: rgba(119, 73, 30, 0.28);
}

.realm-text,
.gold {
    color: #83501d;
    text-shadow: 0 1px 0 rgba(255, 242, 204, 0.9);
}

.stats-card {
    background: rgba(255, 246, 218, 0.34);
}

.progress-track {
    background: rgba(93, 57, 29, 0.14);
}

.progress-fill {
    background: linear-gradient(90deg, #754822, #c18a35);
}

.modal-overlay {
    background: rgba(54, 31, 16, 0.72);
}

.kp-modal {
    box-shadow: 0 18px 50px rgba(47, 26, 12, 0.38), inset 0 0 24px rgba(137, 84, 33, 0.06);
}

.modal-header,
.modal-tabs {
    border-color: rgba(103, 62, 28, 0.2);
}

.modal-title-group h2 {
    color: #70431e;
}

.tab-btn {
    background: rgba(108, 67, 31, 0.08);
}

.tab-btn.active {
    color: #fff4d5;
    background: #7a4c28;
    box-shadow: 0 4px 12px rgba(70, 39, 17, 0.2);
}

.tab-btn:hover:not(.active) {
    background: rgba(108, 67, 31, 0.14);
}

.toast {
    color: #fff6df;
    background: linear-gradient(135deg, #9b6425, #6a4024);
}

/* Responsive */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        max-height: min(72dvh, 620px);
        border-right: none;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    }
    .sidebar.left-sidebar {
        position: absolute;
        z-index: 100;
        top: 0;
        transform: translateY(-100%);
    }
    .sidebar.right-sidebar {
        position: absolute;
        z-index: 100;
        bottom: 0;
        transform: translateY(100%);
    }
    .sidebar.hidden.left-sidebar {
        transform: translateY(-100%);
        left: 0;
    }
    .sidebar.hidden.right-sidebar {
        transform: translateY(100%);
        right: 0;
    }
    .sidebar.visible.left-sidebar {
        transform: translateY(0);
    }
    .sidebar.visible.right-sidebar {
        transform: translateY(0);
    }
    .reading-area {
        padding: 1.25rem;
        overflow-x: hidden;
        box-shadow: none;
    }
    .chapter-content h1.chapter-title {
        font-size: clamp(1.9rem, 8vw, 2.5rem);
        line-height: 1.25;
        margin-top: 1.25rem;
    }
    .chapter-content {
        font-size: 17px;
        line-height: 1.9;
    }
    .chapter-content p {
        margin-bottom: 1.25rem;
    }
    .epigraph {
        max-width: 92%;
        margin-bottom: 2rem;
    }
}

@media (max-width: 600px) {
    .app-header {
        height: 58px;
        min-height: 58px;
        padding: 0.4rem 0.8rem;
        gap: 0.25rem;
    }
    .header-title {
        min-width: 0;
    }
    .header-title h1 {
        font-size: 1.05rem;
        letter-spacing: 1px;
        white-space: nowrap;
    }
    .header-title .subtitle {
        display: none;
    }
    .header-nav {
        gap: 0;
    }
    .icon-btn {
        min-width: 42px;
        min-height: 42px;
        padding: 0.35rem;
        font-size: 1.25rem;
    }
    .reading-area {
        padding: 1rem;
    }
    .chapter-content h1.chapter-title {
        font-size: clamp(1.75rem, 8.5vw, 2.15rem);
    }
    .reading-footer {
        margin-top: 2.5rem;
        margin-bottom: calc(2rem + env(safe-area-inset-bottom));
    }
    .nav-btn {
        min-height: 44px;
        padding: 0.7rem 1.25rem;
    }
    .modal-overlay {
        align-items: flex-end;
    }
    .kp-modal {
        width: 100%;
        max-width: none;
        max-height: 86dvh;
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-radius: 18px 18px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .modal-header {
        padding: 1rem;
    }
    .modal-title-group {
        min-width: 0;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .modal-title-group h2 {
        font-size: 1.1rem;
    }
    .modal-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }
    .tab-btn {
        min-height: 42px;
        padding: 0.5rem 0.25rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }
    .modal-body {
        padding: 1rem;
    }
    #toast-container {
        top: 68px;
        width: calc(100% - 2rem);
        align-items: center;
    }
    .toast {
        max-width: 100%;
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 360px) {
    .app-header {
        padding-inline: 0.35rem;
    }
    .header-nav .icon-btn {
        min-width: 36px;
    }
    .chapter-content {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
