/* The fox. Four clips, each a sprite sheet of 180 x 198 frames drawn on one
   shared box, so the feet stay put when the clip changes. A clip is two
   nested strips: .mascot-rows steps down the sheet's rows while
   .mascot-sheet steps along a row. The hop and the question marks run at
   70 ms a frame; standing and sleeping are slow, so they keep every other
   frame at 140 ms. Only transforms move, and only for the clip that is
   showing. mascot.js sets data-state. */

.mascot {
    position: relative;
    width: 68px;
    aspect-ratio: 10 / 11;
    overflow: hidden;
    flex-shrink: 0;
    pointer-events: none;
    user-select: none;
}

.mascot-clip {
    position: absolute;
    inset: 0;
    overflow: hidden;
    visibility: hidden;
}

.mascot-rows {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(var(--mascot-rows) * 100%);
}

.mascot-sheet {
    width: calc(var(--mascot-cols) * 100%);
    height: 100%;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.mascot-clip--idle {
    --mascot-cols: 10;
    --mascot-rows: 3;
}

.mascot-clip--marks {
    --mascot-cols: 10;
    --mascot-rows: 6;
}

.mascot-clip--sleep {
    --mascot-cols: 10;
    --mascot-rows: 3;
}

.mascot-clip--hop {
    --mascot-cols: 11;
    --mascot-rows: 3;
}

.mascot-clip--idle .mascot-sheet {
    background-image: url("mascot/idle.webp?v=1");
}

/* The other three wait until the page itself has loaded (mascot.js). */
.mascot--loaded .mascot-clip--marks .mascot-sheet {
    background-image: url("mascot/marks.webp?v=1");
}

.mascot--loaded .mascot-clip--sleep .mascot-sheet {
    background-image: url("mascot/sleep.webp?v=1");
}

.mascot--loaded .mascot-clip--hop .mascot-sheet {
    background-image: url("mascot/hop.webp?v=1");
}

.mascot[data-state="idle"] .mascot-clip--idle,
.mascot[data-state="marks"] .mascot-clip--marks,
.mascot[data-state="sleep"] .mascot-clip--sleep,
.mascot[data-state="hop"] .mascot-clip--hop {
    visibility: visible;
}

@keyframes mascot-rows {
    to {
        transform: translateY(-100%);
    }
}

@keyframes mascot-cols {
    to {
        transform: translateX(-100%);
    }
}

/* Until the other sheets have been asked for, a reaction or a nap shows
   the standing frame rather than an empty box. */
.mascot:not(.mascot--loaded) .mascot-clip--idle {
    visibility: visible;
}

/* Sleeping still loops. Standing holds the first frame: a slow 1px
   breath, and a blink every few seconds. The idle sheet's sway is too busy
   to leave running. */
.mascot[data-state="sleep"] .mascot-clip--sleep .mascot-rows {
    animation: mascot-rows 4.2s steps(3) infinite;
}

.mascot[data-state="sleep"] .mascot-clip--sleep .mascot-sheet {
    animation: mascot-cols 1.4s steps(10) infinite;
}

@keyframes mascot-breathe {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(1px); }
}

/* Standing still. The blink below is the only idle motion. */
.mascot[data-state="idle"] {
    animation: none;
}

.mascot-blink {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
}

.mascot-blink::before,
.mascot-blink::after {
    content: "";
    position: absolute;
    top: 31%;
    width: 13%;
    height: 7%;
    border-radius: 2px;
    background: #c96e41;
}

.mascot-blink::before { left: 32%; }
.mascot-blink::after { left: 54%; }

@keyframes mascot-blink {
    0%, 88%, 94%, 100% { opacity: 0; }
    90%, 92% { opacity: 1; }
}

.mascot[data-state="idle"] .mascot-blink {
    animation: mascot-blink 6.4s ease-in-out infinite;
}

/* The question marks and the hop play once and end on their first frame,
   which is the standing pose. */
.mascot[data-state="marks"] .mascot-clip--marks .mascot-rows {
    animation: mascot-rows 4.2s steps(6) 1;
}

.mascot[data-state="marks"] .mascot-clip--marks .mascot-sheet {
    animation: mascot-cols 0.7s steps(10) 6;
}

.mascot[data-state="hop"] .mascot-clip--hop .mascot-rows {
    animation: mascot-rows 2.31s steps(3) 1;
}

.mascot[data-state="hop"] .mascot-clip--hop .mascot-sheet {
    animation: mascot-cols 0.77s steps(11) 3;
}

/* Peeks in from the lower-right of the work area. Hidden until a reaction
   opens him. He does not sit on the paper or in the header. */
.mascot-helper {
    position: absolute;
    right: 6px;
    bottom: 6px;
    left: auto;
    top: auto;
    z-index: 6;
    width: 84px;
    margin: 0;
    pointer-events: none;
    transform: translate(16px, 18px);
}

.fox-reaction {
    position: absolute;
    right: 100px;
    bottom: 18px;
    z-index: 6;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    width: max-content;
    max-width: min(16rem, calc(100% - 110px));
    margin: 0;
    padding: 8px 10px 8px 28px;
    border: 1px solid var(--border-standard);
    border-radius: 12px;
    background: var(--surface-panel);
    color: var(--ink);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
}

.fox-reaction[hidden] {
    display: none;
}

.fox-reaction-text {
    margin: 0;
    flex: 1 1 100%;
    font-size: 0.9rem;
    line-height: 1.35;
}

.fox-reaction-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.fox-reaction-btn,
.fox-reaction-dismiss {
    min-height: 32px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--border-standard);
    background: var(--surface-raised);
    color: var(--ink);
    font-size: 0.85rem;
}

.fox-reaction-dismiss {
    position: absolute;
    top: 4px;
    left: 4px;
    min-height: 24px;
    padding: 0 6px;
}

body[data-fox="reduced"] .mascot-helper,
body[data-fox="off"] .mascot-helper {
    display: none;
}

body.exam-mock .fox-reaction {
    display: none;
}

.mascot-helper[hidden] {
    display: none;
}

.work-mascot {
    width: 100%;
}

/* A mock exam is the exam: no tutor, no fox. */
body.exam-mock .mascot-helper {
    display: none;
}

/* The sign-in card: the fox in place of the old badge. */
.brand-mark.mascot-mark {
    width: 92px;
    height: auto;
    border-radius: 0;
    background: none;
    box-shadow: none;
    overflow: visible;
    animation: none;
}

.mascot-mark .mascot {
    width: 92px;
}

/* Reduced motion: one still frame for each pose instead of the clip. */
@media (prefers-reduced-motion: reduce) {
    .mascot,
    .mascot .mascot-rows,
    .mascot .mascot-sheet,
    .mascot-blink {
        animation: none !important;
    }

    .mascot-blink {
        opacity: 0;
    }

    .mascot-clip--marks .mascot-rows {
        transform: translateY(-50%);
    }

    .mascot-clip--sleep .mascot-rows {
        transform: translateY(-33.3333%);
    }

    .mascot-clip--sleep .mascot-sheet {
        transform: translateX(-50%);
    }

    .mascot-clip--hop .mascot-sheet {
        transform: translateX(-72.7273%);
    }
}
