:root {
  --bg: #0d0d12;
  --bg-2: #15151d;
  --card: #1c1c27;
  --text: #f2f2f7;
  --muted: #9a9aae;
  --accent: #6c8cff;
  --knew: #34d399;   /* je savais */
  --didnt: #fbbf24;  /* je ne savais pas (à apprendre) */
  --skip: #f87171;   /* pas intéressé */
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--bg-2); border-bottom: 1px solid #ffffff10; flex-wrap: wrap;
}
.tab { background: transparent; color: var(--muted); border: none; font-size: 15px; font-weight: 600; padding: 6px 4px; cursor: pointer; }
.tab.active { color: var(--text); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: 2px; }
.lang-toggle { margin-left: auto; display: flex; background: #ffffff12; border-radius: 12px; padding: 3px; }
.lang-toggle button { border: none; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; padding: 5px 9px; border-radius: 9px; cursor: pointer; }
.lang-toggle button.active { background: var(--accent); color: #fff; }

/* ---------- Screens ---------- */
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Barre de rubriques ---------- */
.cat-bar { display: flex; gap: 8px; overflow-x: auto; padding: 8px 16px 2px; scrollbar-width: none; }
.cat-bar::-webkit-scrollbar { display: none; }
.cat-bar button { white-space: nowrap; flex-shrink: 0; border: 1px solid #ffffff18; background: var(--bg-2); color: var(--muted); border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer; }
.cat-bar button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Barre de thème libre ---------- */
.prompt-bar { display: flex; gap: 8px; padding: 8px 16px 2px; }
.prompt-bar input { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--accent); background: var(--bg-2); color: var(--text); font-size: 14px; }
.prompt-bar button { border: none; background: var(--accent); color: #fff; font-weight: 700; border-radius: 12px; padding: 0 16px; font-size: 14px; cursor: pointer; }

/* ---------- Card stack ---------- */
.card-stack { position: relative; flex: 1; min-height: 0; margin: 16px 16px 8px; perspective: 1000px; }
.card {
  position: absolute; inset: 0; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 18px 50px #00000060; display: flex; flex-direction: column;
  will-change: transform; touch-action: none; border: 1px solid #ffffff0d;
}
.card-img { width: 100%; height: 46%; object-fit: cover; background: #000; flex-shrink: 0; pointer-events: none; }
.card-img.placeholder { display: flex; align-items: center; justify-content: center; font-size: 56px; color: #ffffff22; }
.card-content { padding: 16px 18px; overflow-y: auto; flex: 1; }
.card-kicker { font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.card-kicker .lang-pill { background: #ffffff14; color: var(--muted); padding: 1px 7px; border-radius: 8px; letter-spacing: 0; }
.card-title { font-size: 21px; font-weight: 700; margin: 0 0 8px; line-height: 1.2; }
.card-text { font-size: 16px; line-height: 1.6; color: #e7e7ef; margin: 0 0 14px; }
.card-text .link { color: var(--accent); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; cursor: pointer; }
.card-title.link-title { cursor: pointer; }
.card-title.link-title::after { content: " ⓘ"; font-size: 13px; color: var(--accent); vertical-align: middle; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: #ffffff10; border: 1px solid var(--accent); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.chip::before { content: "ⓘ"; color: var(--accent); }

/* swipe badges (3 directions) */
.card::after {
  position: absolute; font-size: 26px; font-weight: 900; padding: 4px 14px;
  border-radius: 12px; border: 3px solid; opacity: 0;
}
.card.tag-knew::after  { content: "JE SAVAIS ✓";        top: 22px; right: 22px; color: var(--knew);  border-color: var(--knew);  transform: rotate(12deg);  opacity: 1; }
.card.tag-didnt::after { content: "JE NE SAVAIS PAS";   top: 22px; left: 22px;  color: var(--didnt); border-color: var(--didnt); transform: rotate(-12deg); opacity: 1; }
.card.tag-skip::after  { content: "PAS INTÉRESSÉ ⤓";    bottom: 22px; left: 50%; transform: translateX(-50%); color: var(--skip); border-color: var(--skip); opacity: 1; }

/* ---------- Actions ---------- */
.actions { display: flex; justify-content: center; align-items: flex-end; gap: 14px; padding: 6px 10px; }
.action-btn {
  border: none; cursor: pointer; background: var(--card); color: var(--text);
  box-shadow: 0 6px 18px #00000050; display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-radius: 18px; padding: 10px 8px; flex: 1; max-width: 120px; transition: transform .1s;
}
.action-btn:active { transform: scale(.94); }
.action-btn .ab-ico { font-size: 22px; font-weight: 900; line-height: 1; }
.action-btn .ab-lbl { font-size: 11px; color: var(--muted); font-weight: 600; }
.action-btn.didnt .ab-ico { color: var(--didnt); }
.action-btn.skip  { max-width: 96px; }
.action-btn.skip .ab-ico { color: var(--skip); }
.action-btn.knew .ab-ico { color: var(--knew); }
.hint { text-align: center; color: var(--muted); font-size: 11.5px; margin: 4px 12px calc(8px + var(--safe-bottom)); }

/* ---------- Profil / Recap ---------- */
#screenRecap { padding: 12px 16px calc(16px + var(--safe-bottom)); overflow-y: auto; }
.recap-h2 { margin: 4px 0 6px; }
.recap-h3 { margin: 22px 0 8px; font-size: 16px; }
.radar-wrap { display: flex; justify-content: center; }
.radar { width: 300px; max-width: 100%; aspect-ratio: 1; }
.mastery-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-top: 8px; }
.mastery-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.mastery-row .ml-bar { flex: 1; height: 6px; background: #ffffff14; border-radius: 4px; overflow: hidden; }
.mastery-row .ml-fill { height: 100%; background: var(--accent); }
.mastery-row .ml-pct { color: var(--muted); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.sync-row { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; flex-wrap: wrap; }
.btn-sync { border: 1px solid var(--accent); background: #ffffff10; color: var(--text); border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-sync:disabled { opacity: .5; }
.sync-status { font-size: 13px; color: var(--muted); }

.recap-stats { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.recap-filters { display: flex; gap: 6px; margin-bottom: 10px; }
.recap-filters button { border: 1px solid #ffffff18; background: var(--bg-2); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
.recap-filters button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#recapSearch { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid #ffffff18; background: var(--bg-2); color: var(--text); font-size: 15px; margin-bottom: 14px; }
.recap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.recap-item { background: var(--card); border-radius: 16px; overflow: hidden; position: relative; cursor: pointer; }
.recap-item img { width: 100%; height: 96px; object-fit: cover; background: #000; display: block; }
.recap-item .ri-body { padding: 9px 11px; }
.recap-item .ri-title { font-size: 14px; font-weight: 700; line-height: 1.25; }
.recap-item .ri-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.recap-item .ri-verdict { width: 8px; height: 8px; border-radius: 50%; }
.recap-item .ri-del { position: absolute; top: 6px; right: 6px; background: #000000aa; border: none; color: #fff; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 13px; }

/* ---------- Bottom sheet ---------- */
.sheet-scrim { position: fixed; inset: 0; background: #000000a0; backdrop-filter: blur(3px); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--card); border-radius: 22px 22px 0 0; max-height: 78dvh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: 0 -10px 40px #000000a0;
  padding-bottom: var(--safe-bottom); transform: translateY(0); transition: transform .28s ease;
}
.sheet.hidden, .sheet-scrim.hidden { display: none; }
.sheet.closing { transform: translateY(100%); }
.sheet-handle { width: 44px; height: 5px; background: #ffffff30; border-radius: 3px; margin: 10px auto 4px; flex-shrink: 0; }
.sheet-body { overflow-y: auto; }
.sheet-body img { width: 100%; max-height: 210px; object-fit: cover; background: #000; }
.sheet-body .sb-text { padding: 14px 18px 4px; }
.sheet-body h3 { margin: 0 0 8px; font-size: 19px; }
.sheet-body p { margin: 0; line-height: 1.5; color: #e7e7ef; font-size: 15px; }
.sheet-link { display: block; text-align: center; padding: 14px; color: var(--accent); text-decoration: none; font-weight: 700; border-top: 1px solid #ffffff14; }

/* ---------- Verrou ---------- */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lock.hidden { display: none; }
.lock-card { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; max-width: 320px; }
.lock-logo { font-size: 56px; }
.lock-title { margin: 0; font-size: 26px; letter-spacing: .02em; }
.lock-card input { width: 100%; padding: 13px 16px; border-radius: 14px; border: 1px solid #ffffff20; background: var(--bg-2); color: var(--text); font-size: 16px; text-align: center; }
.lock-card button { width: 100%; padding: 13px; border: none; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; cursor: pointer; }
.lock-err { color: var(--skip); font-size: 13px; min-height: 16px; margin: 0; }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; margin: auto; }
.btn-ghost { margin-top: 12px; background: transparent; border: 1px solid var(--accent); color: var(--accent); padding: 9px 16px; border-radius: 12px; cursor: pointer; font-size: 14px; }
.hidden { display: none !important; }
.toast { position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); background: #000000d8; color: #fff; padding: 10px 18px; border-radius: 14px; font-size: 14px; z-index: 60; }
.spinner { width: 34px; height: 34px; border: 3px solid #ffffff22; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
