/* --- Design System --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0d0f14; --surface: #13161f; --card: #181c28;
  --muted: #8892a4; --text: #e8ecf4; --stroke: #232840;
  --accent: #7c5cff; --accent-2: #24d8ff; --amber: #f59e0b;
  --success: #22c55e; --danger: #ef4444; --warning: #f59e0b;
  --radius: 16px;
  --shadow: 0 4px 12px rgba(0,0,0,.3), 0 16px 40px rgba(0,0,0,.25);
  --shadow-hover: 0 8px 20px rgba(0,0,0,.4), 0 24px 56px rgba(0,0,0,.3);
  --glow: 0 0 0 3px rgba(124,92,255,.25);
  --transition: all .25s cubic-bezier(0.4,0,0.2,1);
}
body.light-mode {
  --bg: #f0f2f8; --surface: #fff; --card: #fff;
  --text: #111827; --muted: #4b5563; --stroke: #e2e5ef;
  --accent: #6b46ff; --accent-2: #0ea5e9;
  --shadow: 0 2px 8px rgba(16,24,40,.06), 0 12px 28px rgba(16,24,40,.08);
  --shadow-hover: 0 4px 16px rgba(16,24,40,.1), 0 20px 40px rgba(16,24,40,.12);
  --glow: 0 0 0 3px rgba(107,70,255,.2);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box }
html { font-size: 16px; scroll-behavior: smooth }
html, body { height: 100% }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar custom */
::-webkit-scrollbar { width: 6px; height: 6px }
::-webkit-scrollbar-track { background: var(--surface) }
::-webkit-scrollbar-thumb { background: var(--stroke); border-radius: 99px }
::-webkit-scrollbar-thumb:hover { background: var(--accent) }

/* --- Helpers --- */
.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;
}
a { color: var(--accent-2); text-decoration: none }
a:hover { text-decoration: underline }

/* --- Layout --- */
.container {
  max-width: 1100px;
  margin: 92px auto 48px;
  padding: 0 20px;
}
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 68px; z-index: 10;
  background: rgba(13,15,20,.75);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--stroke);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
}
.topbar h1 {
  font-size: 1.1rem; font-weight: 800;
  letter-spacing: -0.03em; margin: 0 8px 0 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.topbar .spacer { flex: 1 }

/* --- Forms --- */
.actions, .profil-form {
  display: flex; gap: 10px; align-items: center; margin: 0;
}
.actions input[type="text"] {
  width: 260px; padding: 10px 14px;
  border-radius: 10px; border: 1px solid var(--stroke);
  background: var(--surface); color: var(--text);
}
select, input[type="text"], input[type="number"], input[type="date"] {
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--surface); color: var(--text);
  font-size: .95rem; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus {
  border-color: var(--accent);
  box-shadow: var(--glow);
}

/* --- Buttons --- */
.btn {
  appearance: none; border: none; border-radius: 10px;
  padding: 10px 16px; cursor: pointer; font-weight: 600;
  font-size: .9rem; transition: var(--transition);
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: .5; cursor: not-allowed }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9f7eff);
  color: #fff;
  box-shadow: 0 4px 14px rgba(124,92,255,.35);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124,92,255,.5);
}
.btn-primary:active { transform: translateY(0) }

/* Ripple on primary button */
.btn-primary::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,.25) 0%, transparent 70%);
  transform: scale(0); opacity: 0;
  transition: transform .4s ease, opacity .4s ease;
}
.btn-primary:active::after { transform: scale(2); opacity: 1; transition: 0s }

.btn-ghost {
  background: rgba(255,255,255,.04); color: var(--text);
  border: 1px solid var(--stroke);
}
.btn-ghost:hover { border-color: var(--accent-2); background: rgba(36,216,255,.07) }
.btn-danger { background: var(--danger); color: #fff }
.btn-danger:hover { filter: brightness(1.1); transform: translateY(-1px) }
.toggle-mode { border: 1px solid var(--stroke); color: var(--muted); background: transparent }
.toggle-mode:hover { border-color: var(--accent-2); color: var(--accent-2) }

/* --- Forms / add box --- */
.add-form {
  background: var(--surface); border: 1px solid var(--stroke);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin: 18px 0 28px;
}
.add-form h2 { margin: 0 0 12px; font-size: 1.1rem; letter-spacing: -0.02em; color: var(--accent) }
.input-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px }
label { font-size: .85rem; font-weight: 500; color: var(--muted) }
.inline { display: flex; gap: 8px; align-items: center }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px }
@media (max-width:640px) { .grid-2 { grid-template-columns: 1fr } }

/* --- Grid & Cards --- */
.grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--stroke);
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: var(--transition);
  overflow: hidden;
}
.card:hover {
  transform: translateY(-6px);
  border-color: rgba(124,92,255,.4);
  box-shadow: var(--shadow-hover);
}

/* Cover image section */
.card .cover {
  position: relative;
  height: 280px;
  background: linear-gradient(135deg, #0e1117, #181c28);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card .cover img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  transition: transform .4s cubic-bezier(0.4,0,0.2,1);
}
.card:hover .cover img { transform: scale(1.04) }
.card .cover::after { content: none }

/* Gradient overlay on cover */
.card .cover-gradient {
  position: absolute; inset: auto 0 0 0;
  height: 60px;
  background: linear-gradient(to top, var(--card), transparent);
  pointer-events: none;
}

.card .content { padding: 14px 16px 16px }
.card .title {
  font-weight: 700; font-size: 1rem;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
  line-height: 1.4;
}

/* Résumé vs Édition */
.card .summary { display: block }
.card .form-fields { display: none }
.card.is-edit .summary { display: none }
.card.is-edit .form-fields { display: block }

/* Meta / badges */
.meta {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin: 6px 0 10px; align-items: center;
}
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 99px;
  font-size: .75rem; font-weight: 500;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.03); color: var(--muted);
}

/* Notes couleurs */
.note {
  font-weight: 700; padding: 3px 10px;
  border-radius: 99px; color: #fff;
  font-size: .75rem;
}
.note-S { background: linear-gradient(135deg,#16a34a,#22c55e) }
.note-Aplus { background: linear-gradient(135deg,#0ea5e9,#38bdf8) }
.note-A { background: #38bdf8 }
.note-Aminus { background: #60a5fa }
.note-Bplus { background: #f59e0b }
.note-B { background: #fbbf24; color: #1a1a1a }
.note-Bminus { background: #fcd34d; color: #1a1a1a }
.note-Cplus { background: #fb923c }
.note-C { background: #fdba74; color: #1a1a1a }
.note-Cminus { background: #fed7aa; color: #1a1a1a }
.note-Dplus { background: #f97316 }
.note-D { background: #fb6a1b }
.note-Dminus { background: #ff8a65 }
.note-Eplus { background: #a855f7 }
.note-E { background: #c084fc }
.note-Eminus { background: #d8b4fe; color: #1a1a1a }
.note-F { background: #ef4444 }
.note-G {
  background: linear-gradient(135deg, #ffd700, #ff9e00);
  color: #1a1a1a; font-weight: 800;
  box-shadow: 0 0 10px rgba(255,215,0,.5);
}

/* Pied de carte */
.card .links { display: flex; gap: 8px; align-items: center; margin: 8px 0 }
.card .dates { opacity: .65; font-size: .8rem; display: flex; gap: 12px; flex-wrap: wrap }
.card .actions { display: flex; gap: 8px; padding: 0 14px 16px }
.card form .btn { width: 100% }
.delete-form { margin-top: 8px }

/* --- Skeleton loader --- */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--stroke) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0 }
  100% { background-position: -200% 0 }
}
.skeleton-card { height: 340px; border-radius: var(--radius) }
.skeleton-line { height: 14px; margin: 8px 0 }
.skeleton-line.short { width: 60% }

/* --- Empty state --- */
.empty-state {
  text-align: center; padding: 64px 20px;
  color: var(--muted);
}
.empty-state .empty-icon {
  font-size: 3.5rem; margin-bottom: 16px;
  opacity: .5; display: block;
}
.empty-state .empty-title {
  font-size: 1.2rem; font-weight: 700;
  color: var(--text); margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.empty-state .empty-sub { font-size: .9rem; color: var(--muted) }

/* --- Filter bar --- */
.filter-bar {
  display: flex; flex-wrap: wrap;
  justify-content: center; align-items: center;
  gap: 8px; margin: 20px auto;
}
.filter-btn {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--stroke); border-radius: 99px;
  padding: 6px 14px; font-weight: 600; font-size: .85rem;
  cursor: pointer; transition: var(--transition);
}
.filter-btn:hover { border-color: var(--accent); color: var(--text) }
.filter-btn.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(124,92,255,.35);
}

/* --- Search bar --- */
.search-bar {
  display: flex; justify-content: center; margin: 0 auto 8px;
}
.search-bar input {
  width: 340px; max-width: 100%;
  padding: 11px 16px; border-radius: 99px;
  border: 1px solid var(--stroke);
  background: var(--surface); color: var(--text);
}
.search-bar input:focus { border-color: var(--accent); box-shadow: var(--glow) }

/* --- Swipe feedback badges --- */
.swipe-badge {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  padding: 4px 10px; border-radius: 99px;
  font-size: .85rem; font-weight: 700; color: #fff;
  pointer-events: none;
  animation: swipeFadeOut 1.2s ease forwards;
}
.swipe-badge.plus { background: var(--success) }
.swipe-badge.minus { background: var(--danger) }
@keyframes swipeFadeOut {
  0%   { opacity: 1; transform: translateY(0) scale(1) }
  60%  { opacity: 1; transform: translateY(-8px) scale(1.1) }
  100% { opacity: 0; transform: translateY(-20px) scale(.9) }
}

/* --- Barre de progression --- */
.progress-wrap {
  height: 6px; background: var(--stroke);
  border-radius: 99px; margin: 8px 0 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .6s cubic-bezier(0.4,0,0.2,1);
}

/* --- Vue liste --- */
.grid.vue-liste {
  grid-template-columns: 1fr;
  gap: 10px;
}
.grid.vue-liste .card {
  display: flex; flex-direction: row;
  width: 100%; max-width: 100%;
}
.grid.vue-liste .card .cover {
  width: 80px; min-width: 80px; height: 110px; flex-shrink: 0;
}
.grid.vue-liste .card .content {
  flex: 1; padding: 10px 14px;
  display: flex; flex-direction: column; justify-content: center;
  text-align: left;
}
.grid.vue-liste .card .chapter-controls { justify-content: flex-start }
.grid.vue-liste .card .progress-wrap { margin: 4px 0 }
.grid.vue-liste .card div[style*="justify-content:center"] { justify-content: flex-start !important }

/* --- Bottom nav mobile --- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: rgba(13,15,20,.9);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--stroke);
  padding: 8px 0 env(safe-area-inset-bottom, 8px);
  justify-content: space-around; align-items: center;
}
.bottom-nav a, .bottom-nav button {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; font-size: .65rem; font-weight: 600;
  color: var(--muted); background: none; border: none;
  cursor: pointer; padding: 4px 12px; border-radius: 10px;
  transition: color .2s;
  text-decoration: none;
}
.bottom-nav a.active, .bottom-nav a:hover,
.bottom-nav button:hover { color: var(--accent) }
.bottom-nav .nav-icon { font-size: 1.3rem; line-height: 1 }

/* --- Bouton retour en haut --- */
#scrollTop {
  display: none; position: fixed; bottom: 72px; right: 16px; z-index: 19;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 1.1rem; cursor: pointer; box-shadow: var(--shadow);
  transition: opacity .3s, transform .3s;
  align-items: center; justify-content: center;
}
#scrollTop.visible { display: flex }
#scrollTop:hover { transform: translateY(-2px) }

/* --- Responsive --- */
@media (max-width: 640px) {
  .topbar { display: none }
  .bottom-nav { display: flex }
  .container { margin-top: 20px; margin-bottom: 80px }
  .actions input[type="text"] { width: 100% }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px }
  .card .cover { height: 200px }
}
