/* ==================== Variables & Reset ==================== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg: #ffffff;
    --bg-secondary: #f9fafb;
    --text: #111827;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --bg: #1f2937;
    --bg-secondary: #111827;
    --text: #f9fafb;
    --text-secondary: #9ca3af;
    --border: #374151;
    --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="blue"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #06b6d4;
}

[data-theme="green"] {
    --primary: #10b981;
    --primary-dark: #059669;
    --secondary: #14b8a6;
}

[data-theme="purple"] {
    --primary: #a855f7;
    --primary-dark: #9333ea;
    --secondary: #ec4899;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body[data-font-size="small"] { font-size: 14px; }
body[data-font-size="large"] { font-size: 18px; }

body[data-animations="false"] * {
    animation: none !important;
    transition: none !important;
}

/* ==================== Layout ==================== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.user-info {
    display: flex;
    gap: 12px;
    font-size: 0.875rem;
    font-weight: 600;
}

.user-level { color: var(--primary); }
.user-xp { color: var(--secondary); }
.user-streak { color: var(--warning); }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.75rem;
}

.nav-btn:hover,
.nav-btn:focus {
    color: var(--primary);
    background: var(--bg-secondary);
}

.nav-btn.active {
    color: var(--primary);
}

.nav-icon { font-size: 1.5rem; }

.app-main {
    max-width: 1200px;
    margin: 60px auto 64px;
    padding: 16px;
    min-height: calc(100vh - 124px);
}

/* ==================== Pages ==================== */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

/* ==================== Components ==================== */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    min-height: 48px;
    touch-action: manipulation;
}

.btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

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

.btn-primary:hover,
.btn-primary:active {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

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

.btn-secondary:hover,
.btn-secondary:active {
    background: var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-secondary);
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.125rem;
    min-height: 56px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.875rem;
    min-height: 36px;
}

.btn-block {
    width: 100%;
    display: flex;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
}

.chip:hover,
.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

.input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 0;
}

/* ==================== Home Page ==================== */
.hero-section {
    text-align: center;
    padding: 40px 0;
}

.hero-section h2 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.hero-subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.daily-challenge {
    text-align: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
}

.daily-challenge h3 {
    margin-bottom: 8px;
}

.daily-challenge p {
    margin-bottom: 16px;
    opacity: 0.9;
}

.daily-challenge .btn {
    background: white;
    color: var(--primary);
}

.section {
    margin-top: 32px;
}

.section h3 {
    margin-bottom: 16px;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.mode-card:hover,
.mode-card:focus {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.mode-icon { font-size: 2rem; }
.mode-name { font-weight: 600; }
.mode-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.premium-badge {
    background: linear-gradient(135deg, var(--warning), var(--error));
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}

/* ==================== Play Page ==================== */
.theme-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.theme-card {
    padding: 20px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.theme-card:hover,
.theme-card:focus {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.theme-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 8px;
}

.theme-name {
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.theme-difficulty {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.theme-card.locked {
    opacity: 0.6;
    position: relative;
}

.theme-card.locked::after {
    content: '🔒';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 1.2rem;
}

/* ==================== Quiz Page ==================== */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 16px;
}

.quiz-progress {
    flex: 1;
}

.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.quiz-timer {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 60px;
    text-align: right;
}

.quiz-timer.warning {
    color: var(--error);
    animation: pulse 1s infinite;
}

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

.question-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.question-theme {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.question-text {
    font-size: 1.25rem;
    line-height: 1.6;
}

.choices {
    display: grid;
    gap: 12px;
    margin-bottom: 24px;
}

.choice-btn {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
}

.choice-btn:hover:not(:disabled),
.choice-btn:focus {
    border-color: var(--primary);
    transform: translateX(4px);
}

.choice-btn:disabled {
    cursor: not-allowed;
}

.choice-btn.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.choice-btn.incorrect {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

.choice-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg);
    border-radius: 8px;
    font-weight: 700;
    margin-right: 12px;
    flex-shrink: 0;
}

.choice-btn.correct .choice-letter,
.choice-btn.incorrect .choice-letter {
    background: rgba(255, 255, 255, 0.2);
}

.quiz-actions {
    text-align: center;
}

.quiz-feedback {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    text-align: center;
}

.quiz-feedback.hidden {
    display: none;
}

.feedback-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.feedback-title {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.feedback-explanation {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.mastery-selector {
    margin: 24px 0;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
}

.mastery-selector p {
    margin-bottom: 12px;
    font-weight: 600;
}

.mastery-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.culture-bridges {
    margin: 24px 0;
}

.bridges-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.bridge-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.bridge-card {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    font-size: 0.875rem;
}

.bridge-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.bridge-theme {
    font-weight: 600;
    color: var(--primary);
    display: block;
    margin-bottom: 4px;
}

/* ==================== Review Page ==================== */
.review-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ==================== Stats Page ==================== */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 32px;
}

.theme-stat {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.theme-stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.theme-stat-name {
    font-weight: 600;
}

.theme-stat-rate {
    color: var(--primary);
    font-weight: 700;
}

.theme-stat-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.theme-stat-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

/* ==================== Settings Page ==================== */
.settings-group {
    margin-bottom: 32px;
}

.settings-group h3 {
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.setting-item {
    padding: 12px 0;
}

.setting-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.setting-item select {
    margin-top: 8px;
}

/* ==================== Premium Page ==================== */
.premium-header {
    text-align: center;
    padding: 40px 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: var(--radius);
    margin-bottom: 24px;
}

.premium-header h2 {
    font-size: 2rem;
    margin-bottom: 8px;
}

.comparison-table {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.comparison-col {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
}

.premium-col {
    border-color: var(--primary);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
}

.comparison-col h3 {
    text-align: center;
    margin-bottom: 16px;
    font-size: 1.25rem;
}

.feature-list {
    list-style: none;
}

.feature-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.feature-list li:last-child {
    border-bottom: none;
}

/* ==================== Toast ==================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 16px 20px;
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px var(--shadow);
    animation: slideIn 0.3s ease;
    max-width: 300px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

/* ==================== Responsive ==================== */
@media (min-width: 768px) {
    .app-main {
        padding: 24px;
    }

    .bottom-nav {
        display: none;
    }

    .app-header {
        height: 70px;
    }

    .header-content {
        padding: 0 24px;
    }

    .app-main {
        margin: 70px auto 0;
    }
}

@media (max-width: 480px) {
    .hero-section h2 {
        font-size: 1.5rem;
    }

    .mode-grid {
        grid-template-columns: 1fr;
    }

    .theme-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .quiz-header {
        flex-direction: column;
        align-items: stretch;
    }

    .quiz-timer {
        text-align: center;
    }

    .comparison-table {
        grid-template-columns: 1fr;
    }
}

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

*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:focus-visible {
    outline-offset: 4px;
}

/* ==================== Print ==================== */
@media print {
    .app-header,
    .bottom-nav,
    .btn {
        display: none;
    }

    .app-main {
        margin: 0;
        padding: 20px;
    }

    .page {
        display: block !important;
    }

    * {
        background: white !important;
        color: black !important;
    }
}

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

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

.mode-card:active {
    transform: scale(0.95);
}

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

.theme-card:active {
    transform: scale(0.98);
}

/* ==================== États de chargement ==================== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ==================== Scrollbar personnalisée ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ==================== Sélection de texte ==================== */
::selection {
    background: var(--primary);
    color: white;
}

::-moz-selection {
    background: var(--primary);
    color: white;
}

/* ===== Profil (header icon) ===== */
.profile-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.profile-btn:hover {
    transform: translateY(-1px);
}

/* ===== Profil page ===== */
.profile-name-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.profile-name-row .input {
    flex: 1;
}

.profile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.medals-preview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.medal-slot {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.text-muted {
    opacity: 0.75;
    margin-top: 10px;
}

.stats-mini {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.stats-mini .mini-stat {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 12px;
}

.stats-mini .mini-stat .label {
    font-size: 0.85rem;
    opacity: 0.75;
}

.stats-mini .mini-stat .value {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 4px;
}

.section-header{
  display:flex;
  align-items:center;
  gap:12px;
  margin-bottom:16px;
}

.section-header h2{
  margin:0;
}

.back-btn{
  border-radius:999px;
  padding:8px 12px;
}

/* ===== Header streak button ===== */
.streak-btn{
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 999px;
}
.streak-btn:hover{
  background: rgba(255,255,255,0.06);
}

/* ===== Calendar ===== */
.calendar{
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.calendar--mini{
  gap: 6px;
}

.cal-weekday{
  opacity: 0.7;
  font-size: 0.85rem;
  text-align: center;
}

.cal-cell{
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.calendar--mini .cal-cell{
  min-height: 34px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.cal-cell.is-empty{
  border: 0;
  background: transparent;
}

.cal-cell.is-today{
  outline: 2px solid rgba(255,255,255,0.28);
  outline-offset: 0;
}

.cal-cell.has-flame .cal-flame{
  font-size: 1.25rem;
}

.cal-num{
  position: absolute;
  font-size: 0.78rem;
  font-weight: 800;
  transform: translateY(2px);
}

/* Header in streak card */
.section-header{
  display:flex;
  align-items:center;
  gap:12px;
  margin-bottom:16px;
}
.section-header h2{ margin:0; }
.back-btn{ border-radius:999px; padding:8px 12px; }

.streak-head{
  display:flex;
  flex-direction: column;
  gap: 6px;
}
.streak-big{
  font-size: 1.25rem;
  font-weight: 800;
}
.streak-sub{
  opacity: 0.8;
}

.streak-row{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.streak-hint{
  opacity: 0.75;
  font-size: 0.9rem;
}

.calendar-legend{
  display:flex;
  gap:16px;
  margin-top: 12px;
  opacity: 0.85;
  font-size: 0.9rem;
  flex-wrap: wrap;
}
.legend-item{
  display:flex;
  gap:8px;
  align-items:center;
}
.legend-dot{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display:inline-block;
}
.legend-dot.today{ outline: 2px solid rgba(255,255,255,0.28); outline-offset: 2px; }
.legend-dot.flame{ background: rgba(255,255,255,0.22); }
