/* Slot — a 3x3 segment-display slot machine. Pairs with slot.js.
   Everything is scoped under .slot, and every colour and amount is a custom property that
   slot.js sets on that element, so nothing here leaks into the page around it. */

.slot {
  /* fallbacks only; slot.js overwrites these from its options */
  --c: #ffffff;  --hot: #ffffff;  --sh1: rgba(255, 255, 255, .8);  --sh2: rgba(255, 255, 255, .55);
  --lc: #ffcac7; --lsh1: rgba(255, 42, 31, 1); --lsh2: rgba(255, 42, 31, .8);
  --gc: #ffffff; --ghost: .14;
  --blur: 1.8; --spin-blur: 4.5; --grain: .3; --slant: 0;
  --ink: rgba(226, 233, 226, .58);

  container-type: inline-size;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.slot.slot-static { cursor: default; }
.slot:focus-visible { outline: 1px solid var(--ink); outline-offset: 6px; }

/* The window is only implied: no outline, just a barely-there lift off black and the grain,
   both cut to the same rounded shape. Meant to sit on a pure black page. */
.slot-glass {
  position: relative;
  padding: 15% 19%;                       /* keep in step with PAD_X / PAD_Y in slot.js */
  background: #070807;
  border-radius: 3.2% / 3%;
  overflow: hidden;
  isolation: isolate;
}

.slot-grid {
  position: relative;
  aspect-ratio: 480 / 520;
  container-type: inline-size;
  z-index: 1;
}

/* one glyph */
.slot-cell {
  --u: calc(100cqw / 480);                /* one drawing unit, in px */
  --fill: var(--c);
  position: absolute;
  width: calc(100% * 100 / 480);
  height: calc(100% * 140 / 520);
  filter:
    blur(calc(var(--u) * var(--blur)))
    drop-shadow(0 0 calc(var(--u) * 8) var(--sh1))
    drop-shadow(0 0 calc(var(--u) * 40) var(--sh2));
  transition: filter .6s cubic-bezier(.2, .7, .2, 1);
  will-change: filter;
}
.slot-cell.spin {
  filter:
    blur(calc(var(--u) * var(--spin-blur)))
    drop-shadow(0 0 calc(var(--u) * 10) var(--sh1))
    drop-shadow(0 0 calc(var(--u) * 42) var(--sh2));
  transition-duration: .35s;
}
.slot-cell svg {
  display: block; width: 100%; height: 100%;
  overflow: visible;
  transform: skewX(calc(var(--slant) * -1deg));
  transition: opacity .5s ease;
}
.slot-cell polygon {                      /* unlit: its own colour, independent of the lit one */
  fill: var(--gc);
  opacity: var(--ghost);
  transition: opacity .16s linear, fill 0s .16s;   /* slow LCD fall time; keep the lit colour while fading */
}
.slot-cell polygon.on { fill: var(--fill); opacity: 1; transition: none; }   /* fast rise */
.slot-cell.spin polygon.on { opacity: .8; }
/* display: 'type'. One letter per cell, heavy and narrow, sized so its capitals fill the cell */
.slot-cell text {
  fill: var(--fill);
  font-family: var(--face); font-weight: 900; font-stretch: 62%;
  font-size: 184px; text-anchor: middle;
}
.slot-cell text.star { font-size: 330px; transform: translateY(124px); }
.slot-cell.spin text { opacity: .8; }
.slot-cell.dim svg { opacity: .2; }
.slot-cell.win { --fill: var(--win, var(--hot)); }
/* winners in a colour of their own glow in that colour */
.slot-cell.win svg { filter: drop-shadow(0 0 2.2cqw var(--winsh, transparent)); }

/* payline connectors: part of the same display, living in the gaps between glyphs */
.slot-links {
  --u: calc(100cqw / 480);
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
  filter:
    blur(calc(var(--u) * var(--blur)))
    drop-shadow(0 0 calc(var(--u) * 8) var(--lsh1))
    drop-shadow(0 0 calc(var(--u) * 34) var(--lsh2));
}
.slot-links polygon {
  fill: var(--gc);
  opacity: var(--ghost);
  transition: opacity .3s linear, fill 0s .3s;
}
.slot-links polygon.off { opacity: 0; }             /* connector of a payline that is not in play */
.slot-links polygon.on { fill: var(--lc); opacity: 1; transition: none; animation: slot-ignite .5s steps(1); }

/* dead-front legend: nothing printed, invisible until the win lights it */
.slot-links .slot-win {
  fill: var(--lc); opacity: 0;
  font: 700 26px ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 12px; text-anchor: middle;
}
.slot-links .slot-win.on { opacity: 1; }

/* winner flash: lit segments and connectors blink off to their ghost state, in step */
.slot-grid.flash .slot-cell.win polygon.on,
.slot-grid.flash .slot-links polygon.on { animation: slot-flash .64s steps(1) infinite; }
.slot-grid.flash .slot-links .slot-win.on { animation: slot-flash-off .64s steps(1) infinite; }
.slot-grid.flash .slot-cell.win text { animation: slot-flash-dim .64s steps(1) infinite; }
@keyframes slot-flash-dim { 0%, 100% { opacity: 1; } 58% { opacity: .2; } }
@keyframes slot-flash {
  0%, 100% { opacity: 1; }
  58% { opacity: var(--ghost); fill: var(--gc); }
}
@keyframes slot-flash-off { 0%, 100% { opacity: 1; } 58% { opacity: 0; } }
@keyframes slot-ignite {
  0% { opacity: .35; } 12% { opacity: 1; } 20% { opacity: .15; }
  30% { opacity: 1; } 42% { opacity: .5; } 55%, 100% { opacity: 1; }
}

/* grain: static, cut to the window */
.slot-grain {
  position: absolute; inset: 0;
  pointer-events: none;
  background-size: 192px 192px;
  z-index: 3;
}
.slot-grain.a { opacity: calc(var(--grain) * .07); }
.slot-grain.b { opacity: calc(var(--grain) * .3); mix-blend-mode: overlay; }

/* the logo lives inside the window, softly lit like the rest of the display */
.slot-brand {
  position: absolute; top: 0; left: 0; right: 0;
  height: 15cqw;                          /* the window's top padding */
  display: grid; place-items: center;
  z-index: 1;
  pointer-events: none;
}
.slot-brand svg {
  width: 8cqw; height: auto;
  fill: var(--hot);
  opacity: .85;
  filter:
    blur(.12cqw)
    drop-shadow(0 0 .9cqw var(--sh1))
    drop-shadow(0 0 3.4cqw var(--sh2));
}

.slot-brand svg { transition: fill .2s linear, opacity .2s linear; }
.slot.logo-ghost .slot-brand svg { fill: var(--gc); opacity: var(--ghost); filter: blur(.12cqw); }
.slot.logo-none .slot-brand { display: none; }

/* crisp: no filters at all (so nothing is rasterised soft), and segments switch instantly */
.slot.slot-crisp .slot-cell,
.slot.slot-crisp .slot-links,
.slot.slot-crisp .slot-brand svg { filter: none; transition: none; will-change: auto; }
.slot.slot-crisp .slot-cell polygon,
.slot.slot-crisp .slot-links polygon { transition: none; }
.slot.slot-crisp .slot-cell.spin polygon.on { opacity: 1; }
.slot.slot-crisp .slot-brand svg { opacity: 1; }

/* payline numbers printed on the glass: crisp ink, no glow, under the grain */
.slot-marks {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 2;
  pointer-events: none;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  fill: var(--ink); stroke: none;
}
/* centred on the middle of the digit, not sat on a baseline that differs from font to font */
.slot-marks text { font-size: 12px; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }
.slot-marks rect, .slot-marks line { fill: none; stroke: var(--ink); stroke-width: 1.1; }
.slot.no-marks .slot-marks { display: none; }
.slot-marks g { transition: opacity .2s linear; }
.slot-marks g.off { opacity: .22; }               /* a payline that is not in play */

@media (prefers-reduced-motion: reduce) {
  .slot-grid.flash .slot-cell.win polygon.on,
  .slot-grid.flash .slot-cell.win text,
  .slot-grid.flash .slot-links polygon.on,
  .slot-grid.flash .slot-links .slot-win.on { animation: none; }
}
