/* ==================== VARIABLES ==================== */
:root {
    --bg: #fefefe;
    --bg-secondary: #f5f5f5;
    --text: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #888;
    --accent: #4a7c59;
    --accent-hover: #3d6b4a;
    --border: #e5e5e5;
    --shadow: rgba(0,0,0,0.1);
    --overlay: rgba(0,0,0,0.5);
    --menu-bg: #ffffff;
    --radius: 12px;
    --font-serif: 'Georgia', 'Times New Roman', serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: var(--font-serif);
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    font-size: 18px;
    min-height: 100vh;
}

/* ==================== READER ==================== */
.reader {
    max-width: 900px;
    margin: 0 auto;
    padding: 3rem 2rem 6rem;
    min-height: 100vh;
}

.page-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border);
    z-index: 100;
}

.page-indicator-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}

.current-page-badge {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0.7;
    transition: opacity 0.3s;
    z-index: 50;
}

/* ==================== IMAGE VIEW ==================== */
.image-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.image-view img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px var(--shadow);
    transition: transform 0.2s ease;
    transform-origin: top center;
}

.image-view img.zoom-70 { transform: scale(0.7); }
.image-view img.zoom-80 { transform: scale(0.8); }
.image-view img.zoom-90 { transform: scale(0.9); }
.image-view img.zoom-100 { transform: scale(1); }
.image-view img.zoom-110 { transform: scale(1.1); }
.image-view img.zoom-120 { transform: scale(1.2); }
.image-view img.zoom-130 { transform: scale(1.3); }
.image-view img.zoom-140 { transform: scale(1.4); }

.image-view.hidden { display: none; }

.zoom-trigger {
    position: fixed;
    left: 0;
    top: 0;
    width: 40px;
    height: 100%;
    z-index: 99;
}

.zoom-controls {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%) translateX(-100%);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 12px 12px 0;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    box-shadow: 2px 0 8px var(--shadow);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    z-index: 100;
}

.zoom-trigger:hover ~ .zoom-controls,
.zoom-controls:hover {
    transform: translateY(-50%) translateX(0);
    opacity: 1;
}

.zoom-controls span {
    color: var(--text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
}

.zoom-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    transition: all 0.2s;
    min-width: 45px;
    text-align: center;
}

.zoom-btn:hover, .zoom-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ==================== TEXT VIEW ==================== */
.text-view { display: none; }
.text-view.active { display: block; }

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

.article-header h1 {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

.article-header .section-label {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.original-content h2 { font-size: 1.5rem; margin: 2rem 0 1rem; }
.original-content h3 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }
.original-content p { margin-bottom: 1.25rem; text-align: justify; }
.original-content ul, .original-content ol { margin: 1rem 0 1.5rem 1.5rem; }
.original-content li { margin-bottom: 0.5rem; }

/* ==================== SPECIAL BOXES ==================== */
.simple-explanation {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid #f59e0b;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 1.05rem;
}

.simple-explanation h4 {
    font-family: var(--font-sans);
    font-size: 1rem;
    color: #92400e;
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.simple-explanation p { color: #78350f; margin-bottom: 0.5rem; }
.simple-explanation ul { color: #78350f; margin-left: 1.25rem; }

.definition-box {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border-left: 4px solid #10b981;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.definition-box h4 {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: #065f46;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.algorithm-box {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-left: 4px solid #3b82f6;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.algorithm-box h4 {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: #1e40af;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.highlight-box {
    background: linear-gradient(135deg, #f3e8ff 0%, #e9d5ff 100%);
    border-left: 4px solid #9333ea;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 var(--radius) var(--radius) 0;
}

.highlight-box h4 {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: #6b21a8;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

/* ==================== D3 GRAPHS ==================== */
.graph-container {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1.5rem 0;
    min-height: 300px;
    position: relative;
    border: 1px solid var(--border);
}

.graph-container svg {
    width: 100%;
    height: 100%;
    min-height: 280px;
}

.graph-container .node { cursor: pointer; }
.graph-container .node circle {
    fill: var(--accent);
    stroke: #fff;
    stroke-width: 3px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    transition: all 0.2s;
}

.graph-container .node:hover circle {
    fill: var(--accent-hover);
    r: 28;
}

.graph-container .node.selected circle {
    fill: #f59e0b;
    stroke: #92400e;
}

.graph-container .node.neighbor circle {
    fill: #3b82f6;
}

.graph-container .node text {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    fill: white;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
}

.graph-container .link {
    stroke: #94a3b8;
    stroke-width: 2.5px;
    stroke-linecap: round;
    transition: all 0.2s;
}

.graph-container .link.highlighted {
    stroke: #f59e0b;
    stroke-width: 4px;
}

.graph-title {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 0.5rem;
}

.graph-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.graph-legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.graph-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.demo-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    justify-content: center;
}

.demo-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.demo-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.demo-btn.active {
    background: #f59e0b;
}

.demo-status {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    margin-top: 0.75rem;
    text-align: center;
}

/* ==================== CODE BLOCKS ==================== */
.code-block {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border-radius: var(--radius);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    overflow-x: auto;
    line-height: 1.5;
}

.code-block .keyword { color: #569cd6; }
.code-block .function { color: #dcdcaa; }
.code-block .comment { color: #6a9955; }
.code-block .string { color: #ce9178; }
.code-block .number { color: #b5cea8; }

/* ==================== MENU ==================== */
.menu-trigger {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    background: var(--text);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000;
}

.menu-trigger:hover {
    background: var(--accent);
    transform: scale(1.05);
}

.menu-trigger.active svg { transform: rotate(45deg); }

.context-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 999;
}

.context-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.context-menu {
    position: fixed;
    bottom: 6rem;
    right: 2rem;
    background: var(--menu-bg);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    min-width: 280px;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1001;
    overflow: hidden;
}

.context-menu.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

.menu-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-sans);
}

.menu-header h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.menu-header .page-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.menu-section {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.menu-section:last-child { border-bottom: none; }

.menu-section-label {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0.25rem 1.25rem 0.5rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.menu-item:hover { background: var(--bg-secondary); }
.menu-item.active { color: var(--accent); }
.menu-item svg { width: 20px; height: 20px; color: var(--text-muted); }
.menu-item.active svg { color: var(--accent); }

.menu-item .shortcut {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.nav-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
}

.nav-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.nav-btn:hover:not(:disabled) {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-input {
    width: 70px;
    text-align: center;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
}

.page-input:focus {
    outline: none;
    border-color: var(--accent);
}

.page-total {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ==================== KEYBOARD HINT ==================== */
.keyboard-hint {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.5;
}

.keyboard-hint kbd {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    margin: 0 0.1rem;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    body { font-size: 16px; }
    .reader { padding: 2rem 1.25rem 5rem; }
    .menu-trigger { bottom: 1.5rem; right: 1.5rem; width: 50px; height: 50px; }
    .context-menu { right: 1rem; left: 1rem; bottom: 5rem; min-width: auto; }
    .keyboard-hint { display: none; }
}

@media print {
    .menu-trigger, .context-menu, .context-menu-overlay,
    .page-indicator, .current-page-badge, .keyboard-hint { display: none; }
    .reader { max-width: 100%; padding: 0; }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
