/* AmeriTube — thème sombre façon iOS. CSS « à la main » : aucun build, aucune dépendance CDN,
   la PWA démarre instantanément et entièrement hors-ligne. */
:root {
  color-scheme: dark;
  --bg: #000;
  --bg2: #1c1c1e;
  --bg3: #2c2c2e;
  --fill: rgba(118, 118, 128, .24);
  --sep: rgba(84, 84, 88, .65);
  --label: #fff;
  --label2: rgba(235, 235, 245, .6);
  --label3: rgba(235, 235, 245, .3);
  --accent: #0a84ff;
  --red: #ff453a;
  --green: #30d158;
  --orange: #ff9f0a;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --tabbar: 50px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--label); overscroll-behavior: none; }
body {
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
input, code { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
img { display: block; }
[hidden] { display: none !important; }
i[data-icon] { display: inline-flex; font-style: normal; }
i[data-icon] svg, .ico { width: 1.15em; height: 1.15em; }

/* Fond flou sous la barre d'état (status-bar-style black-translucent) */
.statusbar-bg {
  position: fixed; inset: 0 0 auto; height: var(--st); z-index: 20;
  background: rgba(0, 0, 0, .78); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}

/* ------------------------------------------------------------------ vues */
.view {
  position: fixed; inset: 0; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: calc(var(--st) + 6px) calc(var(--sr) + 16px) calc(var(--tabbar) + var(--sb) + 28px) calc(var(--sl) + 16px);
}
.view.active { display: block; }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .37px; margin: 6px 0 8px; }
.subtitle { color: var(--label2); font-size: 15px; margin: -4px 0 6px; min-height: 1px; }
.section-title {
  font-size: 13px; font-weight: 400; text-transform: uppercase; letter-spacing: .3px;
  color: var(--label2); margin: 22px 16px 7px;
}

/* ------------------------------------------------------------------ recherche */
.search {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 6px 0 8px;
  background: var(--bg3); border-radius: 10px; color: var(--label2);
}
.sticky {
  position: sticky; top: var(--st); z-index: 10;
  margin: 0 -16px; padding: 4px 16px 8px; background: var(--bg);
}
.search input {
  flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: 0;
  color: var(--label); font-size: 17px; /* >= 16px : pas de zoom automatique iOS */
}
.search input::placeholder { color: var(--label2); }
.search-aux { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--accent); }
.search-aux:active { background: var(--fill); }

/* Puces de flux (Accueil, Abonnements…) façon YouTube */
.chips {
  display: flex; gap: 8px; overflow-x: auto; margin: 10px -16px 0; padding: 0 16px 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; height: 32px; padding: 0 14px; border-radius: 8px; background: var(--bg3);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chips button.active { background: var(--label); color: #000; }
.chips button:active { opacity: .6; }
.list-header { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 17px; font-weight: 600; }
.list-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan { color: var(--label2); font-size: 13px; text-align: left; }
.chan:active { color: var(--label); }
.more { min-height: 60px; display: grid; place-items: center; }
.more.loading::after {
  content: ""; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--fill); border-top-color: var(--label2); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty .btn { margin-top: 16px; }

.banner {
  display: flex; gap: 8px; align-items: center; margin-top: 12px; padding: 10px 12px;
  border-radius: 10px; background: rgba(255, 159, 10, .14); color: var(--orange); font-size: 14px;
}

/* ------------------------------------------------------------------ résultats */
.results { display: grid; gap: 18px; margin-top: 16px; }
@media (min-width: 700px) { .results { grid-template-columns: repeat(2, 1fr); } }
.card { background: var(--bg2); border-radius: 14px; overflow: hidden; }
.thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; background: var(--bg3); overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .play-ovl {
  position: absolute; inset: 0; margin: auto; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); color: #fff; opacity: .9;
}
.thumb .play-ovl svg { width: 22px; height: 22px; margin-left: 3px; }
.dur {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, .78); color: #fff; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.card-body { padding: 10px 12px 12px; }
.title {
  font-size: 15px; font-weight: 600; line-height: 1.3; margin-bottom: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.meta { font-size: 13px; color: var(--label2); margin-bottom: 10px; line-height: 1.4; }
label.cell { color: var(--accent); cursor: pointer; }
label.cell:active { background: var(--bg3); }
.card-actions { min-height: 36px; }

.empty { text-align: center; color: var(--label2); padding: 56px 24px; font-size: 15px; line-height: 1.45; }
.empty .ico, .empty i[data-icon] svg { width: 52px; height: 52px; opacity: .45; margin: 0 auto 12px; display: block; }
.empty strong { display: block; color: var(--label); font-size: 17px; margin-bottom: 4px; }

.skel { background: linear-gradient(90deg, var(--bg2) 20%, var(--bg3) 50%, var(--bg2) 80%);
        background-size: 300% 100%; animation: shimmer 1.3s infinite linear; }
.skel-card { height: 290px; border-radius: 14px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ------------------------------------------------------------------ boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: 18px; background: var(--fill);
  font-size: 15px; font-weight: 600; white-space: nowrap; transition: opacity .15s;
}
.btn:active { opacity: .55; }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-done { color: var(--green); background: rgba(48, 209, 88, .14); }
.btn-danger { color: var(--red); }
.btn-lg { height: 50px; border-radius: 12px; font-size: 17px; width: 100%; }
.link { color: var(--accent); font-size: 14px; font-weight: 500; }
.link.danger { color: var(--red); }
.pill {
  width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center;
  background: var(--fill); color: var(--label);
}
.pill:active { opacity: .55; }

/* ------------------------------------------------------------------ progression */
.prog { display: grid; gap: 6px; }
.prog-top, .prog-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.prog-label { color: var(--label); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prog-pct { color: var(--label2); font-variant-numeric: tabular-nums; }
.prog-bottom { color: var(--label2); min-height: 18px; }
.bar { height: 5px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width .35s ease; }
.bar.green > i { background: var(--green); }
.bar.indeterminate > i { width: 35% !important; animation: indet 1.1s infinite ease-in-out; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.err { color: var(--red); font-size: 13px; line-height: 1.35; margin-bottom: 8px; }

/* ------------------------------------------------------------------ listes groupées (Coffre / Réglages) */
.group { background: var(--bg2); border-radius: 12px; overflow: hidden; }
.row { position: relative; display: flex; align-items: center; gap: 2px; padding: 10px 6px 10px 12px; }
.row + .row::before, .cell + .cell::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px; border-top: .5px solid var(--sep);
}
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; }
.row-main:active { opacity: .6; }
.row-thumb { position: relative; flex: none; width: 116px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--bg3); }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title {
  font-size: 15px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-sub { font-size: 13px; color: var(--label2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub.warn { color: var(--orange); }
.row-actions { display: flex; flex: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 20px; display: grid; place-items: center; color: var(--accent); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--fill); }
.icon-btn.danger { color: var(--red); }
.active-row { display: block; padding: 12px 14px; position: relative; }
.active-row + .active-row::before { content: ""; position: absolute; top: 0; right: 0; left: 14px; border-top: .5px solid var(--sep); }
.active-row .row-title { margin-bottom: 8px; }

.cell {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 46px; padding: 10px 16px; font-size: 17px;
}
.cell .v { color: var(--label2); text-align: right; font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.cell .v.ok { color: var(--green); }
.cell .v.ko { color: var(--red); }
button.cell { width: 100%; color: var(--accent); text-align: left; }
button.cell.danger { color: var(--red); }
button.cell:active { background: var(--bg3); }
.footnote { color: var(--label2); font-size: 13px; line-height: 1.45; margin: 8px 16px 0; }
.footnote b { color: var(--label); font-weight: 600; }
.meter { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; margin: 0 16px 12px; }
.meter > i { display: block; height: 100%; background: var(--accent); }

/* ------------------------------------------------------------------ barre d'onglets */
.tabbar {
  position: fixed; inset: auto 0 0; z-index: 30; display: flex;
  padding: 5px calc(var(--sr) + 4px) calc(var(--sb) + 2px) calc(var(--sl) + 4px);
  background: rgba(20, 20, 22, .82); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
  border-top: .5px solid var(--sep);
}
.tabbar button {
  position: relative; flex: 1; min-height: 46px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #8e8e93; font-size: 10px; font-weight: 500;
}
.tabbar button svg { width: 27px; height: 27px; }
.tabbar button.active { color: var(--accent); }
.badge {
  position: absolute; top: -2px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--red); color: #fff; font-size: 12px; font-weight: 600; line-height: 18px; text-align: center;
}

/* ------------------------------------------------------------------ lecteur */
.player {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: #000;
  padding: var(--st) var(--sr) var(--sb) var(--sl); animation: slide-up .3s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
.player-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; }
.player-bar-title { font-size: 15px; font-weight: 600; color: var(--label2); }
.player-stage { position: relative; background: #000; }
.player video { display: block; width: 100%; max-height: 62vh; background: #000; }
.audio-mode {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(0, 0, 0, .82); color: var(--label2); font-size: 15px; text-align: center; padding: 16px;
}
.audio-mode svg { width: 44px; height: 44px; color: var(--accent); }
.player-info { padding: 16px; overflow-y: auto; }
.player-info h2, .sheet-body h2 { font-size: 20px; font-weight: 700; line-height: 1.25; }
.player-info p, .sheet-body p { color: var(--label2); font-size: 14px; margin: 4px 0 14px; }
.player-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn.on { background: var(--accent); color: #fff; }
@media (orientation: landscape) and (max-height: 500px) {
  .player-bar { position: absolute; z-index: 2; inset: var(--st) var(--sr) auto var(--sl); }
  .player-info, .player-bar-title { display: none; }
  .player-stage { flex: 1; display: flex; align-items: center; }
  .player video { max-height: 100%; height: 100%; }
}

/* ------------------------------------------------------------------ feuille d'aperçu */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .55); animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 720px; background: var(--bg2); border-radius: 14px 14px 0 0; overflow: hidden;
  padding-bottom: calc(var(--sb) + 16px); animation: slide-up .3s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 7px auto; }
.embed { width: 100%; aspect-ratio: 16 / 9; background: #000; }
.embed iframe { width: 100%; height: 100%; border: 0; display: block; }
.sheet-body { padding: 14px 16px 0; }

/* ------------------------------------------------------------------ connexion */
.login {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding: calc(var(--st) + 24px) 24px calc(var(--sb) + 24px); background: var(--bg); text-align: center;
}
.login img { width: 84px; height: 84px; border-radius: 19px; margin: 0 auto 4px; }
.login h1 { font-size: 28px; }
.login p { color: var(--label2); font-size: 15px; line-height: 1.45; }
.login code { color: var(--label); font-size: 13px; }
.login form { display: grid; gap: 12px; margin-top: 10px; width: 100%; max-width: 420px; justify-self: center; align-self: center; }
.field {
  height: 50px; border: 0; border-radius: 12px; padding: 0 14px; outline: 0;
  background: var(--bg2); color: var(--label); font-size: 17px;
}
.error-text { color: var(--red) !important; font-weight: 600; }
.error-text:empty { display: none; }
.app-version { font-size: 12px !important; color: var(--label3) !important; margin-top: 8px; }

/* ------------------------------------------------------------------ toast / partage */
.toast, .share-ready {
  position: fixed; left: 50%; z-index: 70; max-width: calc(100% - 32px);
  bottom: calc(var(--tabbar) + var(--sb) + 14px);
  background: rgba(44, 44, 46, .96); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast {
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
  padding: 11px 16px; font-size: 14px; font-weight: 500; text-align: center; line-height: 1.35;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.share-ready { transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 16px; font-size: 15px; }
