ServerEvents.tick(event => {
  const server = event.server

  // Only run once per world
  if (server.persistentData.firstNightMessageSent) return

  const overworld = server.getLevel("minecraft:overworld")
  if (!overworld) return

  // Minecraft time-of-day (0–23999)
  const dayTime = overworld.getDayTime() % 24000

  // Night starts at ~13000
  if (dayTime >= 13000) {
    server.persistentData.firstNightMessageSent = true

    server.players.forEach(player => {
      player.sendImmersiveMessage({
        text: "The forest is restless awakened…",
        color: "#8b0000",
        fadeIn: 40,
        stay: 120,
        fadeOut: 60,
        textShake: true,
        sound: "minecraft:entity.warden.heartbeat",
        position: "center"
      })
    })
  }
})