/* ============================================================
   Tinson, le petit chat de Mukbang (js/tinson.js)
   Accueil : posé sur la barre de recherche, cœurs en haut à droite, carte.
   Fiches : message de fin de quiz, humeur du chat du coin (#mk-cat).
   Sprites 32 × 32 : assets/cats/AllCatsPaid3/White-DifferentEyes/
   ============================================================ */

/* ---------- Le sprite, partout ---------- */
.tinson-sprite {
    --t: 64px;            /* taille d'une image du sprite */
    --pied: 0px;          /* marge sous les pattes dans certaines planches */
    --sens: 1;            /* -1 : il regarde à gauche */
    position: absolute;
    left: 0;
    bottom: 0;
    width: var(--t);
    height: var(--t);
    background-repeat: no-repeat;
    background-size: auto 100%;
    image-rendering: pixelated;
    transform: translateY(var(--pied)) scaleX(var(--sens));
    transform-origin: 50% 100%;
}
[data-pose="dort"] > .tinson-sprite {
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/SleepCatttt.png');
    animation: tinsonDort 1.8s steps(3) infinite;
}
[data-pose="content"] > .tinson-sprite {
    --pied: calc(var(--t) / 16);
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/Idle2Catttt.png');
    animation: tinsonContent 2.8s steps(14) infinite;
}
[data-pose="assis"] > .tinson-sprite {
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/Sittingggg.png');
    animation: tinsonAssis .4s steps(2) forwards;
}
[data-pose="saut"] > .tinson-sprite {
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/JumpCattttt.png');
    animation: tinsonSaut 1.05s steps(12) forwards;
}
[data-pose="triste"] > .tinson-sprite {
    --pied: calc(var(--t) / 16);
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/DieCattt.png');
    background-position-x: calc(-12 * var(--t));
    animation: tinsonSouffle 2.6s ease-in-out infinite;
}
[data-pose="mort-joue"] > .tinson-sprite,
[data-pose="mort"] > .tinson-sprite {
    --pied: calc(var(--t) / 16);
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/DieCattt.png');
    filter: grayscale(.45);
}
[data-pose="mort-joue"] > .tinson-sprite { animation: tinsonMeurt 1.7s steps(14) forwards; }
[data-pose="mort"] > .tinson-sprite { background-position-x: calc(-14 * var(--t)); opacity: .62; }

@keyframes tinsonDort    { to { background-position-x: calc(-3 * var(--t)); } }
@keyframes tinsonContent { to { background-position-x: calc(-14 * var(--t)); } }
@keyframes tinsonAssis   { to { background-position-x: calc(-2 * var(--t)); } }
@keyframes tinsonSaut    { to { background-position-x: calc(-12 * var(--t)); } }
@keyframes tinsonMeurt   { to { background-position-x: calc(-14 * var(--t)); } }
@keyframes tinsonSouffle {
    50% { transform: translateY(var(--pied)) scaleX(var(--sens)) scaleY(.94); }
}

/* ---------- Accueil : le chat sur la barre de recherche ---------- */
/* De la place au-dessus de la barre : le chat ne touche pas la dernière ligne de l'accroche */
body.tinson-on:not(.yt-recherche) .yt-hero-filtres { margin-top: 50px; }

.tinson {
    position: absolute;
    right: 64px;
    bottom: calc(100% - 3px);    /* les pattes posées sur le bord de la barre */
    width: 64px;
    height: 64px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    z-index: 3;
    -webkit-tap-highlight-color: transparent;
    border-radius: 14px;
}
.tinson > .tinson-sprite { --sens: -1; }
.tinson:focus-visible { outline: 2.5px solid #EC4899; outline-offset: 2px; }
.tinson.secoue { animation: tinsonSecoue .45s ease-in-out; }
.tinson[data-pose="mort"] { animation: tinsonFlotte 3.4s ease-in-out infinite; }

/* Sa gamelle, devant lui sur la barre : vide, ou avec 1 à 3 croquettes */
.tinson-gamelle {
    position: absolute;
    right: 100%;
    bottom: 2px;
    width: 22px;
    height: 14px;
    margin-right: -2px;
    pointer-events: none;
}
.tinson-gamelle svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }
.tinson-gamelle .tg-bord { fill: #be185d; }
.tinson-gamelle .tg-corps { fill: #f472b6; }
.tinson-gamelle .tg-reflet { fill: #fbcfe8; }
.tinson-gamelle .tg-croquettes { fill: #b8742f; }
.tinson-gamelle .tg-croquettes-clair { fill: #e9b36f; }
.tinson[data-pose="mort"] .tinson-gamelle, .tinson[data-pose="mort-joue"] .tinson-gamelle { opacity: .45; filter: grayscale(.6); }

.tinson-aureole {
    position: absolute;
    left: 12px;
    top: 21px;
    width: 18px;
    height: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .6s ease .2s;
}
.tinson-aureole svg { display: block; width: 100%; height: 100%; fill: #eab308; shape-rendering: crispEdges; }
.tinson[data-pose="mort"] .tinson-aureole { opacity: 1; }

@keyframes tinsonSecoue {
    20%, 60% { transform: translateX(-3px); }
    40%, 80% { transform: translateX(3px); }
}
@keyframes tinsonFlotte {
    50% { transform: translateY(-4px); }
}

/* Petits cœurs qui s'envolent */
.tinson-volant {
    --dx: 0px;
    position: absolute;
    left: calc(50% - 7px + var(--dx));
    top: 10px;
    width: 14px;
    height: 13px;
    pointer-events: none;
    opacity: 0;
    animation: tinsonMonte 1.5s ease-out forwards;
}
.tinson-volant .tinson-coeur { width: 14px; height: 13px; }
@keyframes tinsonMonte {
    0%   { opacity: 0; transform: translateY(8px) scale(.6); }
    20%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-36px) scale(1); }
}

/* Bulle */
.tinson-bulle {
    position: absolute;
    right: 40px;
    bottom: calc(100% + 47px);
    width: max-content;
    max-width: min(250px, calc(100vw - 72px));
    margin: 0;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #f1dce4;
    border-radius: 14px;
    box-shadow: 0 10px 24px -18px rgba(15, 23, 42, .45);
    font: 500 13.5px/1.4 'Outfit', system-ui, sans-serif;
    color: #334155;
    text-align: left;
    z-index: 4;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .2s ease, transform .2s ease;
    pointer-events: none;
}
.tinson-bulle.on { opacity: 1; transform: none; }
.tinson-bulle::after {
    content: '';
    position: absolute;
    right: 61px;
    bottom: -6px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-right: 1px solid #f1dce4;
    border-bottom: 1px solid #f1dce4;
    transform: rotate(45deg);
}

/* Mode recherche : la barre remonte tout en haut, Tinson attend au calme */
body.yt-recherche .tinson,
body.yt-recherche .tinson-bulle { display: none; }

/* ---------- Les cœurs (pixels) ---------- */
.tinson-coeur {
    display: block;
    width: 18px;
    height: 16px;
    shape-rendering: crispEdges;
    overflow: visible;
}
.tinson-coeur.plein .tc-bord { fill: #be123c; }
.tinson-coeur.plein .tc-dedans { fill: #f43f5e; }
.tinson-coeur .tc-reflet { fill: #fff; opacity: .85; }
.tinson-coeur.vide .tc-bord { fill: #dcbcc7; }
.tinson-coeur.vide .tc-dedans { fill: #fdf2f5; }

.tinson-vie {
    position: absolute;
    right: 52px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 8px 7px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .88);   /* invisible sur l'accueil blanc, lisible au-dessus des fiches */
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .18s ease;
}
.tinson-vie:hover { background: rgba(15, 23, 42, .045); }
.tinson-vie:focus-visible { outline: 2.5px solid #EC4899; outline-offset: 2px; }
.tinson-vie[aria-expanded="true"] { background: rgba(236, 72, 153, .08); }
.tinson-vie.faim .tinson-coeur.plein { animation: tinsonBat 1.25s ease-in-out infinite; }
.tinson-coeur.gagne { animation: tinsonPop .55s cubic-bezier(.3, 1.6, .5, 1); }
.tinson-coeur.perdu { animation: tinsonPerd .7s ease-out; }
@keyframes tinsonBat { 0%, 60%, 100% { transform: scale(1); } 30% { transform: scale(1.18); } }
@keyframes tinsonPop { 0% { transform: scale(.3); } 100% { transform: scale(1); } }
@keyframes tinsonPerd {
    0% { transform: translateY(0); }
    25% { transform: translateY(-3px) rotate(-8deg); }
    50% { transform: translateY(0) rotate(8deg); }
    100% { transform: none; }
}

/* ---------- La carte de Tinson (ouverte par les cœurs) ---------- */
.tinson-carte {
    position: fixed;
    top: 54px;
    right: 12px;
    width: min(312px, calc(100vw - 24px));
    max-height: calc(100dvh - 70px);
    overflow-y: auto;
    padding: 14px 16px 16px;
    background: #fff;
    border: 1px solid #f1dce4;
    border-radius: 18px;
    box-shadow: 0 18px 40px -24px rgba(15, 23, 42, .45);
    font-family: 'Outfit', system-ui, sans-serif;
    color: #334155;
    z-index: 9000;
    animation: tinsonCarte .2s ease-out;
}
.tinson-carte[hidden] { display: none; }
@keyframes tinsonCarte { from { opacity: 0; transform: translateY(-6px); } }
.tinson-carte p { margin: 0; }
.tinson-carte-tete { display: flex; align-items: center; gap: 12px; }
.tinson-carte-chat {
    position: relative;
    flex: none;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: #fdf2f5;
    overflow: hidden;
}
.tinson-carte-chat .tinson-sprite { --t: 48px; left: 2px; bottom: 0; }
.tinson-carte-nom { flex: 1; min-width: 0; }
.tinson-carte-nom p:first-child {
    font-family: 'Bricolage Grotesque', 'Outfit', sans-serif;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.02em;
    color: #0f172a;
}
.tinson-carte-nom p:last-child { font-size: 13.5px; color: #64748b; line-height: 1.35; }
.tinson-fermer {
    flex: none;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: -4px -6px 0 0;
    border: 0;
    border-radius: 999px;
    background: none;
    color: #94a3b8;
    cursor: pointer;
}
.tinson-fermer:hover { background: rgba(15, 23, 42, .05); color: #0f172a; }
.tinson-fermer:focus-visible { outline: 2.5px solid #EC4899; outline-offset: 1px; }

.tinson-jauges {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}
.tinson-jauges p {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 14px;
    background: #fbf7f9;
}
.tinson-jauges p > span:first-child {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #9a6b7c;
}
.tinson-ligne { display: inline-flex; align-items: center; gap: 3px; }
.tinson-croquette { display: block; width: 18px; height: 15px; shape-rendering: crispEdges; }
.tinson-croquette.pleine path:first-child { fill: #b8742f; }
.tinson-croquette .tk-reflet { fill: #e9b36f; }
.tinson-croquette.vide path { fill: #eee4da; }

.tinson-age { margin-top: 12px !important; font-size: 13.5px; color: #475569; }
.tinson-regles {
    margin: 10px 0 0;
    padding: 10px 0 0;
    border-top: 1px solid #f3e8ec;
    list-style: none;
    font-size: 13px;
    line-height: 1.45;
    color: #64748b;
}
.tinson-regles li { position: relative; padding-left: 14px; }
.tinson-regles li + li { margin-top: 4px; }
.tinson-regles li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: .55em;
    width: 5px;
    height: 5px;
    background: #f9a8d4;
}
.tinson-action {
    display: block;
    width: 100%;
    margin-top: 14px;
    padding: 11px 14px;
    border: 0;
    border-radius: 12px;
    background: #db2777;
    color: #fff;
    font: 700 14px/1.2 'Outfit', system-ui, sans-serif;
    cursor: pointer;
    transition: background-color .18s ease;
}
.tinson-action:hover { background: #be185d; }
.tinson-action:focus-visible { outline: 2.5px solid #0f172a; outline-offset: 2px; }

/* ---------- Fiches : le message de fin de quiz ---------- */
.tinson-toast {
    position: fixed;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    z-index: 10002;
    display: flex;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 8px 14px 8px 8px;
    background: #fff;
    border: 1px solid #f1dce4;
    border-radius: 16px;
    box-shadow: 0 16px 34px -20px rgba(15, 23, 42, .5);
    font-family: 'Outfit', 'Atkinson Hyperlegible Next', system-ui, sans-serif;
    color: #334155;
    cursor: pointer;
    opacity: 0;
    transform: translate(-50%, 14px);
    transition: opacity .22s ease, transform .22s ease;
}
.tinson-toast.on { opacity: 1; transform: translate(-50%, 0); }
.tinson-toast-chat {
    position: relative;
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #fdf2f5;
    overflow: hidden;
}
.tinson-toast-chat .tinson-sprite { --t: 48px; }
.tinson-toast-texte { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tinson-toast-texte strong { font-size: 14.5px; font-weight: 800; color: #0f172a; }
.tinson-toast-texte span { font-size: 13px; line-height: 1.35; color: #475569; }
.tinson-toast .tinson-ligne { flex: none; }
.tinson-toast .tinson-coeur { width: 13.5px; height: 12px; }

/* ---------- Fiches : le chat du coin suit l'humeur de Tinson ---------- */
#mk-cat[data-tinson="triste"] #mk-cat-sprite,
#mk-cat[data-tinson="triste"]:hover #mk-cat-sprite {
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/DieCattt.png') !important;
    background-position: calc(-12 * 56px) 4px !important;
    animation: none !important;
}
/* Sa gamelle vide devant lui : il a faim */
#mk-cat[data-tinson="triste"]::after {
    content: '';
    position: absolute;
    left: 50px;
    bottom: 3px;
    width: 22px;
    height: 14px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 11 7' shape-rendering='crispEdges'%3E%3Cpath fill='%23be185d' d='M0 3h11v1H0zM2 6h7v1H2z'/%3E%3Cpath fill='%23f472b6' d='M0 4h11v1H0zM1 5h9v1H1z'/%3E%3Cpath fill='%23fbcfe8' d='M2 4h1v1H2z'/%3E%3C/svg%3E") no-repeat center / contain;
    image-rendering: pixelated;
    pointer-events: none;
}
#mk-cat[data-tinson="mort"] #mk-cat-sprite,
#mk-cat[data-tinson="mort"]:hover #mk-cat-sprite {
    background-image: url('../assets/cats/AllCatsPaid3/White-DifferentEyes/DieCattt.png') !important;
    background-position: calc(-14 * 56px) 4px !important;
    animation: none !important;
    opacity: .55 !important;
    filter: grayscale(.6) drop-shadow(0 3px 6px rgba(15, 23, 42, .2)) !important;
}

@media (prefers-reduced-motion: reduce) {
    .tinson-sprite, .tinson, .tinson-volant, .tinson-coeur, .tinson-carte { animation: none !important; }
    .tinson-volant { display: none; }
    [data-pose="assis"] > .tinson-sprite { background-position-x: calc(-2 * var(--t)); }
    [data-pose="mort-joue"] > .tinson-sprite { background-position-x: calc(-14 * var(--t)); opacity: .62; }
    .tinson-bulle, .tinson-toast { transition: none; }
}
