/* =============================================================
   Fil — feuille de style unique
   Sombre par défaut, clair si le système le demande.
   ============================================================= */

:root {
  --bg:        #000;
  --surface:   #000;
  --elevated:  #121212;
  --border:    #262626;
  --text:      #f5f5f5;
  --muted:     #a8a8a8;
  --faint:     #5c5c5c;
  --blue:      #0095f6;
  --grad:      linear-gradient(45deg, #FCAF45, #E1306C 45%, #833AB4 80%, #5851DB);
  --topbar-h:  56px;
  --tabbar-h:  50px;
  --radius:    14px;
  --shadow:    0 8px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:       #fafafa;
    --surface:  #fff;
    --elevated: #fff;
    --border:   #dbdbdb;
    --text:     #262626;
    --muted:    #737373;
    --faint:    #c7c7c7;
    --shadow:   0 8px 40px rgba(0,0,0,.14);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

/* les classes .modal/.sheet/.story-viewer imposent un display : on rétablit
   la priorité de l'attribut hidden, qui pilote tout l'affichage en JS */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.locked { overflow: hidden; }

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

svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------------- Barre supérieure ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-in {
  height: var(--topbar-h);
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
}
.brand {
  font-size: 25px; font-weight: 700; letter-spacing: -.8px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  color: transparent; padding: 0;
}
.top-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  transition: background .15s, transform .1s;
}
.icon-btn:active { transform: scale(.9); }
@media (hover: hover) { .icon-btn:hover { background: var(--elevated); } }
.icon-btn.light { color: #fff; }
.icon-btn.on svg { fill: currentColor; }

/* barre de rafraîchissement */
.refresh-bar {
  height: 2px; width: 0%;
  background: var(--grad);
  transition: width .3s ease;
}
.refresh-bar.go { width: 100%; }

/* ---------------- Mise en page ---------------- */

#main {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
.view-title {
  font-size: 17px; font-weight: 700;
  padding: 18px 16px 8px; margin: 0;
}
.feed { display: flex; flex-direction: column; }
.sentinel { height: 1px; }
.end-note {
  text-align: center; color: var(--faint);
  padding: 28px 16px 40px; font-size: 13px;
}

/* ---------------- Stories (sujets chauds) ---------------- */

.stories-wrap { border-bottom: 1px solid var(--border); }
.stories {
  display: flex; gap: 14px;
  padding: 14px 16px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.stories::-webkit-scrollbar { display: none; }

.story {
  flex: 0 0 auto; width: 74px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  scroll-snap-align: start;
  padding: 0;
}
.story-ring {
  width: 68px; height: 68px; border-radius: 50%;
  background: var(--grad);
  padding: 2.5px;
  display: grid; place-items: center;
  transition: transform .12s;
}
.story:active .story-ring { transform: scale(.94); }
.story.seen .story-ring { background: var(--border); }
.story-img {
  width: 100%; height: 100%; border-radius: 50%;
  border: 2.5px solid var(--surface);
  object-fit: cover; background: var(--elevated);
}
.story-label {
  font-size: 11px; line-height: 1.25; color: var(--text);
  width: 76px; text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.story-count {
  font-size: 10px; color: var(--muted);
}

/* ---------------- Carte (article ou cluster) ---------------- */

.card {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
@media (min-width: 660px) {
  .card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 16px 0;
    overflow: hidden;
  }
  .stories-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 16px;
  }
}

.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px;
  flex: 0 0 auto; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.ring {
  padding: 2px; background: var(--grad);
}
.avatar.ring > span {
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
  background: var(--elevated); color: var(--text);
  font-size: 12px;
}
.head-txt { min-width: 0; flex: 1; }
.head-name {
  font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.head-sub { color: var(--muted); font-size: 12px; }
.dot-sep::before { content: "·"; margin: 0 5px; }

.badge-live {
  display: inline-flex; align-items: center; gap: 5px;
  color: #ff3b5c; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .3px;
}
.badge-live i {
  width: 6px; height: 6px; border-radius: 50%; background: #ff3b5c;
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .35; transform: scale(1.5); }
}

/* --- média --- */
.media {
  position: relative;
  width: 100%; aspect-ratio: 5 / 4; max-height: 460px;
  background: var(--elevated);
  overflow: hidden;
}
.media img { width: 100%; height: 100%; object-fit: cover; }
.media.ph { display: grid; place-items: center; }
.media.ph .ph-txt {
  font-size: 15px; font-weight: 700; letter-spacing: .5px;
  color: rgba(255,255,255,.92); text-align: center; padding: 0 24px;
  text-shadow: 0 1px 12px rgba(0,0,0,.35);
}
.media .over {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 44px 14px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.78));
  color: #fff; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}

/* --- actions --- */
.actions {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 2px;
}
.actions .spacer { flex: 1; }
.actions .icon-btn svg { width: 25px; height: 25px; }
.save-btn.on svg { fill: currentColor; }

/* --- texte --- */
.caption { padding: 4px 14px 10px; }
.caption .title {
  font-size: 15px; font-weight: 600; line-height: 1.32;
  letter-spacing: -.1px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.caption .desc {
  color: var(--muted); font-size: 13px; margin-top: 5px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.caption .time { color: var(--faint); font-size: 11px; margin-top: 8px; text-transform: uppercase; }

/* ---------------- Carte cluster ---------------- */

.card.cluster { position: relative; }
.card.cluster .card-head { padding-bottom: 6px; }
.cluster-title {
  font-size: 16.5px; font-weight: 700; line-height: 1.28;
  letter-spacing: -.3px;
  padding: 0 14px 6px;
}
.cluster-sum {
  color: var(--muted); font-size: 13px;
  padding: 0 14px 10px;
}

/* carrousel horizontal, un article par vue */
.carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.carousel::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.slide .media { aspect-ratio: 16 / 10; }   /* un peu plus bas : la carte porte déjà un titre */
.slide-cap {
  padding: 10px 14px 4px;
}
.slide-cap .src {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  margin-bottom: 4px;
}
.slide-cap .src i {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block;
}
.slide-cap .t {
  font-size: 14.5px; font-weight: 600; line-height: 1.32;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* dernière vue du carrousel : « tout voir » */
.slide.more {
  display: grid; place-items: center;
  background: var(--elevated);
}
.slide.more .more-in { text-align: center; padding: 30px 20px; }
.slide.more .n {
  font-size: 34px; font-weight: 800; letter-spacing: -1px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.slide.more .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.slide.more button { margin-top: 14px; }

.dots {
  display: flex; justify-content: center; gap: 5px;
  padding: 10px 0 2px;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint); opacity: .5;
  transition: all .2s;
}
.dot.on { background: var(--blue); opacity: 1; transform: scale(1.15); }

.carousel-wrap { position: relative; }
.counter-pill {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  pointer-events: none;
  background: rgba(0,0,0,.65); color: #fff;
  font-size: 11.5px; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
  backdrop-filter: blur(4px);
}

/* --- déjà lu --- */
.card.read .media,
.slide.read .media,
.row.read .thumb { opacity: .5; }
.card.read .caption .title,
.slide.read .slide-cap .t,
.row.read .txt .t { color: var(--muted); font-weight: 500; }

.tag-read {
  margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--faint);
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
}
.new-count {
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  color: transparent; font-weight: 700;
}

.sources-row {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 14px 10px;
  color: var(--muted); font-size: 12px;
  flex-wrap: wrap;
}
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}

/* ---------------- Boutons ---------------- */

.btn-primary {
  width: 100%; padding: 11px 16px;
  background: var(--blue); color: #fff;
  border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: opacity .15s;
}
.btn-primary:disabled { opacity: .5; }
.btn-outline {
  padding: 9px 16px; border: 1px solid var(--border);
  border-radius: 10px; font-weight: 600; font-size: 13px;
}
.btn-link { color: var(--blue); font-weight: 600; font-size: 13px; padding: 10px; width: 100%; }

/* ---------------- Recherche ---------------- */

.search-box {
  position: relative;
  margin: 14px 16px 6px;
}
.search-box .search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted);
}
.search-box input {
  width: 100%; padding: 11px 14px 11px 38px;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; outline: none;
}

/* ---------------- Compte ---------------- */

.account-box { padding: 6px 16px 40px; }
.account-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center;
}
.account-card .who { font-weight: 600; margin: 10px 0 2px; }
.account-card .sub { color: var(--muted); font-size: 13px; }
.account-card .big-avatar {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 50%; background: var(--grad);
  display: grid; place-items: center; color: #fff;
  font-size: 24px; font-weight: 700;
}
.account-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.install-hint { color: var(--faint); font-size: 12px; text-align: center; margin-top: 18px; }

/* ---------------- États vides / squelettes ---------------- */

.empty {
  text-align: center; color: var(--muted);
  padding: 60px 30px;
}
.empty svg { width: 44px; height: 44px; margin-bottom: 14px; color: var(--faint); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }

.skel { padding: 12px 14px 20px; border-bottom: 1px solid var(--border); }
.skel .l { background: var(--elevated); border-radius: 8px; animation: sh 1.3s infinite; }
.skel .r1 { height: 34px; width: 55%; margin-bottom: 12px; border-radius: 999px; }
.skel .r2 { height: 240px; margin-bottom: 12px; }
.skel .r3 { height: 13px; width: 90%; margin-bottom: 8px; }
.skel .r4 { height: 13px; width: 60%; }
@keyframes sh { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* ---------------- Barre d'onglets ---------------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; height: 100%;
  display: grid; place-items: center;
  color: var(--muted);
}
.tab.is-on { color: var(--text); }
.tab.is-on svg { fill: currentColor; stroke-width: 1.4; }

@media (min-width: 660px) {
  .tabbar { display: none; }
  #main { padding-bottom: 40px; }
}
@media (max-width: 659px) {
  .top-actions [data-tab="search"] { display: none; }
}

/* ---------------- Visionneuse de stories ---------------- */

.story-viewer {
  position: fixed; inset: 0; z-index: 90;
  background: #000; color: #fff;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.story-progress {
  display: flex; gap: 3px; padding: 10px 10px 4px;
}
.story-progress span {
  flex: 1; height: 2.5px; border-radius: 2px;
  background: rgba(255,255,255,.3); overflow: hidden;
}
.story-progress span i {
  display: block; height: 100%; width: 0; background: #fff;
}
.story-progress span.done i { width: 100%; }
.story-progress span.on i { width: 100%; transition: width 6s linear; }

.story-head {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px 10px;
}
.story-head-txt { flex: 1; min-width: 0; }
.story-head-txt strong {
  display: block; font-size: 14px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.story-head-txt span { font-size: 11.5px; color: rgba(255,255,255,.65); }

.story-stage { flex: 1; position: relative; overflow: hidden; }
.story-slot   { position: absolute; inset: 0; }
.story-card {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.story-card .bg { position: absolute; inset: 0; }
.story-card .bg img { width: 100%; height: 100%; object-fit: cover; }
.story-card .shade {
  position: absolute; inset: 0;
  background: linear-gradient(rgba(0,0,0,.25) 0 30%, rgba(0,0,0,.85));
}
.story-card .body {
  position: relative; z-index: 3;     /* au-dessus des zones de navigation */
  padding: 0 22px 32px;
  max-width: 560px; width: 100%; margin: 0 auto;
}
.story-card .src {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: rgba(255,255,255,.8);
  margin-bottom: 10px;
}
.story-card .src i { width: 8px; height: 8px; border-radius: 50%; }
.story-card h3 {
  font-size: 22px; line-height: 1.25; margin: 0 0 12px;
  font-weight: 700; letter-spacing: -.4px;
}
.story-card p {
  font-size: 13.5px; color: rgba(255,255,255,.75); margin: 0 0 18px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.story-cta { display: flex; gap: 10px; align-items: center; }
.story-cta a {
  flex: 1; text-align: center; padding: 12px;
  background: #fff; color: #000; border-radius: 10px;
  font-weight: 600; font-size: 14px;
}
.story-cta .icon-btn { border: 1px solid rgba(255,255,255,.35); border-radius: 10px; width: 46px; height: 46px; }

.story-nav { position: absolute; inset: 0; z-index: 2; display: flex; }
.story-nav button { flex: 1; background: none; }
.story-nav #storyNext { flex: 2; }

/* ---------------- Feuille (tous les articles d'un sujet) ---------------- */

.sheet {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  background: var(--surface);
  width: 100%; max-width: 640px;
  max-height: 88vh;
  border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translateY(6%); opacity: .6; } }
.sheet-head {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.grab {
  position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 4px; border-radius: 2px; background: var(--border);
}
.sheet-title { flex: 1; font-weight: 700; font-size: 15px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.row {
  display: flex; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.row:last-child { border-bottom: 0; }
.row .thumb {
  width: 84px; height: 84px; border-radius: 10px;
  flex: 0 0 auto; overflow: hidden; background: var(--elevated);
}
.row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.row .txt { flex: 1; min-width: 0; }
.row .txt .s { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.row .txt .t {
  font-size: 14px; font-weight: 600; line-height: 1.33;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.row .txt .d { font-size: 11px; color: var(--faint); margin-top: 5px; }
.row .save-btn { flex: 0 0 auto; }

/* ---------------- Modale de connexion ---------------- */

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.7);
  display: grid; place-items: center;
  padding: 20px;
}
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%; max-width: 360px;
  padding: 30px 24px 22px;
  box-shadow: var(--shadow);
  animation: up .2s ease;
}
.modal-x { position: absolute; top: 8px; right: 8px; }
.modal-brand {
  font-size: 30px; font-weight: 700; letter-spacing: -1px; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 18px;
}
.auth-step { display: flex; flex-direction: column; gap: 12px; }
.auth-help { color: var(--muted); font-size: 13px; text-align: center; margin: 0 0 4px; }
.auth-step input[type=email] {
  width: 100%; padding: 12px 14px;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; outline: none;
}
.code-inputs { display: flex; gap: 8px; justify-content: space-between; }
.code-inputs input {
  width: 100%; aspect-ratio: 3/4; text-align: center;
  font-size: 22px; font-weight: 700;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; outline: none;
  padding: 0;
}
.code-inputs input:focus { border-color: var(--blue); }
.auth-msg { text-align: center; font-size: 13px; margin: 10px 0 0; min-height: 18px; }
.auth-msg.err { color: #ed4956; }
.auth-msg.ok  { color: #4bb543; }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  z-index: 120;
  background: var(--elevated); color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow);
  animation: up .2s ease;
  max-width: 88vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}