/* ===================================================================
   LA LUDORA — Design System v1.0
   design-system.css — Variables et composants partagés entre tous les jeux
   Chaque jeu surcharge les variables d'accent/couleur dans son style.css
   =================================================================== */

/* === RESET BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === TOKENS GLOBAUX === */
:root {
  /* --- Espacements --- */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --space-xxl: 64px;

  /* --- Border radius --- */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* --- Transitions --- */
  --transition: 0.25s ease;
  --transition-slow: 0.4s ease;
  --transition-fast: 0.15s ease;

  /* --- Z-index --- */
  --z-base: 1;
  --z-above: 10;
  --z-modal: 100;
  --z-overlay: 200;
  --z-toast: 300;

  /* --- Ombres --- */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.18);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.24);

  /* --- Typographie --- */
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
  --font-display: var(--font-sans);

  /* --- Tailles de police --- */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;

  /* --- Interlignages --- */
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.75;

  /* --- Couleurs neutres (surchargées par chaque jeu) --- */
  --bg: #FFFFFF;
  --bg-secondary: #F5F5F5;
  --surface: #FFFFFF;
  --surface-secondary: #F0F0F0;
  --text: #1A1A2E;
  --text-secondary: #4a4a5e;
  --text-muted: #8a8a9e;
  --border: #e0e0e0;
  --overlay: rgba(0, 0, 0, 0.5);

  /* --- Couleur accent (surchargée par chaque jeu) --- */
  --accent: #E8453C;
  --accent-hover: #d13a32;
  --accent-light: color-mix(in srgb, var(--accent) 15%, transparent);

  /* --- États --- */
  --success: #22c55e;
  --success-bg: color-mix(in srgb, var(--success) 12%, transparent);
  --error: #ef4444;
  --error-bg: color-mix(in srgb, var(--error) 12%, transparent);
  --warning: #f59e0b;
  --warning-bg: color-mix(in srgb, var(--warning) 12%, transparent);
  --info: #3b82f6;
  --info-bg: color-mix(in srgb, var(--info) 12%, transparent);
}

/* === DARK MODE (variables de base) === */
[data-theme="dark"] {
  --overlay: rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.5);
}

/* === BASE HTML/BODY === */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
  min-height: 100dvh;
}

/* === BOUTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

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

.btn-secondary {
  background: var(--surface-secondary, var(--bg-secondary));
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--surface-secondary, var(--bg-secondary));
  color: var(--text);
}

.btn-icon {
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === CARDS === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
}

.card-hover {
  transition: box-shadow var(--transition), transform var(--transition);
}
.card-hover:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-md);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.active,
.modal-overlay[style*="display: flex"] {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  transform: scale(0.95) translateY(8px);
  transition: transform var(--transition);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  line-height: 1;
  width: 32px;
  height: 32px;
}

.modal-close:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

/* === TOAST / NOTIFICATIONS === */
.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.3s ease forwards;
  white-space: nowrap;
}

.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--error); color: white; }
.toast.warning { background: var(--warning); color: white; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0);   }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0);   }
  to   { opacity: 0; transform: translateY(8px); }
}

/* === BADGE === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--surface-secondary, var(--bg-secondary));
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.badge-accent {
  background: var(--accent-light);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 30%, transparent);
}

/* === INPUT === */
.input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input::placeholder {
  color: var(--text-muted);
}

/* === PROGRESS BAR === */
.progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

/* === LOADING SPINNER === */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

/* === DARK MODE TOGGLE === */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  font-size: var(--text-base);
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === DIVIDER === */
.divider {
  height: 1px;
  background: var(--border);
  width: 100%;
}

.divider-v {
  width: 1px;
  background: var(--border);
  align-self: stretch;
}

/* === ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0);    }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0);     }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1);   }
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0);   }
  50%       { transform: translateY(-6px); }
}

@keyframes shake {
  0%, 100%                { transform: translateX(0);   }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80%      { transform: translateX(4px);  }
}

@keyframes flipIn {
  0%   { transform: rotateX(-90deg); opacity: 0; }
  100% { transform: rotateX(0deg);   opacity: 1; }
}

.animate-fade-in    { animation: fadeIn    0.3s ease; }
.animate-slide-up   { animation: slideUp   0.3s ease; }
.animate-slide-down { animation: slideDown 0.3s ease; }
.animate-scale-in   { animation: scaleIn   0.3s ease; }
.animate-pulse      { animation: pulse     1s ease infinite; }
.animate-spin       { animation: spin      1s linear infinite; }
.animate-bounce     { animation: bounce    0.6s ease infinite; }
.animate-shake      { animation: shake     0.5s ease; }
.animate-flip-in    { animation: flipIn    0.4s ease; }

/* === UTILITAIRES === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-center  { text-align: center; }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }
.font-medium  { font-weight: 500; }

.flex          { display: flex; }
.flex-col      { display: flex; flex-direction: column; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-center  { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.flex-wrap     { flex-wrap: wrap; }
.flex-1        { flex: 1; }

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

.w-full  { width: 100%; }
.h-full  { height: 100%; }

.hidden  { display: none; }
.block   { display: block; }
.inline  { display: inline; }

.cursor-pointer { cursor: pointer; }

.text-accent   { color: var(--accent); }
.text-muted    { color: var(--text-muted); }
.text-success  { color: var(--success); }
.text-error    { color: var(--error); }
.text-warning  { color: var(--warning); }

.bg-accent  { background: var(--accent); }
.bg-surface { background: var(--surface); }

/* === RESPONSIVE === */
@media (max-width: 480px) {
  :root {
    --space-lg: 16px;
    --space-xl: 24px;
    --space-xxl: 40px;
    --text-3xl: 1.75rem;
    --text-4xl: 2rem;
  }

  .modal {
    max-width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-top: auto;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .toast-container {
    bottom: var(--space-lg);
    width: calc(100% - var(--space-lg) * 2);
  }

  .toast {
    white-space: normal;
    text-align: center;
  }
}
