/* Lambda, the narrator of the note on constrained optimisation: a pixel lambda with a
   mortarboard that speaks in a dialogue box of an old role-playing game (name plate, stepped
   tail, blinking ▼). The sprite sheet lambda.svg holds eight 20 x 27 pixel frames, drawn by
   scripts/beschraenkte_optimierung_figures.py: 0 idle, 1 blink, 2 talk, 3 point, 4 point and
   talk, 5 surprised, 6 thinking, 7 pushing. Markup in the note:
   <div class="narrator" role="note" data-pose="zeigt"><p>…</p></div>
   Without JavaScript or with reduced motion everything stays visible and still. */
.narrator { --base: 0; --blink: 1; --talk: 2; --px: 3px;
  display: grid; grid-template-columns: calc(20 * var(--px)) minmax(0, 1fr); align-items: start; gap: 0 18px; margin: 30px 0 36px; }
.narrator[data-pose="zeigt"] { --base: 3; --blink: 3; --talk: 4; }
.narrator[data-pose="staunt"] { --base: 5; --blink: 5; --talk: 5; }
.narrator[data-pose="denkt"] { --base: 6; --blink: 6; --talk: 6; }
.narrator[data-pose="schiebt"] { --base: 7; --blink: 7; --talk: 7; }

.narrator::before { content: ""; width: calc(20 * var(--px)); height: calc(27 * var(--px));
  background: url(/img/notes/beschraenkte-optimierung/lambda.svg) no-repeat;
  background-size: calc(160 * var(--px)) calc(27 * var(--px));
  background-position: calc(var(--base) * -20 * var(--px)) 0;
  animation: narrator-blink 5.2s step-end infinite; }
.narrator:nth-of-type(3n + 1)::before { animation-delay: -1.7s; }
.narrator:nth-of-type(3n + 2)::before { animation-delay: -3.4s; }
.narrator.is-talking::before { animation: narrator-talk .32s step-end 6; }
.narrator:hover::before { animation: narrator-blink 5.2s step-end infinite, narrator-hop .5s steps(2, jump-none) 1; }
@keyframes narrator-blink {
  0%, 95% { background-position: calc(var(--base) * -20 * var(--px)) 0; }
  96%, 100% { background-position: calc(var(--blink) * -20 * var(--px)) 0; }
}
@keyframes narrator-talk {
  0% { background-position: calc(var(--base) * -20 * var(--px)) 0; }
  50% { background-position: calc(var(--talk) * -20 * var(--px)) 0; }
}
@keyframes narrator-hop { 50% { transform: translateY(calc(-3 * var(--px))); } }

/* The dialogue box: name plate on the top border, stepped tail towards Lambda's mouth and the
   blinking "more" triangle of old games in the lower right corner. */
.narrator > p { position: relative; margin: 10px 0 0; padding: 16px 18px 14px; font-size: 14px; line-height: 1.65;
  background: #fffdf4 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 5 3' shape-rendering='crispEdges'%3E%3Cpath fill='%23b95a28' d='M0 0h5v1h-1v1h-1v1h-1v-1h-1v-1h-1z'/%3E%3C/svg%3E") no-repeat right 10px bottom 7px / 10px 6px;
  border: 2px solid var(--ink); box-shadow: 4px 4px 0 #e6e3db; animation: narrator-more 1.1s step-end infinite; }
.narrator > p::before { content: "Lambda"; position: absolute; top: -11px; left: 12px; padding: 0 8px; background: var(--ink); color: var(--paper);
  font-size: 11px; font-weight: 700; line-height: 18px; letter-spacing: .16em; text-transform: uppercase; }
.narrator > p::after { content: ""; position: absolute; top: 16px; left: -16px; width: 16px; height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 5' shape-rendering='crispEdges'%3E%3Cpath fill='%23252525' d='M5 0h3v1h-3zM3 1h2v1h-2zM1 2h2v1h-2zM0 3h1v1h-1zM0 4h8v1h-8z'/%3E%3Cpath fill='%23fffdf4' d='M5 1h3v1h-3zM3 2h5v1h-5zM1 3h7v1h-7z'/%3E%3C/svg%3E") no-repeat 0 0 / 100% 100%; }
@keyframes narrator-more { 50% { background-position: right 10px bottom -20px; } }

/* With JavaScript the box opens in three steps when it first scrolls into view. */
.narrator-js .narrator > p { transition: opacity .36s steps(3, end), transform .36s steps(3, end); transform-origin: 0 20px; }
.narrator-js .narrator:not(.is-seen) > p { opacity: 0; transform: scale(.9); }

/* "Merke": the key result of a page on a card like an item card of an old game, in the colour of
   the chapter (--c from course.css). Markup: <div class="merke"> with a $$ formula or a <p>. */
.merke { position: relative; margin: 36px 0 30px; padding: 20px 20px 10px; border: 2px solid var(--ink); background: #fffdf4;
  box-shadow: 5px 5px 0 var(--c, #b95a28); }
.merke::before { content: "★ Merke"; position: absolute; top: -11px; left: 12px; padding: 0 8px; background: var(--c, #b95a28); color: #fffdf4;
  font-size: 11px; font-weight: 700; line-height: 18px; letter-spacing: .16em; text-transform: uppercase; }
.merke p { margin: 0 0 10px; font-size: 14px; }
.merke .math-block { padding: 4px 0; margin: 0 0 8px; }

@media (max-width: 560px) {
  .merke { padding: 18px 14px 8px; box-shadow: 4px 4px 0 var(--c, #b95a28); }
  .merke p { font-size: 13px; }
  .narrator { --px: 2px; gap: 0 14px; margin: 26px 0 30px; }
  .narrator > p { font-size: 13px; padding: 14px 14px 12px; }
  .narrator > p::after { top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .narrator::before, .narrator > p { animation: none !important; }
  .narrator-js .narrator > p { transition: none; }
}
@media print {
  .narrator::before { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .narrator > p, .merke { box-shadow: none; background-image: none; }
}
