            :root {
            --background: #ffffff;
            --foreground: #0a0a0a;
            --primary: #0a0a0a;
            --primary-foreground: #fafafa;
            --muted: #f5f5f5;
            --muted-foreground: #737373;
            --border: #e5e5e5;
            --accent: #f5f5f5;
            --accent-foreground: #0a0a0a;
            --radius: 0.5rem;
            --header-height: 60px;
            --sidebar-width: 300px;
        }
        
        body.dark-theme {
            --background: #1a1a1a;
            --foreground: #fafafa;
            --primary: #fafafa;
            --primary-foreground: #0a0a0a;
            --muted: #2a2a2a;
            --muted-foreground: #a3a3a3;
            --border: #3a3a3a;
            --accent: #2a2a2a;
            --accent-foreground: #fafafa;
        }

        body.sepia-theme {
            --background: #fbf0d9;
            --foreground: #5b4636;
            --primary: #5b4636;
            --primary-foreground: #fbf0d9;
            --muted: #f7e8c8;
            --muted-foreground: #8c7e6e;
            --border: #e8d8b8;
            --accent: #f7e8c8;
            --accent-foreground: #5b4636;
        }


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

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background-color: var(--background);
            color: var(--foreground);
            overflow: hidden;
            user-select: none;
            transition: background-color 0.3s, color 0.3s;
        }

        #reader {
            display: flex;
            flex-direction: column;
            height: 100vh;
            width: 100vw;
        }

        #progress-bar {
            width: 0%;
            height: 2px;
            background-color: var(--primary);
            position: fixed;
            top: var(--header-height);
            left: 0;
            z-index: 100;
            transition: width 0.3s ease;
        }

        #header {
            height: var(--header-height);
            border-bottom: 1px solid var(--border);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 16px;
            flex-shrink: 0;
            background-color: var(--background);
            z-index: 50;
            transition: background-color 0.3s, border-color 0.3s;
        }

        .controls-group {
            display: flex;
            align-items: center;
            gap: 8px;
            flex: 1;
        }

        .controls-group.left { justify-content: flex-start; }
        .controls-group.right { justify-content: flex-end; }
        .controls-group.center {
            justify-content: center;
            flex: 2;
            min-width: 0;
        }

        #book-title {
            font-size: 1rem;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            text-align: center;
            margin: 0 16px;
        }
        
        #page-progress, #reading-time {
            font-size: 0.8rem;
            color: var(--muted-foreground);
            font-weight: 500;
            flex-shrink: 0;
        }

        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: var(--radius);
            font-size: 0.875rem;
            font-weight: 600;
            padding: 8px 12px;
            cursor: pointer;
            transition: background-color 0.2s, color 0.2s, border-color 0.2s, opacity 0.2s;
            border: 1px solid transparent;
            background-color: transparent;
            color: var(--foreground);
        }

        .btn-icon {
            padding: 0;
            width: 36px;
            height: 36px;
            font-size: 1rem;
            border: 1px solid var(--border);
        }
        
        .btn-icon:hover {
            background-color: var(--accent);
            color: var(--accent-foreground);
        }
        
        .btn-icon.active {
            background-color: var(--accent);
            box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
        }

        .btn-primary {
            background-color: var(--primary);
            color: var(--primary-foreground);
            border-color: var(--primary);
        }
        
        .btn-primary:hover { opacity: 0.85; }
        .btn:disabled { opacity: 0.4; cursor: not-allowed; }
        #file-input { display: none; }

        #content-wrapper {
            display: flex;
            flex-grow: 1;
            position: relative;
            overflow: hidden;
            background-color: var(--muted);
        }

        #sidebar {
            width: var(--sidebar-width);
            background-color: var(--background);
            border-right: 1px solid var(--border);
            position: fixed;
            top: var(--header-height);
            left: 0;
            bottom: 0;
            transform: translateX(calc(-1 * var(--sidebar-width)));
            transition: transform 0.3s ease-in-out, background-color 0.3s, border-color 0.3s;
            z-index: 40;
            display: flex;
            flex-direction: column;
        }

        #sidebar.open {
            transform: translateX(0);
        }
        
        .sidebar-tabs {
            display: flex;
            border-bottom: 1px solid var(--border);
        }
        
        .sidebar-tab {
            flex: 1;
            padding: 14px;
            font-size: 0.875rem;
            font-weight: 600;
            text-align: center;
            cursor: pointer;
            color: var(--muted-foreground);
            border-bottom: 2px solid transparent;
            transition: color 0.2s, border-color 0.2s;
        }
        
        .sidebar-tab:hover {
            color: var(--foreground);
        }
        
        .sidebar-tab.active {
            color: var(--primary);
            border-bottom-color: var(--primary);
        }
        
        .sidebar-panel {
            display: none;
            overflow-y: auto;
            flex-grow: 1;
        }
        
        .sidebar-panel.active {
            display: block;
        }

        #toc, #bookmarks-list, #history-list {
            list-style: none;
        }

        #toc li, #bookmarks-list li, #history-list li {
            padding: 12px 16px;
            cursor: pointer;
            font-size: 0.875rem;
            transition: background-color 0.2s;
            border-left: 3px solid transparent;
            line-height: 1.4;
        }
        
        #bookmarks-list li, #history-list li {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .item-title {
            font-weight: 600;
            margin-bottom: 4px;
        }
        
        .item-meta {
            font-size: 0.75rem;
            color: var(--muted-foreground);
        }
        
        .item-remove {
            font-size: 0.8rem;
            color: var(--muted-foreground);
            padding: 4px 8px;
        }
        
        .item-remove:hover {
            color: #f00;
        }

        #toc li:hover, #bookmarks-list li:hover, #history-list li:hover {
            background-color: var(--accent);
        }
        
        #toc li.active {
            background-color: var(--accent);
            font-weight: 600;
            color: var(--accent-foreground);
            border-left-color: var(--primary);
        }
        
        #list-empty {
            padding: 40px 20px;
            text-align: center;
            color: var(--muted-foreground);
            font-size: 0.875rem;
        }

        #main {
            flex-grow: 1;
            position: relative;
            transition: transform 0.3s ease-in-out;
            overflow-y: auto;
            height: calc(100vh - var(--header-height));
        }

        #main.sidebar-open {
            transform: translateX(var(--sidebar-width));
            width: calc(100% - var(--sidebar-width));
        }
        
        #reader-ui { display: none; }

        #content-frame {
            border: none;
            width: 100%;
            height: 100%;
            display: block;
            background-color: var(--background);
            min-height: calc(100vh - var(--header-height));
        }

        #upload-area {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
            text-align: center;
            padding: 20px;
            border: 2px dashed var(--border);
            margin: 8px;
            border-radius: var(--radius);
            transition: border-color 0.2s, background-color 0.2s;
            background: transparent;
        }
        
        #upload-area.dragover {
            border-color: var(--primary);
            background-color: var(--accent);
        }
        
        #upload-area i {
            font-size: 3rem;
            color: var(--muted-foreground);
            margin-bottom: 16px;
        }

        #upload-area p {
            font-size: 1.1rem;
            color: var(--muted-foreground);
            margin-bottom: 20px;
        }

        #loader {
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100%;
        }
        
        #loader .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid var(--border);
            border-top-color: var(--primary);
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin-bottom: 16px;
        }
        
        #loader p {
            font-size: 1rem;
            color: var(--muted-foreground);
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        #settings-popover {
            display: none;
            position: fixed;
            top: calc(var(--header-height) + 8px);
            right: 16px;
            width: 320px;
            background-color: var(--background);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            z-index: 100;
            padding: 20px;
            transition: background-color 0.3s, border-color 0.3s;
        }
        
        .setting-group { margin-bottom: 24px; }
        .setting-group:last-child { margin-bottom: 0; }
        
        .setting-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .setting-row label {
            font-size: 0.9rem;
            font-weight: 500;
        }
        
        .setting-controls { display: flex; gap: 8px; }
        .btn-setting {
            flex: 1;
            border: 1px solid var(--border);
            padding: 6px 8px;
            font-size: 0.8rem;
        }
        .btn-setting:hover { background-color: var(--accent); }
        .btn-setting.active {
            background-color: var(--primary);
            color: var(--primary-foreground);
            border-color: var(--primary);
        }
        .toggle-switch {
            position: relative;
            display: inline-block;
            width: 40px;
            height: 22px;
        }
        .toggle-switch input { 
            opacity: 0;
            width: 0;
            height: 0;
        }
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 22px;
        }
        .slider:before {
            position: absolute;
            content: "";
            height: 16px;
            width: 16px;
            left: 3px;
            bottom: 3px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }
        input:checked + .slider {
            background-color: var(--primary);
        }
        input:checked + .slider:before {
            transform: translateX(18px);
        }
        
        .range-slider {
            width: 100%;
            -webkit-appearance: none;
            appearance: none;
            height: 4px;
            background: var(--border);
            outline: none;
            opacity: 0.7;
            transition: opacity .2s;
            border-radius: 2px;
        }
        .range-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 16px;
            height: 16px;
            background: var(--primary);
            cursor: pointer;
            border-radius: 50%;
        }
        .range-slider::-moz-range-thumb {
            width: 16px;
            height: 16px;
            background: var(--primary);
            cursor: pointer;
            border-radius: 50%;
        }
        
        #text-selection-popover {
            display: none;
            position: absolute;
            background-color: var(--primary);
            color: var(--primary-foreground);
            padding: 6px 12px;
            border-radius: var(--radius);
            font-size: 0.875rem;
            font-weight: 600;
            cursor: pointer;
            z-index: 1000;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        }
        
        #dictionary-modal, #notepad-modal {
            display: none;
            position: fixed;
            background-color: var(--background);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            z-index: 101;
        }
        
        #dictionary-modal {
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 400px;
            max-width: 90vw;
            padding: 20px;
        }
        
        #dictionary-modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid var(--border);
            padding-bottom: 12px;
            margin-bottom: 16px;
        }
        
        #dictionary-modal-word {
            font-size: 1.25rem;
            font-weight: 600;
        }
        
        #dictionary-modal-close {
            font-size: 1rem;
            color: var(--muted-foreground);
            cursor: pointer;
        }
        #dictionary-modal-content {
            font-size: 0.9rem;
            line-height: 1.6;
            max-height: 40vh;
            overflow-y: auto;
        }
        
        #notepad-modal {
            top: 80px;
            right: 20px;
            width: 320px;
            height: 400px;
            resize: both;
            overflow: hidden;
            display: none;
            flex-direction: column;
        }
        
        #notepad-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 8px 12px;
            background-color: var(--accent);
            border-bottom: 1px solid var(--border);
            cursor: move;
        }
        
        #notepad-header h3 {
            font-size: 0.875rem;
            font-weight: 600;
        }
        
        #notepad-close {
            font-size: 0.875rem;
            color: var(--muted-foreground);
            cursor: pointer;
        }
        
        #notepad-textarea {
            flex-grow: 1;
            border: none;
            outline: none;
            padding: 12px;
            font-family: inherit;
            font-size: 0.875rem;
            line-height: 1.6;
            resize: none;
            width: 100%;
            height: 100%;
            background-color: var(--background);
            color: var(--foreground);
        }
