/* MEK design system · part: message log
   A running list of what just happened in a game ("The well is built", "Ana is hungry"), the newest at the bottom and
   kept there unless the reader scrolls up. Opt-in: link it after mek.css, with js/log.js:
     <div class="log px-box" id="log"><ol class="log-lines" aria-label="Chronicle"></ol></div>
     mekLog.add(document.getElementById("log"), "The well is built", { kind: "good", when: "1347" });
   In the mek.parts layer, so a project's CSS wins. */

@layer mek.parts {

/* ---------- Dials ---------- */
/* on every themed area too, so a box in another theme works these out from its own colours */
:root, [data-theme] {
  --log-rows: 6;                       /* how many rows tall the log is: it never grows, it scrolls */
  --log-ink: var(--text);              /* a plain line: 900 */
  --log-when: var(--text-muted);       /* the stamp before a line (a year, a time): 700 */
  --log-good: var(--good);             /* .good: something gained or done. Mark + */
  --log-warn: var(--warn);             /* .warn: something to watch. Mark ! */
  --log-bad: var(--bad);               /* .bad: something lost or gone wrong. Mark - */
  --log-info: var(--info);             /* .info: a fact or a tip. Mark * */
  --log-quiet: var(--text-muted);      /* .quiet: small news, no mark; greyed through --dim-mask in B/W */
}

/* ---------- Log ----------
   A box (a px-box if you want a frame) holding an <ol class="log-lines">, the list that scrolls: Mono 24 on 32px rows
   (.sm: Mono 14 on 20px), --log-rows rows tall whatever is in it (the MEK scrollbar, its room kept). Each line is an
   <li>: a 2-cell gutter for its kind's mark, then an optional stamp (.log-when, in --log-when) and the words, wrapping
   under themselves. A kind sets the line's ink and its mark, so kinds read without colour too (B/W). A new line comes
   in through the dither (a quarter, a half, all: two frames, stepped); at once under reduced motion.
   Scrolled up, new lines don't pull you down: .log-new, a button over the bottom right corner ("3 new lines"), takes
   you back. It's drawn over the list, so showing it moves nothing. */
.log { --p: 2px; --row: 32px; position: relative; display: grid; min-width: 0; }
.log.sm { --p: 1px; --row: 20px; }
.log-lines { list-style: none; margin: 0; padding: var(--space-2) var(--space-3); box-sizing: content-box;
  height: calc(var(--log-rows) * var(--row)); overflow-y: auto; scrollbar-gutter: stable; overflow-anchor: none;   /* js/log.js keeps the place */
  font: var(--text-lg)/var(--row) var(--font-mono); -webkit-font-smoothing: none; color: var(--log-ink); overflow-wrap: anywhere; }
.log.sm > .log-lines { font-size: var(--text-crisp); }
.log-lines:focus-visible { outline: var(--stroke) dashed var(--focus-ring); outline-offset: calc(-1 * var(--space-1)); }
.log-lines > li { position: relative; margin: 0; padding-left: 2ch; }
.log-lines > li::before { position: absolute; left: 0; top: 0; }
.log-when { color: var(--log-when); font-variant-numeric: tabular-nums; }
.log-lines > li.good { color: var(--log-good); }
.log-lines > li.good::before { content: "+"; content: "+" / ""; }
.log-lines > li.warn { color: var(--log-warn); }
.log-lines > li.warn::before { content: "!"; content: "!" / ""; }
.log-lines > li.bad { color: var(--log-bad); }
.log-lines > li.bad::before { content: "-"; content: "-" / ""; }
.log-lines > li.info { color: var(--log-info); }
.log-lines > li.info::before { content: "*"; content: "*" / ""; }
.log-lines > li.quiet { color: var(--log-quiet); -webkit-mask: var(--dim-mask); mask: var(--dim-mask); }
.log-lines > li.in { animation: mek-log-in calc(2 * var(--frame)) steps(1, end) both; }
/* A pixel in four, then two, then all. Each held, so it steps. */
@keyframes mek-log-in {
  0%, 49% { -webkit-mask: conic-gradient(#000 0 25%, #0000 0) 0 0 / calc(2 * var(--p)) calc(2 * var(--p)); mask: conic-gradient(#000 0 25%, #0000 0) 0 0 / calc(2 * var(--p)) calc(2 * var(--p)); }
  50%, 99% { -webkit-mask: conic-gradient(#000 0 25%, #0000 0 50%, #000 0 75%, #0000 0) 0 0 / calc(2 * var(--p)) calc(2 * var(--p)); mask: conic-gradient(#000 0 25%, #0000 0 50%, #000 0 75%, #0000 0) 0 0 / calc(2 * var(--p)) calc(2 * var(--p)); } }

/* The cue: a button over the bottom right, clear of the scrollbar, on the ground so the lines don't show through. */
.log-new { position: absolute; right: calc(var(--space-2) + 6px);   /* 6px: the scrollbar's width (css/scrollbar.css) */
  bottom: var(--space-2); --fill: var(--bg); --fill-to: var(--bg); }
.log-new[hidden] { display: none; }
@media (pointer: coarse) { .log-new { min-height: var(--press-min); } }

@media (max-width: 640px) {   /* --bp-phone: the big size steps down to the small one */
  .log:not(.sm) { --p: 1px; --row: 20px; }
  .log:not(.sm) > .log-lines { font-size: var(--text-crisp); }
}

}
