/* ---------- Nostalgic FX (src/fx.js; sprites in art/fx/, drawn by tools/desk_art/fx_art.py) ----------
   Twinkling 4-point stars, shiny bursts, sparkle dust, the dialogue box's ▼, the menu cursor ▶ and the rank-up ribbon.
   --fxa is one art pixel (two world pixels). A sprite draws at --px = --fxa × --fxs (--fxs 0.5: one world pixel per art
   pixel, for small things). A container can set --fxa itself, for example calc(var(--pu) * 2) inside panels.
   Every sheet keeps a clear one-pixel gutter round each frame, so frame n starts at 1 + n × pitch.
   Settings (fx.applySettings sets the body classes): body.calm (the game's Motion Off) and body.fx-off stop everything;
   body.fx-reduced (Motion Slow, or the system's reduced-motion setting) keeps one slow star and nothing bounces;
   body.fx-low (Particles Low) keeps one star. */
:root { --fxa: calc(var(--g, 2px) * 2); }

.fx-layer { position: fixed; inset: 0; z-index: 44; pointer-events: none; overflow: hidden; contain: strict; }
.fx-probe { position: absolute; left: 0; top: 0; width: calc(var(--fxa) * 64); height: 0; visibility: hidden; pointer-events: none; }
.fx-group { position: absolute; left: 0; top: 0; width: 0; height: 0; }

/* ---------- sprites ---------- */
.fx-spr { --px: calc(var(--fxa) * var(--fxs, 1)); --row: 0; position: absolute; display: block; margin: 0; padding: 0; border: 0; pointer-events: none;
  image-rendering: pixelated; background-repeat: no-repeat; font-style: normal; }
.fx-spr.small { --fxs: 0.5; }
.tint-gold { --row: 0; } .tint-ice { --row: 1; } .tint-pink { --row: 2; } .tint-mint { --row: 3; } .tint-silver { --row: 4; } .tint-rainbow { --row: 5; }
/* an ink edge, for stars over pale paper */
.fx-spr.edge { filter: drop-shadow(calc(var(--px) * 0.5) 0 0 rgba(35, 32, 28, 0.55)) drop-shadow(calc(var(--px) * -0.5) 0 0 rgba(35, 32, 28, 0.55))
  drop-shadow(0 calc(var(--px) * 0.5) 0 rgba(35, 32, 28, 0.55)); }

/* the twinkle: 7 frames of 9×9 in 11-pixel cells (dot, plus, star, long arms, back down); at rest it shows nothing */
.fx-tw { width: calc(var(--px) * 9); height: calc(var(--px) * 9); background-image: url(../art/fx/twinkle.png);
  background-size: calc(var(--px) * 77) calc(var(--px) * 66); background-position: calc(var(--px) * -78) calc(var(--px) * (-1 - 11 * var(--row))); }
.fx-tw.still { background-position-x: calc(var(--px) * -34); } /* the long-arm star, held */
/* the shiny burst: 6 frames of 15×15 in 17-pixel cells (a flare that breaks into a ring of sparks) */
.fx-burst { width: calc(var(--px) * 15); height: calc(var(--px) * 15); background-image: url(../art/fx/shiny.png);
  background-size: calc(var(--px) * 102) calc(var(--px) * 102); background-position: calc(var(--px) * -103) calc(var(--px) * (-1 - 17 * var(--row))); }
/* sparkle dust: 4 frames of 3×3 in 5-pixel cells */
.fx-dust { width: calc(var(--px) * 3); height: calc(var(--px) * 3); background-image: url(../art/fx/dust.png);
  background-size: calc(var(--px) * 20) calc(var(--px) * 30); background-position: calc(var(--px) * -21) calc(var(--px) * (-1 - 5 * var(--row))); }

/* play the frames once: --dur long, after --del */
.fx-tw.play { animation: fxTwPlay var(--dur, 0.56s) steps(7, jump-end) var(--del, 0s) forwards; }
.fx-burst.play { animation: fxBurstPlay var(--dur, 0.42s) steps(6, jump-end) var(--del, 0s) forwards; }
.fx-dust.play { animation: fxDustPlay var(--dur, 0.6s) steps(4, jump-end) var(--del, 0s) forwards; }
@keyframes fxTwPlay { from { background-position-x: calc(var(--px) * -1); } to { background-position-x: calc(var(--px) * -78); } }
@keyframes fxBurstPlay { from { background-position-x: calc(var(--px) * -1); } to { background-position-x: calc(var(--px) * -103); } }
@keyframes fxDustPlay { from { background-position-x: calc(var(--px) * -1); } to { background-position-x: calc(var(--px) * -21); } }
/* a twinkle that comes round now and then: its 7 frames in the first 18% of the period --p, then nothing (no repaints) */
@keyframes fxTwIdle { 0% { background-position-x: calc(var(--px) * -1); animation-timing-function: steps(7, jump-end); } 18%, 100% { background-position-x: calc(var(--px) * -78); } }

/* ---------- idle twinkles on cards in menus: .twinkly (fx.twinkly(root) gives each one 2 or 3 stars) ---------- */
:where(.twinkly) { position: relative; }
.fx-idle { left: var(--x, 50%); top: var(--y, 50%); translate: -50% -50%; z-index: 3; animation: fxTwIdle var(--p, 4s) linear var(--d, 0s) infinite; }

/* ---------- the glint: one star on an object's corner while it holds something new (fx.glint) ---------- */
.fx-glint { --gi: 2; z-index: 4; translate: -50% -50%; animation: fxTwIdle var(--p, 1.7s) linear var(--d, 0s) infinite; }
.fx-glint.at-tr { left: calc(100% - var(--px) * var(--gi)); top: calc(var(--px) * var(--gi)); }
.fx-glint.at-tl { left: calc(var(--px) * var(--gi)); top: calc(var(--px) * var(--gi)); }
.fx-glint.at-br { left: calc(100% - var(--px) * var(--gi)); top: calc(100% - var(--px) * var(--gi)); }
.fx-glint.at-bl { left: calc(var(--px) * var(--gi)); top: calc(100% - var(--px) * var(--gi)); }
.lifted > .fx-glint { visibility: hidden; }

/* ---------- the dialogue box: typed text and its ▼ (fx.type) ---------- */
.fx-rest { visibility: hidden; }
.fx-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* the ▼ sits on the text's baseline without changing the line's height; --more-scale 1 draws it at the art scale */
.fx-more { --px: calc(var(--fxa) * var(--more-scale, 0.5)); --row: 0; position: relative; display: inline-block; width: calc(var(--px) * 6); height: 1px;
  margin-left: calc(var(--px) * 1.5); vertical-align: baseline; pointer-events: none; }
.fx-more::after { content: ''; position: absolute; left: 0; bottom: 0; width: calc(var(--px) * 6); height: calc(var(--px) * 6); image-rendering: pixelated;
  background: url(../art/fx/cursor_down.png) no-repeat; background-size: calc(var(--px) * 32) calc(var(--px) * 24);
  background-position: calc(var(--px) * -1) calc(var(--px) * (-1 - 8 * var(--row))); animation: fxBob 0.72s steps(4, jump-end) infinite; }
.fx-more.corner { position: absolute; right: calc(var(--px) * 9); bottom: calc(var(--px) * 3); margin: 0; }
.fx-more.c-paper { --row: 1; }
.fx-more.c-gold { --row: 2; }
@keyframes fxBob { from { background-position-x: calc(var(--px) * -1); } to { background-position-x: calc(var(--px) * -33); } }
@keyframes fxBlink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }

/* ---------- the menu cursor: a ▶ that nudges beside the hovered or focused item of a .menu-cursor list ----------
   It is the item's ::before (.mc-after: its ::after, for items that already use ::before); .mc-here puts it on an item
   by hand (keyboard selection, fx.cursorTo). --mc-x moves it (default: just left of the item), --mc-scale sizes it.
   Gold by default; .mc-ink for paper lists, .mc-paper for dark ones. */
:where(.menu-cursor) > :where(*) { position: relative; }
.menu-cursor { --row: 2; }
.menu-cursor.mc-ink { --row: 0; }
.menu-cursor.mc-paper { --row: 1; }
.menu-cursor:not(.mc-after) > :is(:hover, :focus-visible, .mc-here)::before,
.menu-cursor.mc-after > :is(:hover, :focus-visible, .mc-here)::after {
  --px: calc(var(--fxa) * var(--mc-scale, 0.5)); content: ''; position: absolute; z-index: 5; left: var(--mc-x, calc(var(--px) * -7)); top: 50%; margin-top: calc(var(--px) * -3);
  width: calc(var(--px) * 6); height: calc(var(--px) * 6); pointer-events: none; image-rendering: pixelated;
  background: url(../art/fx/cursor_right.png) no-repeat; background-size: calc(var(--px) * 32) calc(var(--px) * 24);
  background-position: calc(var(--px) * -1) calc(var(--px) * (-1 - 8 * var(--row))); animation: fxBob 0.6s steps(4, jump-end) infinite; }

/* ---------- settings ---------- */
body.calm .fx-idle, body.fx-off .fx-idle, body.fx-reduced .fx-idle:not(.i0), body.fx-low .fx-idle:not(.i0) { display: none; }
body.fx-reduced .fx-idle { animation-duration: calc(var(--p, 4s) * 1.8); }
body.calm .fx-glint, body.fx-off .fx-glint { animation: none; background-position-x: calc(var(--px) * -34); }
body.fx-reduced .fx-glint { animation-duration: calc(var(--p, 1.7s) * 2); }
body.calm .fx-more::after, body.fx-off .fx-more::after { animation: none; }
body.fx-reduced .fx-more::after { animation: fxBlink 1.1s steps(1, end) infinite; }
/* as specific as the cursor's own rule above, or its bob wins */
body:is(.calm, .fx-off, .fx-reduced) .menu-cursor > :is(:hover, :focus-visible, .mc-here)::before,
body:is(.calm, .fx-off, .fx-reduced) .menu-cursor > :is(:hover, :focus-visible, .mc-here)::after { animation: none; }

