:root {
  --accent: #ff3b5c;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --panel: #111113;
  --panel-2: #1d1d21;
  --panel-3: #2a2a30;
  --line: rgba(255, 255, 255, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

[hidden] { display: none !important; }

/* Sur ordinateur, le fil garde un format téléphone centré. */
#app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  width: 100%;
  max-width: calc(100vh * 9 / 16);
  max-width: calc(100dvh * 9 / 16);
  overflow: hidden;
  background: #000;
}

@media (max-aspect-ratio: 3/4) {
  #app { max-width: none; }
}

/* ---------- Lecteur + fil ---------- */

#stage {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Le lecteur dépasse en haut et en bas : une vidéo verticale garde la même
   taille (elle est calée sur la largeur), mais le titre et les boutons que
   YouTube affiche sur ses bords sortent de l'écran. */
#stage iframe,
#player {
  position: absolute;
  left: 0;
  top: -130px;
  display: block;
  width: 100%;
  height: calc(100% + 260px);
  border: 0;
}

/* Mode « touche la vidéo » (iPhone, premier son) : le lecteur reçoit le geste. */
body.tap-through #stage { pointer-events: auto; z-index: 2; }
body.tap-through #feed { pointer-events: none; }

#feed {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: none;
}

#feed::-webkit-scrollbar { display: none; }

/* Fil vide = chargement en cours (les écrans vides passent par-dessus). */
#feed:empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.slide {
  position: relative;
  height: 100%;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0d0d0f;
  transition: opacity 0.25s ease;
}

.slide.playing .thumb { opacity: 0; }

/* Vidéo horizontale : miniature entière plutôt que recadrée. */
.slide.wide .thumb { object-fit: contain; }

.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 38%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0) 16%);
}

.meta {
  position: absolute;
  left: 14px;
  right: 84px;
  bottom: calc(26px + var(--safe-bottom));
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.topic {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 12px;
  font-weight: 600;
  text-shadow: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.topic:empty { display: none; }

.channel {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}

.title {
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.rail {
  position: absolute;
  right: 6px;
  bottom: calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 64px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 11px;
  font-weight: 600;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}

.rail-btn svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.rail-btn.on { color: var(--accent); }
.rail-btn.on span { color: var(--text); }

.ico-sound { display: none; }
body:not(.muted) .ico-sound { display: block; }
body:not(.muted) .ico-muted { display: none; }

.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--safe-bottom);
  height: 18px;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  transition: opacity 0.2s;
}

.slide.playing .progress,
.slide.paused .progress { opacity: 1; }

.progress::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.22);
}

.bar {
  position: relative;
  height: 2px;
  width: 0;
  background: #fff;
}

.center-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72px;
  height: 72px;
  margin: -36px 0 0 -36px;
  pointer-events: none;
}

.slide.paused .center-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E") center / 40px no-repeat;
}

.slide.loading .center-icon::before {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.burst {
  position: absolute;
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ff3b5c'%3E%3Cpath d='M12 21s-7.5-4.6-9.6-9.3C.9 8.3 3 4.5 6.7 4.5c2.1 0 3.5 1.1 5.3 3.1 1.8-2 3.2-3.1 5.3-3.1 3.7 0 5.8 3.8 4.3 7.2C19.5 16.4 12 21 12 21z'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
  animation: burst 0.8s ease-out forwards;
}

@keyframes burst {
  0% { transform: scale(0.3) rotate(-12deg); opacity: 0; }
  20% { transform: scale(1.15) rotate(-12deg); opacity: 1; }
  40% { transform: scale(0.95) rotate(-12deg); }
  100% { transform: scale(1.3) translateY(-60px) rotate(-12deg); opacity: 0; }
}

/* ---------- Barre du haut ---------- */

#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) 10px 10px;
  pointer-events: none;
}

#topbar > * { pointer-events: auto; }

#chips {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
  mask-image: linear-gradient(to right, #000 88%, transparent);
  padding-right: 24px;
}

#chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chip.on {
  background: #fff;
  color: #000;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Son ---------- */

#sound-pill {
  position: absolute;
  z-index: 4;
  top: calc(var(--safe-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #000;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

#sound-pill svg { width: 20px; height: 20px; fill: currentColor; }

#tap-hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse { 50% { transform: translateX(-50%) scale(1.04); } }

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

#toast {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 28px);
  transform: translate(-50%, 12px);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(30, 30, 34, 0.96);
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast-action {
  margin-left: 12px;
  padding: 0;
  border: 0;
  background: none;
  color: #ff7a90;
  font-size: 14px;
  font-weight: 700;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- États vides / accueil ---------- */

#empty {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  background: radial-gradient(120% 70% at 50% 0%, #2a0f18 0%, #000 60%);
  padding: calc(var(--safe-top) + 64px) 22px calc(var(--safe-bottom) + 32px);
  -webkit-user-select: text;
  user-select: text;
}

#empty.under-bar { z-index: 2; }

.empty-inner {
  max-width: 420px;
  margin: 0 auto;
}

.empty-inner .logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 18px;
}

.empty-inner h1 {
  margin: 0 0 10px;
  font-size: 26px;
  line-height: 1.2;
}

.empty-inner p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.steps {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  position: relative;
  padding: 0 0 14px 38px;
  font-size: 15px;
  line-height: 1.45;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--panel-3);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

.steps a, .empty-inner a { color: #ff7a90; }

.steps b { font-weight: 700; }

.empty-inner .error {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 59, 92, 0.15);
  color: #ff9aab;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.btn-primary:disabled { opacity: 0.5; }

.btn-secondary {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-2);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 22px;
}

.suggestions button {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 14px;
}

.suggestions button.on {
  background: #fff;
  color: #000;
}

/* ---------- Réglages ---------- */

#settings {
  position: absolute;
  inset: 0;
  z-index: 10;
}

.sheet {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  padding: 0 16px calc(var(--safe-bottom) + 32px);
  animation: sheet-in 0.25s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -16px;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: rgba(17, 17, 19, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.sheet-head h1 {
  margin: 0;
  font-size: 20px;
}

.text-btn {
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

.group { margin-top: 26px; }

.group h2 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rows {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  border-radius: 12px;
  overflow: hidden;
}

.rows:empty { display: none; }

.rows li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 8px 8px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.rows li:last-child { border-bottom: 0; }

.rows .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rows li.off .name { color: var(--muted); text-decoration: line-through; }

.rows .warn {
  display: block;
  margin-top: 2px;
  color: #ffb340;
  font-size: 12px;
  white-space: normal;
}

.del-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.restore-btn {
  flex: none;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: var(--panel-3);
  font-size: 13px;
  font-weight: 600;
}

/* Interrupteur */
.switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
}

.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--panel-3);
  transition: background 0.2s;
  pointer-events: none;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.switch input:checked + span { background: #34c759; }
.switch input:checked + span::after { transform: translateX(18px); }

.add-row {
  display: flex;
  gap: 8px;
}

.add-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: #fff;
  font-size: 16px; /* 16px évite le zoom automatique d'iOS */
  outline: none;
}

.add-row input:focus { border-color: rgba(255, 255, 255, 0.3); }

.add-btn {
  flex: none;
  width: 46px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 600;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tags:empty { display: none; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 4px 5px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 14px;
}

.tag button {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field > span { font-size: 14px; }

.seg {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--panel-2);
}

.seg button {
  flex: 1;
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.seg button.on {
  background: var(--panel-3);
  color: #fff;
}

.wide-btn {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 15px;
  font-weight: 600;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: #ff7a90;
  font-size: inherit;
  text-decoration: underline;
}

.footer {
  margin: 30px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
