:root {
  --primary: #4361ee;
  --primary-dark: #3a56d4;
  --secondary: #3f37c9;
  --accent: #f72585;
  --dark: #1a1a2e;
  --light: #f8f9fa;
  --gray: #6c757d;
  --success: #4cc9f0;
  --sidebar-width: 300px;
  --font-size-base: 1.1rem;
  --header-height: 68px;
  --mobile-breakpoint: 992px;
}

/* Reset et base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.8;
  color: #333;
  background-color: #f9f9f9;
  font-size: var(--font-size-base);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--dark), var(--secondary));
  color: white;
  padding: 1rem 0;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-height);
}

.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* Menu Hamburger */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
}

.home-link {
  color: white;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  text-decoration: none;
}

.logo i {
  color: var(--accent);
}

.editor-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.6rem 1.2rem;
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.3s ease;
}

.editor-link:hover {
  background-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Main Layout */
.main-wrapper {
  display: flex;
  flex: 1;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--dark);
  color: white;
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  position: sticky;
  top: var(--header-height);
  padding: 1.5rem;
  transition: transform 0.3s ease;
  z-index: 900;
}

.sidebar-header {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1rem;
}

.sidebar-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-title i {
  color: var(--accent);
}

.sidebar-menu {
  padding: 0.5rem 0;
}

.sidebar-menu h3 {
  font-size: 1rem;
  text-transform: uppercase;
  color: var(--gray);
  margin: 1.8rem 0 0.8rem;
  padding-left: 0.5rem;
  letter-spacing: 0.5px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  padding: 0.8rem 1rem;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.3s ease;
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
}

.sidebar-menu a:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.sidebar-menu a.active {
  background-color: rgba(67, 97, 238, 0.2);
  color: white;
  font-weight: 600;
  position: relative;
}

.sidebar-menu a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--accent);
  border-radius: 0 3px 3px 0;
}

.sidebar-menu a i {
  margin-right: 0.8rem;
  width: 20px;
  text-align: center;
  font-size: 0.95rem;
}

.chapter-number {
  font-weight: bold;
  margin-right: 8px;
  color: var(--gray);
}

/* Main content */
.main-content {
  flex: 1;
  padding: 2rem 3rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  animation: fadeIn 0.6s ease-out;
}

/* Contenu pédagogique */
h1 {
  color: var(--dark);
  font-size: 2.4rem;
  margin: 1.5rem 0;
  line-height: 1.3;
  position: relative;
  padding-bottom: 1rem;
}

h1::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 120px;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
}

h2 {
  color: var(--secondary);
  font-size: 1.9rem;
  margin: 2.5rem 0 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #eee;
}

h3 {
  color: var(--primary);
  font-size: 1.5rem;
  margin: 2rem 0 1.2rem;
}

p {
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
  line-height: 1.8;
}

ul, ol {
  margin-bottom: 2rem;
  padding-left: 2.2rem;
  font-size: 1.1rem;
}

li {
  margin-bottom: 0.8rem;
  line-height: 1.7;
}

/* Blocs spéciaux */
.example, .tip, .warning {
  padding: 1.8rem;
  margin: 2.5rem 0;
  border-radius: 8px;
  border-left: 4px solid;
  background-color: white;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.05);
  font-size: 1.1rem;
}

.example {
  border-color: var(--primary);
}

.tip {
  border-color: var(--success);
  background-color: #f0f9ff;
}

.warning {
  border-color: var(--accent);
  background-color: #fff0f3;
}

/* Blocs de code */
pre[class*="language-"] {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  margin: 2rem 0;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  font-size: 1rem;
}

code:not([class*="language-"]) {
  background-color: #f0f4ff;
  color: var(--primary-dark);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 1em;
}

/* Navigation entre chapitres */
.chapter-navigation {
  display: flex;
  justify-content: space-between;
  margin: 4rem 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.3s ease;
  font-size: 1.1rem;
}

.btn-outline {
  background-color: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-outline:hover {
  background-color: rgba(67, 97, 238, 0.1);
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  border: 2px solid var(--primary);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
}

/* Bouton retour en haut */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background-color: var(--accent);
  color: white;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(247, 37, 133, 0.3);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 99;
  border: none;
}

.back-to-top.visible {
  opacity: 1;
}

.back-to-top:hover {
  background-color: #e5177e;
  transform: translateY(-3px);
}

/* Footer */
footer {
  background-color: var(--dark);
  color: white;
  padding: 3rem 0 1.5rem;
  width: 100%;
  margin-top: auto;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
}

.footer-column h3 {
  color: white;
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-column ul {
  list-style: none;
}

.footer-column li {
  margin-bottom: 0.8rem;
}

.footer-column a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
}

.footer-column a:hover {
  color: white;
  padding-left: 5px;
}

.copyright {
  text-align: center;
  padding-top: 2rem;
  margin-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.95rem;
}

/* Version mobile */
@media (max-width: 992px) {
  .menu-toggle {
    display: block;
  }

  .sidebar {
    position: fixed;
    transform: translateX(-100%);
    height: 100vh;
    top: 0;
    left: 0;
    z-index: 1000;
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
  }

  .sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  .main-content {
    padding: 1.5rem;
  }
}

/* Optimisation pour très petits écrans */
@media (max-width: 576px) {
  :root {
    --font-size-base: 1rem;
  }
  
  h1 {
    font-size: 1.8rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  pre[class*="language-"] {
    margin: 1.5rem -1.5rem;
    width: calc(100% + 3rem);
    border-radius: 0;
  }

  .header-container {
    padding: 0 1rem;
  }

  .chapter-navigation {
    flex-direction: column;
    gap: 1rem;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}