/* ─────────────────────────────────────────────────────────────
   VARIABLES
───────────────────────────────────────────────────────────── */
:root {
  --bg          : #0f0f14;
  --surface     : #1a1a24;
  --surface-2   : #22222f;
  --border      : #2e2e42;
  --text        : #e8e8f2;
  --text-muted  : #7878a4;
  --accent      : #e9c46a;        /* or / étoiles */
  --accent-2    : #48cae4;        /* bleu / en cours */
  --success     : #52b788;        /* vert / vu */
  --danger      : #e05c5c;
  --radius      : 12px;
  --radius-sm   : 8px;
  --topbar-h    : 56px;
  --nav-h       : 60px;
  --safe-bottom : env(safe-area-inset-bottom, 0px);
}

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

html { height: 100%; font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

img { display: block; }
button { font-family: inherit; cursor: pointer; }
a { text-decoration: none; color: inherit; }

/* ─────────────────────────────────────────────────────────────
   APP SHELL
───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.topbar__logo {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--accent);
}
.topbar__logo span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.7rem;
  margin-left: 6px;
  vertical-align: middle;
}

/* ─── View (scrollable area) ─── */
.view {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

/* ─── Bottom nav ─── */
.bottom-nav {
  display: flex;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 500;
  transition: color 0.15s;
  padding: 8px 0;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav__item svg { width: 22px; height: 22px; stroke-width: 1.8; }
.bottom-nav__item.active { color: var(--accent); }
.bottom-nav__item.active svg { stroke-width: 2.2; }

/* ─────────────────────────────────────────────────────────────
   FILTER CHIPS
───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.filter-bar::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chip.active                  { background: var(--accent);   border-color: var(--accent);   color: #000; }
.chip--watchlist.active       { background: var(--text-muted); border-color: var(--text-muted); color: var(--bg); }
.chip--watching.active        { background: var(--accent-2); border-color: var(--accent-2); color: #000; }
.chip--watched.active         { background: var(--success);  border-color: var(--success);  color: #000; }

/* ─────────────────────────────────────────────────────────────
   CARD GRID (bibliothèque)
───────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  padding: 4px 16px 16px;
}

.card {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s;
}
.card:active { transform: scale(0.96); }

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 2rem;
  text-align: center;
  padding: 12px;
}
.card__placeholder span { font-size: 0.65rem; line-height: 1.3; }

.card__overlay {
  position: absolute;
  inset: auto 0 0;
  padding: 28px 8px 8px;
  background: linear-gradient(to top, rgba(0,0,0,.92) 0%, transparent 100%);
}
.card__title {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__rating {
  font-size: 0.62rem;
  color: var(--accent);
  margin-top: 2px;
}

/* Pastille de statut */
.card__status-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,.5);
}
.card__status-dot--watchlist { background: var(--text-muted); }
.card__status-dot--watching  { background: var(--accent-2); }
.card__status-dot--watched   { background: var(--success); }

/* ─────────────────────────────────────────────────────────────
   LISTE DE RÉSULTATS / RECENT
───────────────────────────────────────────────────────────── */
.search-result {
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
  align-items: flex-start;
  -webkit-tap-highlight-color: transparent;
}
.search-result:last-child { border-bottom: none; }
.search-result:active { background: var(--surface); }

.search-result__poster {
  width: 50px;
  height: 75px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}
.search-result__poster--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-muted);
}

.search-result__info { flex: 1; min-width: 0; padding-top: 2px; }
.search-result__title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-result__meta  { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.in-library-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.65rem;
  border: 1px solid var(--border);
}

.search-result__add {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  margin-top: 6px;
  transition: transform 0.12s;
}
.search-result__add:active { transform: scale(0.88); }
.search-result__add svg { width: 16px; height: 16px; }

/* ─────────────────────────────────────────────────────────────
   SEARCH INPUT
───────────────────────────────────────────────────────────── */
.search-box { padding: 4px 16px 8px; }

.search-input-wrap { position: relative; }
.search-input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 12px 12px 12px 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus        { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ─────────────────────────────────────────────────────────────
   STATS
───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.stat-card__value { font-size: 1.75rem; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-card__label { font-size: 0.65rem; color: var(--text-muted); margin-top: 5px; line-height: 1.3; }

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 16px 16px 8px;
}

/* ─────────────────────────────────────────────────────────────
   MODAL (bottom sheet)
───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
}
.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal__content {
  position: relative;
  width: 100%;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: slideUp .22s ease;
}

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

.modal__handle {
  width: 38px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 16px;
}

.modal__header {
  display: flex;
  gap: 14px;
  padding: 0 16px 16px;
}
.modal__poster {
  width: 80px;
  height: 120px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}
.modal__poster--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-muted);
}
.modal__info { flex: 1; min-width: 0; padding-top: 2px; }
.modal__title  { font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.modal__meta   { font-size: 0.78rem; color: var(--text-muted); margin-top: 5px; }
.modal__genres { font-size: 0.73rem; color: var(--text-muted); margin-top: 4px; }
.modal__overview {
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.modal__body {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─────────────────────────────────────────────────────────────
   FORMULAIRE
───────────────────────────────────────────────────────────── */
.form-group  { display: flex; flex-direction: column; gap: 7px; }
.form-label  { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.form-select,
.form-input,
.form-textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237878a4' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-select:focus,
.form-input:focus,
.form-textarea:focus  { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ─────────────────────────────────────────────────────────────
   ÉTOILES
───────────────────────────────────────────────────────────── */
.star-rating { display: flex; gap: 6px; }
.star {
  font-size: 1.6rem;
  color: var(--border);
  cursor: pointer;
  transition: color .1s, transform .1s;
  line-height: 1;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.star.active { color: var(--accent); }
.star:hover  { transform: scale(1.15); }

/* ─────────────────────────────────────────────────────────────
   BOUTONS
───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent);  color: #000; border-color: var(--accent); }
.btn-primary:active { opacity: .82; }
.btn-danger  { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:active  { background: var(--danger); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:active   { background: var(--surface-2); }

.btn-row {
  display: flex;
  gap: 10px;
  padding: 16px 16px 0;
}
.btn-row .btn { flex: 1; }

/* ─────────────────────────────────────────────────────────────
   TOAST
───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 600;
  z-index: 300;
  white-space: nowrap;
  pointer-events: none;
  animation: fadeInToast .2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast[hidden] { display: none; }

@keyframes fadeInToast {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0);    }
}

/* ─────────────────────────────────────────────────────────────
   LOADER / SPINNER
───────────────────────────────────────────────────────────── */
.loader  { display: flex; justify-content: center; padding: 48px; }
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────
   EMPTY STATE
───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
  gap: 14px;
}
.empty-state svg { opacity: .35; }
.empty-state p   { font-size: 0.88rem; line-height: 1.55; }

/* ─────────────────────────────────────────────────────────────
   DESKTOP (≥ 600 px) — légère adaptation
───────────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  #app { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
