/*
 * KWARK — couche responsive premium
 * Présentation uniquement : le comportement du chat et des médias reste intact.
 */

:root {
  --kwark-bg: #030307;
  --kwark-stroke: rgba(255, 255, 255, 0.12);
  --kwark-stroke-strong: rgba(129, 140, 248, 0.3);
  --kwark-text-muted: rgba(255, 255, 255, 0.58);
  --kwark-safe-top: max(0.75rem, env(safe-area-inset-top));
  --kwark-safe-right: max(0.75rem, env(safe-area-inset-right));
  --kwark-safe-bottom: max(0.75rem, env(safe-area-inset-bottom));
  --kwark-safe-left: max(0.75rem, env(safe-area-inset-left));
}

html {
  min-width: 320px;
  background: var(--kwark-bg);
  color-scheme: dark;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% -10%, rgba(99, 102, 241, 0.13), transparent 42rem),
    var(--kwark-bg);
  overflow-x: clip;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

img,
video,
svg {
  max-inline-size: 100%;
}

[data-layout] {
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 18%, rgba(99, 102, 241, 0.12), transparent 34rem),
    linear-gradient(180deg, #05050b 0%, #030307 62%, #050308 100%) !important;
}

[data-layout] input {
  min-height: 44px;
  font-size: 16px !important;
}

[data-layout] button,
[data-layout] a {
  min-height: 44px;
}

[data-layout] [role="group"] button {
  min-width: 44px;
  min-height: 44px;
}

[data-layout] form {
  border-color: rgba(255, 255, 255, 0.13) !important;
  background: rgba(3, 4, 11, 0.7) !important;
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.34),
    inset 0 1px rgba(255, 255, 255, 0.05) !important;
}

[data-layout] form:focus-within {
  border-color: rgba(129, 140, 248, 0.58) !important;
  box-shadow:
    0 0 0 3px rgba(99, 102, 241, 0.14),
    0 18px 42px rgba(0, 0, 0, 0.4) !important;
}

[data-layout] footer a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding-inline: 0.2rem;
}

/* Curseur discret pendant la réponse mot par mot synchronisée au charabia. */
[data-layout] p[data-kwark-typing="true"]::after {
  display: inline-block;
  width: 0.42em;
  height: 1em;
  margin-left: 0.16em;
  border-radius: 0.08em;
  background: rgba(167, 139, 250, 0.78);
  vertical-align: -0.12em;
  content: "";
  animation: kwark-typing-cursor 620ms steps(1, end) infinite;
}

@keyframes kwark-typing-cursor {
  50% {
    opacity: 0.18;
  }
}

/*
 * Scène du personnage
 * Le portrait fixe reste sous la vidéo pendant que chaque nouveau clip apparaît.
 * Cela supprime le flash noir entre deux états sans précharger tout le catalogue.
 */
[data-layout] section[aria-live] [role="img"] {
  --kwark-aura-rgb: 99, 102, 241;
  position: relative;
  isolation: isolate;
}

[data-layout] section[aria-live] [role="img"][aria-label*="/ listen"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ listening"] {
  --kwark-aura-rgb: 56, 189, 248;
}

[data-layout] section[aria-live] [role="img"][aria-label*="/ think"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ whisper"] {
  --kwark-aura-rgb: 168, 85, 247;
}

[data-layout] section[aria-live] [role="img"][aria-label*="/ mock"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ proud"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ laugh"] {
  --kwark-aura-rgb: 249, 115, 22;
}

[data-layout] section[aria-live] [role="img"][aria-label*="/ rage"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ threat"],
[data-layout] section[aria-live] [role="img"][aria-label*="/ error"] {
  --kwark-aura-rgb: 244, 63, 94;
}

[data-layout] section[aria-live] [role="img"]::before {
  position: absolute;
  z-index: -1;
  inset: 12% 8% 8%;
  border-radius: 46%;
  background:
    radial-gradient(
      ellipse at 50% 42%,
      rgba(var(--kwark-aura-rgb), 0.16) 0%,
      rgba(var(--kwark-aura-rgb), 0.06) 46%,
      transparent 72%
    );
  filter: none;
  content: "";
  opacity: 0.62;
  transition:
    background 500ms ease,
    opacity 500ms ease;
}

[data-layout] section[aria-live] [role="img"] div[class*="overflow-hidden"][class*="bg-transparent"] {
  isolation: isolate;
  background: transparent !important;
  -webkit-mask-image: none;
  mask-image: none;
}

/* Le fallback reste présent derrière le clip : aucune image vide pendant le chargement. */
[data-layout] section[aria-live] [role="img"] img {
  opacity: 1 !important;
  mix-blend-mode: normal;
  transform: translateZ(0);
  transition: opacity 180ms ease !important;
}

[data-layout] section[aria-live] [role="img"] video {
  z-index: 2;
  background: transparent !important;
  backface-visibility: hidden;
  mix-blend-mode: normal;
  transform: translateZ(0);
  animation: kwark-video-reveal 240ms ease-out both;
  will-change: opacity;
}

@keyframes kwark-video-reveal {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Mobile first : corrige l'effondrement à 0px du média dans son conteneur flex. */
[data-layout="mobile"] {
  width: 100%;
  min-height: 100svh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

[data-layout="mobile"] > div:not([aria-hidden="true"]):not([role="dialog"]) {
  width: min(100%, 34rem);
}

[data-layout="mobile"] header {
  padding-left: var(--kwark-safe-left) !important;
  padding-right: var(--kwark-safe-right) !important;
}

[data-layout="mobile"] section[aria-live] {
  padding-inline: clamp(0.5rem, 3vw, 1rem) !important;
}

[data-layout="mobile"] section[aria-live] > div:first-child {
  flex: 1 1 auto;
  width: min(70vw, 260px) !important;
  min-height: 0;
}

[data-layout="mobile"] section[aria-live] [role="img"],
[data-layout="mobile"] section[aria-live] [role="img"] > div,
[data-layout="mobile"] section[aria-live] [role="img"] > div > div {
  height: 100% !important;
  min-height: 0 !important;
}

[data-layout="mobile"] section[aria-live] video,
[data-layout="mobile"] section[aria-live] img {
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
}

[data-layout="mobile"] section[aria-live] p {
  flex: 0 0 auto;
  margin-top: 0.35rem !important;
  color: rgba(255, 255, 255, 0.42) !important;
}

[data-layout="mobile"] > div:not([aria-hidden="true"]):not([role="dialog"]) > div:last-child {
  padding-right: var(--kwark-safe-right) !important;
  padding-bottom: var(--kwark-safe-bottom) !important;
  padding-left: var(--kwark-safe-left) !important;
}

[data-layout="mobile"] > div:not([aria-hidden="true"]):not([role="dialog"]) > div:last-child > div:first-child {
  border-color: var(--kwark-stroke) !important;
  background: linear-gradient(180deg, rgba(23, 24, 39, 0.92), rgba(9, 10, 18, 0.9)) !important;
  box-shadow:
    0 22px 54px rgba(0, 0, 0, 0.52),
    inset 0 1px rgba(255, 255, 255, 0.08) !important;
}

/* Consentement : bottom sheet sûre sur les petits écrans. */
[data-layout="mobile"] > [role="dialog"] {
  max-height: 100dvh;
  padding:
    0.75rem
    var(--kwark-safe-right)
    var(--kwark-safe-bottom)
    var(--kwark-safe-left) !important;
  overflow-y: auto;
  overscroll-behavior: contain;
}

[data-layout="mobile"] > [role="dialog"] > div {
  max-height: calc(100dvh - var(--kwark-safe-top) - var(--kwark-safe-bottom) - 1rem);
  overflow-y: auto;
  border-color: rgba(255, 255, 255, 0.15) !important;
  background: rgba(8, 9, 16, 0.97) !important;
  box-shadow:
    0 -20px 60px rgba(0, 0, 0, 0.66),
    inset 0 1px rgba(255, 255, 255, 0.08) !important;
}

[data-layout] [role="dialog"] button,
[data-layout] [role="dialog"] a {
  min-height: 44px;
}

@media (max-width: 389px), (max-height: 700px) {
  [data-layout="mobile"] header {
    gap: 0.25rem !important;
  }

  [data-layout="mobile"] section[aria-live] {
    height: min(31dvh, 220px) !important;
    max-height: 31dvh !important;
  }

  [data-layout="mobile"] section[aria-live] > div:first-child {
    width: min(58vw, 210px) !important;
  }
}

/* Desktop : composition éditoriale en deux colonnes, ample et lisible. */
@media (min-width: 900px) {
  [data-layout="desktop"] {
    min-height: 100dvh !important;
    overflow-x: clip !important;
    overflow-y: auto !important;
  }

  [data-layout="desktop"] > div:not([aria-hidden="true"]):not([role="dialog"]) {
    display: grid !important;
    grid-template-columns: minmax(360px, 0.92fr) minmax(430px, 1.08fr);
    grid-template-rows: auto minmax(0, 1fr);
    row-gap: clamp(0.5rem, 1.4vh, 1rem);
    column-gap: clamp(1.5rem, 3vw, 3.5rem);
    width: min(100%, 1240px) !important;
    min-height: 100dvh !important;
    max-width: none !important;
    padding:
      max(1.5rem, env(safe-area-inset-top))
      max(2rem, env(safe-area-inset-right))
      max(1.5rem, env(safe-area-inset-bottom))
      max(2rem, env(safe-area-inset-left));
  }

  [data-layout="desktop"] header {
    grid-column: 1;
    grid-row: 1;
    align-items: stretch !important;
    justify-content: flex-start !important;
    padding: 0 !important;
  }

  [data-layout="desktop"] header > div {
    align-items: flex-start !important;
    max-width: 32rem !important;
    padding: 0 !important;
  }

  [data-layout="desktop"] header > div > div:first-child {
    justify-content: flex-start !important;
  }

  [data-layout="desktop"] header > div > div:first-child > div:first-child {
    display: none;
  }

  [data-layout="desktop"] header h1 {
    order: -1;
    margin-right: auto;
    font-size: clamp(0.8rem, 1vw, 0.95rem) !important;
    letter-spacing: 0.62em !important;
  }

  [data-layout="desktop"] header p {
    max-width: none !important;
    text-align: left !important;
    color: var(--kwark-text-muted) !important;
    font-size: 0.86rem !important;
  }

  [data-layout="desktop"] header a {
    min-height: 46px;
    margin-top: 1rem !important;
    border-color: rgba(37, 244, 238, 0.22) !important;
    background: rgba(7, 9, 15, 0.76) !important;
    box-shadow:
      0 12px 32px rgba(0, 0, 0, 0.38),
      0 0 0 1px rgba(37, 244, 238, 0.06) !important;
  }

  [data-layout="desktop"] section[aria-live] {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    justify-content: flex-start !important;
    min-height: 0;
    padding: clamp(0.35rem, 1.2vh, 0.8rem) 0 0 !important;
  }

  [data-layout="desktop"] section[aria-live] > div:first-child {
    width: min(100%, 430px) !important;
    max-width: 430px !important;
  }

  [data-layout="desktop"] section[aria-live] [role="img"] > div {
    max-width: 430px !important;
  }

  [data-layout="desktop"] section[aria-live] video,
  [data-layout="desktop"] section[aria-live] img {
    max-height: none !important;
    filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.46));
  }

  [data-layout="desktop"] section[aria-live] p {
    margin-top: 0.75rem !important;
    color: rgba(255, 255, 255, 0.46) !important;
    font-size: 0.78rem !important;
  }

  [data-layout="desktop"] > div:not([aria-hidden="true"]):not([role="dialog"]) > div:last-child {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    width: 100%;
    max-height: calc(100dvh - 3rem);
    padding: 0 !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  [data-layout="desktop"] > div:not([aria-hidden="true"]):not([role="dialog"]) > div:last-child > div:first-child {
    max-width: 100% !important;
    border: 1px solid var(--kwark-stroke-strong) !important;
    border-radius: 1.75rem !important;
    background: linear-gradient(145deg, rgba(25, 26, 43, 0.88), rgba(8, 9, 17, 0.9)) !important;
    box-shadow:
      0 34px 90px rgba(0, 0, 0, 0.52),
      0 0 0 1px rgba(124, 131, 255, 0.06),
      inset 0 1px rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(28px) saturate(1.15) !important;
  }

  [data-layout="desktop"] > div:not([aria-hidden="true"]):not([role="dialog"]) > div:last-child > div:nth-child(2) > div {
    max-width: 100% !important;
  }

  [data-layout="desktop"] footer {
    max-width: 100% !important;
    padding-bottom: 0.25rem;
  }

  [data-layout="desktop"] > [role="dialog"] {
    inset: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    max-height: 100dvh;
    padding:
      max(1.5rem, env(safe-area-inset-top))
      max(1.5rem, env(safe-area-inset-right))
      max(1.5rem, env(safe-area-inset-bottom))
      max(1.5rem, env(safe-area-inset-left)) !important;
    overflow-y: auto;
    background: rgba(1, 2, 7, 0.56);
    backdrop-filter: blur(9px);
  }

  [data-layout="desktop"] > [role="dialog"] > div {
    width: min(100%, 42rem);
    max-width: 42rem !important;
    max-height: calc(100dvh - 3rem);
    overflow-y: auto;
    border-color: rgba(129, 140, 248, 0.28) !important;
    border-radius: 1.6rem !important;
    background: linear-gradient(145deg, rgba(20, 21, 36, 0.98), rgba(7, 8, 15, 0.98)) !important;
    box-shadow:
      0 38px 100px rgba(0, 0, 0, 0.72),
      0 0 0 1px rgba(124, 131, 255, 0.08),
      inset 0 1px rgba(255, 255, 255, 0.1) !important;
  }
}

@media (min-width: 1200px) {
  [data-layout="desktop"] > div:not([aria-hidden="true"]):not([role="dialog"]) {
    grid-template-columns: minmax(430px, 0.95fr) minmax(500px, 1.05fr);
    width: min(100%, 1360px) !important;
    padding-inline: max(3rem, env(safe-area-inset-left));
  }

  [data-layout="desktop"] section[aria-live] > div:first-child,
  [data-layout="desktop"] section[aria-live] [role="img"] > div {
    width: min(100%, 450px) !important;
    max-width: 450px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-layout] section[aria-live] [role="img"] video {
    animation: none !important;
  }

  [data-layout] *,
  [data-layout] *::before,
  [data-layout] *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: more) {
  [data-layout] {
    --kwark-stroke: rgba(255, 255, 255, 0.26);
    --kwark-text-muted: rgba(255, 255, 255, 0.76);
  }
}
