/* базово */
.win-dialog { --win-title-scale: 1; }
/* тільки українська */
:lang(uk) .win-dialog { --win-title-scale: .75; }
.topbar-multiplayer {
  transition: transform .22s ease;
  will-change: transform;
}
#game:has(#error-overlay:not(.hidden)) .topbar-multiplayer {
  transform: translate(-50%, calc(-50% + 48px));
}
#game:has(#win-overlay:not(.hidden)) .topbar-multiplayer {
  transform: translate(-50%, calc(-50% + 68px));
}

.win-overlay {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: 50%;
  right: auto;
  bottom: auto;
  z-index: 2;
  display: grid;
  width: min(45vw, calc(100vw - 112px));
  justify-items: center;
  align-content: start;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity .16s ease, visibility .16s ease;
}

.win-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  height: auto;
  padding: 10px 12px 4px;
  border-radius: 16px;
  background: radial-gradient(
          85.27% 86.29% at 50% 13.71%,
          rgba(46, 56, 102, 0.70) 0%,
          rgba(67, 79, 135, 0.50) 33.98%,
          rgba(165, 175, 220, 0.50) 80.75%
  );
  box-shadow:
          0 1.362px 0 0 rgba(255, 255, 255, 0.55) inset,
          0 0 9.73px 0 rgba(255, 255, 255, 0.60) inset,
          0 3.892px 9.73px 0 rgba(9, 33, 63, 0.90);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  display: grid;
  place-items: center;
  gap: 4px;

  transform-origin: 50% 60%;
  transform: translateY(14px) scale(.92);
  filter: blur(2px);
}

@media (orientation: portrait) and (min-width: 768px) {
  .win-overlay {
    top: calc(env(safe-area-inset-top, 0px) + 20px);
    width: min(30vw, calc(100vw - 112px));
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #game:has(#error-overlay:not(.hidden)) .topbar-multiplayer,
  #game:has(#win-overlay:not(.hidden)) .topbar-multiplayer {
    transform: translate(calc(-100% - 4px), -50%);
  }

  #game:has(#win-overlay:not(.hidden)) #win-overlay,
  #game:has(#error-overlay:not(.hidden)) #error-overlay {
    /*transform: translateX(4px);*/
    max-width: min(44vw, 220px);
  }
}

@media (orientation: landscape) {
  .win-overlay {
    width: auto;
    max-width: calc(100vw - 112px);
  }

  .win-dialog {
    width: fit-content;
    max-width: 100%;
  }

  .win-overlay {
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    left: calc(50% - var(--compact-top-left-slot-offset, 64px) - 60px);
    width: min(34vw, 200px);
    max-width: min(25vw, 240px);
    transform: translateX(-50%);
  }

  #game:has(#bottom-tools.full) .win-overlay {
    left: calc(50% - var(--compact-top-left-slot-offset, 64px) - 24px + var(--compact-top-open-shift, 24px));
  }

  .win-dialog {
    width: 100%;
    padding: 8px 10px 4px;
  }
}

@media (orientation: landscape) and (max-height: 375px) {
  .win-overlay {
    /*top: calc(env(safe-area-inset-top, 0px) + 30px);*/
    left: calc(50% - var(--compact-top-left-slot-offset, 64px));
    width: min(30vw, 170px);
    max-width: min(30vw, 170px);
    transform: translateX(-50%);
  }

  #game:has(#bottom-tools.full) .win-overlay {
    left: calc(50% - var(--compact-top-left-slot-offset, 64px) + var(--compact-top-open-shift, 24px));
  }

  .win-dialog {
    width: 100%;
    padding: 8px 10px 4px;
  }

  .win-overlay {
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    left: calc(47% - var(--compact-top-left-slot-offset));
  }

  #game:has(#bottom-tools.full) .win-overlay {
    left: calc(50% - var(--compact-top-left-slot-offset, 64px) + var(--compact-top-open-shift, 14px));
  }

  .win-dialog {
    width: 100%;
    padding: 6px 8px 3px;
    gap: 2px;
    border-radius: 12px;
  }

  .win-title {
    font-size: clamp(11px, 3vw, 15px);
  }

  .win-amount {
    font-size: clamp(9px, 2.6vw, 13px);
  }

  .win-mult__value {
    font-size: clamp(8px, 2.2vw, 11px);
  }

  .win-divider {
    height: 1px;
  }
}

@media (orientation: landscape) and (max-height: 375px) and (min-width: 800px) {
  .win-overlay {
    left: calc(50% - var(--compact-top-left-slot-offset) - 80px);
  }
}

@media (orientation: landscape) and (min-width: 1180px) {
  .win-overlay,
  #game:has(#bottom-tools.full) .win-overlay {
    left: 50%;
  }
}

@media (orientation: landscape) and (min-width: 768px) and (min-height: 500px) {
  .win-overlay {
    top: calc(env(safe-area-inset-top, 0px) + 20px);
  }
}

.win-dialog::after {
  content: "";
  position: absolute;
  inset: -40% -60%;
  border-radius: inherit;
  clip-path: inset(0 round 23px);
  background: linear-gradient(
          115deg,
          transparent 35%,
          rgba(255,255,255,.22) 45%,
          rgba(255,255,255,.06) 55%,
          transparent 65%
  );
  transform: translateX(-35%) translateY(0);
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}
.win-title-wrap {
  position: relative;
  display: inline-block;
  z-index: 1;
}
.win-title {
  position: relative;
  overflow: visible;
  font-family: var(--basic-font);
  font-weight: 900;
  font-size: calc(clamp(13px, 5vw, 18px) * var(--win-title-scale));
  line-height: 1;
  letter-spacing: .08em;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  background: linear-gradient(180deg, #F9F104 0%, #FEDD09 52%, #FF8401 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
}
.win-title::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow:
          0 -1px 0 rgba(255, 139, 7, 1),
          0 1px 0 rgba(252, 249, 21, 1),
          0 2px 2px rgba(28, 35, 67, 0.80),
          0 0 20px rgba(24, 26, 61, 0.85);
}
.win-text {
  position: relative;
  overflow: visible;
  font-family: var(--basic-font);
  font-weight: 700;
  font-size: calc(clamp(9px, 3.6vw, 13px) * var(--win-title-scale));
  line-height: 1;
  letter-spacing: .05em;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  background: linear-gradient(89deg,
      #21f904 0%,
      #09fe75 25%,
      #03c9c2 50%,
      #09fe75 75%,
      #21f904 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
  animation: gradientMove 2.5s linear infinite;
}
@keyframes gradientMove {
  0% {
    background-position: 0 center;
  }
  100% {
    background-position: 200% center;
  }
}
.win-divider {
  width: 100%;
  height: 2px;
  flex: 0 0 auto;
  align-self: stretch;
  background: linear-gradient(
          90deg,
          rgba(255, 255, 255, 0.01) 4.31%,
          rgba(255, 255, 255, 0.16) 49.04%,
          rgba(255, 255, 255, 0.01) 100%
  );
}
.win-amount {
  position: relative;
  font-family: var(--basic-font);
  font-weight: 800;
  font-size: clamp(11px, 4vw, 16px);
  line-height: 1.15;
  color: #FFFFFF;
  flex: 0 0 70%;
  text-align: left;
  white-space: nowrap;
  padding: 0 2px;

}
.win-amount::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, #1C2343 0%, #4758A9 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 3px transparent;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.35));
  padding: 0 2px;
}
.win-mult {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: baseline;
  font-family: var(--basic-font);
  font-size: clamp(12px, 4vw, 16px);
  font-weight: 700;
  color: #2E3866;
  padding: 0 10px;
}
.win-mult__value {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: clamp(11px, 4vw, 15px);
  line-height: 1;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  color: #2E3866;
  animation: winMult 1s ease-in-out infinite;
}
@keyframes winMult {
  0% {
    transform: translateY(0) scale(1);
    color: #2E3866;
  }
  45% {
    transform: translateY(-2px) scale(1.18);
    color: #017a2c;
    font-weight: 900;
  }
  100% {
    transform: translateY(0) scale(1);
    color: #2E3866;
  }
}
.win-amount {
  flex: 1 1 auto;
  text-align: left;
  animation: winAmount 1s ease-in-out infinite;
}
@keyframes winAmount {
  0% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-2px) scale(1.14);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@media (orientation: portrait) {
  .win-mult {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    align-items: center;
    padding: 0;
  }

  .win-amount {
    flex: 0 0 auto;
    width: 100%;
    text-align: center;
    padding: 0;
  }

  .win-mult__value {
    width: 100%;
    justify-content: center;
    text-align: center;
  }
}

/* region SPARKLES */
.win-sparkles {
  position: absolute;
  inset: -26px;
  pointer-events: none;
  z-index: 2;
}
.win-sparkle {
  position: absolute;
  opacity: .9;
  transform-origin: 50% 50%;
  will-change: transform, opacity, filter;
  animation:
          winTwinkle 1.45s ease-out infinite,
          glowBreath 1.45s ease-in-out infinite;
}
.win-sparkle,
.win-dialog-sparkles .sparkle {
  display: block;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.win-sparkle > svg,
.win-dialog-sparkles .sparkle > svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
@supports (-webkit-touch-callout: none) {
  .win-sparkle,
  .win-dialog-sparkles .sparkle {
    filter: none;
    animation: winTwinkleIos 1.45s ease-out infinite;
  }
}
@keyframes winTwinkleIos {
  0% {
    transform: translateZ(0) scale(.82);
    opacity: 0;
  }
  18% {
    transform: translateZ(0) scale(1);
    opacity: 1;
  }
  55% {
    transform: translateZ(0) scale(.98);
    opacity: .95;
  }
  100% {
    transform: translateZ(0) scale(1.06);
    opacity: 0;
  }
}
.win-sparkle.s1 {
  left: 8%;
  top: 54%;
  width: 14px;
  height: 14px;
  animation-delay: .00s;
  animation-duration: 1.35s, 1.35s;
}
.win-sparkle.s2 {
  left: 40%;
  bottom: 22%;
  width: 14px;
  height: 14px;
  animation-delay: .22s, .22s;
  animation-duration: 1.55s, 1.55s;
}
.win-sparkle.s3 {
  right: 10%;
  top: 26%;
  width: 14px;
  height: 14px;
  animation-delay: .10s, .10s;
  animation-duration: 1.45s, 1.45s;
}
.win-sparkle.s4 {
  right: 3%;
  bottom: 24%;
  width: 26px;
  height: 26px;
  animation-delay: .38s, .38s;
  animation-duration: 1.60s, 1.60s;
}
.win-sparkle.s5 {
  left: 33%;
  top: 16%;
  width: 18px;
  height: 18px;
  animation-delay: .16s, .16s;
  animation-duration: 1.50s, 1.50s;
}
.win-sparkle.s6 {
  right: 1%;
  bottom: 44%;
  width: 14px;
  height: 14px;
  animation-delay: .52s, .52s;
  animation-duration: 1.70s, 1.70s;
}
.win-sparkle.s7 {
  left: -5%;
  bottom: 35%;
  width: 35px;
  height: 35px;
  animation-delay: .30s, .30s;
  animation-duration: 1.58s, 1.58s;
}
.win-dialog-sparkles {
  position: absolute;
  inset: -48px -48px;
  pointer-events: none;
  z-index: 3;
}
.win-dialog-sparkles .sparkle {
  position: absolute;
  opacity: .9;
  width: 14px;
  height: 14px;
  transform-origin: 50% 50%;
  animation: winTwinkle 1.45s ease-out infinite;
}
.win-dialog-sparkles .p1 {
  left: 5%;
  bottom: 20%;
  width: 28px;
  height: 28px;
  animation-delay: .10s;
}
.win-dialog-sparkles .p2 {
  left: 11%;
  bottom: 35%;
  width: 18px;
  height: 18px;
  animation-delay: .70s;
}
.win-dialog-sparkles .p3 {
  left: 15%;
  bottom: 14%;
  width: 22px;
  height: 22px;
  animation-delay: .55s;
}
.win-dialog-sparkles .p4 {
  right: 12%;
  top: 35%;
  width: 18px;
  height: 18px;
  animation-delay: .25s;
}
.win-dialog-sparkles .p5 {
  right: 9%;
  top: 22%;
  width: 22px;
  height: 22px;
  animation-delay: .70s;
}
.win-dialog-sparkles .p6 {
  right: 18%;
  top: 22%;
  width: 14px;
  height: 14px;
  animation-delay: .48s;
}
@keyframes winTwinkle {
  0% {
    transform: scale(.55);
    opacity: 0;
  }
  18% {
    transform: scale(1.05);
    opacity: 1;
  }
  55% {
    transform: scale(.95);
    opacity: .95;
  }
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}
@keyframes glowBreath {
  0%, 100% {
    filter: drop-shadow(0 0 0 rgba(255,255,255,0));
  }
  50% {
    filter: drop-shadow(0 0 6px rgba(255,255,255,.65));
  }
}
/* endregion */
.win-overlay:not(.hidden):not(.is-hiding) .win-dialog {
  animation:
          winPopupIn .28s cubic-bezier(.22, .61, .36, 1) forwards,
          winDialogPulse .72s ease-in-out .32s infinite,
          winGlow .72s ease-in-out .32s infinite;
}
.win-overlay.is-hiding .win-dialog {
  animation: winPopupOut .22s cubic-bezier(.55, .06, .68, .19) forwards;
}

@keyframes winPopupIn {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(.96);
    filter: blur(2px);
  }

  72% {
    opacity: 1;
    transform: translateY(0) scale(1.02);
    filter: blur(0);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}
@keyframes winPopupOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }

  100% {
    opacity: 0;
    transform: translateY(-14px) scale(.99);
    filter: blur(0);
  }
}
@keyframes winDialogPulse {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-1px) scale(1.02);
  }
}
@keyframes winGlow {
  0%, 100% {
    box-shadow:
            0 1.362px 0 rgba(255,255,255,.55) inset,
            0 0 9.73px rgba(255,255,255,.60) inset,
            0 6px 18px rgba(9,33,63,.95);
  }
  50% {
    box-shadow:
            0 1.362px 0 rgba(255,255,255,.70) inset,
            0 0 14px rgba(255,255,255,.75) inset,
            0 3.892px 9.73px rgba(9,33,63,.90);
  }
}
