/* ==========================================
   CLAV'MASTER - SYSTEME DE DESIGN & STYLES
   ========================================== */

:root {
  /* Dynamic Palette */
  --bg-primary: #0b0f19;
  --bg-secondary: #131b2e;
  --bg-card: rgba(23, 32, 54, 0.7);
  --bg-card-hover: rgba(30, 41, 69, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  /* Primary Accent Colors */
  --accent-cyan: #06b6d4;
  --accent-magenta: #ec4899;
  --accent-indigo: #6366f1;
  --accent-purple: #8b5cf6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  /* Typing Feedback */
  --color-correct: #10b981;
  --color-incorrect: #f43f5e;
  --color-current: #38bdf8;
  --bg-incorrect: rgba(244, 63, 94, 0.2);
  --bg-current: rgba(56, 189, 248, 0.25);
  
  /* Finger Mapping Color Tokens */
  --finger-l-pinky: #ff4d6d;
  --finger-l-ring: #c77dff;
  --finger-l-middle: #3a86ff;
  --finger-l-index: #00b4d8;
  --finger-thumbs: #ffb703;
  --finger-r-index: #2ec4b6;
  --finger-r-middle: #48cae4;
  --finger-r-ring: #9d4edd;
  --finger-r-pinky: #ff477e;
  
  /* Fonts & Shadows */
  --font-sans: 'Outfit', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Theme Alternative Tokens */
[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.8);
  --bg-card-hover: rgba(241, 245, 249, 0.95);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-glow: rgba(99, 102, 241, 0.2);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-glow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.1) 0%, transparent 40%);
  background-attachment: fixed;
}

/* HEADER & NAVBAR */
.app-header {
  background: rgba(19, 27, 46, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
}

/* NAVIGATION TABS */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(11, 15, 25, 0.6);
  padding: 0.3rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

/* USER PROFILE & CONTROLS */
.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-xp-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
}

.level-tag {
  background: linear-gradient(135deg, var(--accent-amber), var(--accent-rose));
  color: #000;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
}

.xp-bar-outer {
  width: 70px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.xp-bar-inner {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-emerald));
  border-radius: 3px;
  transition: width 0.4s ease;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

/* LAYOUT SELECTOR (AZERTY/QWERTY) */
.layout-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0.15rem;
}

.layout-opt {
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--text-muted);
  border: none;
  background: transparent;
  transition: all var(--transition-fast);
}

.layout-opt.active {
  background: var(--accent-indigo);
  color: #ffffff;
}

/* MAIN CONTAINER */
.main-container {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* VIEW SECTIONS */
.view-section {
  display: none;
  flex-direction: column;
  gap: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.view-section.active {
  display: flex;
}

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

/* CARD GLASSMORPHISM COMPONENTS */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-glow);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* TYPING DISPLAY AREA (FOR LESSONS & SPRINT) */
.typing-box {
  background: rgba(11, 15, 25, 0.85);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
  transition: border-color var(--transition-normal);
  cursor: text;
}

.typing-box:focus-within, .typing-box.active {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.25), inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.text-stream {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  line-height: 2.2rem;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  user-select: none;
  white-space: pre-wrap;
  word-break: break-word;
}

.char {
  position: relative;
  border-radius: 2px;
  padding: 2px 0;
  transition: color 0.05s ease, background-color 0.05s ease;
}

.char.correct {
  color: var(--color-correct);
}

.char.incorrect {
  color: var(--color-incorrect);
  background-color: var(--bg-incorrect);
  text-decoration: underline;
}

.char.current {
  color: #ffffff;
  background-color: var(--bg-current);
  border-bottom: 3px solid var(--accent-cyan);
  animation: cursorBlink 1s infinite;
}

@keyframes cursorBlink {
  0%, 100% { border-color: var(--accent-cyan); }
  50% { border-color: transparent; }
}

.hidden-input {
  position: absolute;
  opacity: 0;
  left: -9999px;
  top: -9999px;
}

/* SPRINT & STATS BAR ABOVE TYPING BOX */
.metrics-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
}

.metric-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-val {
  font-size: 2rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  line-height: 1.1;
}

.metric-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  font-weight: 600;
  margin-top: 0.2rem;
}

/* KEYBOARD & FINGER GUIDE */
.keyboard-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.finger-guide-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
}

.target-finger-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
}

.finger-pill {
  padding: 0.25rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.keyboard-container {
  background: rgba(19, 27, 46, 0.9);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.05), var(--shadow-glow);
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
}

.key {
  height: 48px;
  min-width: 44px;
  background: rgba(30, 41, 69, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 3px solid rgba(0, 0, 0, 0.4);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  user-select: none;
  position: relative;
  transition: all 0.1s ease;
  padding: 0 0.5rem;
}

.key.small-text {
  font-size: 0.75rem;
}

/* Finger-Based Color Indicators */
.key[data-finger="l-pinky"] { border-top: 3px solid var(--finger-l-pinky); }
.key[data-finger="l-ring"]  { border-top: 3px solid var(--finger-l-ring); }
.key[data-finger="l-middle"]{ border-top: 3px solid var(--finger-l-middle); }
.key[data-finger="l-index"] { border-top: 3px solid var(--finger-l-index); }
.key[data-finger="thumbs"]  { border-top: 3px solid var(--finger-thumbs); }
.key[data-finger="r-index"] { border-top: 3px solid var(--finger-r-index); }
.key[data-finger="r-middle"]{ border-top: 3px solid var(--finger-r-middle); }
.key[data-finger="r-ring"]  { border-top: 3px solid var(--finger-r-ring); }
.key[data-finger="r-pinky"] { border-top: 3px solid var(--finger-r-pinky); }

.key.pressed {
  transform: translateY(2px);
  border-bottom-width: 1px;
  background: var(--accent-indigo);
  color: #ffffff;
  box-shadow: 0 0 12px var(--accent-indigo);
}

.key.target-next {
  animation: keyPulse 1.2s infinite ease-in-out;
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.3);
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.5);
  z-index: 2;
}

@keyframes keyPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 15px rgba(6, 182, 212, 0.4); }
  50% { transform: scale(1.05); box-shadow: 0 0 25px rgba(6, 182, 212, 0.8); }
}

.key-backspace { width: 90px; }
.key-tab { width: 70px; }
.key-caps { width: 80px; }
.key-enter { width: 95px; }
.key-shift { width: 110px; }
.key-space { width: 320px; }

/* VISUAL HANDS SVG DIAGRAM */
.hands-diagram-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 3rem;
  padding: 1.25rem;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.hand-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.hand-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hand-svg {
  width: 170px;
  height: 170px;
}

.finger-path {
  fill: rgba(255, 255, 255, 0.12);
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 2;
  transition: all 0.2s ease;
}

.finger-path.active {
  fill: var(--active-finger-color, var(--accent-cyan));
  stroke: #ffffff;
  filter: drop-shadow(0 0 8px var(--active-finger-color, var(--accent-cyan)));
  transform: translateY(-4px);
}

/* LESSONS MODE */
.lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.lesson-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.lesson-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-indigo);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.lesson-card.completed {
  border-color: rgba(16, 185, 129, 0.4);
}

.lesson-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lesson-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.lesson-stars {
  color: var(--accent-amber);
}

.lesson-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.lesson-keys-badge {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--accent-cyan);
}

/* DICTATION MODE */
.dictation-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-dictation {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  color: white;
  border: none;
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
  transition: all var(--transition-fast);
}

.btn-dictation:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.dictation-hint {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ARCADE MODE */
.arcade-viewport {
  position: relative;
  width: 100%;
  height: 420px;
  background: radial-gradient(circle at center, #1a103c 0%, #090614 100%);
  border: 2px solid var(--accent-purple);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.25);
}

.arcade-word {
  position: absolute;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1.2rem;
  color: #ffffff;
  background: rgba(23, 32, 54, 0.85);
  border: 1px solid var(--accent-cyan);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
  white-space: nowrap;
}

.arcade-word.matched {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 15px var(--accent-emerald);
  color: var(--accent-emerald);
}

.arcade-stats-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 1.1rem;
  z-index: 10;
  pointer-events: none;
}

/* STATS & DASHBOARD */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.stat-card-large {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chart-container {
  width: 100%;
  height: 250px;
  position: relative;
}

canvas {
  width: 100% !important;
  height: 100% !important;
}

/* BADGES GRID */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1rem;
}

.badge-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  opacity: 0.4;
  filter: grayscale(1);
  transition: all var(--transition-fast);
}

.badge-item.unlocked {
  opacity: 1;
  filter: grayscale(0);
  border-color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.2);
}

.badge-icon {
  font-size: 2.2rem;
}

.badge-name {
  font-size: 0.8rem;
  font-weight: 700;
}

/* BUTTONS & GENERAL CONTROLS */
.btn {
  background: var(--bg-card-hover);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.btn:hover {
  border-color: var(--accent-indigo);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  color: #ffffff;
  border: none;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.5);
}

/* MODALS */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: rgba(19, 27, 46, 0.95);
  border: 1px solid var(--accent-indigo);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 30px rgba(99, 102, 241, 0.3);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: center;
}

/* RESPONSIVE DESIGN */
@media (max-width: 850px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  
  .nav-tabs {
    overflow-x: auto;
    justify-content: flex-start;
  }
  
  .key {
    height: 38px;
    min-width: 30px;
    font-size: 0.75rem;
  }

  .key-space { width: 180px; }
  .key-shift { width: 60px; }
  
  .hands-diagram-container {
    display: none;
  }
}
