Both are incomplete.
- User
Both are incomplete.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Both are incomplete.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
You're right. Let me provide a complete implementation with a full book structure and proper sidebar functionality:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Healthy Life Guide</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Georgia', 'Times New Roman', serif;
}
body {
line-height: 1.6;
color: #333;
overflow-x: hidden;
background: #fafafa;
}
/* Burger Menu */
.burger-btn {
display: none;
position: fixed;
top: 1rem;
left: 1rem;
z-index: 1001;
background: #2c3e50;
color: white;
border: none;
padding: 0.5rem 0.75rem;
border-radius: 4px;
cursor: pointer;
font-size: 1.25rem;
transition: all 0.3s ease;
}
.burger-btn:hover {
background: #34495e;
}
/* Sidebar (TOC) */
.sidebar {
position: fixed;
top: 0;
left: 0;
width: 300px;
height: 100vh;
background: #fff;
padding: 1.5rem;
border-right: 1px solid #e0e0e0;
overflow-y: auto;
transition: transform 0.3s ease;
z-index: 1000;
box-shadow: 2px 0 10px rgba(0,0,0,0.1);
}
.sidebar.collapsed {
transform: translateX(-100%);
}
.sidebar-header {
margin-bottom: 1.5rem;
padding-bottom: 1rem;
border-bottom: 2px solid #e0e0e0;
}
.sidebar-header h2 {
font-size: 1.5rem;
color: #2c3e50;
margin-bottom: 0.5rem;
}
.toc-controls {
display: flex;
gap: 0.5rem;
}
.toc-btn {
padding: 0.375rem 0.75rem;
background: #2c3e50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.875rem;
flex: 1;
transition: all 0.2s ease;
}
.toc-btn:hover {
background: #34495e;
transform: translateY(-1px);
}
.toc-list {
list-style: none;
}
.toc-item {
margin: 0.125rem 0;
}
.toc-link-container {
display: flex;
align-items: center;
}
.toc-link {
display: block;
padding: 0.5rem 0.75rem;
border-radius: 4px;
cursor: pointer;
text-decoration: none;
color: #2c3e50;
transition: all 0.2s ease;
flex: 1;
font-size: 0.9rem;
}
.toc-link:hover {
background: #f0f0f0;
transform: translateX(2px);
}
.toc-link.active {
background: #2c3e50;
color: white;
font-weight: 500;
}
.toggle-btn {
margin-right: 0.5rem;
background: #e0e0e0;
border: none;
width: 1.25rem;
height: 1.25rem;
border-radius: 3px;
cursor: pointer;
font-size: 0.75rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
font-family: monospace;
}
.toggle-btn:hover {
background: #d0d0d0;
}
.sub-toc {
list-style: none;
margin-left: 1.5rem;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.sub-toc.open {
max-height: 2000px;
}
/* Level-specific styling */
.level-1 > .toc-link-container > .toc-link {
font-weight: 600;
font-size: 1rem;
}
.level-2 > .toc-link-container > .toc-link {
font-weight: 500;
font-size: 0.925rem;
}
.level-3 > .toc-link-container > .toc-link {
font-weight: 400;
font-size: 0.875rem;
color: #555;
}
/* Main Content */
.main-content {
margin-left: 300px;
padding: 2rem;
transition: margin-left 0.3s ease;
min-height: 100vh;
}
.content-section {
display: none;
max-width: 800px;
margin: 0 auto;
background: white;
padding: 3rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.content-section.active {
display: block;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Typography */
h1 {
font-size: 2.5rem;
margin-bottom: 1.5rem;
color: #2c3e50;
border-bottom: 3px solid #e0e0e0;
padding-bottom: 0.75rem;
font-weight: 300;
letter-spacing: -0.5px;
}
h2 {
font-size: 2rem;
margin: 2rem 0 1rem;
color: #34495e;
font-weight: 400;
}
h3 {
font-size: 1.5rem;
margin: 1.5rem 0 0.75rem;
color: #495057;
font-weight: 500;
}
p {
margin-bottom: 1rem;
font-size: 1.1rem;
color: #555;
line-height: 1.8;
text-align: justify;
}
ul, ol {
margin-bottom: 1rem;
padding-left: 2rem;
color: #555;
}
li {
margin-bottom: 0.5rem;
line-height: 1.7;
}
/* Responsive Design */
@media (max-width: 768px) {
.burger-btn {
display: block;
}
.sidebar {
transform: translateX(-100%);
}
.sidebar.active {
transform: translateX(0);
}
.main-content {
margin-left: 0;
padding: 1rem;
padding-top: 4rem;
}
.content-section {
padding: 1.5rem;
}
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.5rem;
}
h3 {
font-size: 1.25rem;
}
}
/* Overlay for mobile */
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.5);
z-index: 999;
opacity: 0;
transition: opacity 0.3s ease;
}
.overlay.active {
display: block;
opacity: 1;
}
</style>
</head>
<body>
<button class="burger-btn">☰</button>
<div class="overlay"></div>
<div class="sidebar">
<div class="sidebar-header">
<h2>Table of Contents</h2>
<div class="toc-controls">
<button class="toc-btn" id="openAll">Open All</button>
<button class="toc-btn" id="collapseAll">Collapse All</button>
</div>
</div>
<ul class="toc-list" id="toc"></ul>
</div>
<main class="main-content">
<div class="content-section active" id="intro">
<h1>Healthy, Productive & Meaningful Life Guide</h1>
<p>Welcome to your comprehensive guide to living a healthier, more productive, and deeply meaningful life. This book combines evidence-based research with practical wisdom to help you create sustainable changes in all areas of your life.</p>
<p>Through carefully structured chapters, you'll discover how to build strong foundations in health, master productivity without burning out, and create meaningful connections that enrich your daily experience.</p>
<p>Select any section from the table of contents to begin your journey toward a more fulfilling life.</p>
</div>
</main>
<script>
// Comprehensive book content data
const bookSections = [
{
id: 'foundations',
title: 'Part I: Core Foundations of a Healthy Life',
level: 1,
content: `
<p>The foundation of any meaningful life starts with intentional choices in three key areas: physical health, mental clarity, and emotional balance. Without these fundamentals in place, it becomes nearly impossible to sustain productivity or find deep meaning in our daily activities.</p>
<p>This section will help you build a solid base by understanding the interdependence of these elements and how they contribute to overall well-being. We'll explore evidence-based strategies that have stood the test of time, while also incorporating the latest research in health and wellness.</p>
<p>When these foundations are strong, you'll have the energy, focus, and resilience to pursue your goals and find deeper meaning in your daily experiences. Remember, this is not about perfection but about creating sustainable practices that support your unique life circumstances.</p>
`
},
{
id: 'nutrition',
title: 'Chapter 1: Nutrition for Sustained Energy',
level: 2,
parent: 'foundations',
content: `
<p>What you eat directly impacts your energy levels, mood, cognitive function, and long-term health. The right nutritional approach can transform how you feel and perform each day, while poor nutrition can undermine even your best efforts in other areas of life.</p>
<h3>Understanding Nutritional Basics</h3>
<p>Before diving into specific dietary recommendations, it's crucial to understand the fundamental role that nutrition plays in our bodies. Every cell in your body depends on the nutrients you provide through food. These nutrients serve as building blocks for tissues, fuel for energy, and catalysts for countless biochemical reactions.</p>
<h3>The Modern Nutrition Challenge</h3>
<p>In our fast-paced world, convenience often trumps quality when it comes to food choices. Processed foods dominate supermarket shelves, and busy schedules make it tempting to rely on quick, nutrient-poor options. Breaking free from these patterns requires both knowledge and practical strategies.</p>
`
},
{
id: 'nutrition-principles',
title: 'Core Nutritional Principles',
level: 3,
parent: 'nutrition',
content: `
<p>Building a sustainable approach to nutrition starts with understanding and applying these fundamental principles:</p>
<h3>1. Whole Foods First</h3>
<p>Focus on whole, unprocessed foods that provide balanced macronutrients (proteins, carbs, fats) and essential micronutrients. The less processing a food has undergone, the more nutritional value it typically retains. Think of foods that look like they did when they came from nature.</p>
<h3>2. Colorful Variety</h3>
<p>Aim for 5-7 servings of fruits and vegetables daily, emphasizing variety in color. Each color represents different phytonutrients and antioxidants that support cellular health and reduce inflammation. Red tomatoes provide lycopene, orange carrots offer beta-carotene, and dark leafy greens deliver folate and iron.</p>
<h3>3. Adequate Hydration</h3>
<p>Stay hydrated with 8-10 cups of water daily, adjusting for activity level and climate. Proper hydration supports every bodily function, from nutrient transport to waste elimination. Consider starting each day with a glass of water to rehydrate after the overnight fast.</p>
<h3>4. Mindful Eating</h3>
<p>Slow down and pay attention to your meals. Eating mindfully improves digestion, increases satisfaction, and helps you recognize true hunger and fullness cues. Put away devices during meals and focus on the flavors, textures, and experience of eating.</p>
`
},
{
id: 'meal-timing',
title: 'Strategic Meal Timing',
level: 3,
parent: 'nutrition',
content: `
<h3>Optimizing When You Eat</h3>
<p>While what you eat is crucial, when you eat can significantly impact your energy levels, metabolism, and overall health. Strategic meal timing aligns your eating patterns with your body's natural rhythms.</p>
<h3>Balanced Meal Frequency</h3>
<p>Eat small, balanced meals every 3-4 hours to maintain stable blood sugar levels and avoid energy crashes. This approach helps regulate hunger hormones and prevents the overeating that often occurs after long periods without food. A typical day might include breakfast, mid-morning snack, lunch, afternoon snack, and dinner.</p>
<h3>The Power of Overnight Fasting</h3>
<p>Consider a 12-hour overnight fasting window to support cellular repair processes and digestive rest. For example, finish dinner by 7pm and have breakfast no earlier than 7am the next day. This natural fasting period allows your body to shift from digestion to repair and regeneration.</p>
<h3>Pre and Post-Workout Nutrition</h3>
<p>If you exercise regularly, timing your nutrition around workouts becomes important. A light snack 30-60 minutes before exercise provides energy, while post-workout nutrition within 30 minutes helps with recovery and muscle repair. Focus on combining protein and carbohydrates for optimal results.</p>
`
},
{
id: 'sleep',
title: 'Chapter 2: Restorative Sleep Practices',
level: 2,
parent: 'foundations',
content: `
<p>Quality sleep is the foundation of physical health, mental clarity, and emotional resilience. During sleep, your body repairs tissues, consolidates memories, and regulates hormones. Yet in our always-on society, sleep is often the first thing we sacrifice.</p>
<h3>The Science of Sleep</h3>
<p>Understanding sleep cycles helps us optimize our rest. Each night, we cycle through different sleep stages, including light sleep, deep sleep, and REM sleep. Each stage serves specific functions, from physical restoration to memory consolidation and emotional processing.</p>
<h3>The Cost of Sleep Deprivation</h3>
<p>Chronic sleep deprivation affects every system in your body. It impairs cognitive function, weakens immune response, disrupts hormone balance, and increases risk for numerous health conditions. Even one night of poor sleep can impact your mood, decision-making, and productivity the next day.</p>
`
},
{
id: 'sleep-environment',
title: 'Creating the Ideal Sleep Environment',
level: 3,
parent: 'sleep',
content: `
<h3>Your Sleep Sanctuary</h3>
<p>Transform your bedroom into a sleep sanctuary that promotes deep, restorative rest. Every element of your sleep environment sends signals to your brain about whether it's time to be alert or time to rest.</p>
<h3>Temperature Control</h3>
<p>Maintain a cool bedroom temperature between 65-68°F (18-20°C). Your body temperature naturally drops during sleep, and a cool environment supports this process. Consider breathable bedding materials and sleepwear that help regulate temperature throughout the night.</p>
<h3>Darkness and Light</h3>
<p>Create complete darkness with blackout curtains or an eye mask. Even small amounts of light can disrupt melatonin production and sleep quality. Remove or cover LED lights from electronics, and consider using dim red lights if you need illumination during the night.</p>
<h3>Sound Management</h3>
<p>Minimize disruptive noises with white noise machines, fans, or earplugs. Consistent background sound can mask sudden noises that might wake you. Some people find nature sounds or gentle music helpful, while others prefer complete silence.</p>
<h3>Comfort Essentials</h3>
<p>Invest in a quality mattress and pillows that support your preferred sleep position. Your mattress should maintain proper spinal alignment while providing pressure relief. Replace pillows regularly and choose materials that suit your needs for support and temperature regulation.</p>
`
},
{
id: 'movement',
title: 'Chapter 3: Movement as Medicine',
level: 2,
parent: 'foundations',
content: `
<p>Regular physical activity is one of the most powerful tools we have for maintaining health and vitality. Movement isn't just about building muscle or losing weight—it's medicine for your entire body and mind, influencing everything from mood to cognitive function to longevity.</p>
<h3>The Holistic Benefits of Movement</h3>
<p>When we move our bodies, we trigger a cascade of positive changes. Exercise improves cardiovascular health, strengthens bones and muscles, enhances immune function, and releases endorphins that boost mood. Regular movement also improves sleep quality, reduces stress, and enhances cognitive performance.</p>
<h3>Redefining Exercise</h3>
<p>Many people associate exercise with grueling gym sessions or competitive sports. However, beneficial movement comes in many forms. The key is finding activities that you enjoy and can sustain over time. Movement should enhance your life, not feel like punishment.</p>
`
},
{
id: 'productivity',
title: 'Part II: Productivity Without Burnout',
level: 1,
content: `
<p>True productivity isn't about doing more—it's about doing what matters most. In a world that glorifies busyness, we must learn to work smarter, not harder. This section teaches sustainable productivity strategies that respect your energy, boundaries, and long-term wellbeing.</p>
<p>By focusing on effectiveness rather than mere efficiency, you'll accomplish more meaningful work while maintaining balance in your life. We'll explore how to harness your natural energy rhythms, eliminate distractions, and create systems that support consistent progress toward your goals.</p>
<p>Remember, productivity is not an end in itself but a means to create the life you want. The goal is to be productive in service of your values and vision, not to squeeze every possible minute of work from each day.</p>
`
},
{
id: 'focus',
title: 'Chapter 4: Mastering Deep Work',
level: 2,
parent: 'productivity',
content: `
<p>In our hyper-connected world, the ability to focus deeply on cognitively demanding tasks has become both increasingly rare and increasingly valuable. Deep work—the ability to concentrate without distraction on challenging tasks—is the key to producing high-quality work and achieving breakthrough results.</p>
<h3>The Deep Work Advantage</h3>
<p>When you work deeply, you're able to learn faster, produce better output, and find more satisfaction in your work. Deep work allows you to push your cognitive capabilities to their limit, creating value that's hard to replicate in our increasingly automated world.</p>
<h3>The Attention Residue Problem</h3>
<p>Every time you switch between tasks, part of your attention remains stuck on the previous task. This "attention residue" reduces your cognitive performance on the current task. By working deeply on one thing at a time, you avoid this productivity drain and maintain peak mental performance.</p>
`
},
{
id: 'focus-strategies',
title: 'Deep Work Implementation Strategies',
level: 3,
parent: 'focus',
content: `
<h3>Time Blocking for Deep Work</h3>
<p>Schedule 90-minute deep work blocks with 15-minute breaks between them. This aligns with your brain's natural ultradian rhythm—the cycles of high and low alertness we experience throughout the day. During these blocks, focus exclusively on one important task without interruption.</p>
<h3>The Digital Detox Protocol</h3>
<p>Eliminate digital distractions ruthlessly during deep work sessions. Turn off all notifications, use website blockers to prevent access to distracting sites, and keep your phone in another room or in airplane mode. Consider using apps that lock you out of distracting programs during designated work times.</p>
<h3>The Pomodoro Variation</h3>
<p>For tasks requiring less intense concentration or when your energy is lower, use the Pomodoro Technique: 25 minutes of focused work followed by a 5-minute break. After four pomodoros, take a longer 15-30 minute break. This technique helps maintain focus while preventing mental fatigue.</p>
<h3>Rituals and Routines</h3>
<p>Develop specific rituals that signal the start of deep work. This might include clearing your desk, making a specific beverage, putting on noise-canceling headphones, or reviewing your goals for the session. Consistent rituals help your brain transition into a focused state more quickly.</p>
`
},
{
id: 'energy',
title: 'Chapter 5: Energy Management',
level: 2,
parent: 'productivity',
content: `
<p>Time management gets all the attention, but energy management is the real secret to sustainable productivity. You can have all the time in the world, but without energy, you won't be able to use it effectively. Learning to manage and renew your energy is crucial for long-term success.</p>
<h3>The Four Types of Energy</h3>
<p>Human energy exists in four dimensions: physical, emotional, mental, and spiritual. Each type influences the others, and depleting any one dimension affects your overall capacity. Sustainable productivity requires managing and renewing energy in all four dimensions.</p>
<h3>Energy Rhythms</h3>
<p>Everyone has natural rhythms of high and low energy throughout the day. Some people are morning larks, while others are night owls. By understanding and working with your natural rhythms rather than against them, you can schedule your most important work during peak energy times.</p>
`
},
{
id: 'meaning',
title: 'Part III: Creating a Meaningful Life',
level: 1,
content: `
<p>Health and productivity provide the foundation, but meaning gives life its richness and depth. This final section explores how to cultivate deeper connections, find your purpose, and create a life that feels genuinely fulfilling.</p>
<p>Meaning doesn't come from achievement alone but from the quality of our relationships, our contribution to something larger than ourselves, and our ability to align our daily actions with our deepest values. We'll explore practical ways to infuse more meaning into every aspect of your life.</p>
<p>Remember, a meaningful life looks different for everyone. The goal is not to follow someone else's blueprint but to discover and create your own unique path to fulfillment.</p>
`
},
{
id: 'relationships',
title: 'Chapter 6: Building Meaningful Relationships',
level: 2,
parent: 'meaning',
content: `
<p>Human beings are fundamentally social creatures. The quality of our relationships is one of the strongest predictors of happiness, health, and longevity. Yet in our busy, digitally-mediated world, deep connections can be challenging to build and maintain.</p>
<h3>The Connection Crisis</h3>
<p>Despite being more "connected" than ever through technology, many people report feeling lonely and isolated. True connection requires vulnerability, presence, and emotional availability—qualities that can't be replaced by digital communication alone.</p>
<h3>Quality Over Quantity</h3>
<p>Research consistently shows that having a few deep, meaningful relationships is far more beneficial than having many superficial connections. It's better to invest deeply in a small circle of relationships than to spread yourself thin trying to maintain numerous shallow connections.</p>
`
},
{
id: 'purpose',
title: 'Chapter 7: Discovering Your Purpose',
level: 2,
parent: 'meaning',
content: `
<p>Purpose provides direction and meaning to our lives. It's the sense that what we do matters, that we're contributing to something beyond ourselves. While purpose can feel elusive or abstract, it often emerges from the intersection of our values, strengths, and the needs we see in the world.</p>
<h3>Purpose vs. Passion</h3>
<p>Popular culture often conflates purpose with passion, suggesting we should "follow our passion" to find fulfillment. However, purpose is often quieter and more sustainable than passion. It's less about intense emotion and more about consistent contribution aligned with your values.</p>
<h3>The Evolution of Purpose</h3>
<p>Your purpose isn't fixed—it evolves as you grow and change. What gives your life meaning at 25 may be different from what provides meaning at 45 or 65. Embracing this evolution allows you to remain flexible while staying true to your core values.</p>
`
},
{
id: 'legacy',
title: 'Chapter 8: Creating Your Legacy',
level: 2,
parent: 'meaning',
content: `
<p>Legacy isn't just about what we leave behind when we're gone—it's about the impact we have every day through our choices, actions, and relationships. Creating a meaningful legacy starts with being intentional about how we show up in the world right now.</p>
<h3>Daily Legacy Building</h3>
<p>Every interaction is an opportunity to build your legacy. The way you treat others, the work you produce, and the example you set all contribute to the lasting impact you'll have on the world. Small, consistent actions often create more lasting change than grand gestures.</p>
<h3>Beyond Personal Achievement</h3>
<p>A meaningful legacy extends beyond personal accomplishments to include how we've helped others grow, the problems we've helped solve, and the positive changes we've contributed to in our communities. Consider how your unique skills and experiences can serve others.</p>
`
}
];
// DOM Elements
const tocContainer = document.getElementById('toc');
const mainContent = document.querySelector('.main-content');
const burgerBtn = document.querySelector('.burger-btn');
const sidebar = document.querySelector('.sidebar');
const overlay = document.querySelector('.overlay');
const openAllBtn = document.getElementById('openAll');
const collapseAllBtn = document.getElementById('collapseAll');
// Build hierarchical structure
function buildHierarchy() {
const hierarchy = {};
const rootItems = [];
bookSections.forEach(section => {
if (!section.parent) {
rootItems.push(section);
hierarchy[section.id] = [];
}
});
bookSections.forEach(section => {
if (section.parent) {
if (!hierarchy[section.parent]) {
hierarchy[section.parent] = [];
}
hierarchy[section.parent].push(section);
}
});
return { rootItems, hierarchy };
}
// Build TOC recursively
function buildTOCItem(section, hierarchy) {
const li = document.createElement('li');
li.className = `toc-item level-${section.level}`;
const container = document.createElement('div');
container.className = 'toc-link-container';
// Add toggle button if section has children
if (hierarchy[section.id] && hierarchy[section.id].length > 0) {
const toggleBtn = document.createElement('button');
toggleBtn.className = 'toggle-btn';
toggleBtn.textContent = '+';
toggleBtn.addEventListener('click', toggleSubToc);
container.appendChild(toggleBtn);
}
// Add TOC link
const link = document.createElement('span');
link.className = 'toc-link';
link.textContent = section.title;
link.dataset.id = section.id;
link.addEventListener('click', handleSectionClick);
container.appendChild(link);
li.appendChild(container);
// Add children if they exist
if (hierarchy[section.id] && hierarchy[section.id].length > 0) {
const subToc = document.createElement('ul');
subToc.className = 'sub-toc';
hierarchy[section.id].forEach(child => {
subToc.appendChild(buildTOCItem(child, hierarchy));
});
li.appendChild(subToc);
}
return li;
}
// Initialize TOC
function buildTOC() {
const { rootItems, hierarchy } = buildHierarchy();
rootItems.forEach(section => {
tocContainer.appendChild(buildTOCItem(section, hierarchy));
});
}
// TOC interaction handlers
function toggleSubToc(e) {
const subToc = e.target.parentElement.nextElementSibling;
if (subToc && subToc.classList.contains('sub-toc')) {
subToc.classList.toggle('open');
e.target.textContent = subToc.classList.contains('open') ? '−' : '+';
}
}
function handleSectionClick(e) {
const sectionId = e.target.dataset.id;
const section = bookSections.find(s => s.id === sectionId);
// Update active state
document.querySelectorAll('.toc-link').forEach(link => {
link.classList.remove('active');
});
e.target.classList.add('active');
// Update content
showContent(section);
// Close sidebar on mobile
if (window.innerWidth <= 768) {
sidebar.classList.add('collapsed');
sidebar.classList.remove('active');
overlay.classList.remove('active');
}
}
function showContent(section) {
// Hide all sections
document.querySelectorAll('.content-section').forEach(sec => {
sec.classList.remove('active');
});
// Check if section already exists
let contentSection = document.getElementById(section.id);
if (!contentSection) {
// Create new section
contentSection = document.createElement('div');
contentSection.className = 'content-section';
contentSection.id = section.id;
// Build heading based on level
const heading = document.createElement(`h${section.level}`);
heading.textContent = section.title;
contentSection.innerHTML = heading.outerHTML + section.content;
mainContent.appendChild(contentSection);
}
contentSection.classList.add('active');
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// Control buttons
openAllBtn.addEventListener('click', () => {
document.querySelectorAll('.sub-toc').forEach(toc => {
toc.classList.add('open');
});
document.querySelectorAll('.toggle-btn').forEach(btn => {
btn.textContent = '−';
});
});
collapseAllBtn.addEventListener('click', () => {
document.querySelectorAll('.sub-toc').forEach(toc => {
toc.classList.remove('open');
});
document.querySelectorAll('.toggle-btn').forEach(btn => {
btn.textContent = '+';
});
});
// Mobile menu handling
burgerBtn.addEventListener('click', () => {
sidebar.classList.toggle('active');
overlay.classList.toggle('active');
});
overlay.addEventListener('click', () => {
sidebar.classList.add('collapsed');
sidebar.classList.remove('active');
overlay.classList.remove('active');
});
// Initialize on load
buildTOC();
// Handle responsive behavior
window.addEventListener('resize', () => {
if (window.innerWidth > 768) {
sidebar.classList.remove('collapsed');
sidebar.classList.remove('active');
overlay.classList.remove('active');
} else {
if (!sidebar.classList.contains('active')) {
sidebar.classList.add('collapsed');
}
}
});
// Initial responsive check
if (window.innerWidth <= 768) {
sidebar.classList.add('collapsed');
}
</script>
</body>
</html>
This complete implementation includes:
Full Book Structure:
Complete Sidebar/TOC:
Responsive Design:
Professional Book Formatting:
Interactive Features:
The content covers comprehensive topics about healthy living, productivity, and creating meaning, with each section containing substantive information that would be found in an actual self-help book.