/* =========================================================================
   EduTok — feuille de style
   Deux "mondes" volontairement contrastés :
   • un monde CLAIR et calme pour l'accueil / le profil (rassurant, parents)
   • un monde SOMBRE et immersif pour le feed vidéo (focus, plein écran)
   ========================================================================= */

/* ------------------------------------------------------------------ TOKENS */
:root {
  /* Nuit — base du feed immersif */
  --night-900: #0f0b2e;
  --night-800: #14103a;
  --night-700: #1f1a4d;
  --night-600: #2b2568;

  /* Jour — base des écrans calmes (accueil, profil) */
  --day-50:  #f7f6ff;
  --day-100: #efedff;
  --day-200: #e3e0fb;

  /* Accents */
  --spark:   #ff5d8f;   /* corail-rose : action "j'aime", énergie */
  --aqua:    #35d0ba;   /* turquoise : sciences, fraîcheur */
  --sun:     #ffd166;   /* or doux : progression, badges, favoris */
  --violet:  #8b7bff;   /* liant de marque */

  /* Texte */
  --ink:        #1b1740;   /* texte sur fond clair */
  --ink-soft:   #55507e;
  --paper:      #f4f2ff;   /* texte sur fond sombre */
  --paper-soft: #b3add9;

  /* Couleurs par matière (pastilles de catégorie) */
  --c-sciences:      #35d0ba;
  --c-histoire:      #f4a259;
  --c-mathematiques: #8b7bff;
  --c-geographie:    #4cc9f0;
  --c-numerique:     #ff5d8f;
  --c-creativite:    #ffca3a;
  --c-langues:       #90be6d;
  --c-environnement: #52b788;

  /* Système */
  --radius:    22px;
  --radius-sm: 14px;
  --shadow:    0 18px 50px -18px rgba(20, 16, 58, .55);
  --ease:      cubic-bezier(.22, .61, .36, 1);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--night-900);
  overflow: hidden;                 /* l'app gère elle-même le défilement */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; max-width: 100%; }

/* Cadre "téléphone" : mobile-first, mais présentable sur grand écran */
#app {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--night-900);
  overflow: hidden;
  box-shadow: var(--shadow);
}
@media (min-width: 500px) {
  body { background: radial-gradient(120% 120% at 50% 0%, #17123f 0%, #0a0722 70%); padding: 0; display: grid; place-items: center; }
  #app { height: min(920px, 96dvh); border-radius: 34px; border: 1px solid rgba(255,255,255,.06); }
}

/* Chaque "écran" occupe tout le cadre ; on bascule via .is-active */
.screen { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .45s var(--ease); }
.screen.is-active { opacity: 1; pointer-events: auto; }

/* =======================================================================
   RÉGLAGES — feuille modale claire, glisse depuis le bas par-dessus le feed
   ======================================================================= */
#screen-reglages {
  top: auto; height: 88%;
  background:
    radial-gradient(90% 60% at 80% -10%, rgba(139,123,255,.20), transparent 60%),
    radial-gradient(80% 50% at 0% 105%, rgba(53,208,186,.18), transparent 60%),
    var(--day-50);
  color: var(--ink);
  overflow-y: auto;
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -24px 60px -20px rgba(10, 8, 30, .55);
  opacity: 1;                                  /* on pilote la transition via transform, pas l'opacité */
  transform: translateY(100%);
  transition: transform .42s var(--ease);
}
#screen-reglages.is-active { transform: translateY(0); }

.reglages-inner { min-height: 100%; padding: 14px 26px 40px; display: flex; flex-direction: column; }
.reglages-handle { width: 40px; height: 5px; border-radius: 999px; background: var(--day-200); margin: 0 auto 18px; }
.reglages-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 30px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-spark {
  width: 30px; height: 30px; border-radius: 10px;
  background: conic-gradient(from 210deg, var(--spark), var(--sun), var(--aqua), var(--violet), var(--spark));
  box-shadow: 0 6px 20px -6px var(--violet);
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -.02em; }
.brand-name span { color: var(--violet); }

.hero { margin-top: 44px; }
.hero-eyebrow {
  display: inline-block; font-weight: 800; font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--violet); background: var(--day-100); padding: 6px 12px; border-radius: 999px;
}
.hero-title {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(34px, 10vw, 44px);
  line-height: 1.02; letter-spacing: -.03em; margin: 16px 0 12px;
}
.hero-title em { font-style: italic; color: var(--spark); }
.hero-sub { font-size: 16px; line-height: 1.5; color: var(--ink-soft); max-width: 34ch; }

/* Mini-configuration */
.setup { margin-top: 34px; display: flex; flex-direction: column; gap: 26px; }
.setup-block-label { font-weight: 800; font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.setup-block-label small { font-weight: 700; color: var(--ink-soft); }

.field-name {
  width: 100%; font-size: 16px; font-weight: 700; color: var(--ink);
  background: #fff; border: 2px solid var(--day-200); border-radius: var(--radius-sm);
  padding: 14px 16px; transition: border-color .2s var(--ease);
}
.field-name:focus { outline: none; border-color: var(--violet); }
.field-name::placeholder { color: #b7b2d6; font-weight: 600; }

.age-row { display: flex; gap: 10px; flex-wrap: wrap; }
.age-chip {
  font-weight: 800; font-size: 14px; color: var(--ink-soft);
  background: #fff; border: 2px solid var(--day-200); border-radius: 999px; padding: 10px 16px;
  transition: all .18s var(--ease);
}
.age-chip[aria-pressed="true"] { color: #fff; background: var(--violet); border-color: var(--violet); transform: translateY(-1px); }

.subject-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.subject-pick {
  display: flex; align-items: center; gap: 10px; text-align: left;
  font-weight: 800; font-size: 14px; color: var(--ink);
  background: #fff; border: 2px solid var(--day-200); border-radius: var(--radius-sm); padding: 12px 14px;
  transition: all .18s var(--ease);
}
.subject-pick .emo { font-size: 18px; }
.subject-pick[aria-pressed="true"] { border-color: var(--c, var(--violet)); background: color-mix(in srgb, var(--c, var(--violet)) 12%, #fff); transform: translateY(-1px); }

.cta {
  margin-top: 30px; width: 100%;
  font-weight: 900; font-size: 17px; color: #fff;
  background: linear-gradient(135deg, var(--spark), var(--violet));
  border-radius: var(--radius); padding: 17px 20px;
  box-shadow: 0 16px 34px -12px var(--violet);
  transition: transform .16s var(--ease), box-shadow .16s var(--ease);
}
.cta:hover { transform: translateY(-2px); box-shadow: 0 22px 40px -12px var(--violet); }
.cta:active { transform: translateY(0); }

.reassure { margin-top: 18px; font-size: 12.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; line-height: 1.4; }
.reassure svg { flex: 0 0 auto; }

/* =======================================================================
   FEED VIDÉO — monde SOMBRE
   ======================================================================= */
#screen-feed { background: #000; }

/* Barre supérieure : filtres matières + profil */
.feed-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 12px 30px;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
  pointer-events: none;
}
.feed-top-row { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.feed-logo { font-family: var(--font-display); font-weight: 600; font-size: 18px; color: #fff; letter-spacing: -.02em; padding-right: 4px; }
.feed-logo span { color: var(--sun); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-weight: 800; font-size: 13px; color: #fff;
  background: rgba(255,255,255,.14); backdrop-filter: blur(8px);
  border-radius: 999px; padding: 8px 13px; white-space: nowrap;
  border: 1.5px solid transparent; transition: all .18s var(--ease);
}
.chip .emo { margin-right: 5px; }
.chip[aria-pressed="true"] { background: #fff; color: var(--ink); }
.icon-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.16); backdrop-filter: blur(8px);
  display: grid; place-items: center; font-weight: 900; color: #fff; font-size: 15px;
  border: 1.5px solid rgba(255,255,255,.25);
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn--dark {
  background: var(--day-100); color: var(--ink); border-color: var(--day-200); font-size: 14px;
}

/* Conteneur défilant avec accroche (snap) */
.feed-scroll {
  position: absolute; inset: 0;
  overflow-y: scroll; scroll-snap-type: y mandatory;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;   /* empêche le rebond de tirer la page hôte */
  touch-action: pan-y;              /* swipe vertical exclusif, moins de latence tactile */
  scroll-behavior: smooth;
}
.feed-scroll::-webkit-scrollbar { display: none; }

/* Une carte = un plein écran */
.slide {
  position: relative; height: 100%; width: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  background: #05040f; overflow: hidden;
  contain: layout paint style;      /* isole chaque carte : moins de recalcul au scroll */
}

/* Média (poster ↔ iframe) */
.slide-media { position: absolute; inset: 0; }
.slide-poster {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  filter: brightness(.82);
}
.slide-media .yt-mount,
.slide-media iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
  opacity: 0; animation: fadeIn .35s var(--ease) forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

/* Voile de lecture pour la lisibilité du texte */
.slide::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,.78) 0%, rgba(0,0,0,.15) 42%, rgba(0,0,0,.30) 100%);
}

/* Gros bouton lecture (état poster) */
.play-badge {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 5;
  width: 74px; height: 74px; border-radius: 50%;
  background: rgba(255,255,255,.16); backdrop-filter: blur(6px);
  border: 2px solid rgba(255,255,255,.7);
  display: grid; place-items: center; transition: transform .2s var(--ease), opacity .2s var(--ease);
}
.play-badge svg { margin-left: 4px; }
.slide.is-playing .play-badge { opacity: 0; transform: translate(-50%,-50%) scale(.6); pointer-events: none; }
.slide.embed-blocked .play-badge { background: rgba(0,0,0,.5); border-color: rgba(255,255,255,.85); }

/* Repli quand une chaîne désactive l'intégration (erreurs YouTube 101/150/153) */
.embed-hint {
  display: none; position: absolute; top: calc(50% + 54px); left: 50%; transform: translateX(-50%); z-index: 6;
  color: #fff; font-weight: 800; font-size: 12px; text-align: center; white-space: nowrap;
  background: rgba(0,0,0,.55); backdrop-filter: blur(6px);
  padding: 7px 12px; border-radius: 999px;
}
.slide.embed-blocked .embed-hint { display: block; }

/* Infos en bas à gauche */
.slide-info { position: absolute; left: 18px; right: 76px; bottom: calc(env(safe-area-inset-bottom, 0px) + 26px); z-index: 10; color: #fff; }
.slide-cat {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 12px; letter-spacing: .02em;
  background: var(--cat-color, var(--violet)); color: #08121f;
  padding: 5px 11px; border-radius: 999px; margin-bottom: 12px;
}
.slide-title { font-family: var(--font-display); font-weight: 600; font-size: 23px; line-height: 1.12; letter-spacing: -.02em; margin-bottom: 8px; }
.slide-desc { font-size: 13.5px; line-height: 1.45; color: rgba(255,255,255,.86); max-height: 3.9em; overflow: hidden; }
.slide-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.tag {
  font-weight: 800; font-size: 11.5px; color: #fff;
  background: rgba(255,255,255,.16); backdrop-filter: blur(6px);
  border-radius: 999px; padding: 5px 10px;
}
.tag.source { text-transform: capitalize; }

/* Rail d'actions vertical, façon TikTok : son + ouvrir sur la source */
.action-rail {
  position: absolute; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 130px); z-index: 20;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.rail-btn {
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255,255,255,.14); backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255,255,255,.25);
  display: grid; place-items: center; font-size: 19px; color: #fff;
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.rail-btn:active { transform: scale(.9); background: rgba(255,255,255,.24); }
.sound-btn { display: none; }
.slide.is-playing .sound-btn { display: grid; }

/* État vide (matière sans vidéo) */
.feed-empty {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px; color: var(--paper); z-index: 15;
  background: radial-gradient(80% 60% at 50% 30%, var(--night-700), var(--night-900));
}
.feed-empty.is-visible { display: flex; }
.feed-empty .big { font-size: 46px; margin-bottom: 14px; }
.feed-empty h3 { font-family: var(--font-display); font-weight: 600; font-size: 22px; margin-bottom: 8px; }
.feed-empty p { font-size: 14px; color: var(--paper-soft); max-width: 30ch; line-height: 1.5; margin-bottom: 20px; }
.feed-empty button { font-weight: 800; color: var(--ink); background: #fff; padding: 12px 20px; border-radius: 999px; }

/* Indice de swipe (première visite) */
.swipe-hint {
  position: absolute; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 12;
  color: rgba(255,255,255,.9); font-weight: 800; font-size: 12px; text-align: center;
  pointer-events: none; animation: floaty 1.8s var(--ease) infinite;
}
.swipe-hint .arrow { font-size: 22px; display: block; }
@keyframes floaty { 0%,100%{transform:translate(-50%,0);opacity:.5} 50%{transform:translate(-50%,-8px);opacity:1} }

/* =======================================================================
   PROFIL — monde CLAIR
   ======================================================================= */
#screen-profil { background: var(--day-50); color: var(--ink); overflow-y: auto; }
.profil-inner { min-height: 100%; padding: calc(env(safe-area-inset-top, 0px) + 20px) 22px 40px; }

.profil-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.back-btn { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; color: var(--ink); background: var(--day-100); padding: 9px 15px; border-radius: 999px; }

.profil-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.avatar {
  width: 66px; height: 66px; border-radius: 22px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--violet), var(--aqua));
  display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 26px;
  box-shadow: 0 12px 26px -10px var(--violet);
}
.profil-name { font-family: var(--font-display); font-weight: 600; font-size: 24px; letter-spacing: -.02em; }
.profil-age { font-weight: 700; color: var(--ink-soft); font-size: 14px; }

/* Bandeau progression */
.progress-card {
  margin-top: 22px; border-radius: var(--radius); padding: 22px;
  background: linear-gradient(135deg, #1f1a4d, #2b2568); color: #fff; position: relative; overflow: hidden;
}
.progress-card::after {
  content: "🎉"; position: absolute; right: -8px; top: -10px; font-size: 90px; opacity: .12; transform: rotate(12deg);
}
.progress-line { font-size: 15px; line-height: 1.5; position: relative; }
.progress-line b { color: var(--sun); font-family: var(--font-display); font-size: 30px; display: block; letter-spacing: -.02em; }
.progress-ring-row { display: flex; gap: 14px; margin-top: 16px; position: relative; }
.mini-stat { flex: 1; background: rgba(255,255,255,.08); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.mini-stat .n { font-family: var(--font-display); font-weight: 600; font-size: 22px; color: #fff; }
.mini-stat .l { font-size: 11px; font-weight: 800; color: var(--paper-soft); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* Centres d'intérêt */
.interest-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.interest { font-weight: 800; font-size: 13px; padding: 8px 13px; border-radius: 999px; background: var(--day-100); color: var(--ink); display: inline-flex; align-items: center; gap: 6px; }

/* Onglets favoris / historique / terminées */
.tabs { display: flex; gap: 6px; margin-top: 26px; background: var(--day-100); padding: 5px; border-radius: 999px; }
.tab { flex: 1; font-weight: 800; font-size: 13px; color: var(--ink-soft); padding: 10px; border-radius: 999px; transition: all .18s var(--ease); }
.tab[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 4px 12px -6px rgba(0,0,0,.25); }

.tab-list { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.mini-card {
  display: flex; gap: 12px; align-items: center; background: #fff; border: 1.5px solid var(--day-200);
  border-radius: var(--radius-sm); padding: 8px; transition: transform .16s var(--ease);
}
.mini-card:active { transform: scale(.99); }
.mini-thumb { width: 78px; height: 52px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; background: var(--day-200); }
.mini-body { min-width: 0; }
.mini-title { font-weight: 800; font-size: 14px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mini-sub { font-size: 12px; color: var(--ink-soft); font-weight: 700; margin-top: 3px; }
.tab-empty { text-align: center; color: var(--ink-soft); font-weight: 700; font-size: 14px; padding: 34px 10px; }
.tab-empty .em { font-size: 34px; display: block; margin-bottom: 8px; }

.section-label { font-weight: 900; font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink-soft); margin: 26px 0 12px; }

/* Toast de partage / confirmation */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; font-weight: 800; font-size: 13.5px;
  padding: 12px 18px; border-radius: 999px; z-index: 100; opacity: 0;
  transition: all .3s var(--ease); pointer-events: none; box-shadow: var(--shadow);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Accessibilité : focus visible clavier */
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; border-radius: 6px; }

/* Respect de "réduire les animations" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Sentinelle du rendu progressif (invisible) */
.feed-sentinel { height: 1px; width: 100%; }
