/* The julenisse (public/nisse.js). Drawn like Alv the Skald's nisse: a tall red cone hat pulled down to his eyes, a big
   white beard, a round pink nose and a green coat, flat colours with the room's ink as the outline. */
.nisse-layer { position: fixed; z-index: 10; overflow: hidden; pointer-events: none; }
.nisse {
  --n-line: #1d2140; --n-red: #d9262d; --n-green: #1f7a45; --n-skin: #f5cdb8; --n-nose: #eaa493; --n-felt: #2b2a33;
  position: absolute; left: 0; top: 0; width: 58px; height: 88px; pointer-events: auto; cursor: pointer;
  -webkit-tap-highlight-color: transparent; will-change: transform;
}
.nisse svg { display: block; overflow: visible; }
.nisse.face-left svg { transform: scaleX(-1); }
.nisse svg path, .nisse svg circle, .nisse svg ellipse, .nisse svg rect { stroke: var(--n-line); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.nisse .n-shadow { fill: var(--n-line); opacity: .16; stroke: none !important; }
.nisse .n-hat path { fill: var(--n-red); }
.nisse .n-coat { fill: var(--n-green); }
.nisse .n-belt { fill: var(--n-felt); stroke: none !important; }
.nisse .n-boot path { fill: var(--n-felt); }
.nisse .n-skin { fill: var(--n-skin); }
.nisse .n-nose { fill: var(--n-nose); }
.nisse .n-eye { fill: var(--n-line); stroke: none !important; }
.nisse .n-beard { fill: #fff; }
.nisse .n-strand { fill: none; stroke-width: 1 !important; opacity: .35; }
.nisse .n-nib { fill: var(--n-line); }
.nisse .n-wood { fill: #a8672f; }
.nisse .n-grot { fill: #fbf1dc; }
.nisse .n-butter { fill: #f6dc85; stroke-width: 1 !important; }
.nisse .n-bowl { display: none; }
.nisse.fed .n-bowl { display: inline; }
.nisse.fed .n-quill { display: none; }

/* What he says: a little paper speech bubble over his hat. */
.nisse-say {
  position: absolute; bottom: calc(100% - 2px); right: -2px; white-space: nowrap;
  padding: 5px 10px 6px; border-radius: 12px; background: var(--paper, #fff); color: var(--ink, #1d2140);
  font-size: 14px; font-weight: 700; line-height: 1.2; box-shadow: 0 0 0 1.5px var(--n-line);
}
.nisse-say::after { content: ""; position: absolute; right: 22px; top: 100%; border: 5px solid transparent; border-top-color: var(--paper, #fff); }
.nisse.from-left .nisse-say { right: auto; left: -2px; }
.nisse.from-left .nisse-say::after { right: auto; left: 22px; }
.nisse:focus-visible { outline: 2.5px solid var(--indigo, #3340a0); outline-offset: 2px; border-radius: 10px; }
.nisse.on-top .nisse-say { bottom: auto; top: -30px; }

/* Walking: boots take turns, the body bobs, the hat tip sways. */
.nisse .n-body, .nisse .n-hat, .nisse .n-boot, .nisse .n-arm { transform-box: view-box; }
.nisse .n-hat { transform-origin: 30px 42px; }
.nisse .n-arm-r { transform-origin: 43px 56px; }
.nisse .n-arm-l { transform-origin: 17px 56px; }
.nisse[data-pose="walk"] .n-body { animation: n-bob .5s ease-in-out infinite; }
.nisse[data-pose="walk"] .n-boot-l { animation: n-step .5s ease-in-out infinite; }
.nisse[data-pose="walk"] .n-boot-r { animation: n-step .5s ease-in-out -.25s infinite; }
.nisse[data-pose="walk"] .n-hat { animation: n-sway 1s ease-in-out infinite; }
.nisse[data-pose="walk"] .n-arm-l { animation: n-swing .5s ease-in-out infinite; }
.nisse[data-pose="run"] .n-body { animation: n-bob .26s ease-in-out infinite; }
.nisse[data-pose="run"] .n-boot-l { animation: n-step .26s ease-in-out infinite; }
.nisse[data-pose="run"] .n-boot-r { animation: n-step .26s ease-in-out -.13s infinite; }
.nisse[data-pose="run"] .n-hat { animation: n-sway .52s ease-in-out infinite; }
.nisse[data-pose="scribble"] .n-arm-r { animation: n-scribble .22s ease-in-out infinite alternate; }
.nisse[data-pose="scribble"] .n-hat { animation: n-sway .44s ease-in-out infinite; }
.nisse[data-pose="eat"] .n-arm-r { animation: n-eat .6s ease-in-out infinite; }
.nisse[data-pose="eat"] .n-body { animation: n-bob .6s ease-in-out infinite; }
.nisse.asked { animation: n-squish .3s ease-out; }
@keyframes n-bob { 50% { transform: translateY(-2px); } }
@keyframes n-step { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes n-sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(4deg); } }
@keyframes n-swing { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@keyframes n-scribble { from { transform: rotate(-14deg) translateY(-2px); } to { transform: rotate(10deg) translateY(1px); } }
@keyframes n-eat { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-12deg) translateY(-3px); } }
@keyframes n-squish { 40% { transform-origin: bottom; scale: 1.08 .92; } }

/* The message he's working on: red quill scratches run across it and it trembles. */
.msg .bubble.nisse-scribbling { position: relative; animation: n-tremble .18s linear infinite; }
.msg .bubble.nisse-scribbling::after {
  content: ""; position: absolute; inset: 4px 6px; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 20' preserveAspectRatio='none'%3E%3Cpath d='M1 6 5 14 9 4 13 15 17 5 21 14 25 3 29 16 33 5 37 14 41 4 45 15 49 5 53 14 57 6' fill='none' stroke='%23d9262d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") repeat-x left center / 60px 100%;
  animation: n-scratch 2.4s linear forwards;
}
@keyframes n-tremble { 25% { transform: rotate(-.6deg); } 75% { transform: rotate(.6deg); } }
@keyframes n-scratch { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.msg .bubble.nisse-poof { animation: n-poof .7s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes n-poof { 0% { transform: scale(.9); filter: blur(2px); } 60% { transform: scale(1.05); filter: none; } 100% { transform: scale(1); } }

/* A rewritten message keeps a little nisse hat on its corner. Tap it to see what it said before. */
.msg .bubble.nissed { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.msg .bubble .nisse-hat {
  position: absolute; top: -13px; right: -3px; width: 15px; height: 20px; transform: rotate(16deg); pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 20'%3E%3Cpath d='M1.5 18.5C2 12 4.5 6 9.2 1.3c.5-.5 1.3-.3 1.3.4.6 5.6 2 11.2 3 16.8-2 .8-3.8 1.1-6 1.1s-4-.4-6-1.1z' fill='%23d9262d' stroke='%231d2140' stroke-width='1.2' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
}
.msg .bubble.was .nisse-hat { opacity: .4; }

@media (prefers-reduced-motion: reduce) {
  .nisse *, .nisse, .msg .bubble.nisse-scribbling, .msg .bubble.nisse-poof { animation: none !important; }
  .msg .bubble.nisse-scribbling::after { animation: none; }
}
@media (prefers-color-scheme: dark) { .nisse svg { filter: drop-shadow(0 0 1px #e8eaf5aa); } }

/* His own lines in the chat: a member-style bubble in his green coat, with his head as the face. */
.msg.nisse-msg .bubble { background: #1f7a45; color: #fff; box-shadow: 0 1px 0 #0f3d23; }
.msg.nisse-msg .bubble a { color: #fff; }
.msg.nisse-msg .who { color: #ffb4b0; }
.msg .mface.nisse-face svg { overflow: visible; }
.nisse-face path, .nisse-face circle, .nisse-face ellipse { stroke: #1d2140; stroke-width: 1.4; stroke-linejoin: round; }
.nisse-face .n-hat { fill: #d9262d; }
.nisse-face .n-beard { fill: #fff; }
.nisse-face .n-skin { fill: #f5cdb8; }
.nisse-face .n-nose { fill: #eaa493; }
.nisse-face .n-eye { fill: #1d2140; stroke: none; }
