/* OpenPix 2026 — thème « galerie de nuit »
 *
 * Contraintes du tour (ne pas casser) :
 *  - tuiles CARRÉES, 2 colonnes sur téléphone, ordre DOM = ordre des résultats ;
 *  - rien d'écrit sur les tuiles (le nom / les likes réels trahiraient le forçage) ;
 *  - aucune animation ni transform CSS sur l'<img> des tuiles (le propless peek la
 *    fait pivoter en style inline) ;
 *  - carré « peek » visible dans les coins du bas ;
 *  - #freeimages sans text-transform (« Free IMAGES » -> « FREE IMAGES » = synchro) ;
 *  - #logo garde ses 3 variantes (logo / logol / logor = indice gauche/droite) ;
 *  - #scroll-to-top garde ses images top / topl / topr (indice pair / impair).
 */
:root {
  --opx-pink: #ff2e88;
  --opx-violet: #8b5cff;
  --opx-cyan: #22d3ee;
  --grad: linear-gradient(120deg, #ff2e88 0%, #c13bff 50%, #6d6bff 100%);
  --bg: #07070b;
  --surface: #121219;
  --surface-2: #1a1a24;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f4f8;
  --muted: #8e8ea0;
  --glass: rgba(18, 18, 26, 0.62);
  --tile-gap: 10px;
  --tile-radius: 22px;
}

@media (min-width: 768px) {
  :root {
    --tile-gap: 16px;
    --tile-radius: 26px;
  }
}

html {
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background: transparent; /* fond porté par <html> : l'aurore passe derrière le contenu */
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Aurore lumineuse derrière la page */
body::before {
  content: "";
  position: fixed;
  inset: -20vh -30vw auto;
  height: 70vh;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(40% 50% at 20% 40%, rgba(255, 46, 136, 0.28), transparent 70%),
    radial-gradient(45% 55% at 80% 30%, rgba(109, 107, 255, 0.3), transparent 70%),
    radial-gradient(35% 40% at 55% 70%, rgba(34, 211, 238, 0.12), transparent 70%);
  filter: blur(30px);
  animation: opx-aurora 18s ease-in-out infinite alternate;
}

@keyframes opx-aurora {
  to {
    transform: translate3d(4vw, 3vh, 0) scale(1.08);
  }
}

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

.no-callout {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
}

/* ---------- En-tête (verre sombre) ---------- */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  overflow-x: hidden;
  max-width: 100vw;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(170%) blur(22px);
  backdrop-filter: saturate(170%) blur(22px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  padding: 10px 14px 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Logo PNG sombre : inversion + rotation de teinte => texte clair, rose conservé. */
#logo {
  width: 148px;
  height: auto;
  display: block;
  cursor: pointer;
  touch-action: manipulation;
  filter: invert(1) hue-rotate(180deg) saturate(1.3) brightness(1.08);
}

#logomenu {
  filter: invert(1) hue-rotate(180deg) saturate(1.3) brightness(1.08);
}

#freeimages {
  margin: 3px 0 0 2px;
  padding: 0;
  min-height: 1.1em;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.12);
}

.icon-btn img {
  filter: invert(1);
  opacity: 0.9;
}

/* ---------- Recherche ---------- */
.searchbar {
  position: relative;
  display: flex;
  align-items: center;
  height: 50px;
  margin-top: 10px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.searchbar:focus-within {
  background: rgba(255, 255, 255, 0.1);
  border-color: transparent;
  box-shadow:
    0 0 0 1.5px rgba(255, 46, 136, 0.85),
    0 0 28px -4px rgba(193, 59, 255, 0.55);
}

.search-ico {
  width: 20px;
  height: 20px;
  margin: 0 6px 0 12px;
  flex: 0 0 auto;
  background: no-repeat center / contain
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8ea0' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
}

.search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* pas de zoom automatique sur iPhone */
  caret-color: var(--opx-pink);
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder {
  color: #6f6f80;
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-go {
  position: relative;
  flex: 0 0 auto;
  height: 100%;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  background: var(--grad);
  background-size: 200% 100%;
  box-shadow: 0 8px 22px -8px rgba(255, 46, 136, 0.9);
  transition: transform 0.15s ease, background-position 0.6s ease;
}

.search-go:hover {
  background-position: 100% 0;
}

.search-go:active {
  transform: scale(0.94);
}

/* ---------- Bannière d'accueil ---------- */
#startlogo {
  margin: 14px 0 6px;
  border-radius: 28px;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.9);
}

#startlogo > img {
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

#startlogo::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(7, 7, 11, 0.1) 0%, rgba(7, 7, 11, 0.55) 60%, rgba(7, 7, 11, 0.92) 100%),
    radial-gradient(80% 60% at 50% 100%, rgba(193, 59, 255, 0.35), transparent 70%);
  pointer-events: none;
}

.start-text {
  z-index: 1;
  color: #fff;
  width: calc(100% - 40px);
  box-sizing: border-box;
  margin: 5px;
}

#big-title {
  font-weight: 800;
  letter-spacing: -0.03em;
}

.btn-custom,
.btn-custom:hover,
.btn-custom:focus,
.btn-custom:active {
  border: 0;
  color: #fff;
  background: var(--grad);
  box-shadow: 0 8px 22px -8px rgba(255, 46, 136, 0.9);
}

/* ---------- Grille ---------- */
#images-row {
  --bs-gutter-x: 0;
  --bs-gutter-y: 0;
  margin: 12px calc(var(--tile-gap) / -2) 0;
  padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
}

.image-container {
  padding: calc(var(--tile-gap) / 2);
}

.image-link {
  position: relative;
  display: block;
  border-radius: var(--tile-radius);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.square {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--tile-radius);
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(110deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%) var(--surface);
  background-size: 300% 100%;
  animation: opx-shimmer 1.3s ease-in-out infinite;
  box-shadow: 0 18px 36px -22px rgba(0, 0, 0, 0.95);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.22s ease;
}

@supports not (aspect-ratio: 1 / 1) {
  .square {
    height: 0;
    padding-bottom: 100%;
  }
}

.square.loaded {
  animation: none;
  background: var(--surface);
}

.square .image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: none; /* propless peek : le retournement doit être instantané, sans animation */
}

/* Liseré lumineux + léger voile en bas pour la profondeur */
.square::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, transparent 28%, transparent 70%, rgba(0, 0, 0, 0.28) 100%);
}

/* Apparition au chargement : calque qui s'efface (jamais sur l'<img>) */
.square .tile-fade {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--surface);
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.square.loaded .tile-fade {
  opacity: 0;
}

/* Bordure dégradée qui s'allume au toucher */
.image-link::before {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: 0;
  border-radius: calc(var(--tile-radius) + 2px);
  background: var(--grad);
  opacity: 0;
  filter: blur(0.5px);
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.image-link:active::before {
  opacity: 1;
}

.image-link:active .square {
  transform: scale(0.955);
}

@media (hover: hover) {
  .image-link:hover::before {
    opacity: 0.9;
  }
  .image-link:hover .square {
    transform: translateY(-3px);
    box-shadow: 0 30px 50px -24px rgba(193, 59, 255, 0.55);
  }
}

.image-link:focus-visible::before {
  opacity: 1;
}

/* Arrivée des tuiles pilotée par le défilement (Safari 26+, Chrome 115+).
 * L'animation se termine quand la tuile est entièrement entrée à l'écran :
 * le calcul « image entièrement visible » du tour n'est donc pas faussé. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .image-container {
      animation: opx-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 100%;
    }
  }
}

@keyframes opx-rise {
  from {
    opacity: 0.15;
    transform: translateY(40px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes opx-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* Indicateur discret (peek) : dans le coin, décalé pour ne pas être rogné par l'arrondi */
.image-peek {
  position: absolute;
  z-index: 6;
  width: 8px;
  height: 8px;
  padding: 1px;
  border-radius: 1px;
  background-color: rgba(255, 255, 255, 0.86);
  display: flex;
  justify-content: center;
  align-items: center;
}

.image-peek.bottom-left {
  bottom: 7px;
  left: 7px;
}

.image-peek.bottom-right {
  bottom: 7px;
  right: 7px;
}

.inner-box {
  width: 4px;
  height: 4px;
  background-color: #000;
}

/* ---------- Menu ---------- */
#menu {
  --bs-offcanvas-width: 100%;
  --bs-offcanvas-bg: rgba(10, 10, 16, 0.88);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  color: var(--text);
}

#menu .list-group {
  gap: 8px;
}

#menu .list-group-item {
  border: 1px solid var(--line);
  border-radius: 16px !important;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 14px 16px;
  font-weight: 600;
}

#menu .list-group-item:active {
  background: rgba(255, 46, 136, 0.18);
}

/* ---------- Popups ---------- */
.popup {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.popup.d-none {
  display: none !important;
}

/* ---------- Consentement cookies ----------
   Pendant l'affichage, la grille est réorganisée derrière : le fond doit
   masquer complètement les images (voile quasi opaque + flou fort). */
.cookie-overlay {
  align-items: flex-start;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: radial-gradient(120% 80% at 50% 0%, rgba(193, 59, 255, 0.16), transparent 60%), rgba(7, 7, 11, 0.9);
  -webkit-backdrop-filter: blur(28px) saturate(120%);
  backdrop-filter: blur(28px) saturate(120%);
}

.cookie-card {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 22px 20px 18px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)), var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  color: var(--text);
  animation: ck-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

@keyframes ck-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
}

.cookie-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.cookie-ico {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, #ff2e88, #c13bff 55%, #6d6bff);
  box-shadow: 0 10px 24px -10px rgba(193, 59, 255, 0.8);
}

.cookie-ico svg {
  width: 26px;
  height: 26px;
}

.cookie-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.cookie-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.cookie-desc {
  margin: 16px 0 14px;
  font-size: 14.5px;
  line-height: 1.5;
  color: #c9c9d6;
}

.cookie-opts {
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  overflow: hidden;
}

.cookie-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 12px 14px;
  cursor: pointer;
}

.cookie-opt + .cookie-opt {
  border-top: 1px solid var(--line);
}

.cookie-opt strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}

.cookie-opt small {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
}

/* Interrupteur type iOS */
.ck-switch {
  flex: 0 0 auto;
  position: relative;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background 0.2s;
}

.ck-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s;
}

.ck-switch:checked {
  background: #30d158;
}

.ck-switch:checked::after {
  transform: translateX(18px);
}

.ck-switch:disabled {
  background: rgba(48, 209, 88, 0.45);
  cursor: default;
}

.ck-btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 16px;
  font-size: 15.5px;
  font-weight: 650;
  color: #fff;
  transition: transform 0.12s, filter 0.2s;
}

.ck-btn:active {
  transform: scale(0.98);
}

.ck-primary {
  margin-top: 16px;
  background: linear-gradient(135deg, #ff2e88, #c13bff 60%, #6d6bff);
  box-shadow: 0 12px 26px -12px rgba(255, 46, 136, 0.7);
}

.ck-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.ck-ghost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#avatar-popup img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: 24px;
}

.modal-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 22px;
}

/* ---------- Détails image ---------- */
#imgdetails {
  --bs-offcanvas-width: 100%;
  --bs-offcanvas-bg: var(--bg);
  height: 100vh;
  height: 100dvh;
  color: var(--text);
}

#imgdetails .text-dark {
  color: var(--text) !important;
}

#imgdetails .offcanvas-title {
  font-weight: 800;
  letter-spacing: -0.02em;
}

#imgdetailslink {
  border-radius: 22px;
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.95);
}

#imgdetailsusername {
  font-size: 1.05rem;
}

#imgdetails hr {
  border-color: var(--line);
  opacity: 1;
}

#imgdetailstags {
  color: var(--muted);
}

#imgdetailstags strong {
  color: var(--text);
}

.stat {
  color: var(--text);
  border-color: var(--line) !important;
  border-radius: 16px !important;
  background: rgba(255, 255, 255, 0.05);
}

#share-btn.bg-white {
  background: rgba(255, 255, 255, 0.05) !important;
  color: var(--text);
}

.stat-icon {
  opacity: 0.75;
  filter: invert(1);
}

/* Après .stat-icon : le cœur « aimé » reste rouge */
.heart-on {
  opacity: 1;
  filter: invert(20%) sepia(94%) saturate(7477%) hue-rotate(356deg) brightness(100%) contrast(119%);
}

.user-avatar {
  object-fit: cover;
  cursor: pointer;
  padding: 2px;
  background: var(--grad);
}

.btn-close {
  filter: invert(1) grayscale(1) brightness(2);
}

/* ---------- Bouton haut de page (images = indice, ne pas changer) ---------- */
.scroll-to-top {
  position: fixed;
  bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  z-index: 1010;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background-color: var(--opx-pink);
  background-image: url("../img/top.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15), 0 10px 30px -6px rgba(255, 46, 136, 0.9);
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.scroll-to-top.show {
  opacity: 1;
  pointer-events: auto;
}

.scroll-to-top:active {
  transform: scale(0.92);
}

.scroll-to-top.image-visible-pair {
  background-image: url("../img/topl.png");
}

.scroll-to-top.image-visible-impair {
  background-image: url("../img/topr.png");
}

/* ---------- Chargement ---------- */
#loading-circle {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1050;
  transform: translate(-50%, -50%);
  padding: 22px 26px;
  text-align: center;
  border-radius: 22px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.9);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.loading-content p {
  margin: 12px 0 0;
  font-size: 15px;
  color: var(--text);
}

/* Anneau de progression avec pourcentage */
.progress-ring {
  position: relative;
  width: 68px;
  height: 68px;
}

.progress-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 6;
}

.ring-bar {
  fill: none;
  stroke: url(#ring-grad);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 169.65;
  stroke-dashoffset: 169.65;
}

.ring-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 25%, #ff2e88, #c13bff, #6d6bff);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  animation: opx-spin 0.9s linear infinite;
}

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

/* ---------- Message court ---------- */
.opx-toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  z-index: 3000;
  max-width: 90vw;
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: #fff;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(20px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.opx-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  .square,
  .square .tile-fade {
    animation: none;
    transition: none;
  }
}
