/* UNDERFLOW — the fault meter in the base game, and the pocket world behind it.

   The base game is a small bright box on a dark stage: one panel, five digits,
   the same shape every single tap. That rigid sameness is load-bearing. It is
   the only reason breaking the frame lands at all — you cannot be whisked away
   from somewhere that keeps changing. So nothing here is a modal on top of the
   game. The app is physically destroyed and the space behind it is boundless,
   which is the exact inversion of every other screen in this product. */

/* ---------- faults, in the ordinary game ---------- */

/* A draw under 0.01. The number goes wrong for a moment: the two leading zeros
   are the tell, and they are the thing that glitches. */
.number.fault .d:nth-child(2),
.number.fault .d:nth-child(3) {
  animation: fault-glitch 520ms steps(2, end) 3;
  color: var(--tier-mythic);
  text-shadow: 0 0 18px var(--tier-mythic);
}
@keyframes fault-glitch {
  0%, 100% { translate: 0 0; }
  25% { translate: -2px 1px; }
  50% { translate: 2px -1px; }
  75% { translate: -1px -1px; }
}

/* Three pins on a lock. They live in the panel head from the first fault on,
   because a feature nobody knows about generates no anticipation at all. */
.faultmeter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding: 3px 8px;
  background: color-mix(in srgb, var(--tier-mythic) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--tier-mythic) 40%, transparent);
  font-family: var(--display);
  font-size: 0.5rem;
  letter-spacing: 0.1em;
  color: var(--tier-mythic);
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  animation: fault-in 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes fault-in { from { opacity: 0; scale: 0.7; } to { opacity: 1; scale: 1; } }
.faultmeter i {
  width: 7px;
  height: 7px;
  background: color-mix(in srgb, var(--tier-mythic) 22%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tier-mythic) 55%, transparent);
  border-radius: 50%;
}
.faultmeter i.lit {
  background: var(--tier-mythic);
  box-shadow: 0 0 10px var(--tier-mythic), 0 0 20px color-mix(in srgb, var(--tier-mythic) 60%, transparent);
}
/* Two of three. The machine is visibly straining and the player should feel it
   in the room. This state is 1 in 42 games — it is the feature's real payload. */
.faultmeter.brink {
  animation: brink 900ms ease-in-out infinite;
  background: color-mix(in srgb, var(--tier-mythic) 26%, transparent);
}
@keyframes brink {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 22px color-mix(in srgb, var(--tier-mythic) 75%, transparent); }
}
.panel.brink { animation: panel-strain 1600ms ease-in-out infinite; }
@keyframes panel-strain {
  0%, 100% { filter: none; }
  50% { filter: hue-rotate(-8deg) saturate(1.25); }
}

/* ---------- the break ---------- */

body.uf-active { overflow: hidden; }
/* The app is not hidden — it is thrown away from the camera, so the player sees
   the thing they were just holding recede. */
body.uf-active #app {
  transition: transform 900ms cubic-bezier(0.6, 0, 0.2, 1), opacity 900ms ease, filter 900ms ease;
  transform: scale(1.35);
  opacity: 0;
  filter: blur(14px) saturate(0.2);
  pointer-events: none;
}
body.uf-active #confetti { z-index: 260; }

.uf {
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 50%, #0b0716 0%, #05040b 55%, #000 100%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  animation: uf-in 260ms ease both;
}
@keyframes uf-in { from { opacity: 0; } to { opacity: 1; } }

.uf-field { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Its own scanline pass, denser than the app's — we are deeper into the tube. */
.uf::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background:
    radial-gradient(120% 110% at 50% 50%, transparent 48%, rgba(0, 0, 0, 0.72) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.028) 0 1px, transparent 1px 3px);
}

/* --- the fracture --- */

.uf-cracks { position: absolute; inset: 0; z-index: 20; pointer-events: none; opacity: 0; }
.uf-cracks svg { width: 100%; height: 100%; }
.uf-cracks path {
  fill: none;
  stroke: #fff;
  stroke-width: 0.35;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 120;
  stroke-dashoffset: 120;
  filter: drop-shadow(0 0 6px #ff4dd8);
}
.uf.fracturing { animation: uf-shock 900ms steps(3, end); }
.uf.fracturing .uf-cracks { opacity: 1; }
.uf.fracturing .uf-cracks path { animation: crack 620ms cubic-bezier(0.2, 0.9, 0.1, 1) forwards; }
.uf.fracturing .uf-cracks path:nth-child(2) { animation-delay: 90ms; }
.uf.fracturing .uf-cracks path:nth-child(3) { animation-delay: 165ms; }
.uf.fracturing .uf-cracks path:nth-child(4) { animation-delay: 240ms; }
.uf.fracturing .uf-cracks path:nth-child(5) { animation-delay: 305ms; }
@keyframes crack { to { stroke-dashoffset: 0; } }
@keyframes uf-shock {
  0% { filter: invert(1) hue-rotate(90deg); }
  20% { filter: none; }
  38% { filter: invert(1); }
  55% { filter: none; }
  70% { filter: contrast(2.4) brightness(1.7); }
  100% { filter: none; }
}
.uf.open .uf-cracks { opacity: 0; transition: opacity 700ms ease; }

/* --- the title --- */

.uf-title {
  position: relative;
  z-index: 30;
  text-align: center;
  opacity: 0;
  transform: scale(1.5);
  transition: opacity 520ms ease, transform 900ms cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}
.uf.titled .uf-title { opacity: 1; transform: scale(1); }
.uf.playing .uf-title,
.uf.open:not(.titled) .uf-stage ~ .uf-title {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  opacity: 0.9;
  transform: translateX(-50%) scale(0.4);
  transform-origin: top center;
  transition: opacity 500ms ease, transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}
.uf.playing .uf-sub { margin-top: 2px; }
.uf-word {
  position: relative;
  font-family: var(--display);
  font-size: clamp(2.4rem, 13vw, 8rem);
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 0 60px rgba(255, 77, 216, 0.8);
}
/* Chromatic split — the signal is coming apart on the way to your eye. */
.uf-word::before,
.uf-word::after {
  content: attr(data-t);
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
}
.uf-word::before { color: #ff4dd8; animation: ab-l 2.8s ease-in-out infinite; }
.uf-word::after { color: #4fd8eb; animation: ab-r 2.8s ease-in-out infinite; }
@keyframes ab-l { 0%, 100% { translate: -4px 0; } 50% { translate: -1px 1px; } }
@keyframes ab-r { 0%, 100% { translate: 4px 0; } 50% { translate: 1px -1px; } }
.uf-sub {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: clamp(0.6rem, 2.6vw, 0.85rem);
  letter-spacing: 0.28em;
  color: var(--dim);
}

/* --- the build --- */

.uf-stage {
  position: relative;
  z-index: 32;
  width: min(94vw, 680px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.4vh, 22px);
  animation: stage-in 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
  pointer-events: none;
}
@keyframes stage-in { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }

.uf-toprow {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--display);
}
.uf-place { font-size: clamp(0.5rem, 2.2vw, 0.72rem); letter-spacing: 0.16em; color: var(--dim); }
.uf-mult {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-size: clamp(1.3rem, 5vw, 2.2rem);
  color: var(--gold);
  text-shadow: 0 0 24px color-mix(in srgb, var(--gold) 70%, transparent);
}
.uf-mult span { font-size: 0.6em; opacity: 0.7; }
.uf.clutched .uf-mult { animation: mult-pop 620ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes mult-pop {
  0% { scale: 1; }
  30% { scale: 1.55; filter: brightness(2); }
  100% { scale: 1; }
}
.uf.maxmult .uf-mult { color: var(--tier-mythic); text-shadow: 0 0 30px var(--tier-mythic); }

/* The number under construction. Slots fill right to left, so the last grab is
   the tenths place — worth ten times everything banked before it. The drama is
   structural: after four locks the player is staring at one empty box that is
   the entire difference between 0.9xxxx and 0.1xxxx. */
.uf-num {
  --sh: clamp(52px, 14.5vw, 104px);
  display: flex;
  align-items: center;
  gap: clamp(2px, 0.8vw, 6px);
  font-family: var(--mono);
  font-weight: 700;
}
.uf-lead {
  font-size: calc(var(--sh) * 0.62);
  color: var(--dim);
  margin-right: 2px;
}
.uf-slot {
  position: relative;
  display: block;
  width: calc(var(--sh) * 0.66);
  height: var(--sh);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.09);
  transition: box-shadow 200ms ease, background 200ms ease, scale 220ms cubic-bezier(0.16, 1, 0.3, 1);
  /* the window softens at its edges so the reel reads as a physical strip */
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 22%, #000 78%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 22%, #000 78%, transparent 100%);
}
.uf-reel { display: block; will-change: transform; }
.uf-reel b {
  display: block;
  height: var(--sh);
  line-height: var(--sh);
  font-size: calc(var(--sh) * 0.78);
  text-align: center;
  color: var(--ink);
}
.uf-slot.active {
  background: rgba(255, 77, 216, 0.13);
  box-shadow: inset 0 0 0 1px var(--tier-mythic), 0 0 34px color-mix(in srgb, var(--tier-mythic) 45%, transparent);
  scale: 1.1;
}
.uf-slot.active .uf-reel { filter: blur(0.7px); }
.uf-slot.locked {
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  animation: slam 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slam {
  0% { scale: 1.34; filter: brightness(2.4); }
  100% { scale: 1; filter: none; }
}
/* 7, 8, 9 — the digits actually worth stopping on. */
.uf-slot.locked.high {
  background: color-mix(in srgb, var(--gold) 16%, transparent);
  box-shadow: inset 0 0 0 1px var(--gold), 0 0 26px color-mix(in srgb, var(--gold) 45%, transparent);
}
.uf-slot.locked.high .uf-reel b { color: var(--gold); }
/* Places the machine spun out because the meter ran dry. They used to be zeroes
   and were styled as a loss; they are real digits now, so they read as "not
   yours" — dashed, desaturated — rather than as damage. */
.uf-slot.dead {
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--dim) 55%, transparent);
  animation: slam 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
.uf-slot.dead .uf-reel b { color: var(--dim); }
.uf-slot.dead::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--dim) 0 4px, transparent 4px 8px);
  opacity: 0.7;
}

/* the meter — the most-watched object on the screen */
.uf-meter {
  position: relative;
  width: min(78vw, 460px);
  height: 12px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.uf-clutch {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 2; /* above the fill — it is a target, and targets must be visible */
  background: repeating-linear-gradient(45deg, rgba(255, 210, 63, 0.5) 0 5px, transparent 5px 10px);
  box-shadow: inset -2px 0 0 var(--gold);
  pointer-events: none;
}
.uf-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--tier-mythic), var(--tier-uncommon));
  will-change: transform;
}
.uf.hot .uf-fill { background: linear-gradient(90deg, var(--miss), var(--gold)); }
.uf.hot .uf-meter { animation: meter-panic 340ms ease-in-out infinite; }
@keyframes meter-panic {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 24px color-mix(in srgb, var(--miss) 80%, transparent); }
}
.uf-hint {
  font-family: var(--display);
  font-size: clamp(0.55rem, 2.4vw, 0.78rem);
  letter-spacing: 0.18em;
  color: var(--dim);
}
.uf.final .uf-hint { color: var(--gold); animation: hint-flash 700ms ease-in-out infinite; }
@keyframes hint-flash { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.uf.collapsing .uf-num { animation: uf-shock 520ms steps(3, end); }

/* --- the payout --- */

.uf-stage.resolved .uf-meter,
.uf-stage.resolved .uf-hint,
.uf-stage.resolved .uf-toprow { opacity: 0.25; transition: opacity 400ms ease; }

.uf-payout {
  position: relative;
  z-index: 34;
  margin-top: clamp(10px, 2.4vh, 24px);
  max-width: min(96vw, 680px);
  text-align: center;
  pointer-events: none;
  animation: stage-in 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.uf-special {
  font-family: var(--display);
  font-size: clamp(1rem, 5vw, 2rem);
  color: var(--sc, var(--gold));
  text-shadow: 0 0 34px var(--sc, var(--gold));
  opacity: 0;
  scale: 0.6;
}
.uf-special.on { animation: spec-in 620ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes spec-in {
  0% { opacity: 0; scale: 2.2; filter: blur(10px); }
  60% { opacity: 1; scale: 0.94; filter: none; }
  100% { opacity: 1; scale: 1; }
}
.uf-tier {
  font-family: var(--display);
  font-size: clamp(0.7rem, 3.2vw, 1.1rem);
  letter-spacing: 0.22em;
  color: var(--tc, var(--tier-uncommon));
  margin-top: 6px;
}
.uf-tier.pop { animation: tier-pop 520ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes tier-pop {
  0% { scale: 0.5; filter: brightness(3); letter-spacing: 0.6em; }
  100% { scale: 1; filter: none; letter-spacing: 0.22em; }
}
.uf-total {
  font-family: var(--display);
  font-size: clamp(2.4rem, 13vw, 5.6rem);
  color: var(--ink);
  text-shadow: 0 0 44px color-mix(in srgb, var(--tc, var(--gold)) 70%, transparent);
  line-height: 1;
}
.uf-total.landed { animation: total-land 620ms cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes total-land {
  0% { scale: 1.28; filter: brightness(2.2); }
  100% { scale: 1; filter: none; }
}
.uf-breakdown {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin-top: 12px;
  font-family: var(--mono);
  font-size: clamp(0.52rem, 2.2vw, 0.7rem);
  color: var(--dim);
  letter-spacing: 0.06em;
}
.uf-breakdown b { color: var(--hit); font-weight: 700; }

/* --- the return --- */

.uf.closing { animation: uf-out 760ms cubic-bezier(0.6, 0, 0.2, 1) forwards; }
@keyframes uf-out {
  0% { opacity: 1; transform: scale(1); filter: none; }
  100% { opacity: 0; transform: scale(0.55); filter: blur(12px) brightness(2); }
}

/* ---------- reduced motion ----------
   The feature is shortened, never skipped. Someone who has waited five hundred
   games for this does not get a text box instead — they get the same reel, the
   same decision and the same roll-up, with the camera work taken out. */
@media (prefers-reduced-motion: reduce) {
  body.uf-active #app { transition: none; transform: none; opacity: 0; filter: none; }
  .uf.fracturing,
  .uf.collapsing .uf-num,
  .uf-word::before,
  .uf-word::after,
  .uf.hot .uf-meter,
  .panel.brink,
  .faultmeter.brink { animation: none; }
  .uf-title, .uf.playing .uf-title { transition: opacity 200ms ease; transform: none; }
  .uf.playing .uf-title { display: none; }
  .uf, .uf-stage, .uf-payout { animation: none; }
  .uf.closing { animation: uf-fadeout 240ms ease forwards; }
  @keyframes uf-fadeout { to { opacity: 0; } }
}

/* ---------- short landscape phones ---------- */
@media (max-height: 460px) {
  .uf-num { --sh: clamp(38px, 12vh, 62px); }
  .uf-stage { gap: 8px; }
  .uf-payout { margin-top: 8px; }
  .uf-total { font-size: clamp(1.8rem, 9vh, 3.2rem); }
  .uf.playing .uf-title { display: none; }
}

/* ---------- the paytable line ---------- */
/* Top of the trophy case, above every special, priced "???" on purpose. */
.trophy-row.underflow-row {
  background: linear-gradient(90deg, color-mix(in srgb, var(--tier-mythic) 15%, transparent), transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--tier-mythic) 45%, transparent);
  padding-left: 10px;
  margin-bottom: 6px;
}
.trophy-row.underflow-row .tname {
  font-size: 0.86rem;
  text-shadow: 0 0 18px color-mix(in srgb, var(--tier-mythic) 70%, transparent);
}
.trophy-row.underflow-row span:nth-child(2) {
  color: var(--tier-mythic);
  letter-spacing: 0.24em;
}

/* Idle places — not yet played, and they must not read as digits you already
   own. Dim, unlit, clearly waiting. */
.uf-slot:not(.locked):not(.active):not(.dead) {
  background: rgba(255, 255, 255, 0.025);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.uf-slot:not(.locked):not(.active):not(.dead) .uf-reel b { color: color-mix(in srgb, var(--dim) 34%, transparent); }
.uf-slot:not(.locked):not(.active):not(.dead) .uf-reel { filter: blur(1.4px); }
.trophy-row.underflow-row.owned span:nth-child(2) { color: var(--gold); letter-spacing: 0.1em; }

/* ---------- LOW GRAPHICS ----------
   The pocket worlds are the heaviest screens in the game: persistent blurs on
   the spinning reels, layered glows, and a starfield behind everything. The
   blanket in styles.css already removes the shadows and filters; these are the
   ambient loops, killed by name. Every outcome, digit and payout still renders. */
html[data-gfx='low'] .uf-word::before,
html[data-gfx='low'] .uf-word::after,
html[data-gfx='low'] .rc-word::before,
html[data-gfx='low'] .rc-word::after,
html[data-gfx='low'] .uf.hot .uf-meter,
html[data-gfx='low'] .uf.final .uf-hint,
html[data-gfx='low'] .rc.lastseed .rc-seeds b,
html[data-gfx='low'] .rc.lastseed .rc-hint,
html[data-gfx='low'] .rc.spinning .rc-picklabel,
html[data-gfx='low'] .faultmeter.brink,
html[data-gfx='low'] .panel.brink,
html[data-gfx='low'] .chainmeter.brink {
  animation: none !important;
}
