:root {
  --bg-1: #04131a;
  --bg-2: #0d2a35;
  --bg-3: #f4a23a;
  --panel: rgba(5, 16, 22, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #f6f8f9;
  --muted: #b6c4c9;
  --accent: #ffbd59;
  --accent-2: #2de2c6;
  --danger: #ff7a7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Sora", sans-serif;
  color: var(--text);
  background: radial-gradient(
      1200px 620px at 90% -10%,
      rgba(255, 189, 89, 0.3),
      transparent 60%
    ),
    radial-gradient(
      900px 540px at 10% 110%,
      rgba(45, 226, 198, 0.2),
      transparent 60%
    ),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(
      rgba(255, 255, 255, 0.04) 1px,
      transparent 1px
    ),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 100%);
}

.app-version-chip {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 70;
  border: 1px solid rgba(45, 226, 198, 0.5);
  border-radius: 999px;
  padding: 6px 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: #d5fff7;
  background: rgba(4, 19, 26, 0.82);
  backdrop-filter: blur(10px);
}

.apk-chip {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 70;
  border: 1px solid rgba(255, 189, 89, 0.5);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: rgba(4, 19, 26, 0.82);
  backdrop-filter: blur(10px);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.apk-chip:hover {
  background: rgba(255, 189, 89, 0.15);
  border-color: var(--accent);
}

.layout {
  width: min(1000px, 92vw);
  margin: 54px auto 72px;
  display: grid;
  gap: 20px;
  justify-items: center;
}

.hero h1 {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.kicker {
  margin: 0;
  color: var(--accent-2);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
}

.subtitle {
  margin: 0;
  max-width: 780px;
  color: var(--muted);
}

.hero {
  text-align: center;
}

.panel {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px;
  width: 100%;
  max-width: 920px;
}

.tabs {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.tab-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  min-height: 44px;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), #ffe0a6);
  color: #111;
  border-color: transparent;
}

.tab-panel {
  width: 100%;
}

.form {
  max-width: 860px;
  margin: 0 auto;
}

.label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.remember-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.remember-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border-radius: 4px;
  accent-color: var(--accent-2);
}

input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 12px;
  font-size: 1rem;
  padding: 14px 16px;
  outline: none;
}

select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 12px;
  font-size: 1rem;
  padding: 12px 14px;
  outline: none;
}

select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(45, 226, 198, 0.12);
}

select option {
  color: #111;
}

input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(45, 226, 198, 0.12);
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #111;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #ffe0a6);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.tabs .tab-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.tabs .tab-btn.active {
  background: linear-gradient(135deg, var(--accent), #ffe0a6);
  color: #111;
  border-color: transparent;
}

.status {
  margin: 14px auto 0;
  max-width: 860px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(45, 226, 198, 0.4);
  background: rgba(45, 226, 198, 0.08);
  color: #c9fff5;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
}

.status.error {
  border-color: rgba(255, 122, 122, 0.5);
  background: rgba(255, 122, 122, 0.12);
  color: #ffd3d3;
}

.category-row {
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

.result-top {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 190px;
}

.meta-title {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.85rem;
  font-family: "JetBrains Mono", monospace;
}

.desc {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
}

.cover {
  width: 190px;
  height: 190px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.metrics {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric-value {
  display: block;
  margin-top: 5px;
  font-size: 1.05rem;
  font-weight: 700;
}

.actions {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.source-chip {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: #bff5ec;
  border: 1px solid rgba(45, 226, 198, 0.45);
  border-radius: 999px;
  padding: 4px 8px;
  margin-left: auto;
}

.reused-badge {
  display: inline-block;
  margin-bottom: 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: #bff5ec;
  border: 1px solid rgba(45, 226, 198, 0.45);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(45, 226, 198, 0.1);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.library-categories {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-pill {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  padding: 6px 10px;
  cursor: pointer;
}

.filter-pill.active {
  border-color: rgba(45, 226, 198, 0.45);
  background: rgba(45, 226, 198, 0.14);
  color: #bff5ec;
}

.card {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px;
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

.card img:hover {
  transform: scale(1.01);
  opacity: 0.92;
}

.card p {
  margin: 10px 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--muted);
  max-height: 78px;
  overflow: auto;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.card-actions button,
.card-actions a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  font-size: 0.8rem;
  padding: 8px 10px;
  border-radius: 8px;
  min-height: 40px;
}

.card-actions a {
  border: 1px solid rgba(45, 226, 198, 0.4);
  color: var(--accent-2);
}

.player {
  width: 100%;
  border-radius: 12px;
  max-height: 70vh;
  background: #000;
  object-fit: contain;
}

.player-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 80px;
  color: #8ab4c2;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}
.player-loading::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #8ab4c2;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 10px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.video-modal-card {
  width: min(980px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.video-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

#filmstrip-toggle.active {
  background: var(--accent);
  color: #000;
}

.video-modal-card.filmstrip-open .player {
  flex: 1 1 auto;
  min-height: 80px;
  max-height: none;
}

.filmstrip-panel {
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  height: 90px;
  margin: 6px 0;
  background: #000;
  border-radius: 8px;
  scroll-behavior: auto;
}

.filmstrip-track {
  display: flex;
  height: 100%;
  gap: 1px;
  padding: 1px;
}

.filmstrip-slot {
  flex-shrink: 0;
  width: 50px;
  height: 88px;
  background: #1a1a1a;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  border: 2px solid transparent;
  box-sizing: border-box;
}

.filmstrip-slot.active {
  border-color: var(--accent);
}

.filmstrip-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.filmstrip-slot .slot-loading {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.2);
  font-size: 9px;
}

.frame-tools {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.frame-tools input {
  width: 72px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.frame-tools label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.frame-tools-sep {
  width: 1px;
  height: 24px;
  background: var(--muted);
  opacity: 0.3;
  margin: 0 2px;
}

#extract-frames-btn {
  background: var(--accent);
  color: #fff;
}

.sql-wrap {
  overflow: auto;
}

.sql-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.sql-table th,
.sql-table td {
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.sql-table th {
  background: rgba(255, 255, 255, 0.08);
}

.category-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 12px;
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-pill {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 6px 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: #d9f4ff;
  background: rgba(255, 255, 255, 0.05);
}

.category-pill-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-select {
  width: 100%;
  margin: 8px 0;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.category-pill.clickable {
  cursor: pointer;
  border-color: rgba(255, 122, 122, 0.45);
  color: #ffd3d3;
  background: rgba(255, 122, 122, 0.12);
}

.category-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.tiny-btn {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 122, 122, 0.14);
  color: #ffd3d3;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 0.72rem;
  cursor: pointer;
}

.cat-chip {
  display: inline-block;
  margin: 8px 0;
  border: 1px solid rgba(45, 226, 198, 0.4);
  border-radius: 999px;
  padding: 6px 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: #bff5ec;
  background: rgba(45, 226, 198, 0.1);
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 18px;
}

.modal-card {
  width: min(360px, 100%);
  background: #0d2028;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 12px;
}

.modal-category-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.modal-option {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 0.86rem;
  line-height: 1.1;
}

.modal-option input[type="radio"] {
  margin: 0;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  transform: translateY(0);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.download-btn {
  text-decoration: none;
  color: #111;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #ffe0a6);
  border-radius: 12px;
  padding: 12px 16px;
}

.play-result-btn {
  color: #fff;
  font-weight: 700;
  background: var(--accent-2);
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 0.9rem;
}

.source-link {
  color: var(--accent-2);
  text-decoration: none;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
}

.debug-log {
  margin: 0 auto;
  max-width: 860px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.25);
  color: #d3fff7;
  font-size: 0.8rem;
  line-height: 1.35;
  font-family: "JetBrains Mono", monospace;
}

.reveal {
  opacity: 0;
  transform: translateY(14px);
  animation: rise 620ms ease forwards;
}

.delay-1 {
  animation-delay: 120ms;
}

.delay-2 {
  animation-delay: 240ms;
}

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 800px) {
  .layout {
    width: min(1000px, 94vw);
    margin-top: 18px;
    margin-bottom: 28px;
    gap: 12px;
  }

  .hero {
    text-align: left;
  }

  .hero h1 {
    font-size: clamp(1.45rem, 8.3vw, 2.15rem);
    line-height: 1.12;
  }

  .subtitle {
    font-size: 0.94rem;
    line-height: 1.4;
  }

  .panel {
    border-radius: 14px;
    padding: 14px;
  }

  .input-row {
    grid-template-columns: 1fr auto;
  }

  button {
    min-height: 46px;
  }

  input,
  select {
    min-height: 46px;
    font-size: 16px;
  }

  .tab-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .source-chip {
    margin-left: 0;
    align-self: flex-start;
  }

  .result-top {
    grid-template-columns: 1fr;
  }

  .cover {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
    gap: 10px;
  }

  .download-btn,
  .source-link {
    width: 100%;
    text-align: center;
  }

  .source-link {
    border: 1px solid rgba(45, 226, 198, 0.35);
    border-radius: 12px;
    padding: 12px 14px;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .tabs .tab-btn {
    width: 100%;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
  }

  #logout-btn {
    grid-column: 1 / -1;
  }

  .library-grid {
    grid-template-columns: 1fr;
  }

  .card-actions {
    flex-direction: column;
  }

  .card-actions button,
  .card-actions a {
    width: 100%;
  }

  .category-form {
    grid-template-columns: 1fr;
  }

  .sql-table {
    min-width: 760px;
    font-size: 0.76rem;
  }

  .debug-log {
    max-height: 180px;
  }
}

@media (max-width: 480px) {
  .app-version-chip {
    top: 8px;
    right: 8px;
    font-size: 0.7rem;
    padding: 5px 8px;
  }

  .kicker {
    font-size: 0.74rem;
  }

  .tab-btn {
    font-size: 0.84rem;
    padding: 9px 12px;
  }

  .meta-title {
    font-size: 0.78rem;
  }

  .card {
    padding: 9px;
  }

  .card p {
    max-height: 92px;
  }

  .video-modal-card {
    padding: 10px;
  }

  .frame-tools {
    gap: 6px;
  }

  .frame-tools input {
    width: 66px;
  }
}

@media (max-width: 768px) {
  .modal {
    padding: 10px;
  }

  .video-modal-card {
    width: min(100%, 720px);
    height: min(92vh, calc(100dvh - 12px));
  }

  .player {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    max-height: none;
  }

  .frame-tools {
    flex-shrink: 0;
  }
}

/* Contrôles frame en plein écran mobile */
.video-modal-card.fullscreen-active .frame-tools {
  padding: 10px 4px;
  gap: 10px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 10px;
  justify-content: center;
  flex-shrink: 0;
}
.video-modal-card.fullscreen-active .frame-tools button {
  min-width: 72px;
  min-height: 44px;
  font-size: 1rem;
  padding: 10px 14px;
}
.video-modal-card.fullscreen-active .frame-tools input {
  width: 64px;
  min-height: 44px;
  font-size: 1rem;
  text-align: center;
}
.video-modal-card.fullscreen-active .video-modal-head {
  flex-shrink: 0;
}

/* Video plein écran mobile (classe ajoutée par JS via IS_MOBILE) */
#video-modal.mobile-fullscreen {
  padding: 0;
  place-items: stretch;
}
#video-modal.mobile-fullscreen .video-modal-card {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  padding: 8px 10px;
  box-sizing: border-box;
}
#video-modal.mobile-fullscreen .player {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: none;
  border-radius: 0;
}
#video-modal.mobile-fullscreen .frame-tools {
  flex-shrink: 0;
}

/* ── Log panel ffmpeg ─────────────────────────────────────────────────────── */
.ffmpeg-panel { margin: 10px auto 0; max-width: 860px; }
.ffmpeg-progress-bar {
  height: 3px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.ffmpeg-progress-fill {
  height: 100%;
  background: #2de2c6;
  border-radius: 2px;
  transition: width 0.35s;
  width: 0%;
}
.ffmpeg-log {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 200px;
  overflow-y: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75em;
  line-height: 1.8;
}
.log-line { display: flex; gap: 0.6rem; }
.log-ts   { color: #374151; min-width: 6rem; flex-shrink: 0; }
.log-ok   { color: #4ade80; }
.log-err  { color: #f87171; }
.log-info { color: #7dd3fc; }
.log-time { color: #fbbf24; }
.log-warn { color: #fb923c; }
.log-ffm  { color: #374151; }

/* ── Cookies tab ─────────────────────────────────────────────────────────── */
.cookies-help {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.6;
}
.cookies-textarea {
  width: 100%;
  min-height: 160px;
  background: #0d1f2b;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: var(--fg);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  padding: 10px 12px;
  resize: vertical;
  box-sizing: border-box;
}
.cookies-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.btn-danger {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.cookies-msg {
  margin-top: 10px;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(56,189,248,0.1);
  color: var(--accent);
}
.cookies-msg.error {
  background: rgba(239,68,68,0.1);
  color: #f87171;
}
#cookies-tab-btn.has-cookies::after {
  content: " ✓";
  color: #4ade80;
}
