.window-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #3a3a3a;
  border: 3px solid #2a2520;
  border-top: 0;
  box-shadow:
    inset 0 0 20px rgba(0, 0, 0, 0.8),
    0 10px 40px rgba(0, 0, 0, 0.9);
  overflow: hidden;

  &::before {
    content: "";
    position: absolute;
    inset: -20px;
    border: 5px solid #1a1510;
    border-top: 0;
    pointer-events: none;
    z-index: 10;
  }
}

.cityscape {
  width: 100%;
  height: 100%;
  position: relative;
  background: linear-gradient(
    180deg,
    #1a2332 0%,
    #2a3a52 30%,
    #4a5a72 60%,
    #6a7a92
  );
  overflow: hidden;
}

.starfield {
  position: absolute;
  inset: 0;
  height: 100%;
  background: linear-gradient(180deg, #0a0f1a 0%, #1a2a3a 50%, #2a3a52);
}

.building-windows {
  width: 100%;
  display: grid;
  gap: 10%;
  padding: 5%;

  > .window-light {
    width: 100%;
    aspect-ratio: 1;
  }
}

@mixin buildings($opacity, $bg-start, $bg-end) {
  position: absolute;
  inset: 0 0 0 0;
  display: flex;
  align-items: flex-end;

  > .building {
    background: linear-gradient(180deg, $bg-start, $bg-end);
    box-shadow:
      inset -2px 0 5px rgba(0, 0, 0, 0.1),
      0 0 10px rgba(42, 38, 31, 0.1);

    > .building-windows {
      height: 50%;
      opacity: $opacity;
    }
  }
}

.buildings-far {
  @include buildings(0.3, #272629, #2a3a52);

  @for $i from 1 through 20 {
    > .building:nth-child(#{$i}) {
      width: if(random(2) ==1, (random(10) + 5) * 1%, random(15) + 20px);
      height: (random(60) + 30) * 1%;
      @if random(4) ==1 {
        opacity: 0;
      }

      > .building-windows {
        grid-template-columns: repeat(#{random(3) + 3}, 1fr);
        > .window-light {
          aspect-ratio: #{0.5 + random(150) / 100};
        }
      }
    }
  }
}

.buildings-mid {
  @include buildings(0.7, #201e22, #2a3a52);

  @for $i from 1 through 20 {
    > .building:nth-child(#{$i}) {
      width: if(random(2) ==1, (random(10) + 10) * 1%, random(15) + 25px);
      height: (random(20) + 30) * 1%;
      @if random(4) ==1 {
        opacity: 0;
      }

      > .building-windows {
        grid-template-columns: repeat(#{random(3) + 3}, 1fr);
        > .window-light {
          aspect-ratio: #{0.5 + random(150) / 100};
        }
      }
    }
  }
}

.buildings-near {
  @include buildings(0.8, #121113, #182230);

  @for $i from 1 through 20 {
    > .building:nth-child(#{$i}) {
      width: if(random(2) ==1, random(3) * 7 * 1%, random(10) + 65px);
      height: random(3) * 10 * 1%;
      @if random(4) ==1 {
        opacity: 0;
      }

      > .building-windows {
        grid-template-columns: repeat(#{random(2) + 3}, 1fr);
        > .window-light {
          aspect-ratio: #{0.5 + random(150) / 100};
        }
      }
    }
  }
}

.buildings {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;

  > .building {
    animation: buildingGlow 4s ease-in-out infinite;
  }
}

.building {
  position: relative;
  background: linear-gradient(180deg, #1a1a2e, #0a0a1e);
  box-shadow:
    inset -2px 0 10px rgba(0, 0, 0, 0.5),
    0 0 20px rgba(255, 200, 100, 0.1);
}

.window-light {
  --hue: 45;
  --sat: 85%;
  --light: 65%;
  background: hsl(var(--hue), var(--sat), var(--light));
  box-shadow: 0 0 10px hsl(var(--hue), var(--sat), var(--light));
  animation: windowFlicker 5s ease-in-out infinite;

  &[data-off] {
    background: transparent;
    box-shadow: none;
  }

  &:nth-child(odd) {
    animation-delay: 0.5s;
  }
  &:nth-child(3n) {
    animation-delay: 3s;
  }
  &:nth-child(4n) {
    animation-delay: 5.5s;
  }
}

@keyframes windowFlicker {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.9;
  }
}

@keyframes buildingGlow {
  0%,
  100% {
    box-shadow:
      inset -2px 0 10px rgba(0, 0, 0, 0.5),
      0 0 20px rgba(255, 200, 100, 0.1);
  }
  50% {
    box-shadow:
      inset -2px 0 10px rgba(0, 0, 0, 0.5),
      0 0 30px rgba(255, 200, 100, 0.2);
  }
}

.window-grime {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      circle at 20% 30%,
      rgba(50, 40, 30, 0.2) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 80% 60%,
      rgba(40, 35, 25, 0.15) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 50% 80%,
      rgba(45, 38, 28, 0.18) 0%,
      transparent 45%
    );
  pointer-events: none;
  z-index: 6;
}

.glass-reflection {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1) 0%,
    transparent 30%,
    transparent 70%,
    rgba(255, 255, 255, 0.05)
  );
  pointer-events: none;
  z-index: 7;
}

.ambient-light {
  position: absolute;
  bottom: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 200%;
  height: 200px;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 200, 100, 0.2) 0%,
    transparent 70%
  );
  filter: blur(40px);
  animation: ambientPulse 3s ease-in-out infinite;
}

@keyframes ambientPulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.8;
  }
}
