/* ============ CSS Variables ============ */
:root {
  /* Colors - Green theme */
  --color-primary: #1a7f4b;
  --color-primary-light: #22a861;
  --color-primary-dark: #0d5c34;
  --color-accent: #ffd700;
  --color-accent-hover: #ffed4a;
  
  /* Background colors */
  --bg-main: linear-gradient(135deg, #0d3d23 0%, #1a5c3a 50%, #0d3d23 100%);
  --bg-navbar: linear-gradient(180deg, #1a5c3a 0%, #0d3d23 100%);
  --bg-dropdown: rgba(255, 255, 255, 0.98);
  --bg-glass: rgba(255, 255, 255, 0.1);
  
  /* Text colors */
  --text-light: #ffffff;
  --text-dark: #1a1a1a;
  --text-muted: #6b7280;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.25);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.3);
  
  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  
  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
  
  /* Typography */
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Poppins', var(--font-sans);
  
  /* Z-index layers */
  --z-dropdown: 100;
  --z-navbar: 200;
  --z-modal: 300;
  --z-tooltip: 400;
}

/* ============ Reset & Base ============ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  min-height: 100vh;
  color: var(--text-light);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ============ Typography ============ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

/* ============ Navbar ============ */
.navbar {
  position: sticky;
  top: 0;
  z-index: var(--z-navbar);
  background: var(--bg-navbar);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
}

.navbar__container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

.navbar__item {
  position: relative;
  list-style: none;
}

.navbar__link {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-light);
  transition: all var(--transition-normal);
  border-radius: var(--radius-md);
  position: relative;
}

.navbar__link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 3px;
  background: var(--color-accent);
  transition: all var(--transition-normal);
  transform: translateX(-50%);
  border-radius: var(--radius-full);
}

.navbar__link:hover {
  background: var(--bg-glass);
  color: var(--color-accent);
}

.navbar__link:hover::after {
  width: 60%;
}

.navbar__link--active {
  color: var(--color-accent);
}

/* Dropdown icon */
.navbar__link--dropdown::before {
  content: '';
  position: absolute;
  right: var(--spacing-sm);
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-top-color: currentColor;
  transition: transform var(--transition-fast);
}

.navbar__item:hover .navbar__link--dropdown::before {
  transform: translateY(-50%) rotate(180deg);
}

/* ============ Dropdown ============ */
.dropdown {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-dropdown);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  min-width: 280px;
  padding: var(--spacing-sm);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
  z-index: var(--z-dropdown);
}

.navbar__item:hover .dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.dropdown__link {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  color: var(--text-dark);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  transition: all var(--transition-fast);
}

.dropdown__link:hover {
  background: var(--color-primary);
  color: var(--text-light);
  transform: translateX(5px);
}

.dropdown__link--chapter {
  padding-left: var(--spacing-lg);
}

.dropdown__link--chapter::before {
  margin-right: var(--spacing-xs);
}

/* ============ Main Container ============ */
.main-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--spacing-lg);
  padding: var(--spacing-lg);
  min-height: calc(100vh - 70px);
  flex-wrap: nowrap;
  overflow-x: auto;
}

/* ============ Canvas Containers ============ */
.canvas-wrapper {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-xl);
  padding: 0;
  margin: 0;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  flex-shrink: 0;
  overflow: hidden;
  line-height: 0;
  font-size: 0;
}

/* Canvas de jeu (gauche) */
.canvas-wrapper:first-child {
  order: 1;
}

/* Canvas de texte (droite) */
.canvas-wrapper:last-child {
  order: 2;
}

/* ============ Mode Introduction ============ */
.intro-mode {
  justify-content: flex-start;
  padding-left: var(--spacing-xl);
}

.canvas-wrapper.hidden {
  display: none;
}

.canvas-wrapper:hover {
  transform: translateY(-2px);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.35);
}

.canvas-wrapper canvas {
  display: block;
  border-radius: var(--radius-xl);
  margin: 0;
  padding: 0;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn--primary {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: var(--text-light);
  box-shadow: var(--shadow-md);
}

.btn--primary:hover {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn--accent {
  background: linear-gradient(135deg, var(--color-accent-hover), var(--color-accent));
  color: var(--text-dark);
  box-shadow: var(--shadow-md);
}

.btn--accent:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn--danger {
  background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
  color: var(--text-light);
}

.btn--ghost {
  background: transparent;
  border: 2px solid var(--text-light);
  color: var(--text-light);
}

.btn--ghost:hover {
  background: var(--text-light);
  color: var(--color-primary-dark);
}

/* ============ Loading Indicator ============ */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

.loader__dot {
  width: 12px;
  height: 12px;
  background: var(--color-accent);
  border-radius: var(--radius-full);
  animation: bounce 1.4s ease-in-out infinite;
}

.loader__dot:nth-child(1) { animation-delay: 0s; }
.loader__dot:nth-child(2) { animation-delay: 0.2s; }
.loader__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

/* ============ Tooltips ============ */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-5px);
  background: var(--text-dark);
  color: var(--text-light);
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: var(--z-tooltip);
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* ============ Utility Classes ============ */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }

.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.hidden { display: none !important; }
.visible { display: block !important; }

/* ============ Animations ============ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.animate-fadeIn {
  animation: fadeIn var(--transition-slow) ease-out;
}

.animate-slideIn {
  animation: slideInLeft var(--transition-slow) ease-out;
}

.animate-pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ============ Scrollbar Styling ============ */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--color-primary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary-light);
}

/* ============ Responsive Design ============ */
@media (max-width: 2100px) {
  .main-container {
    flex-wrap: nowrap;
  }
}

@media (max-width: 1300px) {
  .main-container {
    flex-direction: column;
    align-items: center;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  :root {
    font-size: 14px;
  }
  
  .navbar__container {
    flex-wrap: wrap;
    justify-content: space-around;
  }
  
  .navbar__link {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.9rem;
  }
  
  .dropdown {
    min-width: 220px;
  }
  
  .main-container {
    padding: var(--spacing-md);
    gap: var(--spacing-md);
  }
  
  .canvas-wrapper {
    overflow-x: auto;
  }
}

@media (max-width: 480px) {
  .navbar__container {
    gap: 0;
  }
  
  .navbar__link {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
  }
}

/* ============ Print Styles ============ */
@media print {
  .navbar,
  .btn {
    display: none !important;
  }
  
  body {
    background: white;
    color: black;
  }
}

/* ============ Focus Styles (Accessibility) ============ */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* ============ Reduced Motion ============ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
