/* リセットとベース設定 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #9ca3af;
    --border-color: #d1d5db;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --font-size: 16px;
    --line-height: 1.6;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: var(--line-height);
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: var(--transition);
}

/* ダークモード */
body.dark {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border-color: #4b5563;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
}

/* ヘッダー */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-btn,
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.menu-btn:hover,
.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.lang-select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.lang-select:hover {
    border-color: var(--primary-color);
}

/* サイドバー */
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
    z-index: 200;
    overflow-y: auto;
}

.sidebar.active {
    transform: translateX(320px);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    color: var(--text-primary);
}

.toc {
    padding: 1rem;
}

.toc-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.toc-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.toc-item.active {
    background: var(--primary-color);
    color: white;
}

.toc-empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-tertiary);
}

/* メインコンテンツ */
.main-content {
    min-height: calc(100vh - 73px);
    padding: 2rem;
}

/* アップロードエリア */
.upload-area {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.upload-area.dragover .upload-card {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
}

.upload-card {
    max-width: 480px;
    width: 100%;
    padding: 3rem;
    border: 2px dashed var(--border-color);
    border-radius: 1rem;
    background: var(--bg-primary);
    text-align: center;
    transition: var(--transition);
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    color: var(--primary-color);
}

.upload-card h2 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.upload-card p {
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.upload-btn {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.upload-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* リーダーコンテナ */
.reader-container {
    max-width: 900px;
    margin: 0 auto;
}

.reader-content {
    min-height: 70vh;
    padding: 2rem;
    background: var(--bg-primary);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-md);
    font-size: var(--font-size);
    line-height: var(--line-height);
    transition: opacity 0.2s ease;
}

.chapter-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.chapter-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chapter-content {
    color: var(--text-primary);
}

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

.chapter-content h1,
.chapter-content h2,
.chapter-content h3,
.chapter-content h4,
.chapter-content h5,
.chapter-content h6 {
    margin: 2rem 0 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chapter-content img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
    border-radius: 0.5rem;
}

.chapter-content blockquote {
    margin: 1.5rem 0;
    padding: 1rem;
    border-left: 4px solid var(--primary-color);
    background: var(--bg-secondary);
    font-style: italic;
}

.chapter-content code {
    padding: 0.125rem 0.25rem;
    background: var(--bg-tertiary);
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
}

.chapter-content pre {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    overflow-x: auto;
}

/* ページコントロール */
.page-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 2rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

.page-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.page-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.page-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* プログレスバー */
.progress-bar {
    position: relative;
    height: 4px;
    margin-top: 1rem;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    top: -1.5rem;
    right: 0;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal-content {
    width: 90%;
    max-width: 480px;
    padding: 2rem;
    background: var(--bg-primary);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* 文字サイズコントロール */
.font-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.size-btn {
    flex: 1;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.size-btn:nth-child(1) { font-size: 0.875rem; }
.size-btn:nth-child(2) { font-size: 1rem; }
.size-btn:nth-child(3) { font-size: 1.25rem; }
.size-btn:nth-child(4) { font-size: 1.5rem; }

.size-btn:hover {
    background: var(--bg-secondary);
}

.size-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.slider-container {
    margin-top: 1.5rem;
}

.slider-container label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.slider-container input[type="range"] {
    width: 100%;
    margin-bottom: 0.5rem;
}

/* しおり */
.bookmark-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.bookmark-empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-tertiary);
}

.bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
}

.bookmark-info strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.bookmark-info small {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.bookmark-actions {
    display: flex;
    gap: 0.5rem;
}

.bookmark-goto,
.bookmark-delete {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.bookmark-goto:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.bookmark-delete:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.add-bookmark-btn {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 0.5rem;
    background: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.add-bookmark-btn:hover {
    background: var(--primary-hover);
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
    }
    
    .app-title {
        font-size: 1.125rem;
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .menu-btn,
    .icon-btn {
        width: 2.25rem;
        height: 2.25rem;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .upload-card {
        padding: 2rem 1.5rem;
    }
    
    .reader-content {
        padding: 1.5rem 1rem;
    }
    
    .sidebar {
        width: 280px;
        left: -280px;
    }
    
    .sidebar.active {
        transform: translateX(280px);
    }
    
    .modal-content {
        width: 95%;
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .lang-select {
        font-size: 0.75rem;
        padding: 0.375rem;
    }
    
    .page-controls {
        flex-direction: column;
        gap: 1rem;
    }
    
    .page-btn {
        width: 100%;
    }
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reader-content {
    animation: fadeIn 0.3s ease;
}

/* プリント対応 */
@media print {
    .header,
    .sidebar,
    .page-controls,
    .progress-bar,
    .modal {
        display: none !important;
    }
    
    .reader-content {
        box-shadow: none;
        padding: 0;
    }
    
    body {
        background: white;
        color: black;
    }
}